diff options
author | Ian Baker <ibaker@google.com> | 2023-05-30 19:19:13 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-05-30 19:19:13 +0000 |
commit | 0b137cec215f129a3456c29faa7db142e26684a0 (patch) | |
tree | 28a2c6ac69d494b9c98ed81240d5729ee6e5ef7e | |
parent | c482fe20005a3f77a1ac6c50477020efdc20e317 (diff) | |
parent | 55498f65cf049b3217777d556868cc156fc2562f (diff) | |
download | misc-0b137cec215f129a3456c29faa7db142e26684a0.tar.gz |
Copy update-from-gmaven.py script from androidx-test to androidx-media3 am: 55498f65cf
Original change: https://android-review.googlesource.com/c/platform/prebuilts/misc/+/2607050
Change-Id: If278a743372fd60422648ef482a7039e852c134b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | common/androidx-media3/prepend-license.txt | 4 | ||||
-rwxr-xr-x | common/androidx-media3/update-from-gmaven.py | 158 |
2 files changed, 162 insertions, 0 deletions
diff --git a/common/androidx-media3/prepend-license.txt b/common/androidx-media3/prepend-license.txt new file mode 100644 index 00000000..d137074a --- /dev/null +++ b/common/androidx-media3/prepend-license.txt @@ -0,0 +1,4 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + diff --git a/common/androidx-media3/update-from-gmaven.py b/common/androidx-media3/update-from-gmaven.py new file mode 100755 index 00000000..a99113ed --- /dev/null +++ b/common/androidx-media3/update-from-gmaven.py @@ -0,0 +1,158 @@ +#!/usr/bin/python3 + +# Helper script for updating androidx.test prebuilts from maven +# +# Usage: +# a. Initialize android environment eg . build/envsetup.sh; lunch <target> +# b. Update the version numbers in this file +# c. ./prebuilts/misc/androidx-test/update-from-gmaven.py +# +# The script will then: +# 1. Remove the previous artifacts +# 2. Download the aars and poms into a file structure mirroring their maven +# path +# 3. Extract the AndroidManifest from the aars into the manifests folder +# 4. Run pom2bp to generate the Android.bp + +import os +import subprocess +import sys + +annotationVersion="1.0.1" +monitorVersion="1.6.1" +runnerVersion="1.5.2" +rulesVersion="1.5.0" +espressoVersion="3.5.1" +coreVersion="1.5.0" +extJUnitVersion="1.1.5" +extTruthVersion="1.5.0" +servicesVersion="1.4.2" +jankTestHelperVersion="1.0.1" + +mavenToBpPatternMap = { + "androidx.test:" : "androidx.test.", + "androidx.test.annotation:annotation" : "androidx.test.annotation", + "androidx.test.ext:": "androidx.test.ext.", + "androidx.test.espresso:espresso-":"androidx.test.espresso.", + "androidx.test.janktesthelper:janktesthelper":"androidx.test.janktesthelper", + "androidx.test.services:storage":"androidx.test.services.storage", + "androidx.test.services:test-services":"androidx.test.services.test-services", + "androidx.tracing:tracing":"androidx.tracing_tracing", + "androidx.concurrent:concurrent-futures":"androidx.concurrent_concurrent-futures", + "com.google.guava:listenablefuture":"guava-listenablefuture-prebuilt-jar", + } + +extraLibs = { + "androidx.test.rules" : "android.test.base", + } + +def cmd(args): + print(args) + out = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + if (out.returncode != 0): + print(out.stderr.decode("utf-8")) + sys.exit(out.returncode) + out_string = out.stdout.decode("utf-8") + print(out_string) + return out_string + +def chdir(path): + print("cd %s" % path) + os.chdir(path) + +def getAndroidRoot(): + if os.path.isdir(".repo/projects"): + return os.getcwd() + elif 'TOP' in os.environ: + return os.environ['TOP'] + else: + print("Error: Run from android source root or set TOP envvar") + sys.exit(-1) + +def downloadArtifact(groupId, artifactId, version): + """Downloads an aar, sources.jar and pom from google maven""" + groupPath = groupId.replace('.', '/') + artifactDirPath = os.path.join(groupPath, artifactId, version) + artifactPath = os.path.join(artifactDirPath, "%s-%s" % (artifactId, version)) + cmd("mkdir -p " + artifactDirPath) + # download aar + cmd("wget -O %s.aar https://dl.google.com/dl/android/maven2/%s.aar" % (artifactPath, artifactPath)) + + # extract AndroidManifest.xml from aar, into path expected by pom2bp + manifestDir = getManifestPath("%s:%s" % (groupId,artifactId)) + cmd("mkdir -p " + manifestDir) + cmd("unzip -o %s.aar AndroidManifest.xml -d %s" % (artifactPath, manifestDir)) + + # download pom + cmd("wget -O %s.pom https://dl.google.com/dl/android/maven2/%s.pom" % (artifactPath, artifactPath)) + + # download sources.jar + cmd("wget -O %s-sources.jar https://dl.google.com/dl/android/maven2/%s-sources.jar" % (artifactPath, artifactPath)) + +def downloadApk(groupId, artifactId, version): + """Downloads an apk from google maven""" + groupPath = groupId.replace('.', '/') + artifactDirPath = os.path.join(groupPath, artifactId, version) + artifactPath = os.path.join(artifactDirPath, "%s-%s" % (artifactId, version)) + cmd("mkdir -p " + artifactDirPath) + # download apk + cmd("wget -O %s.apk https://dl.google.com/dl/android/maven2/%s.apk" % (artifactPath, artifactPath)) + # download pom + cmd("wget -O %s.pom https://dl.google.com/dl/android/maven2/%s.pom" % (artifactPath, artifactPath)) + +def getManifestPath(mavenArtifactName): + """Get the path to the aar's manifest as generated by pom2bp.""" + manifestPath = mavenArtifactName + for searchPattern in mavenToBpPatternMap: + manifestPath = manifestPath.replace(searchPattern, mavenToBpPatternMap[searchPattern]) + return "manifests/%s" % manifestPath + +prebuiltDir = os.path.join(getAndroidRoot(), "prebuilts/misc/common/androidx-test") +chdir(prebuiltDir) + +cmd("rm -rf androidx/test") +cmd("rm -rf manifests") + +downloadArtifact("androidx.test", "annotation", annotationVersion) +downloadArtifact("androidx.test", "core", coreVersion) +downloadArtifact("androidx.test.espresso", "espresso-accessibility", espressoVersion) +downloadArtifact("androidx.test.espresso", "espresso-core", espressoVersion) +downloadArtifact("androidx.test.espresso", "espresso-contrib", espressoVersion) +downloadArtifact("androidx.test.espresso", "espresso-idling-resource", espressoVersion) +downloadArtifact("androidx.test.espresso", "espresso-intents", espressoVersion) +downloadArtifact("androidx.test.espresso", "espresso-idling-resource", espressoVersion) +downloadArtifact("androidx.test.espresso", "espresso-web", espressoVersion) +downloadArtifact("androidx.test", "monitor", monitorVersion) +downloadArtifact("androidx.test", "rules", rulesVersion) +downloadArtifact("androidx.test", "runner", runnerVersion) +downloadArtifact("androidx.test.ext", "junit", extJUnitVersion) +downloadArtifact("androidx.test.ext", "truth", extTruthVersion) +downloadArtifact("androidx.test.janktesthelper", "janktesthelper", jankTestHelperVersion) +downloadArtifact("androidx.test.services", "storage", servicesVersion) +downloadApk("androidx.test.services", "test-services", servicesVersion) + + +atxRewriteStr = "" +for name in mavenToBpPatternMap: + atxRewriteStr += "-rewrite %s=%s " % (name, mavenToBpPatternMap[name]) +for name in extraLibs: + atxRewriteStr += "-extra-libs %s=%s " % (name, extraLibs[name]) + +cmd("pom2bp " + atxRewriteStr + + # map external maven dependencies to Android module names + "-rewrite com.google.truth:truth=truth-prebuilt " + + "-rewrite net.sf.kxml:kxml2=kxml2-android " + + "-rewrite androidx.lifecycle:lifecycle-common=androidx.lifecycle_lifecycle-common " + + "-rewrite androidx.annotation:annotation=androidx.annotation_annotation " + + "-rewrite org.hamcrest:hamcrest-integration=hamcrest " + + "-rewrite javax.inject:javax.inject=jsr330 " + + "-rewrite com.google.android.material:material=com.google.android.material_material " + + "-rewrite androidx.drawerlayout:drawerlayout=androidx.drawerlayout_drawerlayout " + + "-rewrite androidx.viewpager:viewpager=androidx.viewpager_viewpager " + + "-rewrite androidx.recyclerview:recyclerview=androidx.recyclerview_recyclerview " + + "-rewrite androidx.core:core=androidx.core_core " + + "-rewrite androidx.legacy:legacy-support-core-utils=androidx.legacy_legacy-support-core-utils " + + "-sdk-version current " + + "-static-deps " + + "-prepend prepend-license.txt " + + ". > Android.bp") |