1 --- a/base/build_time.cc 2 +++ b/base/build_time.cc 3 @@ -4,20 +4,31 @@ 4 5 #include "base/build_time.h" 6 7 -// Imports the generated build date, i.e. BUILD_DATE. 8 -#include "base/generated_build_date.h" 9 - 10 #include "base/logging.h" 11 #include "base/time/time.h" 12 13 +#ifdef __ANDROID__ 14 +#include <cutils/properties.h> 15 +#endif 16 + 17 namespace base { 18 19 Time GetBuildTime() { 20 Time integral_build_time; 21 - // BUILD_DATE is exactly "Mmm DD YYYY HH:MM:SS". 22 - // See //build/write_build_date_header.py. "HH:MM:SS" is normally expected to 23 - // be "05:00:00" but is not enforced here. 24 - bool result = Time::FromUTCString(BUILD_DATE, &integral_build_time); 25 + // The format of __DATE__ and __TIME__ is specified by the ANSI C Standard, 26 + // section 6.8.8. 27 + // 28 + // __DATE__ is exactly "Mmm DD YYYY". 29 + // __TIME__ is exactly "hh:mm:ss". 30 +#if defined(__ANDROID__) 31 + char kDateTime[PROPERTY_VALUE_MAX]; 32 + property_get("ro.build.date", kDateTime, "Sep 02 2008 08:00:00 PST"); 33 +#elif defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) 34 + const char kDateTime[] = "Sep 02 2008 08:00:00 PST"; 35 +#else 36 + const char kDateTime[] = __DATE__ " " __TIME__ " PST"; 37 +#endif 38 + bool result = Time::FromString(kDateTime, &integral_build_time); 39 DCHECK(result); 40 return integral_build_time; 41 } 42 --- a/base/build_time_unittest.cc 43 +++ b/base/build_time_unittest.cc 44 @@ -3,13 +3,19 @@ 45 // found in the LICENSE file. 46 47 #include "base/build_time.h" 48 +#if !defined(DONT_EMBED_BUILD_METADATA) 49 #include "base/generated_build_date.h" 50 +#endif 51 #include "base/time/time.h" 52 53 #include "testing/gtest/include/gtest/gtest.h" 54 55 TEST(BuildTime, DateLooksValid) { 56 +#if !defined(DONT_EMBED_BUILD_METADATA) 57 char build_date[] = BUILD_DATE; 58 +#else 59 + char build_date[] = "Sep 02 2008 05:00:00"; 60 +#endif 61 62 EXPECT_EQ(20u, strlen(build_date)); 63 EXPECT_EQ(' ', build_date[3]); 64 @@ -30,8 +36,10 @@ TEST(BuildTime, InThePast) { 65 EXPECT_LT(base::GetBuildTime(), base::Time::NowFromSystemTime()); 66 } 67 68 +#if !defined(DONT_EMBED_BUILD_METADATA) 69 TEST(BuildTime, NotTooFar) { 70 // BuildTime must be less than 45 days old. 71 base::Time cutoff(base::Time::Now() - base::TimeDelta::FromDays(45)); 72 EXPECT_GT(base::GetBuildTime(), cutoff); 73 } 74 +#endif 75