You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2 KiB

--- a/base/build_time.cc
+++ b/base/build_time.cc
@@ -4,20 +4,31 @@
#include "base/build_time.h"
-// Imports the generated build date, i.e. BUILD_DATE.
-#include "base/generated_build_date.h"
-
#include "base/logging.h"
#include "base/time/time.h"
+#ifdef __ANDROID__
+#include <cutils/properties.h>
+#endif
+
namespace base {
Time GetBuildTime() {
Time integral_build_time;
- // BUILD_DATE is exactly "Mmm DD YYYY HH:MM:SS".
- // See //build/write_build_date_header.py. "HH:MM:SS" is normally expected to
- // be "05:00:00" but is not enforced here.
- bool result = Time::FromUTCString(BUILD_DATE, &integral_build_time);
+ // The format of __DATE__ and __TIME__ is specified by the ANSI C Standard,
+ // section 6.8.8.
+ //
+ // __DATE__ is exactly "Mmm DD YYYY".
+ // __TIME__ is exactly "hh:mm:ss".
+#if defined(__ANDROID__)
+ char kDateTime[PROPERTY_VALUE_MAX];
+ property_get("ro.build.date", kDateTime, "Sep 02 2008 08:00:00 PST");
+#elif defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD)
+ const char kDateTime[] = "Sep 02 2008 08:00:00 PST";
+#else
+ const char kDateTime[] = __DATE__ " " __TIME__ " PST";
+#endif
+ bool result = Time::FromString(kDateTime, &integral_build_time);
DCHECK(result);
return integral_build_time;
}
--- a/base/build_time_unittest.cc
+++ b/base/build_time_unittest.cc
@@ -3,13 +3,19 @@
// found in the LICENSE file.
#include "base/build_time.h"
+#if !defined(DONT_EMBED_BUILD_METADATA)
#include "base/generated_build_date.h"
+#endif
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(BuildTime, DateLooksValid) {
+#if !defined(DONT_EMBED_BUILD_METADATA)
char build_date[] = BUILD_DATE;
+#else
+ char build_date[] = "Sep 02 2008 05:00:00";
+#endif
EXPECT_EQ(20u, strlen(build_date));
EXPECT_EQ(' ', build_date[3]);
@@ -30,8 +36,10 @@ TEST(BuildTime, InThePast) {
EXPECT_LT(base::GetBuildTime(), base::Time::NowFromSystemTime());
}
+#if !defined(DONT_EMBED_BUILD_METADATA)
TEST(BuildTime, NotTooFar) {
// BuildTime must be less than 45 days old.
base::Time cutoff(base::Time::Now() - base::TimeDelta::FromDays(45));
EXPECT_GT(base::GetBuildTime(), cutoff);
}
+#endif