Remove generated_build_date.h Change-Id: I9e8cbd6ecb6047ab3232b24eb13d8c6c6ab98edf Reviewed-on: https://gn-review.googlesource.com/1220 Reviewed-by: Brett Wilson <brettw@chromium.org> Reviewed-by: Scott Graham <scottmg@chromium.org>
diff --git a/base/build_time.cc b/base/build_time.cc deleted file mode 100644 index 834b041..0000000 --- a/base/build_time.cc +++ /dev/null
@@ -1,25 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#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" - -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); - DCHECK(result); - return integral_build_time; -} - -} // namespace base
diff --git a/base/build_time.h b/base/build_time.h deleted file mode 100644 index 83c9875..0000000 --- a/base/build_time.h +++ /dev/null
@@ -1,30 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_BUILD_TIME_H_ -#define BASE_BUILD_TIME_H_ - -#include "base/base_export.h" -#include "base/time/time.h" - -namespace base { - -// GetBuildTime returns the time at which the current binary was built, -// rounded down to 5:00:00am at the start of the day in UTC. -// -// This uses a generated file, which doesn't trigger a rebuild when the time -// changes. It will, however, be updated whenever //build/util/LASTCHANGE -// changes. -// -// This value should only be considered accurate to within a day. -// It will always be in the past. -// -// Note: If the build is not official (i.e. is_official_build = false) -// this time will be set to 5:00:00am on the most recent first Sunday -// of a month. -Time BASE_EXPORT GetBuildTime(); - -} // namespace base - -#endif // BASE_BUILD_TIME_H_
diff --git a/base/build_time_unittest.cc b/base/build_time_unittest.cc deleted file mode 100644 index 3a35736..0000000 --- a/base/build_time_unittest.cc +++ /dev/null
@@ -1,37 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/build_time.h" -#include "base/generated_build_date.h" -#include "base/time/time.h" - -#include "testing/gtest/include/gtest/gtest.h" - -TEST(BuildTime, DateLooksValid) { - char build_date[] = BUILD_DATE; - - EXPECT_EQ(20u, strlen(build_date)); - EXPECT_EQ(' ', build_date[3]); - EXPECT_EQ(' ', build_date[6]); - EXPECT_EQ(' ', build_date[11]); - EXPECT_EQ('0', build_date[12]); - EXPECT_EQ('5', build_date[13]); - EXPECT_EQ(':', build_date[14]); - EXPECT_EQ('0', build_date[15]); - EXPECT_EQ('0', build_date[16]); - EXPECT_EQ(':', build_date[17]); - EXPECT_EQ('0', build_date[18]); - EXPECT_EQ('0', build_date[19]); -} - -TEST(BuildTime, InThePast) { - EXPECT_LT(base::GetBuildTime(), base::Time::Now()); - EXPECT_LT(base::GetBuildTime(), base::Time::NowFromSystemTime()); -} - -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); -}
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc index ff37880..ed4f147 100644 --- a/base/metrics/field_trial.cc +++ b/base/metrics/field_trial.cc
@@ -8,7 +8,6 @@ #include <utility> #include "base/base_switches.h" -#include "base/build_time.h" #include "base/command_line.h" #include "base/debug/activity_tracker.h" #include "base/logging.h" @@ -500,10 +499,7 @@ DCHECK(!used_without_global_); global_ = this; - Time two_years_from_build_time = GetBuildTime() + TimeDelta::FromDays(730); - Time::Exploded exploded; - two_years_from_build_time.LocalExplode(&exploded); - kNoExpirationYear = exploded.year; + CHECK(false); // TODO(scottmg): Remove FieldTrialList. } FieldTrialList::~FieldTrialList() { @@ -592,9 +588,7 @@ FieldTrial* field_trial = new FieldTrial(trial_name, total_probability, default_group_name, entropy_value); - if (GetBuildTime() > CreateTimeFromParams(year, month, day_of_month)) - field_trial->Disable(); - FieldTrialList::Register(field_trial); + CHECK(false); // TODO(scottmg): Remove FieldTrialList. return field_trial; }
diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc index 3f7cc30..41550dd 100644 --- a/base/metrics/field_trial_unittest.cc +++ b/base/metrics/field_trial_unittest.cc
@@ -7,7 +7,6 @@ #include <stddef.h> #include "base/base_switches.h" -#include "base/build_time.h" #include "base/feature_list.h" #include "base/macros.h" #include "base/memory/ptr_util.h" @@ -43,13 +42,6 @@ default_group_number); } -int OneYearBeforeBuildTime() { - Time one_year_before_build_time = GetBuildTime() - TimeDelta::FromDays(365); - Time::Exploded exploded; - one_year_before_build_time.LocalExplode(&exploded); - return exploded.year; -} - // FieldTrialList::Observer implementation for testing. class TestFieldTrialObserver : public FieldTrialList::Observer { public: @@ -273,26 +265,6 @@ EXPECT_EQ(trial->group_name(), winner_name); } -TEST_F(FieldTrialTest, DisableProbability) { - const std::string default_group_name = "Default group"; - const std::string loser = "Loser"; - const std::string name = "Trial"; - - // Create a field trail that has expired. - int default_group_number = -1; - FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial( - name, 1000000000, default_group_name, OneYearBeforeBuildTime(), 1, 1, - FieldTrial::SESSION_RANDOMIZED, - &default_group_number); - trial->AppendGroup(loser, 999999999); // 99.9999999% chance of being chosen. - - // Because trial has expired, we should always be in the default group. - EXPECT_EQ(default_group_number, trial->group()); - - // And that default_group_name should ALWAYS win. - EXPECT_EQ(default_group_name, trial->group_name()); -} - TEST_F(FieldTrialTest, ActiveGroups) { std::string no_group("No Group"); scoped_refptr<FieldTrial> trial = @@ -452,69 +424,6 @@ EXPECT_EQ("Some name/Winner/xxx/yyyy/zzz/default/", save_string); } -TEST_F(FieldTrialTest, SaveAll) { - std::string save_string; - - scoped_refptr<FieldTrial> trial = - CreateFieldTrial("Some name", 10, "Default some name", nullptr); - EXPECT_EQ("", trial->group_name_internal()); - FieldTrialList::AllStatesToString(&save_string, false); - EXPECT_EQ("Some name/Default some name/", save_string); - // Getting all states should have finalized the trial. - EXPECT_EQ("Default some name", trial->group_name_internal()); - save_string.clear(); - - // Create a winning group. - trial = CreateFieldTrial("trial2", 10, "Default some name", nullptr); - trial->AppendGroup("Winner", 10); - // Finalize the group selection by accessing the selected group. - trial->group(); - FieldTrialList::AllStatesToString(&save_string, false); - EXPECT_EQ("Some name/Default some name/*trial2/Winner/", save_string); - save_string.clear(); - - // Create a second trial and winning group. - scoped_refptr<FieldTrial> trial2 = - CreateFieldTrial("xxx", 10, "Default xxx", nullptr); - trial2->AppendGroup("yyyy", 10); - // Finalize the group selection by accessing the selected group. - trial2->group(); - - FieldTrialList::AllStatesToString(&save_string, false); - // We assume names are alphabetized... though this is not critical. - EXPECT_EQ("Some name/Default some name/*trial2/Winner/*xxx/yyyy/", - save_string); - save_string.clear(); - - // Create a third trial with only the default group. - scoped_refptr<FieldTrial> trial3 = - CreateFieldTrial("zzz", 10, "default", nullptr); - - FieldTrialList::AllStatesToString(&save_string, false); - EXPECT_EQ("Some name/Default some name/*trial2/Winner/*xxx/yyyy/zzz/default/", - save_string); - - // Create expired study. - int default_group_number = -1; - scoped_refptr<FieldTrial> expired_trial = - FieldTrialList::FactoryGetFieldTrial( - "Expired trial name", 1000000000, "Default group", - OneYearBeforeBuildTime(), 1, 1, FieldTrial::SESSION_RANDOMIZED, - &default_group_number); - expired_trial->AppendGroup("Expired trial group name", 999999999); - - save_string.clear(); - FieldTrialList::AllStatesToString(&save_string, false); - EXPECT_EQ("Some name/Default some name/*trial2/Winner/*xxx/yyyy/zzz/default/", - save_string); - save_string.clear(); - FieldTrialList::AllStatesToString(&save_string, true); - EXPECT_EQ( - "Expired trial name/Default group/" - "Some name/Default some name/*trial2/Winner/*xxx/yyyy/zzz/default/", - save_string); -} - TEST_F(FieldTrialTest, Restore) { ASSERT_FALSE(FieldTrialList::TrialExists("Some_name")); ASSERT_FALSE(FieldTrialList::TrialExists("xxx"));
diff --git a/build/write_build_date_header.py b/build/write_build_date_header.py deleted file mode 100755 index 6fe514f..0000000 --- a/build/write_build_date_header.py +++ /dev/null
@@ -1,118 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2016 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. -"""Writes a file that contains a define that approximates the build date. - -build_type impacts the timestamp generated: -- default: the build date is set to the most recent first Sunday of a month at - 5:00am. The reason is that it is a time where invalidating the build cache - shouldn't have major reprecussions (due to lower load). -- official: the build date is set to the current date at 5:00am, or the day - before if the current time is before 5:00am. -Either way, it is guaranteed to be in the past and always in UTC. - -It is also possible to explicitly set a build date to be used. -""" - -import argparse -import calendar -import datetime -import doctest -import os -import sys - - -def GetFirstSundayOfMonth(year, month): - """Returns the first sunday of the given month of the given year. - - >>> GetFirstSundayOfMonth(2016, 2) - 7 - >>> GetFirstSundayOfMonth(2016, 3) - 6 - >>> GetFirstSundayOfMonth(2000, 1) - 2 - """ - weeks = calendar.Calendar().monthdays2calendar(year, month) - # Return the first day in the first week that is a Sunday. - return [date_day[0] for date_day in weeks[0] if date_day[1] == 6][0] - - -def GetBuildDate(build_type, utc_now): - """Gets the approximate build date given the specific build type. - - >>> GetBuildDate('default', datetime.datetime(2016, 2, 6, 1, 2, 3)) - 'Jan 03 2016 01:02:03' - >>> GetBuildDate('default', datetime.datetime(2016, 2, 7, 5)) - 'Feb 07 2016 05:00:00' - >>> GetBuildDate('default', datetime.datetime(2016, 2, 8, 5)) - 'Feb 07 2016 05:00:00' - """ - day = utc_now.day - month = utc_now.month - year = utc_now.year - if build_type != 'official': - first_sunday = GetFirstSundayOfMonth(year, month) - # If our build is after the first Sunday, we've already refreshed our build - # cache on a quiet day, so just use that day. - # Otherwise, take the first Sunday of the previous month. - if day >= first_sunday: - day = first_sunday - else: - month -= 1 - if month == 0: - month = 12 - year -= 1 - day = GetFirstSundayOfMonth(year, month) - now = datetime.datetime( - year, month, day, utc_now.hour, utc_now.minute, utc_now.second) - return '{:%b %d %Y %H:%M:%S}'.format(now) - - -def main(): - if doctest.testmod()[0]: - return 1 - argument_parser = argparse.ArgumentParser( - description=sys.modules[__name__].__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - argument_parser.add_argument('output_file', help='The file to write to') - argument_parser.add_argument( - 'build_type', help='The type of build', choices=('official', 'default')) - argument_parser.add_argument( - 'build_date_override', nargs='?', - help='Optional override for the build date. Format must be ' - '\'Mmm DD YYYY HH:MM:SS\'') - args = argument_parser.parse_args() - - if args.build_date_override: - # Format is expected to be "Mmm DD YYYY HH:MM:SS". - build_date = args.build_date_override - else: - now = datetime.datetime.utcnow() - if now.hour < 5: - # The time is locked at 5:00 am in UTC to cause the build cache - # invalidation to not happen exactly at midnight. Use the same calculation - # as the day before. - # See //base/build_time.cc. - now = now - datetime.timedelta(days=1) - now = datetime.datetime(now.year, now.month, now.day, 5, 0, 0) - build_date = GetBuildDate(args.build_type, now) - - output = ('// Generated by //build/write_build_date_header.py\n' - '#ifndef BUILD_DATE\n' - '#define BUILD_DATE "{}"\n' - '#endif // BUILD_DATE\n'.format(build_date)) - - current_contents = '' - if os.path.isfile(args.output_file): - with open(args.output_file, 'r') as current_file: - current_contents = current_file.read() - - if current_contents != output: - with open(args.output_file, 'w') as output_file: - output_file.write(output) - return 0 - - -if __name__ == '__main__': - sys.exit(main())
diff --git a/tools/gn/bootstrap/bootstrap.py b/tools/gn/bootstrap/bootstrap.py index f2caac7..00bfa56 100755 --- a/tools/gn/bootstrap/bootstrap.py +++ b/tools/gn/bootstrap/bootstrap.py
@@ -192,31 +192,10 @@ os.path.join(SRC_ROOT, source), ]) -def write_build_date_header(root_gen_dir): - check_call([ - sys.executable, - os.path.join(SRC_ROOT, 'build', 'write_build_date_header.py'), - os.path.join(root_gen_dir, 'base/generated_build_date.h'), - 'default', - ]) - def build_gn_with_ninja_manually(tempdir, options, windows_x64_toolchain): root_gen_dir = os.path.join(tempdir, 'gen') mkdir_p(root_gen_dir) - write_build_date_header(root_gen_dir) - - if is_mac: - # //base/build_time.cc needs base/generated_build_date.h, - # and this file is only included for Mac builds. - mkdir_p(os.path.join(root_gen_dir, 'base')) - check_call([ - sys.executable, - os.path.join(SRC_ROOT, 'build', 'write_build_date_header.py'), - os.path.join(root_gen_dir, 'base', 'generated_build_date.h'), - 'default' - ]) - if is_win: write_compiled_message(root_gen_dir, 'base/trace_event/etw_manifest/chrome_events_win.man') @@ -435,7 +414,6 @@ 'base/at_exit.cc', 'base/base_paths.cc', 'base/base_switches.cc', - 'base/build_time.cc', 'base/callback_helpers.cc', 'base/callback_internal.cc', 'base/command_line.cc',