From 55d75f13c1eaed784233690a2c5528a62bad88dc Mon Sep 17 00:00:00 2001 From: Kevin Marshall Date: Thu, 1 Aug 2019 17:43:57 +0000 Subject: [PATCH] [Fuchsia] Make local-sdk.py import locally built system images. Modifies the build to produce system image tarballs. Adds logic to unpack the tarballs and restructure their contents to mirror the layout of the image repository uploaded to CIPD. Bug: 977018 Change-Id: Ib4ccff8a514d72cd426232c6e1a548f593e38082 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1722287 Commit-Queue: Kevin Marshall Reviewed-by: Wez Cr-Commit-Position: refs/heads/master@{#683231} --- tools/fuchsia/local-sdk.py | 39 +++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/tools/fuchsia/local-sdk.py b/tools/fuchsia/local-sdk.py index a95d6b4c327377..51db83b004504b 100755 --- a/tools/fuchsia/local-sdk.py +++ b/tools/fuchsia/local-sdk.py @@ -34,7 +34,7 @@ def EnsureEmptyDir(path): def BuildForArch(arch): build_dir = 'out/release-' + arch - Run('scripts/fx', '--dir', build_dir, 'set', 'terminal.' + arch, + Run('scripts/fx', '--dir', build_dir, 'set', 'terminal.qemu-'+ arch, '--with=//topaz/packages/sdk:topaz', '--with-base=//sdk/bundles:tools', '--args=is_debug=false', '--args=build_sdk_archives=true') Run('scripts/fx', 'build', 'topaz/public/sdk:fuchsia_dart', 'sdk') @@ -59,9 +59,12 @@ def main(args): # Nuke the SDK from DEPS, put our just-built one there, and set a fake .hash # file. This means that on next gclient runhooks, we'll restore to the # real DEPS-determined SDK. - output_dir = os.path.join(REPOSITORY_ROOT, 'third_party', 'fuchsia-sdk', + sdk_output_dir = os.path.join(REPOSITORY_ROOT, 'third_party', 'fuchsia-sdk', 'sdk') - EnsureEmptyDir(output_dir) + images_output_dir = os.path.join(REPOSITORY_ROOT, 'third_party', + 'fuchsia-sdk', 'images') + EnsureEmptyDir(sdk_output_dir) + EnsureEmptyDir(images_output_dir) original_dir = os.getcwd() fuchsia_root = os.path.abspath(args[0]) @@ -74,20 +77,19 @@ def main(args): for arch in target_archs: BuildForArch(arch) + arch_output_dir = os.path.join(fuchsia_root, 'out', 'release-' + arch) sdk_tars = [ - os.path.join(fuchsia_root, 'out', 'release-' + arch, 'sdk', 'archive', - 'core.tar.gz'), - os.path.join(fuchsia_root, 'out', 'release-' + arch, 'sdk', 'archive', - 'fuchsia_dart.tar.gz'), + os.path.join(arch_output_dir, 'sdk', 'archive', 'core.tar.gz'), + os.path.join(arch_output_dir, 'sdk', 'archive', 'fuchsia_dart.tar.gz'), ] # Extract tars merging manifests - manifest_path = os.path.join(output_dir, 'meta', 'manifest.json') + manifest_path = os.path.join(sdk_output_dir, 'meta', 'manifest.json') for sdk_tar in sdk_tars: with tarfile.open(sdk_tar, mode='r:gz') as tar: for tar_file in tar: try: - tar.extract(tar_file, output_dir) + tar.extract(tar_file, sdk_output_dir) except IOError: # Ignore overwrite of read-only files. pass @@ -106,6 +108,21 @@ def main(args): manifest_parts.add(part['meta']) merged_manifest['parts'].append(part) + arch_image_dir = os.path.join(images_output_dir, arch, 'qemu') + os.mkdir(os.path.join(images_output_dir, arch)) + os.mkdir(arch_image_dir) + + # Stage the image directory using entries specified in the build image + # manifest. + images_json = json.load(open(os.path.join(arch_output_dir, 'images.json'))) + for entry in images_json: + if entry['type'] not in ['blk', 'zbi', 'kernel']: + continue + + shutil.copyfile(os.path.join(arch_output_dir, entry['path']), + os.path.join(arch_image_dir, entry['name']) + '.' + + entry['type']) + # Write merged manifest file. with open(manifest_path, 'w') as manifest_file: json.dump(merged_manifest, manifest_file, indent=2) @@ -115,14 +132,14 @@ def main(args): # tree, as we want to avoid rebuilding all of Chromium if it's only e.g. the # kernel blob has changed. https://crbug.com/793956. sysroot_hash_obj = hashlib.sha1() - for root, dirs, files in os.walk(os.path.join(output_dir, 'sysroot')): + for root, dirs, files in os.walk(os.path.join(sdk_output_dir, 'sysroot')): for f in files: path = os.path.join(root, f) sysroot_hash_obj.update(path) sysroot_hash_obj.update(open(path, 'rb').read()) sysroot_hash = sysroot_hash_obj.hexdigest() - hash_filename = os.path.join(output_dir, '.hash') + hash_filename = os.path.join(sdk_output_dir, '.hash') with open(hash_filename, 'w') as f: f.write('locally-built-sdk-' + sysroot_hash)