Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 2 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 3 | # This script is used to update platform SDK prebuilts, Support Library, and a variety of other |
| 4 | # prebuilt libraries used by Android's Makefile builds. For details on how to use this script, |
| 5 | # visit go/update-prebuilts. |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 6 | import os, sys, getopt, zipfile, re |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 7 | import argparse |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 8 | import glob |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 9 | import subprocess |
shepshapard | e4127cf | 2019-09-03 16:08:44 -0700 | [diff] [blame] | 10 | from shutil import copyfile, rmtree, which, move |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 11 | from distutils.version import LooseVersion |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 12 | from functools import reduce |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 13 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 14 | current_path = 'current' |
Andy Wickham | c3c99af | 2020-10-26 20:47:58 +0000 | [diff] [blame] | 15 | framework_sdk_target = 'sdk_phone_armv7-win_sdk' |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 16 | androidx_dir = os.path.join(current_path, 'androidx') |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 17 | extras_dir = os.path.join(current_path, 'extras') |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 18 | buildtools_dir = 'tools' |
Jeff Gaston | 553a437 | 2018-03-29 18:34:22 -0400 | [diff] [blame] | 19 | jetifier_dir = os.path.join(buildtools_dir, 'jetifier', 'jetifier-standalone') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 20 | |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 21 | temp_dir = os.path.join(os.getcwd(), "support_tmp") |
| 22 | os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) |
| 23 | git_dir = os.getcwd() |
| 24 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 25 | # See go/fetch_artifact for details on this script. |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 26 | FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact' |
Jeff Sharkey | abe16df | 2021-05-25 10:09:03 -0600 | [diff] [blame] | 27 | FETCH_ARTIFACT_BEYOND_CORP = '/usr/bin/fetch_artifact' |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 28 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 29 | maven_to_make = { |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 30 | # AndroidX |
Michael Rosenfeld | 64b4b0e | 2021-05-21 17:53:36 -0700 | [diff] [blame] | 31 | 'androidx.benchmark:benchmark-macro': {'name':'androidx.benchmark_benchmark-macro', 'path':'androidx/benchmark/benchmark-macro'}, |
| 32 | 'androidx.benchmark:benchmark-macro-junit4': {'name':'androidx.benchmark_benchmark-macro-junit4', 'path':'androidx/benchmark/benchmark-macro-junit4'}, |
Dustin Lam | da15cd4 | 2020-04-01 19:06:23 -0700 | [diff] [blame] | 33 | 'androidx.benchmark:benchmark-common': {'name':'androidx.benchmark_benchmark-common', 'path':'androidx/benchmark/benchmark-common'}, |
| 34 | 'androidx.benchmark:benchmark-junit4': {'name':'androidx.benchmark_benchmark-junit4', 'path':'androidx/benchmark/benchmark-junit4'}, |
| 35 | 'androidx.tracing:tracing': {'name':'androidx.tracing_tracing', 'path':'androidx/tracing/tracing'}, |
| 36 | 'androidx.tracing:tracing-ktx': {'name':'androidx.tracing_tracing-ktx', 'path':'androidx/tracing/tracing-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 37 | 'androidx.slice:slice-builders': {'name':'androidx.slice_slice-builders', 'path':'androidx/slice/slice-builders'}, |
| 38 | 'androidx.slice:slice-core': {'name':'androidx.slice_slice-core', 'path':'androidx/slice/slice-core'}, |
| 39 | 'androidx.slice:slice-view': {'name':'androidx.slice_slice-view', 'path':'androidx/slice/slice-view'}, |
Jeff Gaston | 07a3cf7 | 2018-08-24 14:16:34 -0400 | [diff] [blame] | 40 | 'androidx.remotecallback:remotecallback': {'name':'androidx.remotecallback_remotecallback', 'path':'androidx/remotecallback/remotecallback'}, |
| 41 | 'androidx.remotecallback:remotecallback-processor': {'name':'androidx.remotecallback_remotecallback-processor', 'path':'androidx/remotecallback/remotecallback-processor', 'host':True}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 42 | 'androidx.versionedparcelable:versionedparcelable': {'name':'androidx.versionedparcelable_versionedparcelable', 'path':'androidx/versionedparcelable'}, |
| 43 | 'androidx.vectordrawable:vectordrawable-animated': {'name':'androidx.vectordrawable_vectordrawable-animated', 'path':'androidx/vectordrawable/vectordrawable-animated'}, |
Aurimas Liutikas | abaa49f | 2018-09-18 15:30:20 -0700 | [diff] [blame] | 44 | 'androidx.activity:activity': {'name':'androidx.activity_activity', 'path':'androidx/activity/activity'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 45 | 'androidx.activity:activity-ktx': {'name':'androidx.activity_activity-ktx', 'path':'androidx/activity/activity-ktx'}, |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 46 | 'androidx.annotation:annotation': {'name':'androidx.annotation_annotation', 'path':'androidx/annotation/annotation', 'host_and_device' : True}, |
Dustin Lam | da15cd4 | 2020-04-01 19:06:23 -0700 | [diff] [blame] | 47 | 'androidx.annotation:annotation-experimental': {'name':'androidx.annotation_annotation-experimental', 'path':'androidx/annotation/annotation-experimental'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 48 | 'androidx.asynclayoutinflater:asynclayoutinflater': {'name':'androidx.asynclayoutinflater_asynclayoutinflater', 'path':'androidx/asynclayoutinflater/asynclayoutinflater'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 49 | 'androidx.collection:collection': {'name':'androidx.collection_collection', 'path':'androidx/collection/collection'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 50 | 'androidx.collection:collection-ktx': {'name':'androidx.collection_collection-ktx', 'path':'androidx/collection/collection-ktx'}, |
Aurimas Liutikas | d912476 | 2018-09-28 15:31:35 -0700 | [diff] [blame] | 51 | 'androidx.concurrent:concurrent-futures': {'name':'androidx.concurrent_concurrent-futures', 'path':'androidx/concurrent/concurrent-futures'}, |
Aurimas Liutikas | 8af28d3 | 2019-06-06 14:04:01 -0700 | [diff] [blame] | 52 | 'androidx.concurrent:concurrent-listenablefuture-callback': {'name':'androidx.concurrent_concurrent-listenablefuture-callback', 'path':'androidx/concurrent/concurrent-listenablefuture-callback'}, |
| 53 | 'androidx.concurrent:concurrent-listenablefuture': {'name':'androidx.concurrent_concurrent-listenablefuture', 'path':'androidx/concurrent/concurrent-listenablefuture'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 54 | 'androidx.core:core': {'name':'androidx.core_core', 'path':'androidx/core/core'}, |
Yvan Hsueh | 5efba6e | 2020-04-30 01:17:47 +0800 | [diff] [blame] | 55 | 'androidx.core:core-animation': {'name':'androidx.core_core-animation', 'path':'androidx/core/core-animation'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 56 | 'androidx.core:core-ktx': {'name':'androidx.core_core-ktx', 'path':'androidx/core/core-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 57 | 'androidx.contentpaging:contentpaging': {'name':'androidx.contentpaging_contentpaging', 'path':'androidx/contentpaging/contentpaging'}, |
| 58 | 'androidx.coordinatorlayout:coordinatorlayout': {'name':'androidx.coordinatorlayout_coordinatorlayout', 'path':'androidx/coordinatorlayout/coordinatorlayout'}, |
| 59 | 'androidx.legacy:legacy-support-core-ui': {'name':'androidx.legacy_legacy-support-core-ui', 'path':'androidx/legacy/legacy-support-core-ui'}, |
| 60 | 'androidx.legacy:legacy-support-core-utils': {'name':'androidx.legacy_legacy-support-core-utils', 'path':'androidx/legacy/legacy-support-core-utils'}, |
| 61 | 'androidx.cursoradapter:cursoradapter': {'name':'androidx.cursoradapter_cursoradapter', 'path':'androidx/cursoradapter/cursoradapter'}, |
| 62 | 'androidx.browser:browser': {'name':'androidx.browser_browser', 'path':'androidx/browser/browser'}, |
| 63 | 'androidx.customview:customview': {'name':'androidx.customview_customview', 'path':'androidx/customview/customview'}, |
| 64 | 'androidx.documentfile:documentfile': {'name':'androidx.documentfile_documentfile', 'path':'androidx/documentfile/documentfile'}, |
| 65 | 'androidx.drawerlayout:drawerlayout': {'name':'androidx.drawerlayout_drawerlayout', 'path':'androidx/drawerlayout/drawerlayout'}, |
| 66 | 'androidx.dynamicanimation:dynamicanimation': {'name':'androidx.dynamicanimation_dynamicanimation', 'path':'androidx/dynamicanimation/dynamicanimation'}, |
| 67 | 'androidx.emoji:emoji': {'name':'androidx.emoji_emoji', 'path':'androidx/emoji/emoji'}, |
| 68 | 'androidx.emoji:emoji-appcompat': {'name':'androidx.emoji_emoji-appcompat', 'path':'androidx/emoji/emoji-appcompat'}, |
| 69 | 'androidx.emoji:emoji-bundled': {'name':'androidx.emoji_emoji-bundled', 'path':'androidx/emoji/emoji-bundled'}, |
| 70 | 'androidx.exifinterface:exifinterface': {'name':'androidx.exifinterface_exifinterface', 'path':'androidx/exifinterface/exifinterface'}, |
| 71 | 'androidx.fragment:fragment': {'name':'androidx.fragment_fragment', 'path':'androidx/fragment/fragment'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 72 | 'androidx.fragment:fragment-ktx': {'name':'androidx.fragment_fragment-ktx', 'path':'androidx/fragment/fragment-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 73 | 'androidx.heifwriter:heifwriter': {'name':'androidx.heifwriter_heifwriter', 'path':'androidx/heifwriter/heifwriter'}, |
| 74 | 'androidx.interpolator:interpolator': {'name':'androidx.interpolator_interpolator', 'path':'androidx/interpolator/interpolator'}, |
| 75 | 'androidx.loader:loader': {'name':'androidx.loader_loader', 'path':'androidx/loader/loader'}, |
| 76 | 'androidx.localbroadcastmanager:localbroadcastmanager': {'name':'androidx.localbroadcastmanager_localbroadcastmanager', 'path':'androidx/localbroadcastmanager/localbroadcastmanager'}, |
| 77 | 'androidx.media:media': {'name':'androidx.media_media', 'path':'androidx/media/media'}, |
Oussama Ben Abdelbaki | 09fffcb | 2019-05-13 15:11:37 -0400 | [diff] [blame] | 78 | 'androidx.media2:media2-player': {'name':'androidx.media2_media2-player', 'path':'androidx/media2/media2-player'}, |
| 79 | 'androidx.media2:media2-session': {'name':'androidx.media2_media2-session', 'path':'androidx/media2/media2-session'}, |
| 80 | 'androidx.media2:media2-common': {'name':'androidx.media2_media2-common', 'path':'androidx/media2/media2-common'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 81 | 'androidx.media2:media2-exoplayer': {'name':'androidx.media2_media2-exoplayer', 'path':'androidx/media2/media2-exoplayer'}, |
Gyumin Sim | 1752eca | 2018-12-13 11:34:10 +0900 | [diff] [blame] | 82 | 'androidx.media2:media2-widget': {'name':'androidx.media2_media2-widget', 'path':'androidx/media2/media2-widget'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 83 | 'androidx.navigation:navigation-common': {'name':'androidx.navigation_navigation-common', 'path':'androidx/navigation/navigation-common'}, |
| 84 | 'androidx.navigation:navigation-common-ktx': {'name':'androidx.navigation_navigation-common-ktx', 'path':'androidx/navigation/navigation-common-ktx'}, |
| 85 | 'androidx.navigation:navigation-fragment': {'name':'androidx.navigation_navigation-fragment', 'path':'androidx/navigation/navigation-fragment'}, |
| 86 | 'androidx.navigation:navigation-fragment-ktx': {'name':'androidx.navigation_navigation-fragment-ktx', 'path':'androidx/navigation/navigation-fragment-ktx'}, |
| 87 | 'androidx.navigation:navigation-runtime': {'name':'androidx.navigation_navigation-runtime', 'path':'androidx/navigation/navigation-runtime'}, |
| 88 | 'androidx.navigation:navigation-runtime-ktx': {'name':'androidx.navigation_navigation-runtime-ktx', 'path':'androidx/navigation/navigation-runtime-ktx'}, |
| 89 | 'androidx.navigation:navigation-ui': {'name':'androidx.navigation_navigation-ui', 'path':'androidx/navigation/navigation-ui'}, |
| 90 | 'androidx.navigation:navigation-ui-ktx': {'name':'androidx.navigation_navigation-ui-ktx', 'path':'androidx/navigation/navigation-ui-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 91 | 'androidx.percentlayout:percentlayout': {'name':'androidx.percentlayout_percentlayout', 'path':'androidx/percentlayout/percentlayout'}, |
| 92 | 'androidx.print:print': {'name':'androidx.print_print', 'path':'androidx/print/print'}, |
| 93 | 'androidx.recommendation:recommendation': {'name':'androidx.recommendation_recommendation', 'path':'androidx/recommendation/recommendation'}, |
| 94 | 'androidx.recyclerview:recyclerview-selection': {'name':'androidx.recyclerview_recyclerview-selection', 'path':'androidx/recyclerview/recyclerview-selection'}, |
Oussama Ben Abdelbaki | 00f9b39 | 2019-03-18 14:45:12 -0400 | [diff] [blame] | 95 | 'androidx.savedstate:savedstate': {'name':'androidx.savedstate_savedstate', 'path':'androidx/savedstate/savedstate'}, |
Chang Li | 0a70090 | 2020-10-07 16:03:26 +0100 | [diff] [blame] | 96 | 'androidx.savedstate:savedstate-ktx': {'name':'androidx.savedstate_savedstate-ktx', 'path':'androidx/savedstate/savedstate-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 97 | 'androidx.slidingpanelayout:slidingpanelayout': {'name':'androidx.slidingpanelayout_slidingpanelayout', 'path':'androidx/slidingpanelayout/slidingpanelayout'}, |
| 98 | 'androidx.swiperefreshlayout:swiperefreshlayout': {'name':'androidx.swiperefreshlayout_swiperefreshlayout', 'path':'androidx/swiperefreshlayout/swiperefreshlayout'}, |
| 99 | 'androidx.textclassifier:textclassifier': {'name':'androidx.textclassifier_textclassifier', 'path':'androidx/textclassifier/textclassifier'}, |
| 100 | 'androidx.transition:transition': {'name':'androidx.transition_transition', 'path':'androidx/transition/transition'}, |
| 101 | 'androidx.tvprovider:tvprovider': {'name':'androidx.tvprovider_tvprovider', 'path':'androidx/tvprovider/tvprovider'}, |
| 102 | 'androidx.legacy:legacy-support-v13': {'name':'androidx.legacy_legacy-support-v13', 'path':'androidx/legacy/legacy-support-v13'}, |
| 103 | 'androidx.legacy:legacy-preference-v14': {'name':'androidx.legacy_legacy-preference-v14', 'path':'androidx/legacy/legacy-preference-v14'}, |
| 104 | 'androidx.leanback:leanback': {'name':'androidx.leanback_leanback', 'path':'androidx/leanback/leanback'}, |
| 105 | 'androidx.leanback:leanback-preference': {'name':'androidx.leanback_leanback-preference', 'path':'androidx/leanback/leanback-preference'}, |
| 106 | 'androidx.legacy:legacy-support-v4': {'name':'androidx.legacy_legacy-support-v4', 'path':'androidx/legacy/legacy-support-v4'}, |
| 107 | 'androidx.appcompat:appcompat': {'name':'androidx.appcompat_appcompat', 'path':'androidx/appcompat/appcompat'}, |
Oussama Ben Abdelbaki | 61551b8 | 2019-02-12 15:56:27 -0500 | [diff] [blame] | 108 | 'androidx.appcompat:appcompat-resources': {'name':'androidx.appcompat_appcompat-resources', 'path':'androidx/appcompat/appcompat-resources'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 109 | 'androidx.cardview:cardview': {'name':'androidx.cardview_cardview', 'path':'androidx/cardview/cardview'}, |
| 110 | 'androidx.gridlayout:gridlayout': {'name':'androidx.gridlayout_gridlayout', 'path':'androidx/gridlayout/gridlayout'}, |
| 111 | 'androidx.mediarouter:mediarouter': {'name':'androidx.mediarouter_mediarouter', 'path':'androidx/mediarouter/mediarouter'}, |
| 112 | 'androidx.palette:palette': {'name':'androidx.palette_palette', 'path':'androidx/palette/palette'}, |
| 113 | 'androidx.preference:preference': {'name':'androidx.preference_preference', 'path':'androidx/preference/preference'}, |
| 114 | 'androidx.recyclerview:recyclerview': {'name':'androidx.recyclerview_recyclerview', 'path':'androidx/recyclerview/recyclerview'}, |
| 115 | 'androidx.vectordrawable:vectordrawable': {'name':'androidx.vectordrawable_vectordrawable', 'path':'androidx/vectordrawable/vectordrawable'}, |
| 116 | 'androidx.viewpager:viewpager': {'name':'androidx.viewpager_viewpager', 'path':'androidx/viewpager/viewpager'}, |
Fabian Kozynski | e514c12 | 2020-03-04 14:41:08 -0500 | [diff] [blame] | 117 | 'androidx.viewpager2:viewpager2': {'name':'androidx.viewpager2_viewpager2', 'path':'androidx/viewpager2/viewpager2'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 118 | 'androidx.wear:wear': {'name':'androidx.wear_wear', 'path':'androidx/wear/wear'}, |
Josh Yang | 7660f12 | 2021-06-11 11:14:29 -0700 | [diff] [blame] | 119 | 'androidx.wear:wear-ongoing': {'name':'androidx.wear_wear-ongoing', 'path':'androidx/wear/wear-ongoing'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 120 | 'androidx.webkit:webkit': {'name':'androidx.webkit_webkit', 'path':'androidx/webkit/webkit'}, |
Kevin Chyn | b6ae85d | 2018-10-02 12:12:20 -0700 | [diff] [blame] | 121 | 'androidx.biometric:biometric': {'name':'androidx.biometric_biometric', 'path':'androidx/biometric/biometric'}, |
Adam He | 7dec9ff | 2020-01-27 14:05:45 -0800 | [diff] [blame] | 122 | 'androidx.autofill:autofill': {'name':'androidx.autofill_autofill', 'path':'androidx/autofill/autofill'}, |
Alexander Dorokhine | 2cf37af | 2020-08-03 14:16:37 -0700 | [diff] [blame] | 123 | 'androidx.appsearch:appsearch': {'name':'androidx.appsearch_appsearch', 'path':'androidx/appsearch/appsearch'}, |
Winson Chung | e758860 | 2021-01-08 09:57:25 -0800 | [diff] [blame] | 124 | 'androidx.appsearch:appsearch-local-storage': {'name':'androidx.appsearch_appsearch_local_storage', 'path':'androidx/appsearch/appsearch/appsearch-local-storage'}, |
Alexander Dorokhine | ebb6906 | 2021-02-03 07:10:32 +0000 | [diff] [blame] | 125 | 'androidx.appsearch:appsearch-platform-storage': {'name':'androidx.appsearch_appsearch_platform_storage', 'path':'androidx/appsearch/appsearch/appsearch-platform-storage'}, |
Alexander Dorokhine | 2cf37af | 2020-08-03 14:16:37 -0700 | [diff] [blame] | 126 | 'androidx.appsearch:appsearch-compiler': {'name':'androidx.appsearch_appsearch-compiler', 'path':'androidx/appsearch/appsearch-compiler', 'host' : True}, |
Calvin Huang | b7946e8 | 2021-04-01 01:02:21 +0000 | [diff] [blame] | 127 | 'androidx.car.app:app': {'name':'androidx.car.app_app', 'path':'androidx/car/app/app'}, |
| 128 | 'androidx.car.app:app-activity': {'name':'androidx.car.app_app-activity', 'path':'androidx/car/app/app-activity'}, |
| 129 | 'androidx.car.app:app-testing': {'name':'androidx.car.app_app-testing', 'path':'androidx/car/app/app-testing'}, |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 130 | # AndroidX for Multidex |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 131 | 'androidx.multidex:multidex': {'name':'androidx-multidex_multidex', 'path':'androidx/multidex/multidex'}, |
| 132 | 'androidx.multidex:multidex-instrumentation': {'name':'androidx-multidex_multidex-instrumentation', 'path':'androidx/multidex/multidex-instrumentation'}, |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 133 | |
| 134 | # AndroidX for Constraint Layout |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 135 | 'androidx.constraintlayout:constraintlayout': {'name':'androidx-constraintlayout_constraintlayout', 'path':'androidx/constraintlayout/constraintlayout'}, |
| 136 | 'androidx.constraintlayout:constraintlayout-solver': {'name':'androidx-constraintlayout_constraintlayout-solver', 'path':'androidx/constraintlayout/constraintlayout-solver'}, |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 137 | |
| 138 | # AndroidX for Architecture Components |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 139 | 'androidx.arch.core:core-common': {'name':'androidx.arch.core_core-common', 'path':'androidx/arch/core/core-common'}, |
| 140 | 'androidx.arch.core:core-runtime': {'name':'androidx.arch.core_core-runtime', 'path':'androidx/arch/core/core-runtime'}, |
| 141 | 'androidx.lifecycle:lifecycle-common': {'name':'androidx.lifecycle_lifecycle-common', 'path':'androidx/lifecycle/lifecycle-common'}, |
| 142 | 'androidx.lifecycle:lifecycle-common-java8': {'name':'androidx.lifecycle_lifecycle-common-java8', 'path':'androidx/lifecycle/lifecycle-common-java8'}, |
| 143 | 'androidx.lifecycle:lifecycle-extensions': {'name':'androidx.lifecycle_lifecycle-extensions', 'path':'androidx/lifecycle/lifecycle-extensions'}, |
| 144 | 'androidx.lifecycle:lifecycle-livedata': {'name':'androidx.lifecycle_lifecycle-livedata', 'path':'androidx/lifecycle/lifecycle-livedata'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 145 | 'androidx.lifecycle:lifecycle-livedata-ktx': {'name':'androidx.lifecycle_lifecycle-livedata-ktx', 'path':'androidx/lifecycle/lifecycle-livedata-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 146 | 'androidx.lifecycle:lifecycle-livedata-core': {'name':'androidx.lifecycle_lifecycle-livedata-core', 'path':'androidx/lifecycle/lifecycle-livedata-core'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 147 | 'androidx.lifecycle:lifecycle-livedata-core-ktx': {'name':'androidx.lifecycle_lifecycle-livedata-core-ktx', 'path':'androidx/lifecycle/lifecycle-livedata-core-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 148 | 'androidx.lifecycle:lifecycle-process': {'name':'androidx.lifecycle_lifecycle-process', 'path':'androidx/lifecycle/lifecycle-process'}, |
| 149 | 'androidx.lifecycle:lifecycle-runtime': {'name':'androidx.lifecycle_lifecycle-runtime', 'path':'androidx/lifecycle/lifecycle-runtime'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 150 | 'androidx.lifecycle:lifecycle-runtime-ktx': {'name':'androidx.lifecycle_lifecycle-runtime-ktx', 'path':'androidx/lifecycle/lifecycle-runtime-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 151 | 'androidx.lifecycle:lifecycle-service': {'name':'androidx.lifecycle_lifecycle-service', 'path':'androidx/lifecycle/lifecycle-service'}, |
| 152 | 'androidx.lifecycle:lifecycle-viewmodel': {'name':'androidx.lifecycle_lifecycle-viewmodel', 'path':'androidx/lifecycle/lifecycle-viewmodel'}, |
Nate Myren | 1fa4716 | 2019-11-12 11:28:06 -0800 | [diff] [blame] | 153 | 'androidx.lifecycle:lifecycle-viewmodel-ktx': {'name':'androidx.lifecycle_lifecycle-viewmodel-ktx', 'path':'androidx/lifecycle/lifecycle-viewmodel-ktx'}, |
Aurimas Liutikas | b5836e2 | 2019-09-06 09:00:45 -0700 | [diff] [blame] | 154 | 'androidx.lifecycle:lifecycle-viewmodel-savedstate': {'name':'androidx.lifecycle_lifecycle-viewmodel-savedstate', 'path':'androidx/lifecycle/lifecycle-viewmodel-savedstate'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 155 | 'androidx.paging:paging-common': {'name':'androidx.paging_paging-common', 'path':'androidx/paging/paging-common'}, |
Aurimas Liutikas | b5836e2 | 2019-09-06 09:00:45 -0700 | [diff] [blame] | 156 | 'androidx.paging:paging-common-ktx': {'name':'androidx.paging_paging-common-ktx', 'path':'androidx/paging/paging-common-ktx'}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 157 | 'androidx.paging:paging-runtime': {'name':'androidx.paging_paging-runtime', 'path':'androidx/paging/paging-runtime'}, |
| 158 | 'androidx.sqlite:sqlite': {'name':'androidx.sqlite_sqlite', 'path':'androidx/sqlite/sqlite'}, |
| 159 | 'androidx.sqlite:sqlite-framework': {'name':'androidx.sqlite_sqlite-framework', 'path':'androidx/sqlite/sqlite-framework'}, |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 160 | 'androidx.room:room-common': {'name':'androidx.room_room-common', 'path':'androidx/room/room-common', 'host_and_device' : True}, |
| 161 | 'androidx.room:room-compiler': {'name':'androidx.room_room-compiler', 'path':'androidx/room/room-compiler', 'host' : True}, |
| 162 | 'androidx.room:room-migration': {'name':'androidx.room_room-migration', 'path':'androidx/room/room-migration', 'host_and_device' : True}, |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 163 | 'androidx.room:room-runtime': {'name':'androidx.room_room-runtime', 'path':'androidx/room/room-runtime'}, |
| 164 | 'androidx.room:room-testing': {'name':'androidx.room_room-testing', 'path':'androidx/room/room-testing'}, |
Ming-Shin Lu | 97a1dc0 | 2020-09-11 21:55:21 +0800 | [diff] [blame] | 165 | 'androidx.room:room-compiler-processing': {'name':'androidx.room_room-compiler-processing', 'path':'androidx/room/room-compiler-processing', 'host' : True}, |
Chang Li | 0a70090 | 2020-10-07 16:03:26 +0100 | [diff] [blame] | 166 | 'androidx.work:work-runtime': {'name':'androidx.work_work-runtime', 'path':'androidx/work/work-runtime'}, |
| 167 | 'androidx.work:work-runtime-ktx': {'name':'androidx.work_work-runtime-ktx', 'path':'androidx/work/work-runtime-ktx'}, |
| 168 | 'androidx.work:work-testing': {'name':'androidx.work_work-testing', 'path':'androidx/work/work-testing'}, |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 169 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 170 | # Lifecycle |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 171 | # Missing dependencies: |
| 172 | # - auto-common |
| 173 | # - javapoet |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 174 | #'android.arch.lifecycle:compiler': {'name':'android-arch-lifecycle-compiler', 'path':'arch-lifecycle/compiler'}, |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 175 | # Missing dependencies: |
| 176 | # - reactive-streams |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 177 | #'android.arch.lifecycle:reactivestreams': 'android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams', |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 178 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 179 | # Room |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 180 | # Missing dependencies: |
| 181 | # - auto-common |
| 182 | # - javapoet |
| 183 | # - antlr4 |
| 184 | # - kotlin-metadata |
| 185 | # - commons-codec |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 186 | #'android.arch.persistence.room:compiler': {'name':'android-arch-room-compiler', 'path':'arch-room/compiler'}, |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 187 | # Missing dependencies: |
| 188 | # - rxjava |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 189 | #'android.arch.persistence.room:rxjava2': {'name':'android-arch-room-rxjava2', 'path':'arch-room/rxjava2'}, |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 190 | |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 191 | # Third-party dependencies |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 192 | 'com.google.android:flexbox': {'name':'flexbox', 'path':'flexbox'}, |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 193 | |
Jeff Gaston | fa7c7e8 | 2018-04-06 13:35:48 -0400 | [diff] [blame] | 194 | # Androidx Material Design Components |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 195 | 'com.google.android.material:material': {'name':'com.google.android.material_material', 'path':'com/google/android/material/material'}, |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | # Always remove these files. |
| 199 | blacklist_files = [ |
| 200 | 'annotations.zip', |
| 201 | 'public.txt', |
| 202 | 'R.txt', |
Alan Viverette | 44ad4e4 | 2017-08-09 17:45:00 -0400 | [diff] [blame] | 203 | 'AndroidManifest.xml', |
Alan Viverette | f48d9b4 | 2017-08-17 14:45:46 -0400 | [diff] [blame] | 204 | os.path.join('libs','noto-emoji-compat-java.jar') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 205 | ] |
| 206 | |
Alan Viverette | 44ad4e4 | 2017-08-09 17:45:00 -0400 | [diff] [blame] | 207 | artifact_pattern = re.compile(r"^(.+?)-(\d+\.\d+\.\d+(?:-\w+\d+)?(?:-[\d.]+)*)\.(jar|aar)$") |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 208 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 209 | |
| 210 | class MavenLibraryInfo: |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 211 | def __init__(self, key, group_id, artifact_id, version, dir, repo_dir, file): |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 212 | self.key = key |
| 213 | self.group_id = group_id |
| 214 | self.artifact_id = artifact_id |
| 215 | self.version = version |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 216 | self.dir = dir |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 217 | self.repo_dir = repo_dir |
| 218 | self.file = file |
| 219 | |
| 220 | |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 221 | def print_e(*args, **kwargs): |
| 222 | print(*args, file=sys.stderr, **kwargs) |
| 223 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 224 | |
| 225 | def touch(fname, times=None): |
| 226 | with open(fname, 'a'): |
| 227 | os.utime(fname, times) |
| 228 | |
| 229 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 230 | def path(*path_parts): |
| 231 | return reduce((lambda x, y: os.path.join(x, y)), path_parts) |
| 232 | |
| 233 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 234 | def flatten(list): |
| 235 | return reduce((lambda x, y: "%s %s" % (x, y)), list) |
| 236 | |
| 237 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 238 | def rm(path): |
| 239 | if os.path.isdir(path): |
| 240 | rmtree(path) |
| 241 | elif os.path.exists(path): |
| 242 | os.remove(path) |
| 243 | |
| 244 | |
| 245 | def mv(src_path, dst_path): |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 246 | if os.path.exists(dst_path): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 247 | rm(dst_path) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 248 | if not os.path.exists(os.path.dirname(dst_path)): |
| 249 | os.makedirs(os.path.dirname(dst_path)) |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 250 | for f in (glob.glob(src_path)): |
| 251 | if '*' in dst_path: |
| 252 | dst = os.path.join(os.path.dirname(dst_path), os.path.basename(f)) |
| 253 | else: |
| 254 | dst = dst_path |
shepshapard | e4127cf | 2019-09-03 16:08:44 -0700 | [diff] [blame] | 255 | move(f, dst) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 256 | |
| 257 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 258 | def detect_artifacts(maven_repo_dirs): |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 259 | maven_lib_info = {} |
| 260 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 261 | # Find the latest revision for each artifact, remove others |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 262 | for repo_dir in maven_repo_dirs: |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 263 | for root, dirs, files in os.walk(repo_dir): |
| 264 | for file in files: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 265 | if file[-4:] == ".pom": |
| 266 | # Read the POM (hack hack hack). |
| 267 | group_id = '' |
| 268 | artifact_id = '' |
| 269 | version = '' |
| 270 | file = os.path.join(root, file) |
| 271 | with open(file) as pom_file: |
| 272 | for line in pom_file: |
| 273 | if line[:11] == ' <groupId>': |
| 274 | group_id = line[11:-11] |
| 275 | elif line[:14] == ' <artifactId>': |
| 276 | artifact_id = line[14:-14] |
| 277 | elif line[:11] == ' <version>': |
| 278 | version = line[11:-11] |
| 279 | if group_id == '' or artifact_id == '' or version == '': |
| 280 | print_e('Failed to find Maven artifact data in ' + file) |
| 281 | continue |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 282 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 283 | # Locate the artifact. |
| 284 | artifact_file = file[:-4] |
| 285 | if os.path.exists(artifact_file + '.jar'): |
| 286 | artifact_file = artifact_file + '.jar' |
| 287 | elif os.path.exists(artifact_file + '.aar'): |
| 288 | artifact_file = artifact_file + '.aar' |
| 289 | else: |
| 290 | print_e('Failed to find artifact for ' + artifact_file) |
| 291 | continue |
| 292 | |
| 293 | # Make relative to root. |
| 294 | artifact_file = artifact_file[len(root) + 1:] |
| 295 | |
| 296 | # Find the mapping. |
| 297 | group_artifact = group_id + ':' + artifact_id |
Jeff Gaston | 3e622ba | 2018-03-26 23:24:46 -0400 | [diff] [blame] | 298 | if group_artifact in maven_to_make: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 299 | key = group_artifact |
Jeff Gaston | 3e622ba | 2018-03-26 23:24:46 -0400 | [diff] [blame] | 300 | elif artifact_id in maven_to_make: |
| 301 | key = artifact_id |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 302 | else: |
| 303 | print_e('Failed to find artifact mapping for ' + group_artifact) |
| 304 | continue |
| 305 | |
| 306 | # Store the latest version. |
| 307 | version = LooseVersion(version) |
| 308 | if key not in maven_lib_info \ |
| 309 | or version > maven_lib_info[key].version: |
| 310 | maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version, |
| 311 | root, repo_dir, artifact_file) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 312 | |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 313 | return maven_lib_info |
| 314 | |
| 315 | |
Colin Cross | 59b59db | 2018-04-24 13:58:05 -0700 | [diff] [blame] | 316 | def transform_maven_repos(maven_repo_dirs, transformed_dir, extract_res=True, include_static_deps=True): |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 317 | cwd = os.getcwd() |
| 318 | |
| 319 | # Use a temporary working directory. |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 320 | maven_lib_info = detect_artifacts(maven_repo_dirs) |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 321 | working_dir = temp_dir |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 322 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 323 | if not maven_lib_info: |
| 324 | print_e('Failed to detect artifacts') |
| 325 | return False |
| 326 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 327 | # extract some files (for example, AndroidManifest.xml) from any relevant artifacts |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 328 | for info in maven_lib_info.values(): |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 329 | transform_maven_lib(working_dir, info, extract_res) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 330 | |
Colin Cross | 74683bc | 2018-04-11 17:36:18 -0700 | [diff] [blame] | 331 | # generate a single Android.bp that specifies to use all of the above artifacts |
| 332 | makefile = os.path.join(working_dir, 'Android.bp') |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 333 | with open(makefile, 'w') as f: |
Anton Hansson | bd2021c | 2021-04-06 19:21:34 +0000 | [diff] [blame] | 334 | args = ["pom2bp"] |
Anton Hansson | 8e84b61 | 2021-04-06 14:24:29 +0100 | [diff] [blame] | 335 | args.extend(["-sdk-version", "30"]) |
Anton Hansson | bd2021c | 2021-04-06 19:21:34 +0000 | [diff] [blame] | 336 | args.extend(["-default-min-sdk-version", "24"]) |
Jeff Gaston | 1cc0609 | 2018-03-28 15:51:02 -0400 | [diff] [blame] | 337 | if include_static_deps: |
| 338 | args.append("-static-deps") |
Jeff Gaston | 54868ee | 2018-04-25 19:43:35 -0400 | [diff] [blame] | 339 | rewriteNames = sorted([name for name in maven_to_make if ":" in name] + [name for name in maven_to_make if ":" not in name]) |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 340 | args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name]['name'] for name in rewriteNames]) |
Colin Cross | 5542fc2 | 2021-04-14 11:36:46 -0700 | [diff] [blame] | 341 | args.extend(["-rewrite=^auto-common$=auto_common"]) |
| 342 | args.extend(["-rewrite=^auto-value-annotations$=auto_value_annotations"]) |
Dustin Lam | da15cd4 | 2020-04-01 19:06:23 -0700 | [diff] [blame] | 343 | args.extend(["-rewrite=^monitor$=androidx.test.monitor"]) |
| 344 | args.extend(["-rewrite=^rules$=androidx.test.rules"]) |
| 345 | args.extend(["-rewrite=^runner$=androidx.test.runner"]) |
Yiqun Wu | 9e020fe | 2020-11-18 21:16:08 +0000 | [diff] [blame] | 346 | args.extend(["-rewrite=^com.squareup:javapoet$=javapoet"]) |
Aurimas Liutikas | d912476 | 2018-09-28 15:31:35 -0700 | [diff] [blame] | 347 | args.extend(["-rewrite=^com.google.guava:listenablefuture$=guava-listenablefuture-prebuilt-jar"]) |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 348 | args.extend(["-rewrite=^sqlite-jdbc$=xerial-sqlite-jdbc"]) |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 349 | args.extend(["-rewrite=^gson$=gson-prebuilt-jar"]) |
Sunny Goyal | 6667ddb | 2020-03-03 15:15:54 -0800 | [diff] [blame] | 350 | args.extend(["-rewrite=^com.intellij:annotations$=jetbrains-annotations"]) |
Sunny Goyal | 6667ddb | 2020-03-03 15:15:54 -0800 | [diff] [blame] | 351 | args.extend(["-extra-static-libs=androidx.room_room-compiler=guava-21.0"]) |
Jeff Gaston | 07a3cf7 | 2018-08-24 14:16:34 -0400 | [diff] [blame] | 352 | args.extend(["-host=" + name for name in maven_to_make if maven_to_make[name].get('host')]) |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 353 | args.extend(["-host-and-device=" + name for name in maven_to_make if maven_to_make[name].get('host_and_device')]) |
Colin Cross | 2106007 | 2018-04-24 13:52:29 -0700 | [diff] [blame] | 354 | # these depend on GSON which is not in AOSP |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 355 | args.extend(["-exclude=android-arch-room-migration", |
Colin Cross | 2106007 | 2018-04-24 13:52:29 -0700 | [diff] [blame] | 356 | "-exclude=android-arch-room-testing"]) |
Jeff Gaston | 7ec1d8f | 2018-03-27 00:25:12 -0400 | [diff] [blame] | 357 | args.extend(["."]) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 358 | subprocess.check_call(args, stdout=f, cwd=working_dir) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 359 | |
| 360 | # Replace the old directory. |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 361 | output_dir = os.path.join(cwd, transformed_dir) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 362 | mv(working_dir, output_dir) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 363 | return True |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 364 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 365 | # moves <artifact_info> (of type MavenLibraryInfo) into the appropriate part of <working_dir> , and possibly unpacks any necessary included files |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 366 | def transform_maven_lib(working_dir, artifact_info, extract_res): |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 367 | # Move library into working dir |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 368 | new_dir = os.path.normpath(os.path.join(working_dir, os.path.relpath(artifact_info.dir, artifact_info.repo_dir))) |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 369 | mv(artifact_info.dir, new_dir) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 370 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 371 | matcher = artifact_pattern.match(artifact_info.file) |
| 372 | maven_lib_name = artifact_info.key |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 373 | maven_lib_vers = matcher.group(2) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 374 | maven_lib_type = artifact_info.file[-3:] |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 375 | |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 376 | make_lib_name = maven_to_make[artifact_info.key]['name'] |
| 377 | make_dir_name = maven_to_make[artifact_info.key]['path'] |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 378 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 379 | artifact_file = os.path.join(new_dir, artifact_info.file) |
| 380 | |
Colin Cross | 59b59db | 2018-04-24 13:58:05 -0700 | [diff] [blame] | 381 | if maven_lib_type == "aar": |
| 382 | if extract_res: |
| 383 | target_dir = os.path.join(working_dir, make_dir_name) |
| 384 | if not os.path.exists(target_dir): |
| 385 | os.makedirs(target_dir) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 386 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 387 | process_aar(artifact_file, target_dir) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 388 | |
Colin Cross | 59b59db | 2018-04-24 13:58:05 -0700 | [diff] [blame] | 389 | with zipfile.ZipFile(artifact_file) as zip: |
| 390 | manifests_dir = os.path.join(working_dir, "manifests") |
| 391 | zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name)) |
Dan Willemsen | d677b60 | 2017-11-08 22:13:17 -0800 | [diff] [blame] | 392 | |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 393 | print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 394 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 395 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 396 | def process_aar(artifact_file, target_dir): |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 397 | # Extract AAR file to target_dir. |
| 398 | with zipfile.ZipFile(artifact_file) as zip: |
| 399 | zip.extractall(target_dir) |
| 400 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 401 | # Remove classes.jar |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 402 | classes_jar = os.path.join(target_dir, "classes.jar") |
| 403 | if os.path.exists(classes_jar): |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 404 | os.remove(classes_jar) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 405 | |
| 406 | # Remove or preserve empty dirs. |
| 407 | for root, dirs, files in os.walk(target_dir): |
| 408 | for dir in dirs: |
| 409 | dir_path = os.path.join(root, dir) |
| 410 | if not os.listdir(dir_path): |
| 411 | os.rmdir(dir_path) |
| 412 | |
| 413 | # Remove top-level cruft. |
| 414 | for file in blacklist_files: |
| 415 | file_path = os.path.join(target_dir, file) |
| 416 | if os.path.exists(file_path): |
| 417 | os.remove(file_path) |
| 418 | |
Alan Viverette | f17c940 | 2017-07-19 12:57:40 -0400 | [diff] [blame] | 419 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 420 | def fetch_artifact(target, build_id, artifact_path): |
Jeff Sharkey | abe16df | 2021-05-25 10:09:03 -0600 | [diff] [blame] | 421 | global args |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 422 | download_to = os.path.join('.', os.path.dirname(artifact_path)) |
| 423 | print('Fetching %s from %s ...' % (artifact_path, target)) |
| 424 | if not os.path.exists(download_to): |
| 425 | os.makedirs(download_to) |
Jeff Sharkey | abe16df | 2021-05-25 10:09:03 -0600 | [diff] [blame] | 426 | if args.beyond_corp: |
| 427 | fetch_cmd = [FETCH_ARTIFACT_BEYOND_CORP, '--use_oauth2', |
| 428 | '--bid', str(build_id), '--target', target, artifact_path, download_to] |
| 429 | else: |
| 430 | fetch_cmd = [FETCH_ARTIFACT, |
| 431 | '--bid', str(build_id), '--target', target, artifact_path, download_to] |
Jeff Gaston | 97a9b76 | 2018-10-02 15:15:12 -0400 | [diff] [blame] | 432 | print("Running: " + ' '.join(fetch_cmd)) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 433 | try: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 434 | subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 435 | except subprocess.CalledProcessError: |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 436 | print_e('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id)) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 437 | print_e('Please make sure you are authenticated for build server access!') |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 438 | return None |
| 439 | return artifact_path |
| 440 | |
| 441 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 442 | def fetch_artifacts(target, build_id, artifact_dict): |
| 443 | for artifact, target_path in artifact_dict.items(): |
| 444 | artifact_path = fetch_artifact(target, build_id.url_id, artifact) |
| 445 | if not artifact_path: |
| 446 | return False |
| 447 | mv(artifact_path, target_path) |
| 448 | return True |
| 449 | |
| 450 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 451 | def extract_artifact(artifact_path): |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 452 | # Unzip the repo archive into a separate directory. |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 453 | repo_dir = os.path.basename(artifact_path)[:-4] |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 454 | with zipfile.ZipFile(artifact_path) as zipFile: |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 455 | zipFile.extractall(repo_dir) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 456 | return repo_dir |
| 457 | |
| 458 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 459 | def fetch_and_extract(target, build_id, file, artifact_path=None): |
| 460 | if not artifact_path: |
| 461 | artifact_path = fetch_artifact(target, build_id, file) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 462 | if not artifact_path: |
| 463 | return None |
| 464 | return extract_artifact(artifact_path) |
| 465 | |
| 466 | |
Jeff Gaston | 08a2ee4 | 2018-05-07 18:08:41 -0400 | [diff] [blame] | 467 | def update_androidx(target, build_id, local_file): |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 468 | if build_id: |
Anthony Chen | acbb487 | 2018-07-02 11:22:48 -0700 | [diff] [blame] | 469 | repo_file = 'top-of-tree-m2repository-all-%s.zip' % build_id.fs_id |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 470 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None) |
| 471 | else: |
| 472 | repo_dir = fetch_and_extract(target, None, None, local_file) |
| 473 | if not repo_dir: |
| 474 | print_e('Failed to extract AndroidX repository') |
| 475 | return False |
| 476 | |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 477 | # Keep JavaPlugins.bp file untounched. |
| 478 | java_plugins_bp_path = os.path.join(androidx_dir, 'JavaPlugins.bp') |
| 479 | tmp_java_plugins_bp_path = os.path.join('/tmp', 'JavaPlugins.bp') |
| 480 | mv(java_plugins_bp_path, tmp_java_plugins_bp_path) |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 481 | |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 482 | # Transform the repo archive into a Makefile-compatible format. |
| 483 | if not transform_maven_repos([repo_dir], androidx_dir, extract_res=False): |
| 484 | return False |
| 485 | |
| 486 | # Import JavaPlugins.bp in Android.bp. |
| 487 | makefile = os.path.join(androidx_dir, 'Android.bp') |
| 488 | with open(makefile, "a+") as f: |
| 489 | f.write('\nbuild = ["JavaPlugins.bp"]\n') |
| 490 | mv(tmp_java_plugins_bp_path, java_plugins_bp_path) |
| 491 | |
| 492 | return True |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 493 | |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 494 | |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 495 | def update_jetifier(target, build_id): |
| 496 | repo_file = 'jetifier-standalone.zip' |
| 497 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file) |
| 498 | if not repo_dir: |
| 499 | print_e('Failed to extract Jetifier') |
| 500 | return False |
| 501 | |
| 502 | rm(jetifier_dir) |
Jeff Gaston | 553a437 | 2018-03-29 18:34:22 -0400 | [diff] [blame] | 503 | mv(os.path.join(repo_dir, 'jetifier-standalone'), jetifier_dir) |
| 504 | os.chmod(os.path.join(jetifier_dir, 'bin', 'jetifier-standalone'), 0o755) |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 505 | return True |
| 506 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 507 | |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 508 | def update_constraint(local_file): |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 509 | repo_dir = extract_artifact(local_file) |
| 510 | if not repo_dir: |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 511 | print_e('Failed to extract Constraint Layout') |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 512 | return False |
| 513 | return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'constraint-layout-x'), extract_res=False) |
| 514 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 515 | |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 516 | def update_material(file): |
| 517 | design_dir = extract_artifact(file) |
| 518 | if not design_dir: |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 519 | print_e('Failed to extract Material Design Components') |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 520 | return False |
| 521 | |
| 522 | # Don't bother extracting resources -- this should only be used with AAPT2. |
| 523 | return transform_maven_repos([design_dir], |
| 524 | os.path.join(extras_dir, 'material-design-x'), extract_res=False) |
| 525 | |
| 526 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 527 | def update_framework(build_id, sdk_dir): |
Anton Hansson | 83f9217 | 2020-03-26 11:12:03 +0000 | [diff] [blame] | 528 | api_scope_list = ['public', 'system', 'test', 'module-lib', 'system-server'] |
Sundong Ahn | 66091f2 | 2018-08-29 18:54:28 +0900 | [diff] [blame] | 529 | if sdk_dir == 'current': |
| 530 | api_scope_list.append('core') |
| 531 | |
| 532 | for api_scope in api_scope_list: |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 533 | target_dir = path(sdk_dir, api_scope) |
Sundong Ahn | 66091f2 | 2018-08-29 18:54:28 +0900 | [diff] [blame] | 534 | if api_scope == 'core': |
| 535 | artifact_to_path = {'core.current.stubs.jar': path(target_dir, 'android.jar')} |
| 536 | else: |
| 537 | artifact_to_path = {'apistubs/android/' + api_scope + '/*.jar': path(target_dir, '*')} |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 538 | |
| 539 | if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path): |
| 540 | return False |
| 541 | |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 542 | if api_scope == 'public': |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 543 | # Fetch a few artifacts from the public sdk. |
Sundong Ahn | 66091f2 | 2018-08-29 18:54:28 +0900 | [diff] [blame] | 544 | artifact = 'sdk-repo-linux-platforms-%s.zip' % build_id.fs_id |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 545 | artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, artifact) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 546 | if not artifact_path: |
| 547 | return False |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 548 | |
| 549 | with zipfile.ZipFile(artifact_path) as zipFile: |
Colin Cross | d338d70 | 2020-07-10 19:17:54 -0700 | [diff] [blame] | 550 | extra_files = [ |
| 551 | 'android.jar', |
| 552 | 'framework.aidl', |
| 553 | 'uiautomator.jar', |
| 554 | 'core-for-system-modules.jar', |
| 555 | 'data/annotations.zip', |
| 556 | 'data/api-versions.xml'] |
| 557 | for filename in extra_files: |
Anton Hansson | a26e481 | 2020-03-25 12:54:39 +0000 | [diff] [blame] | 558 | matches = list(filter(lambda path: filename in path, zipFile.namelist())) |
| 559 | if len(matches) != 1: |
| 560 | print_e('Expected 1 file named \'%s\' in zip %s, found %d' % |
| 561 | (filename, zipFile.filename, len(matches))) |
| 562 | return False |
| 563 | zip_path = matches[0] |
| 564 | src_path = zipFile.extract(zip_path) |
| 565 | dst_path = path(target_dir, filename) |
| 566 | mv(src_path, dst_path) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 567 | |
Anton Hansson | 73be151 | 2021-06-24 10:56:05 +0100 | [diff] [blame] | 568 | # Filtered API DB is currently only available for "public" |
| 569 | fetch_artifacts(framework_sdk_target, build_id, {'api-versions-public-filtered.xml': path(target_dir, 'data/api-versions-filtered.xml')}) |
| 570 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 571 | return True |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 572 | |
Sundong Ahn | cc34cc3 | 2018-07-11 15:18:47 +0900 | [diff] [blame] | 573 | def update_makefile(build_id): |
| 574 | template = '"%s",\n\ |
| 575 | "current"' |
| 576 | makefile = os.path.join(git_dir, 'Android.bp') |
| 577 | |
| 578 | with open(makefile, 'r+') as f: |
| 579 | contents = f.read().replace('"current"', template % build_id) |
| 580 | f.seek(0) |
| 581 | f.write(contents) |
| 582 | |
| 583 | return True |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 584 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 585 | def finalize_sdk(build_id, sdk_version): |
| 586 | target_finalize_dir = '%d' % sdk_version |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 587 | |
Anton Hansson | aa554c0 | 2020-04-30 14:06:20 +0100 | [diff] [blame] | 588 | for api_scope in ['public', 'system', 'test', 'module-lib', 'system-server']: |
Sundong Ahn | 66091f2 | 2018-08-29 18:54:28 +0900 | [diff] [blame] | 589 | artifact_to_path = {'apistubs/android/' + api_scope + '/api/*.txt': |
| 590 | path(target_finalize_dir, api_scope, 'api', '*')} |
| 591 | |
| 592 | if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path): |
| 593 | return False |
| 594 | |
| 595 | return update_framework(build_id, target_finalize_dir) \ |
Sundong Ahn | cc34cc3 | 2018-07-11 15:18:47 +0900 | [diff] [blame] | 596 | and update_makefile(target_finalize_dir) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 597 | |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 598 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 599 | def update_framework_current(build_id): |
| 600 | return update_framework(build_id, current_path) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 601 | |
| 602 | |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 603 | def update_buildtools(target, arch, build_id): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 604 | artifact_path = fetch_and_extract(target, build_id.url_id, |
| 605 | "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id)) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 606 | if not artifact_path: |
| 607 | return False |
| 608 | |
| 609 | top_level_dir = os.listdir(artifact_path)[0] |
| 610 | src_path = os.path.join(artifact_path, top_level_dir) |
| 611 | dst_path = path(buildtools_dir, arch) |
Colin Cross | 20648d3 | 2021-02-12 13:30:51 -0800 | [diff] [blame] | 612 | |
| 613 | # There are a few libraries that have been manually added to the |
| 614 | # build tools, copy them from the destination back to the source |
| 615 | # before the destination is overwritten. |
| 616 | files_to_save = ( |
| 617 | 'lib64/libconscrypt_openjdk_jni.dylib', |
| 618 | 'lib64/libconscrypt_openjdk_jni.so', |
| 619 | 'bin/lib64/libwinpthread-1.dll', |
| 620 | ) |
| 621 | for file in files_to_save: |
| 622 | src_file = os.path.join(dst_path, file) |
| 623 | dst_file = os.path.join(src_path, file) |
| 624 | if os.path.exists(dst_path): |
| 625 | mv(src_file, dst_file) |
| 626 | |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 627 | mv(src_path, dst_path) |
| 628 | |
| 629 | # Move all top-level files to /bin and make them executable |
| 630 | bin_path = path(dst_path, 'bin') |
| 631 | top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path)) |
| 632 | for file in top_level_files: |
| 633 | src_file = path(dst_path, file) |
| 634 | dst_file = path(bin_path, file) |
| 635 | mv(src_file, dst_file) |
| 636 | os.chmod(dst_file, 0o755) |
| 637 | |
Colin Cross | 6673ceb | 2021-02-12 13:14:14 -0800 | [diff] [blame] | 638 | # Make the files under lld-bin executable |
| 639 | lld_bin_files = os.listdir(os.path.join(dst_path, 'lld-bin')) |
| 640 | for file in lld_bin_files: |
| 641 | os.chmod(os.path.join(dst_path, 'lld-bin', file), 0o755) |
| 642 | |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 643 | # Remove renderscript |
| 644 | rm(path(dst_path, 'renderscript')) |
| 645 | |
| 646 | return True |
| 647 | |
| 648 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 649 | def append(text, more_text): |
| 650 | if text: |
| 651 | return "%s, %s" % (text, more_text) |
| 652 | return more_text |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 653 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 654 | |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 655 | class buildId(object): |
| 656 | def __init__(self, url_id, fs_id): |
| 657 | # id when used in build server urls |
| 658 | self.url_id = url_id |
| 659 | # id when used in build commands |
| 660 | self.fs_id = fs_id |
| 661 | |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 662 | def getBuildId(args): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 663 | # must be in the format 12345 or P12345 |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 664 | source = args.source |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 665 | number_text = source[:] |
| 666 | presubmit = False |
| 667 | if number_text.startswith("P"): |
| 668 | presubmit = True |
| 669 | number_text = number_text[1:] |
| 670 | if not number_text.isnumeric(): |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 671 | return None |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 672 | url_id = source |
| 673 | fs_id = url_id |
| 674 | if presubmit: |
| 675 | fs_id = "0" |
| 676 | args.file = False |
| 677 | return buildId(url_id, fs_id) |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 678 | |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 679 | def getFile(args): |
| 680 | source = args.source |
| 681 | if not source.isnumeric(): |
| 682 | return args.source |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 683 | return None |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 684 | |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 685 | |
| 686 | def script_relative(rel_path): |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 687 | return os.path.join(script_dir, rel_path) |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 688 | |
| 689 | |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 690 | def uncommittedChangesExist(): |
| 691 | try: |
| 692 | # Make sure we don't overwrite any pending changes. |
| 693 | diffCommand = "cd " + git_dir + " && git diff --quiet" |
| 694 | subprocess.check_call(diffCommand, shell=True) |
| 695 | subprocess.check_call(diffCommand + " --cached", shell=True) |
| 696 | return False |
| 697 | except subprocess.CalledProcessError: |
| 698 | return True |
| 699 | |
| 700 | |
Jeff Gaston | a7fba9b | 2018-03-26 23:48:51 -0400 | [diff] [blame] | 701 | rm(temp_dir) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 702 | parser = argparse.ArgumentParser( |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 703 | description=('Update current prebuilts')) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 704 | parser.add_argument( |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 705 | 'source', |
| 706 | help='Build server build ID or local Maven ZIP file') |
| 707 | parser.add_argument( |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 708 | '-m', '--material', action="store_true", |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 709 | help='If specified, updates only Material Design Components') |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 710 | parser.add_argument( |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 711 | '-c', '--constraint', action="store_true", |
| 712 | help='If specified, updates only Constraint Layout') |
| 713 | parser.add_argument( |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 714 | '-j', '--jetifier', action="store_true", |
| 715 | help='If specified, updates only Jetifier') |
| 716 | parser.add_argument( |
Alan Viverette | 5bfe05b | 2017-06-06 14:21:29 -0400 | [diff] [blame] | 717 | '-p', '--platform', action="store_true", |
| 718 | help='If specified, updates only the Android Platform') |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 719 | parser.add_argument( |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 720 | '-f', '--finalize_sdk', type=int, |
| 721 | help='If specified, imports the source build as the specified finalized SDK version') |
| 722 | parser.add_argument( |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 723 | '-b', '--buildtools', action="store_true", |
| 724 | help='If specified, updates only the Build Tools') |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 725 | parser.add_argument( |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 726 | '-x', '--androidx', action="store_true", |
| 727 | help='If specified, updates only the Jetpack (androidx) libraries excluding those covered by other arguments') |
Jeff Gaston | 41fd5e6 | 2018-04-25 17:02:02 -0400 | [diff] [blame] | 728 | parser.add_argument( |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 729 | '--commit-first', action="store_true", |
| 730 | help='If specified, then if uncommited changes exist, commit before continuing') |
Jeff Sharkey | abe16df | 2021-05-25 10:09:03 -0600 | [diff] [blame] | 731 | parser.add_argument( |
| 732 | '--beyond-corp', action="store_true", |
| 733 | help='If specified, then fetch artifacts with tooling that works on BeyondCorp devices') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 734 | args = parser.parse_args() |
Jeff Gaston | 56fe276 | 2018-02-06 14:54:37 -0500 | [diff] [blame] | 735 | args.file = True |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 736 | if not args.source: |
| 737 | parser.error("You must specify a build ID or local Maven ZIP file") |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 738 | sys.exit(1) |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 739 | if not (args.platform or args.buildtools \ |
| 740 | or args.jetifier or args.androidx or args.material \ |
| 741 | or args.finalize_sdk or args.constraint): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 742 | parser.error("You must specify at least one target to update") |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 743 | sys.exit(1) |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 744 | if (args.constraint or args.material or args.androidx) \ |
Colin Cross | 74683bc | 2018-04-11 17:36:18 -0700 | [diff] [blame] | 745 | and which('pom2bp') is None: |
Louis Pullen-Freilich | 61bb70e | 2019-04-09 16:15:32 +0100 | [diff] [blame] | 746 | parser.error("Cannot find pom2bp in path; please run lunch to set up build environment. You may also need to run 'm pom2bp' if it hasn't been built already.") |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 747 | sys.exit(1) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 748 | |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 749 | if uncommittedChangesExist(): |
| 750 | if args.commit_first: |
| 751 | subprocess.check_call("cd " + git_dir + " && git add -u", shell=True) |
| 752 | subprocess.check_call("cd " + git_dir + " && git commit -m 'save working state'", shell=True) |
| 753 | |
| 754 | if uncommittedChangesExist(): |
Anton Hansson | 10861a0 | 2018-04-06 13:57:08 +0100 | [diff] [blame] | 755 | print_e('FAIL: There are uncommitted changes here. Please commit or stash before continuing, because %s will run "git reset --hard" if execution fails' % os.path.basename(__file__)) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 756 | sys.exit(1) |
| 757 | |
| 758 | try: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 759 | components = None |
| 760 | if args.constraint: |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 761 | if update_constraint_x(getFile(args)): |
| 762 | components = append(components, 'Constraint Layout X') |
| 763 | else: |
| 764 | print_e('Failed to update Constraint Layout X, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 765 | sys.exit(1) |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 766 | if args.androidx: |
Jeff Gaston | 17ccf8f | 2018-08-29 11:33:19 -0400 | [diff] [blame] | 767 | if update_androidx('androidx', \ |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 768 | getBuildId(args), getFile(args)): |
| 769 | components = append(components, 'AndroidX') |
| 770 | else: |
| 771 | print_e('Failed to update AndroidX, aborting...') |
| 772 | sys.exit(1) |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 773 | if args.jetifier: |
Jeff Gaston | 17ccf8f | 2018-08-29 11:33:19 -0400 | [diff] [blame] | 774 | if update_jetifier('androidx', getBuildId(args)): |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 775 | components = append(components, 'Jetifier') |
| 776 | else: |
| 777 | print_e('Failed to update Jetifier, aborting...') |
| 778 | sys.exit(1) |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 779 | if args.platform or args.finalize_sdk: |
Anton Hansson | 87654c4 | 2018-04-26 15:19:42 +0100 | [diff] [blame] | 780 | if update_framework_current(getBuildId(args)): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 781 | components = append(components, 'platform SDK') |
| 782 | else: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 783 | print_e('Failed to update platform SDK, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 784 | sys.exit(1) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 785 | if args.finalize_sdk: |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 786 | n = args.finalize_sdk |
| 787 | if finalize_sdk(getBuildId(args), n): |
| 788 | # We commit the finalized dir separately from the current sdk update. |
| 789 | msg = "Import final sdk version %d from build %s" % (n, getBuildId(args).url_id) |
| 790 | subprocess.check_call(['git', 'add', '%d' % n]) |
Sundong Ahn | cc34cc3 | 2018-07-11 15:18:47 +0900 | [diff] [blame] | 791 | subprocess.check_call(['git', 'add', 'Android.bp']) |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 792 | subprocess.check_call(['git', 'commit', '-m', msg]) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 793 | else: |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 794 | print_e('Failed to finalize SDK %d, aborting...' % n) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 795 | sys.exit(1) |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 796 | if args.material: |
| 797 | if update_material(getFile(args)): |
| 798 | components = append(components, 'intermediate-AndroidX Design Library') |
| 799 | else: |
| 800 | print_e('Failed to update intermediate-AndroidX Design Library, aborting...') |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 801 | sys.exit(1) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 802 | if args.buildtools: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 803 | if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \ |
| 804 | and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \ |
| 805 | and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 806 | components = append(components, 'build tools') |
| 807 | else: |
| 808 | print_e('Failed to update build tools, aborting...') |
| 809 | sys.exit(1) |
Jeff Gaston | b70daa9 | 2018-03-29 20:10:22 -0400 | [diff] [blame] | 810 | |
Jeff Gaston | f12f3ce | 2018-03-23 16:41:24 -0400 | [diff] [blame] | 811 | |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 812 | |
Colin Cross | 941d980 | 2018-05-03 21:37:57 -0700 | [diff] [blame] | 813 | subprocess.check_call(['git', 'add', current_path, buildtools_dir]) |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 814 | if not args.source.isnumeric(): |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 815 | src_msg = "local Maven ZIP" |
| 816 | else: |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 817 | src_msg = "build %s" % (getBuildId(args).url_id) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 818 | msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv)) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 819 | subprocess.check_call(['git', 'commit', '-m', msg]) |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 820 | if args.finalize_sdk: |
| 821 | print('NOTE: Created two commits:') |
| 822 | subprocess.check_call(['git', 'log', '-2', '--oneline']) |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 823 | print('Remember to test this change before uploading it to Gerrit!') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 824 | |
| 825 | finally: |
| 826 | # Revert all stray files, including the downloaded zip. |
| 827 | try: |
| 828 | with open(os.devnull, 'w') as bitbucket: |
| 829 | subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket) |
| 830 | subprocess.check_call( |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 831 | ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!', '--allow-empty'], stdout=bitbucket) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 832 | subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket) |
| 833 | except subprocess.CalledProcessError: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 834 | print_e('ERROR: Failed cleaning up, manual cleanup required!!!') |