diff options
author | Anton Hansson <hansson@google.com> | 2022-04-07 12:50:38 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-04-07 12:50:38 +0000 |
commit | 25deb674a2b9394678eb4115fc802d70ad9a70dc (patch) | |
tree | 274b729e53c4255add711eeeaa92e2b9f91776df | |
parent | 3d89ee0bb1195ba6a596ba64381d69c6e12462d6 (diff) | |
parent | d204d7feaa540b8e5d6208c6f4241b15227a149e (diff) | |
download | common-25deb674a2b9394678eb4115fc802d70ad9a70dc.tar.gz |
Merge changes I31848ad3,Icaf4937b,Ie7b44da3,I94f7c6f0 am: f949851fc0 am: d204d7feaa
Original change: https://android-review.googlesource.com/c/platform/packages/modules/common/+/2056030
Change-Id: I3ecb21d99c045c278e815bd0cf665d5d789990de
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rwxr-xr-x | tools/finalize_sdk.py | 85 |
1 files changed, 57 insertions, 28 deletions
diff --git a/tools/finalize_sdk.py b/tools/finalize_sdk.py index c862d892..84fd762e 100755 --- a/tools/finalize_sdk.py +++ b/tools/finalize_sdk.py @@ -1,19 +1,27 @@ #!/usr/bin/python3 import argparse +import glob import os import re +import shutil import subprocess import sys import tempfile import zipfile from collections import defaultdict +from pathlib import Path # See go/fetch_artifact for details on this script. FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact' -BUILD_TARGET = 'mainline_modules-userdebug' -ARTIFACT_PATTERN = 'mainline-sdks/*-%d.zip' +COMPAT_REPO = Path('prebuilts/sdk') +# This build target is used when fetching from a train build (TXXXXXXXX) +BUILD_TARGET_TRAIN = 'train_build' +# This build target is used when fetching from a non-train build (XXXXXXXX) +BUILD_TARGET_CONTINUOUS = 'mainline_modules-user' +# The glob of sdk artifacts to fetch +ARTIFACT_PATTERN = 'mainline-sdks/current/{module_name}/sdk/*.zip' COMMIT_TEMPLATE = """Finalize artifacts for extension SDK %d Import from build id %s. @@ -29,14 +37,14 @@ def fail(*args, **kwargs): sys.exit(1) def fetch_artifacts(target, build_id, artifact_path): - tmpdir = tempfile.TemporaryDirectory().name - os.mkdir(tmpdir) + tmpdir = Path(tempfile.TemporaryDirectory().name) + tmpdir.mkdir() print('Fetching %s from %s ...' % (artifact_path, target)) fetch_cmd = [FETCH_ARTIFACT] fetch_cmd.extend(['--bid', str(build_id)]) fetch_cmd.extend(['--target', target]) fetch_cmd.append(artifact_path) - fetch_cmd.append(tmpdir) + fetch_cmd.append(str(tmpdir)) print("Running: " + ' '.join(fetch_cmd)) try: subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT) @@ -47,8 +55,8 @@ def fetch_artifacts(target, build_id, artifact_path): def repo_for_sdk(filename): module = filename.split('-')[0] target_dir = '' - if module == 'media': return 'prebuilts/module_sdk/Media' - if module == 'tethering': return 'prebuilts/module_sdk/Connectivity' + if module == 'media': return Path('prebuilts/module_sdk/Media') + if module == 'tethering': return Path('prebuilts/module_sdk/Connectivity') for dir in os.listdir('prebuilts/module_sdk/'): if module.lower() in dir.lower(): if target_dir: @@ -57,7 +65,7 @@ def repo_for_sdk(filename): if not target_dir: fail('Could not find a target dir for %s' % filename) - return 'prebuilts/module_sdk/%s' % target_dir + return Path('prebuilts/module_sdk/%s' % target_dir) def dir_for_sdk(filename, version): base = str(version) @@ -74,35 +82,56 @@ parser = argparse.ArgumentParser(description=('Finalize an extension SDK with pr parser.add_argument('-f', '--finalize_sdk', type=int, required=True, help='The numbered SDK to finalize.') parser.add_argument('-b', '--bug', type=int, required=True, help='The bug number to add to the commit message.') parser.add_argument('-a', '--amend_last_commit', action="store_true", help='Amend current HEAD commits instead of making new commits.') +parser.add_argument('-m', '--modules', action='append', help='Modules to include. Can be provided multiple times, or not at all for all modules.') parser.add_argument('bid', help='Build server build ID') args = parser.parse_args() +build_target = BUILD_TARGET_TRAIN if args.bid[0] == 'T' else BUILD_TARGET_CONTINUOUS branch_name = 'finalize-%d' % args.finalize_sdk -cmdline = " ".join(filter(lambda x: x not in ['-a', '--amend_last_commit'], sys.argv)) +cmdline = " ".join([x for x in sys.argv if x not in ['-a', '--amend_last_commit']]) commit_message = COMMIT_TEMPLATE % (args.finalize_sdk, args.bid, cmdline, args.bug) - -tmpdir = fetch_artifacts(BUILD_TARGET, args.bid, ARTIFACT_PATTERN % args.finalize_sdk) - -created_dirs = defaultdict(list) - -for f in os.listdir(tmpdir): - repo = repo_for_sdk(f) - dir = dir_for_sdk(f, args.finalize_sdk) - target_dir = os.path.join(repo, dir) - if os.path.isfile(target_dir): - print('Removing existing dir %s' % target_dir) - shutil.rmtree(target_dir) - with zipfile.ZipFile(os.path.join(tmpdir, f)) as zipFile: - zipFile.extractall(target_dir) - - print('Created %s' % target_dir) - created_dirs[repo].append(dir) +module_names = args.modules +if not module_names: + module_names = ['*'] + +compat_dir = COMPAT_REPO.joinpath('extensions/%d' % args.finalize_sdk) +if compat_dir.is_dir(): + print('Removing existing dir %s' % compat_dir) + shutil.rmtree(compat_dir) + +created_dirs = defaultdict(set) +for m in module_names: + tmpdir = fetch_artifacts(build_target, args.bid, ARTIFACT_PATTERN.format(module_name=m)) + for f in tmpdir.iterdir(): + repo = repo_for_sdk(f.name) + dir = dir_for_sdk(f.name, args.finalize_sdk) + target_dir = repo.joinpath(dir) + if target_dir.is_dir(): + print('Removing existing dir %s' % target_dir) + shutil.rmtree(target_dir) + with zipfile.ZipFile(tmpdir.joinpath(f)) as zipFile: + zipFile.extractall(target_dir) + + # Just capture the artifacts, not the bp files of finalized versions + os.remove(target_dir.joinpath('Android.bp')) + + print('Created %s' % target_dir) + created_dirs[repo].add(dir) + + # Copy api txt files to compat tracking dir + txt_files = [Path(p) for p in glob.glob(os.path.join(target_dir, 'sdk_library/*/*.txt'))] + for txt_file in txt_files: + api_type = txt_file.parts[-2] + dest_dir = compat_dir.joinpath(api_type, 'api') + os.makedirs(dest_dir, exist_ok = True) + shutil.copy(txt_file, dest_dir) + created_dirs[COMPAT_REPO].add(dest_dir.relative_to(COMPAT_REPO)) subprocess.check_output(['repo', 'start', branch_name] + list(created_dirs.keys())) print('Running git commit') for repo in created_dirs: - git = ['git', '-C', repo] - subprocess.check_output(git + ['add'] + created_dirs[repo]) + git = ['git', '-C', str(repo)] + subprocess.check_output(git + ['add'] + list(created_dirs[repo])) if args.amend_last_commit: change_id = '\n' + re.search(r'Change-Id: [^\\n]+', str(subprocess.check_output(git + ['log', '-1']))).group(0) subprocess.check_output(git + ['commit', '--amend', '-m', commit_message + change_id]) |