Merge "multi_update.py update all VNDK snapshots at once." am: 0f52d13b21
Original change: https://android-review.googlesource.com/c/platform/development/+/2318229 Change-Id: Ia5dfc44ecd4badc2ca80a7e91d7c4a4d8209b9cb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
88
vndk/snapshot/multi_update.py
Normal file
88
vndk/snapshot/multi_update.py
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2022 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import update
|
||||
import utils
|
||||
|
||||
VNDK_SNAPSHOT_SOURCE_BRANCHES = {
|
||||
29: 'qt-gsi-release',
|
||||
30: 'android11-gsi',
|
||||
31: 'android12-gsi',
|
||||
32: 'android12L-gsi',
|
||||
33: 'android13-gsi',
|
||||
}
|
||||
|
||||
def fetch_and_update_snapshots(versions, args):
|
||||
for version in versions:
|
||||
if version not in VNDK_SNAPSHOT_SOURCE_BRANCHES:
|
||||
raise ValueError ('Unknown VNDK version: {}'.format(version))
|
||||
logging.info('Updating snapshot version {}'.format(version))
|
||||
branch = VNDK_SNAPSHOT_SOURCE_BRANCHES[version]
|
||||
bid = utils.get_latest_vndk_bid(branch)
|
||||
|
||||
update.run(version, branch, bid, None, args.use_current_branch,
|
||||
args.remote, args.verbose)
|
||||
|
||||
def get_args(parser):
|
||||
parser.add_argument(
|
||||
'versions',
|
||||
metavar='vndk_version',
|
||||
type=int,
|
||||
nargs='*',
|
||||
help='list of versions to fetch and update')
|
||||
parser.add_argument(
|
||||
'--all',
|
||||
action='store_true',
|
||||
help='fetch all vndk snapshots')
|
||||
parser.add_argument(
|
||||
'--use-current-branch',
|
||||
action='store_true',
|
||||
help='Perform the update in the current branch. Do not repo start.')
|
||||
parser.add_argument(
|
||||
'--remote',
|
||||
default='aosp',
|
||||
help=('Remote name to fetch and check if the revision of VNDK snapshot '
|
||||
'is included in the source to conform GPL license. default=aosp'))
|
||||
parser.add_argument(
|
||||
'-v',
|
||||
'--verbose',
|
||||
action='count',
|
||||
default=0,
|
||||
help='Increase output verbosity, e.g. "-v", "-vv"')
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
args = get_args(parser)
|
||||
utils.set_logging_config(args.verbose)
|
||||
|
||||
if args.all:
|
||||
versions = VNDK_SNAPSHOT_SOURCE_BRANCHES.keys()
|
||||
fetch_and_update_snapshots(versions, args)
|
||||
return
|
||||
|
||||
if not args.versions:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
fetch_and_update_snapshots(args.versions, args)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -188,6 +188,97 @@ def commit(branch, build, version):
|
||||
utils.check_call(['git', 'commit', '-m', message])
|
||||
|
||||
|
||||
def run(vndk_version, branch, build_id, local, use_current_branch, remote,
|
||||
verbose):
|
||||
''' Fetch and updtate the VNDK snapshots
|
||||
|
||||
Args:
|
||||
vndk_version: int, VNDK snapshot version to install.
|
||||
branch: string, Branch to pull build from.
|
||||
build: string, Build number to pull.
|
||||
local: string, Fetch local VNDK snapshot artifacts from specified local
|
||||
directory instead of Android Build server.
|
||||
use-current-branch: boolean, Perform the update in the current branch.
|
||||
Do not repo start.
|
||||
remote: string, Remote name to fetch and check if the revision of VNDK
|
||||
snapshot is included in the source to conform GPL license.
|
||||
verbose: int, Increase log output verbosity.
|
||||
'''
|
||||
local_path = None
|
||||
if local:
|
||||
local_path = os.path.abspath(os.path.expanduser(local))
|
||||
|
||||
if local_path:
|
||||
if build_id or branch:
|
||||
raise ValueError(
|
||||
'When --local option is set, --branch or --build cannot be '
|
||||
'specified.')
|
||||
elif not os.path.isdir(local_path):
|
||||
raise RuntimeError(
|
||||
'The specified local directory, {}, does not exist.'.format(
|
||||
local_path))
|
||||
else:
|
||||
if not (build_id and branch):
|
||||
raise ValueError(
|
||||
'Please provide both --branch and --build or set --local '
|
||||
'option.')
|
||||
|
||||
install_dir = os.path.join(PREBUILTS_VNDK_DIR, 'v{}'.format(vndk_version))
|
||||
if not os.path.isdir(install_dir):
|
||||
raise RuntimeError(
|
||||
'The directory for VNDK snapshot version {ver} does not exist.\n'
|
||||
'Please request a new git project for prebuilts/vndk/v{ver} '
|
||||
'before installing new snapshot.'.format(ver=vndk_version))
|
||||
|
||||
utils.set_logging_config(verbose)
|
||||
root_dir = os.getcwd()
|
||||
os.chdir(install_dir)
|
||||
|
||||
if not use_current_branch:
|
||||
start_branch(build_id)
|
||||
|
||||
remove_old_snapshot(install_dir)
|
||||
os.makedirs(utils.COMMON_DIR_PATH)
|
||||
|
||||
temp_artifact_dir = None
|
||||
if not local_path:
|
||||
temp_artifact_dir = tempfile.mkdtemp()
|
||||
|
||||
try:
|
||||
install_snapshot(branch, build_id, local_path, install_dir,
|
||||
temp_artifact_dir)
|
||||
gather_notice_files(install_dir)
|
||||
post_processe_files_if_needed(vndk_version)
|
||||
|
||||
buildfile_generator = GenBuildFile(install_dir, vndk_version)
|
||||
update_buildfiles(buildfile_generator)
|
||||
|
||||
copy_owners(root_dir, install_dir)
|
||||
|
||||
if not local_path and not branch.startswith('android'):
|
||||
license_checker = GPLChecker(install_dir, ANDROID_BUILD_TOP,
|
||||
temp_artifact_dir, remote)
|
||||
check_gpl_license(license_checker)
|
||||
logging.info(
|
||||
'Successfully updated VNDK snapshot v{}'.format(vndk_version))
|
||||
except Exception as error:
|
||||
logging.error('FAILED TO INSTALL SNAPSHOT: {}'.format(error))
|
||||
raise
|
||||
finally:
|
||||
if temp_artifact_dir:
|
||||
logging.info(
|
||||
'Deleting temp_artifact_dir: {}'.format(temp_artifact_dir))
|
||||
shutil.rmtree(temp_artifact_dir)
|
||||
|
||||
if not local_path:
|
||||
commit(branch, build_id, vndk_version)
|
||||
logging.info(
|
||||
'Successfully created commit for VNDK snapshot v{}'.format(
|
||||
vndk_version))
|
||||
|
||||
logging.info('Done.')
|
||||
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
@@ -223,82 +314,8 @@ def get_args():
|
||||
def main():
|
||||
"""Program entry point."""
|
||||
args = get_args()
|
||||
|
||||
local = None
|
||||
if args.local:
|
||||
local = os.path.abspath(os.path.expanduser(args.local))
|
||||
|
||||
if local:
|
||||
if args.build or args.branch:
|
||||
raise ValueError(
|
||||
'When --local option is set, --branch or --build cannot be '
|
||||
'specified.')
|
||||
elif not os.path.isdir(local):
|
||||
raise RuntimeError(
|
||||
'The specified local directory, {}, does not exist.'.format(
|
||||
local))
|
||||
else:
|
||||
if not (args.build and args.branch):
|
||||
raise ValueError(
|
||||
'Please provide both --branch and --build or set --local '
|
||||
'option.')
|
||||
|
||||
vndk_version = args.vndk_version
|
||||
|
||||
install_dir = os.path.join(PREBUILTS_VNDK_DIR, 'v{}'.format(vndk_version))
|
||||
if not os.path.isdir(install_dir):
|
||||
raise RuntimeError(
|
||||
'The directory for VNDK snapshot version {ver} does not exist.\n'
|
||||
'Please request a new git project for prebuilts/vndk/v{ver} '
|
||||
'before installing new snapshot.'.format(ver=vndk_version))
|
||||
|
||||
utils.set_logging_config(args.verbose)
|
||||
root_dir = os.getcwd()
|
||||
os.chdir(install_dir)
|
||||
|
||||
if not args.use_current_branch:
|
||||
start_branch(args.build)
|
||||
|
||||
remove_old_snapshot(install_dir)
|
||||
os.makedirs(utils.COMMON_DIR_PATH)
|
||||
|
||||
temp_artifact_dir = None
|
||||
if not local:
|
||||
temp_artifact_dir = tempfile.mkdtemp()
|
||||
|
||||
try:
|
||||
install_snapshot(args.branch, args.build, local, install_dir,
|
||||
temp_artifact_dir)
|
||||
gather_notice_files(install_dir)
|
||||
post_processe_files_if_needed(vndk_version)
|
||||
|
||||
buildfile_generator = GenBuildFile(install_dir, vndk_version)
|
||||
update_buildfiles(buildfile_generator)
|
||||
|
||||
copy_owners(root_dir, install_dir)
|
||||
|
||||
if not local:
|
||||
license_checker = GPLChecker(install_dir, ANDROID_BUILD_TOP,
|
||||
temp_artifact_dir, args.remote)
|
||||
check_gpl_license(license_checker)
|
||||
logging.info(
|
||||
'Successfully updated VNDK snapshot v{}'.format(vndk_version))
|
||||
except Exception as error:
|
||||
logging.error('FAILED TO INSTALL SNAPSHOT: {}'.format(error))
|
||||
raise
|
||||
finally:
|
||||
if temp_artifact_dir:
|
||||
logging.info(
|
||||
'Deleting temp_artifact_dir: {}'.format(temp_artifact_dir))
|
||||
shutil.rmtree(temp_artifact_dir)
|
||||
|
||||
if not local:
|
||||
commit(args.branch, args.build, vndk_version)
|
||||
logging.info(
|
||||
'Successfully created commit for VNDK snapshot v{}'.format(
|
||||
vndk_version))
|
||||
|
||||
logging.info('Done.')
|
||||
run(args.vndk_version, args.branch, args.build, args.local,
|
||||
args.use_current_branch, args.remote, args.verbose)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -169,3 +169,25 @@ def fetch_artifact(branch, build, pattern, destination='.'):
|
||||
build, pattern, destination
|
||||
]
|
||||
check_call(cmd)
|
||||
|
||||
|
||||
def get_latest_vndk_bid(branch):
|
||||
"""Get the build id of the latest green build of the vndk target
|
||||
from the Android Build Server.
|
||||
|
||||
Args:
|
||||
branch: string, branch to pull build artifacts from
|
||||
|
||||
Returns:
|
||||
string: bid of the latest green build
|
||||
"""
|
||||
ab_tool_path = '/google/data/ro/projects/android/ab'
|
||||
cmd = [
|
||||
ab_tool_path, 'lkgb', '--branch', branch, '--target', 'vndk'
|
||||
]
|
||||
|
||||
# output will be 'branch target build_id status successful'
|
||||
output = check_output(cmd).strip()
|
||||
|
||||
# return build_id from the output
|
||||
return output.split()[2]
|
||||
|
||||
Reference in New Issue
Block a user