Skip to content

Commit cc3110c

Browse files
authored
feat: Tag Fuchsia artifacts by content hash (flutter#172132)
After the fuchsia build process, be sure to tag uploaded artifacts with `content_aware_hash:` if configured. fixes flutter#171985 This was a bit of a rabbit hole, with some "magic parameters" that control uploading / tagging. I'm not sure cipd supports two tags with the say keys; but I wouldn't want the content hash having the key "git_revision". Pre-submits: Not affected since --engine-version is always '' which is read as "do not upload" Post-submits: Reads the `linux_fuchsia.json` builder to look for flags. > Note: This needs to land before the tool can be updated to download the content_aware_hash tag. Tested: locally, on linux, after building all the x64 targets. With and without engine-version, with and without linux_fuchsia.json flags. ```shell $ src/flutter/tools/fuchsia/merge_and_upload_debug_symbols.py --target-arch x64 --engine 'abcd' --upload --out-dir tmp --symbol-dirs out/ci/fuchsia_debug_x64/.build-id out/ci/fuchsia_release_x64/.build-id out/ci/fuchsia_profile_x64/.build-id Using content hash 2201006225127f112f6576fcf73dd00671b2012e for engine version ['cipd', 'create', '-pkg-def', '/usr/local/google/home/codefu/src/flutter/engine/tmp/debug_symbols.cipd.yaml', '-ref', 'latest', '-tag', 'git_revision:abcd', '-verification-timeout', '10m0s', '-tag', 'content_aware_hash:2201006225127f112f6576fcf73dd00671b2012e'] ``` ``` $ python3 src/flutter/tools/fuchsia/build_fuchsia_artifacts.py --archs x64 --engine 'abc' --cipd-dry-run --upload Using content hash 2201006225127f112f6576fcf73dd00671b2012e for engine version codefu: ['cipd', 'create', '-pkg-def', 'fuchsia.cipd.yaml', '-ref', 'latest', '-tag', 'git_revision:abc', '-tag', 'content_aware_hash:2201006225127f112f6576fcf73dd00671b2012e'] ```
1 parent 6e1ebc7 commit cc3110c

File tree

3 files changed

+88
-16
lines changed

3 files changed

+88
-16
lines changed

engine/src/flutter/tools/fuchsia/build_fuchsia_artifacts.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import subprocess
1717
import sys
1818
import tempfile
19+
from get_content_hash import get_content_hash
1920

2021
_script_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), '..'))
2122
_src_root_dir = os.path.join(_script_dir, '..', '..', '..')
@@ -240,7 +241,7 @@ def RunCIPDCommandWithRetries(command):
240241
raise
241242

242243

243-
def ProcessCIPDPackage(upload, engine_version):
244+
def ProcessCIPDPackage(upload, engine_version, content_hash):
244245
if not upload or not IsLinux():
245246
RunCIPDCommandWithRetries([
246247
'cipd', 'pkg-build', '-pkg-def', 'fuchsia.cipd.yaml', '-out',
@@ -256,22 +257,32 @@ def ProcessCIPDPackage(upload, engine_version):
256257
print('--upload requires --engine-version to be specified.')
257258
return
258259

259-
tag = 'git_revision:%s' % engine_version
260-
already_exists = CheckCIPDPackageExists('flutter/fuchsia', tag)
260+
git_tag = 'git_revision:%s' % engine_version
261+
already_exists = CheckCIPDPackageExists('flutter/fuchsia', git_tag)
261262
if already_exists:
262-
print('CIPD package flutter/fuchsia tag %s already exists!' % tag)
263+
print('CIPD package flutter/fuchsia tag %s already exists!' % git_tag)
263264
return
264265

265-
RunCIPDCommandWithRetries([
266+
command = [
266267
'cipd',
267268
'create',
268269
'-pkg-def',
269270
'fuchsia.cipd.yaml',
270271
'-ref',
271272
'latest',
272273
'-tag',
273-
tag,
274-
])
274+
git_tag,
275+
]
276+
277+
content_tag = 'content_aware_hash:%s' % content_hash
278+
already_exists = CheckCIPDPackageExists('flutter/fuchsia', content_tag)
279+
if already_exists:
280+
print('CIPD package flutter/fuchsia tag %s already exists!' % content_tag)
281+
# do not return; content hash can match multiple PRs (reverts, framework only)
282+
else:
283+
command.extend(['-tag', content_tag])
284+
285+
RunCIPDCommandWithRetries(command)
275286

276287

277288
def main():
@@ -400,13 +411,18 @@ def main():
400411
# presubmit workflows.
401412
should_upload = args.upload
402413
engine_version = args.engine_version
403-
if not engine_version:
414+
content_hash = ''
415+
if engine_version:
416+
# When content hashing is enabled, the engine version will be a content
417+
# hash instead of a git revision.
418+
content_hash = get_content_hash()
419+
else:
404420
engine_version = 'HEAD'
405421
should_upload = False
406422

407423
# Create and optionally upload CIPD package
408424
if args.cipd_dry_run or args.upload:
409-
ProcessCIPDPackage(should_upload, engine_version)
425+
ProcessCIPDPackage(should_upload, engine_version, content_hash)
410426

411427
return 0
412428

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2013 The Flutter Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
""" Shared code for handling content_aware_hashing for fuchsia.
8+
"""
9+
import json
10+
import os
11+
import subprocess
12+
13+
_script_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), '..'))
14+
_src_root_dir = os.path.join(_script_dir, '..', '..', '..')
15+
16+
17+
def get_content_hash():
18+
ci_config_path = os.path.join(_src_root_dir, 'flutter', 'ci', 'builders', 'linux_fuchsia.json')
19+
upload_content_hash = False
20+
if os.path.exists(ci_config_path):
21+
with open(ci_config_path, 'r') as f:
22+
ci_config = json.load(f)
23+
upload_content_hash = ci_config.get('luci_flags', {}).get('upload_content_hash', False)
24+
if upload_content_hash:
25+
script_path = os.path.join(
26+
_src_root_dir, '..', '..', 'bin', 'internal', 'content_aware_hash.sh'
27+
)
28+
if os.path.exists(script_path):
29+
command = [script_path]
30+
try:
31+
content_hash = subprocess.check_output(command, text=True).strip()
32+
print('Using content hash %s for engine version' % content_hash)
33+
return content_hash
34+
except subprocess.CalledProcessError as e:
35+
print('Error getting content hash, falling back to git hash: %s' % e)
36+
else:
37+
print('Could not find content_aware_hash.sh at %s' % script_path)
38+
return ''

