From 56c36b3bb1e6b1baae71e4de129b3b82b38c2f87 Mon Sep 17 00:00:00 2001 From: Alex Buynytskyy Date: Thu, 19 Jan 2023 17:42:10 +0000 Subject: [PATCH] Add local mode to the script. Local mainline SDK artifacts can be built via TARGET_BUILD_VARIANT=userdebug UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true vendor/google/build/mainline_modules_sdks.sh Bug: 260755259 Test: run locally Change-Id: I0eb13441201d62db1686f2930957e33b4aa4ce37 --- tools/finalize_sdk.py | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/tools/finalize_sdk.py b/tools/finalize_sdk.py index 87a2b16..9599ebc 100755 --- a/tools/finalize_sdk.py +++ b/tools/finalize_sdk.py @@ -22,8 +22,10 @@ COMPAT_README = Path('extensions/README.md') BUILD_TARGET_TRAIN = 'train_build' # This build target is used when fetching from a non-train build (XXXXXXXX) BUILD_TARGET_CONTINUOUS = 'mainline_modules_sdks-userdebug' -# The glob of sdk artifacts to fetch +# The glob of sdk artifacts to fetch from remote build ARTIFACT_PATTERN = 'mainline-sdks/for-latest-build/current/{module_name}/sdk/*.zip' +# The glob of sdk artifacts to fetch from local build +ARTIFACT_LOCAL_PATTERN = 'out/dist/mainline-sdks/for-latest-build/current/{module_name}/sdk/*.zip' COMMIT_TEMPLATE = """Finalize artifacts for extension SDK %d Import from build id %s. @@ -38,20 +40,27 @@ def fail(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) sys.exit(1) -def fetch_artifacts(target, build_id, artifact_path): +def fetch_artifacts(target, build_id, module_name): 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(str(tmpdir)) - print("Running: " + ' '.join(fetch_cmd)) - try: - subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT) - except subprocess.CalledProcessError: - fail('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id)) + if args.local_mode: + artifact_path = ARTIFACT_LOCAL_PATTERN.format(module_name='*') + print('Copying %s to %s ...' % (artifact_path, tmpdir)) + for file in glob.glob(artifact_path): + shutil.copy(file, tmpdir) + else: + artifact_path = ARTIFACT_PATTERN.format(module_name=module_name) + 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(str(tmpdir)) + print("Running: " + ' '.join(fetch_cmd)) + try: + subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + fail('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id)) return tmpdir def repo_for_sdk(filename): @@ -108,12 +117,13 @@ parser.add_argument('-b', '--bug', type=int, required=True, help='The bug number parser.add_argument('-r', '--readme', required=True, help='Version history entry to add to %s' % (COMPAT_REPO / COMPAT_README)) 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('-l', '--local_mode', action="store_true", help='Local mode: use locally built artifacts and don\'t upload the result to Gerrit.') 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 = shlex.join([x for x in sys.argv if x not in ['-a', '--amend_last_commit']]) +cmdline = shlex.join([x for x in sys.argv if x not in ['-a', '--amend_last_commit', '-l', '--local_mode']]) commit_message = COMMIT_TEMPLATE % (args.finalize_sdk, args.bid, cmdline, args.bug) module_names = args.modules or ['*'] @@ -124,7 +134,7 @@ if compat_dir.is_dir(): created_dirs = defaultdict(set) for m in module_names: - tmpdir = fetch_artifacts(build_target, args.bid, ARTIFACT_PATTERN.format(module_name=m)) + tmpdir = fetch_artifacts(build_target, args.bid, m) for f in tmpdir.iterdir(): repo = repo_for_sdk(f.name) dir = dir_for_sdk(f.name, args.finalize_sdk) @@ -153,6 +163,9 @@ for m in module_names: shutil.copy(src_file, dest_file) created_dirs[COMPAT_REPO].add(dest_dir.relative_to(COMPAT_REPO)) +if args.local_mode: + sys.exit(0) + subprocess.check_output(['repo', 'start', branch_name] + list(created_dirs.keys())) print('Running git commit') for repo in created_dirs: