From 12b45d719a3f29e636f6a6ad85841839828f7073 Mon Sep 17 00:00:00 2001 From: Aravind Vasudevan Date: Thu, 1 Jun 2023 22:37:21 +0000 Subject: [PATCH] Reland "Add git_cache epoch to bot_update output.properties" This reverts commit ede859f9eeafd245239c37dcf2b1b20b8f792cb4. Reason for revert: This change includes a fix for the missing path issue. if the `cache_path` doesn't exist, it runs os.mkdirs before setting the cache epoch marker. Original change's description: > Revert "Add git_cache epoch to bot_update output.properties" > > This reverts commit 867d3267c1bc63a0bab67e2ecbdde843434e6d90. > > Reason for revert: breaks some builders, https://crbug.com/1448769#c5 > > Original change's description: > > Add git_cache epoch to bot_update output.properties > > > > This change adds git cache's epoch timestamp to bot_update's output.properties. It achieves this by adding a marker file to the cache directory which stores the epoch time. > > > > Design: go/query-bot-update-cache-age > > > > Bug: 1448769 > > Change-Id: I610c6bca5ced7e2a0fe3ee8570decf0f135fe54c > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4563726 > > Reviewed-by: Josip Sokcevic > > Commit-Queue: Aravind Vasudevan > > Bug: 1448769 > Change-Id: I29db9ac364a9cf1d615b00ed75c1346e56b3f3b6 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4582291 > Commit-Queue: Gavin Mak > Bot-Commit: Rubber Stamper > Reviewed-by: Aravind Vasudevan Bug: 1448769 Change-Id: Ia6fd5b27f7556dd81f65011364506d3aa535de62 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4583007 Reviewed-by: Josip Sokcevic Commit-Queue: Aravind Vasudevan --- .../bot_update/resources/bot_update.py | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/recipes/recipe_modules/bot_update/resources/bot_update.py b/recipes/recipe_modules/bot_update/resources/bot_update.py index 369c023b7..4422a2a8d 100755 --- a/recipes/recipe_modules/bot_update/resources/bot_update.py +++ b/recipes/recipe_modules/bot_update/resources/bot_update.py @@ -1044,6 +1044,22 @@ def checkout(options, git_slns, specs, revisions, step_text): ver = git('version').strip() print('Using %s' % ver) + # Get the epoch of the git cache from a cache epoch marker file. If this file + # does not exist, create one with the current timestamp. + cache_epoch_marker_path = os.path.join(options.git_cache_dir, '.cache_epoch') + if os.path.isfile(cache_epoch_marker_path): + with open(cache_epoch_marker_path) as f: + cache_epoch = f.readline().strip() + else: + # This ensures the cache path exists. This is a noop if the path already + # exists. See crbug.com/1448769#c8. + os.makedirs(options.git_cache_dir, exist_ok=True) + with open(cache_epoch_marker_path, 'w') as f: + cache_epoch = int(time.time()) + print(cache_epoch, file=f) + + print('git_cache epoch: {}'.format(datetime.fromtimestamp(int(cache_epoch)))) + try: protocol = git('config', '--get', 'protocol.version') print('Using git protocol version %s' % protocol) @@ -1133,15 +1149,18 @@ def checkout(options, git_slns, specs, revisions, step_text): revision_mapping['got_revision'] = first_sln manifest = create_manifest() - got_revisions = parse_got_revision(manifest, revision_mapping) + properties = parse_got_revision(manifest, revision_mapping) - if not got_revisions: + if not properties: # TODO(hinoka): We should probably bail out here, but in the interest # of giving mis-configured bots some time to get fixed use a dummy # revision here. - got_revisions = { 'got_revision': 'BOT_UPDATE_NO_REV_FOUND' } + properties = {'got_revision': 'BOT_UPDATE_NO_REV_FOUND'} #raise Exception('No got_revision(s) found in gclient output') + # Add git cache age to the output.properties + properties['git_cache_epoch'] = cache_epoch + # Tell recipes information such as root, got_revision, etc. emit_json(options.output_json, did_run=True, @@ -1149,7 +1168,7 @@ def checkout(options, git_slns, specs, revisions, step_text): patch_root=options.patch_root, step_text=step_text, fixed_revisions=revisions, - properties=got_revisions, + properties=properties, manifest=manifest)