engine/src/flutter/tools/fuchsia/merge_and_upload_debug_symbols.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import sys
1919
import tarfile
2020
import tempfile
21+
from get_content_hash import get_content_hash
2122

2223
# Path to the engine root checkout. This is used to calculate absolute
2324
# paths if relative ones are passed to the script.
@@ -77,13 +78,23 @@ def CheckCIPDPackageExists(package_name, tag):
7778
return True
7879

7980

80-
def ProcessCIPDPackage(upload, cipd_yaml, engine_version, out_dir, target_arch):
81+
def ProcessCIPDPackage(upload, cipd_yaml, engine_version, content_hash, out_dir, target_arch):
8182
_packaging_dir = GetPackagingDir(out_dir)
82-
tag = 'git_revision:%s' % engine_version
8383
package_name = 'flutter/fuchsia-debug-symbols-%s' % target_arch
84-
already_exists = CheckCIPDPackageExists(package_name, tag)
84+
85+
git_tag = 'git_revision:%s' % engine_version
86+
already_exists = CheckCIPDPackageExists(package_name, git_tag)
8587
if already_exists:
86-
print('CIPD package %s tag %s already exists!' % (package_name, tag))
88+
print('CIPD package %s tag %s already exists!' % (package_name, git_tag))
89+
90+
content_tag = ''
91+
if content_hash:
92+
content_tag = 'content_aware_hash:%s' % content_hash
93+
content_already_exists = CheckCIPDPackageExists(package_name, content_tag)
94+
if content_already_exists:
95+
print('CIPD package %s tag %s already exists!' % (package_name, content_tag))
96+
content_tag = ''
97+
# do not return; content hash can match multiple PRs (reverts, framework only)
8798

8899
if upload and IsLinux() and not already_exists:
89100
command = [
@@ -94,10 +105,12 @@ def ProcessCIPDPackage(upload, cipd_yaml, engine_version, out_dir, target_arch):
94105
'-ref',
95106
'latest',
96107
'-tag',
97-
tag,
108+
git_tag,
98109
'-verification-timeout',
99110
'10m0s',
100111
]
112+
if content_tag:
113+
command.extend(['-tag', content_tag])
101114
else:
102115
command = [
103116
'cipd', 'pkg-build', '-pkg-def', cipd_yaml, '-out',
@@ -210,11 +223,16 @@ def main():
210223
# on presubmit.
211224
should_upload = args.upload
212225
engine_version = args.engine_version
213-
if not engine_version:
226+
content_hash = ''
227+
if engine_version:
228+
# When content hashing is enabled, the engine version will be a content
229+
# hash instead of a git revision.
230+
content_hash = get_content_hash()
231+
else:
214232
engine_version = 'HEAD'
215233
should_upload = False
216234

217-
ProcessCIPDPackage(should_upload, cipd_def, engine_version, out_dir, arch)
235+
ProcessCIPDPackage(should_upload, cipd_def, engine_version, content_hash, out_dir, arch)
218236
return 0
219237

220238

0 commit comments

Comments
 (0)