summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2017-05-12 23:47:51 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-05-12 23:47:51 +0000
commit862d0494d5c6271fedb39048fbd1df5175d116dd (patch)
tree1fd8a2e146225a2d9a4864e5e8e86f2368411582
parentbb773394f7f7d028f641aede6085e6ff3c67fdee (diff)
parent7826fb94e5697dc06c478e13555065622e3d46e5 (diff)
downloadsdk-862d0494d5c6271fedb39048fbd1df5175d116dd.tar.gz
Migrate old update script to directly pull from build server am: 45837098e0
am: 7826fb94e5 Change-Id: I5dd0a459e813a1cfcad9df869190e8dc8bc7ee28
-rwxr-xr-xupdate_current.py (renamed from update_support.py)118
-rwxr-xr-xupdate_current.sh114
2 files changed, 94 insertions, 138 deletions
diff --git a/update_support.py b/update_current.py
index e594cac13..db2675e1f 100755
--- a/update_support.py
+++ b/update_current.py
@@ -6,7 +6,9 @@ import subprocess
from shutil import copyfile, rmtree
from distutils.version import LooseVersion
-output_path = 'current/support'
+current_path = 'current'
+system_path = 'system_current'
+support_path = os.path.join(current_path, 'support')
# See go/fetch_artifact
FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact'
@@ -67,6 +69,22 @@ def touch(fname, times=None):
os.utime(fname, times)
+def path(*path_parts):
+ return reduce((lambda x, y: os.path.join(x, y)), path_parts)
+
+
+def rm(path):
+ if os.path.isdir(path):
+ rmtree(path)
+ elif os.path.exists(path):
+ os.remove(path)
+
+
+def mv(src_path, dst_path):
+ rm(dst_path)
+ os.rename(src_path, dst_path)
+
+
def transform_support(repoDir):
cwd = os.getcwd()
@@ -94,7 +112,7 @@ def transform_support(repoDir):
transform_maven_lib(working_dir, info[1], info[2])
# Replace the old directory.
- output_dir = os.path.join(cwd, output_path)
+ output_dir = os.path.join(cwd, support_path)
if os.path.exists(output_dir):
rmtree(output_dir)
os.rename(working_dir, output_dir)
@@ -154,18 +172,83 @@ def process_aar(artifact_file, target_dir, make_lib_name):
if os.path.exists(file_path):
os.remove(file_path)
+def fetch_artifact(target, buildId, artifact_path):
+ print 'Fetching %s from %s...' % (artifact_path, target)
+ fetchCmd = [FETCH_ARTIFACT, '--bid', str(buildId), '--target', target, artifact_path]
+ try:
+ subprocess.check_output(fetchCmd, stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError:
+ print >> sys.stderr, 'FAIL: Unable to retrieve %s artifact for build ID %d' % (artifact_path, buildId)
+ return None
+ return artifact_path
+
+
+def update_support(target, buildId):
+ platform = 'darwin' if 'mac' in target else 'linux'
+ artifact_path = fetch_artifact(target, buildId, 'sdk-repo-%s-m2repository-%s.zip' % (platform, buildId))
+ if not artifact_path:
+ return
+
+ # Unzip the repo archive into a separate directory.
+ repoDir = os.path.basename(artifact_path)[:-4]
+ with zipfile.ZipFile(artifact_path) as zipFile:
+ zipFile.extractall(repoDir)
+
+ # Transform the repo archive into a Makefile-compatible format.
+ transform_support(repoDir)
+
+
+def extract_to(zip_file, paths, filename, parent_path):
+ zip_path = filter(lambda path: filename in path, paths)[0]
+ src_path = zip_file.extract(zip_path)
+ dst_path = path(parent_path, filename)
+ mv(src_path, dst_path)
+
+
+def update_sdk_repo(target, buildId):
+ platform = 'darwin' if 'mac' in target else 'linux'
+ artifact_path = fetch_artifact(target, buildId, 'sdk-repo-%s-platforms-%s.zip' % (platform, buildId))
+ if not artifact_path:
+ return
+
+ with zipfile.ZipFile(artifact_path) as zipFile:
+ paths = zipFile.namelist()
+
+ extract_to(zipFile, paths, 'android.jar', current_path)
+ extract_to(zipFile, paths, 'uiautomator.jar', current_path)
+ extract_to(zipFile, paths, 'framework.aidl', current_path)
+
+ # Unclear if this is actually necessary.
+ extract_to(zipFile, paths, 'framework.aidl', system_path)
+
+
+def update_system(target, buildId):
+ artifact_path = fetch_artifact(target, buildId, 'android_system.jar')
+ if not artifact_path:
+ return
+
+ mv(artifact_path, path(system_path, 'android.jar'))
+
parser = argparse.ArgumentParser(
- description=('Update prebuilt android extras'))
+ description=('Update current prebuilts'))
parser.add_argument(
'buildId',
type=int,
nargs='?',
help='Build server build ID')
parser.add_argument(
- '--target',
+ '--support',
default='support_library',
- help='Download m2repository from the specified build server target')
+ help='Specifies the build server target from which the m2repository ZIP is obtained')
+parser.add_argument(
+ '--sdk_repo',
+ default='sdk_phone_armv7-sdk_mac',
+ help='Specifies the build server target from which the platforms ZIP is obtained')
+parser.add_argument(
+ '--system',
+ default='sdk_phone_armv7-sdk_mac',
+ help='Specifies the build server target from which the android_system JAR is obtained')
args = parser.parse_args()
if not args.buildId:
parser.error("You must specify a build ID")
@@ -180,27 +263,14 @@ except subprocess.CalledProcessError:
sys.exit(1)
try:
- repoArtifact = 'sdk-repo-linux-m2repository-' + str(args.buildId) + '.zip'
-
- # Download the repo zip archive.
- fetchCmd = [FETCH_ARTIFACT, '--bid', str(args.buildId), '--target', args.target, repoArtifact]
- try:
- subprocess.check_output(fetchCmd, stderr=subprocess.STDOUT)
- except subprocess.CalledProcessError:
- print >> sys.stderr, "FAIL: Unable to retrieve artifact for build ID %d" % args.buildId
- sys.exit(1)
-
- # Unzip the repo archive into a separate directory.
- repoDir = os.path.basename(repoArtifact)[:-4]
- with zipfile.ZipFile(repoArtifact) as zipFile:
- zipFile.extractall(repoDir)
-
- # Transform the repo archive into a Makefile-compatible format.
- transform_support(repoDir)
+ update_support(args.support, args.buildId)
+ update_sdk_repo(args.sdk_repo, args.buildId)
+ update_system(args.system, args.buildId)
# Commit all changes.
- subprocess.check_call(['git', 'add', output_path])
- msg = ("Import support libs from build %s\n\n%s\n" % (args.buildId, " ".join(fetchCmd)))
+ subprocess.check_call(['git', 'add', current_path])
+ subprocess.check_call(['git', 'add', system_path])
+ msg = "Import support libs from build %s" % args.buildId
subprocess.check_call(['git', 'commit', '-m', msg])
print 'Be sure to upload this manually to gerrit.'
diff --git a/update_current.sh b/update_current.sh
deleted file mode 100755
index f7421efc4..000000000
--- a/update_current.sh
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/bin/bash
-
-set -e
-
-usage() {
-
-cat <<EOF
- $0
- --sdk <SDK file path>
- --system <system sdk file path>
- --support <support library file path>
-EOF
- exit 2
-
-}
-
-banner() {
- echo "**************************************************"
- echo "Updating $1 "
- echo "**************************************************"
-}
-
-update_sdk() {
- if [ -f "$SDK" ]
- then
- banner "SDK"
- cd $ROOT_DIR/current
- rm -f android.jar uiautomator.jar framework.aidl
- unzip -j $SDK */android.jar */uiautomator.jar */framework.aidl
- fi
-}
-
-update_system_sdk() {
- if [ -f "$SYSTEM_SDK" ]
- then
- banner "system SDK"
- cp -f $SYSTEM_SDK $ROOT_DIR/system_current/android.jar
- fi
-}
-
-update_support_lib() {
- if [ -f "$SUPPORT" ]
- then
- banner "support library"
- rm -rf $ROOT_DIR/current/support/
- cd $ROOT_DIR/current
- unzip $SUPPORT >/dev/null
-
- # Remove duplicates
- rm -f support/v7/appcompat/libs/android-support-v4.jar
- rm -f support/multidex/instrumentation/libs/android-support-multidex.jar
-
- # Remove samples
- rm -rf support/samples
-
- # Remove source files
- find support -name "*.java" \
- -o -name "*.aidl" \
- -o -name AndroidManifest.xml \
- | xargs rm
-
- # Other misc files we don't need
- find support -name "*.gradle" \
- -o -name ".classpath" \
- -o -name ".project" \
- -o -name "project.properties" \
- -o -name "source.properties" \
- -o -name ".readme" \
- -o -name "README.txt" \
- -o -name "package.html" \
- -o -name "NOTICE.txt" \
- | xargs rm
-
- # Now we can remove empty dirs
- find . -type d -empty -delete
- fi
-}
-
-main() {
- while [ "$#" -gt 0 ]
- do
- case "$1" in
- --help|-h)
- usage
- ;;
- --sdk)
- export SDK="$2"
- shift; shift
- ;;
- --system)
- export SYSTEM_SDK="$2"
- shift; shift
- ;;
- --support)
- export SUPPORT="$2"
- shift; shift
- ;;
- -*)
- usage
- ;;
- *)
- break
- ;;
- esac
- done
-
- ROOT_DIR=$(realpath $(dirname $0))
-
- update_sdk
- update_system_sdk
- update_support_lib
-}
-
-main $*