Skip to content

Commit

Permalink
[Fuchsia] Make local-sdk.py import locally built system images.
Browse files Browse the repository at this point in the history
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 <kmarshall@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683231}
  • Loading branch information
Kevin Marshall authored and Commit Bot committed Aug 1, 2019
1 parent eaf1f61 commit 55d75f1
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions tools/fuchsia/local-sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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])
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 55d75f1

Please sign in to comment.