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 |
| 8 | import subprocess |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 9 | from shutil import copyfile, rmtree, which |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 10 | from distutils.version import LooseVersion |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 11 | from functools import reduce |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 12 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 13 | current_path = 'current' |
| 14 | system_path = 'system_current' |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 15 | api_path = 'api' |
| 16 | system_api_path = 'system-api' |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 17 | framework_sdk_target = 'sdk_phone_armv7-sdk_mac' |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 18 | support_dir = os.path.join(current_path, 'support') |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 19 | androidx_dir = os.path.join(current_path, 'androidx') |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 20 | extras_dir = os.path.join(current_path, 'extras') |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 21 | buildtools_dir = 'tools' |
Jeff Gaston | 553a437 | 2018-03-29 18:34:22 -0400 | [diff] [blame] | 22 | jetifier_dir = os.path.join(buildtools_dir, 'jetifier', 'jetifier-standalone') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 23 | |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 24 | temp_dir = os.path.join(os.getcwd(), "support_tmp") |
| 25 | os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) |
| 26 | git_dir = os.getcwd() |
| 27 | |
Jeff Gaston | f12f3ce | 2018-03-23 16:41:24 -0400 | [diff] [blame] | 28 | rerun_extract_deps = False |
| 29 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 30 | # See go/fetch_artifact for details on this script. |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 31 | FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact' |
| 32 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 33 | maven_to_make = { |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 34 | # Support Library |
| 35 | 'com.android.support:animated-vector-drawable': ['android-support-animatedvectordrawable', 'graphics/drawable'], |
| 36 | 'com.android.support:appcompat-v7': ['android-support-v7-appcompat', 'v7/appcompat'], |
| 37 | 'com.android.support:cardview-v7': ['android-support-v7-cardview', 'v7/cardview'], |
| 38 | 'com.android.support:collections': ['android-support-collections', 'collections', 'jar'], |
| 39 | 'com.android.support:customtabs': ['android-support-customtabs', 'customtabs'], |
| 40 | 'com.android.support:exifinterface': ['android-support-exifinterface', 'exifinterface'], |
| 41 | 'com.android.support:gridlayout-v7': ['android-support-v7-gridlayout', 'v7/gridlayout'], |
| 42 | 'com.android.support:leanback-v17': ['android-support-v17-leanback', 'v17/leanback'], |
| 43 | 'com.android.support:mediarouter-v7': ['android-support-v7-mediarouter', 'v7/mediarouter'], |
| 44 | 'com.android.support:palette-v7': ['android-support-v7-palette', 'v7/palette'], |
| 45 | 'com.android.support:percent': ['android-support-percent', 'percent'], |
| 46 | 'com.android.support:preference-leanback-v17': ['android-support-v17-preference-leanback', 'v17/preference-leanback'], |
| 47 | 'com.android.support:preference-v14': ['android-support-v14-preference', 'v14/preference'], |
| 48 | 'com.android.support:preference-v7': ['android-support-v7-preference', 'v7/preference'], |
| 49 | 'com.android.support:recommendation': ['android-support-recommendation', 'recommendation'], |
| 50 | 'com.android.support:recyclerview-v7': ['android-support-v7-recyclerview', 'v7/recyclerview'], |
| 51 | 'com.android.support:support-annotations': ['android-support-annotations', 'annotations', 'jar'], |
| 52 | 'com.android.support:support-compat': ['android-support-compat', 'compat'], |
| 53 | 'com.android.support:support-core-ui': ['android-support-core-ui', 'core-ui'], |
| 54 | 'com.android.support:support-core-utils': ['android-support-core-utils', 'core-utils'], |
| 55 | 'com.android.support:support-dynamic-animation': ['android-support-dynamic-animation', 'dynamic-animation'], |
| 56 | 'com.android.support:support-emoji-appcompat': ['android-support-emoji-appcompat', 'emoji-appcompat'], |
| 57 | 'com.android.support:support-emoji-bundled': ['android-support-emoji-bundled', 'emoji-bundled'], |
| 58 | 'com.android.support:support-emoji': ['android-support-emoji', 'emoji'], |
| 59 | 'com.android.support:support-fragment': ['android-support-fragment', 'fragment'], |
| 60 | 'com.android.support:support-media-compat': ['android-support-media-compat', 'media-compat'], |
| 61 | 'com.android.support:support-tv-provider': ['android-support-tv-provider', 'tv-provider'], |
| 62 | 'com.android.support:support-v13': ['android-support-v13', 'v13'], |
| 63 | 'com.android.support:support-v4': ['android-support-v4', 'v4'], |
| 64 | 'com.android.support:support-vector-drawable': ['android-support-vectordrawable', 'graphics/drawable'], |
| 65 | 'com.android.support:transition': ['android-support-transition', 'transition'], |
| 66 | 'com.android.support:wear': ['android-support-wear', 'wear'], |
Alan Viverette | 7bb86da | 2018-02-21 18:29:02 -0500 | [diff] [blame] | 67 | |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 68 | # Support Library (28.0.0 splits + new modules) |
| 69 | 'com.android.support:heifwriter': ['android-support-heifwriter', 'heifwriter'], |
| 70 | 'com.android.support:webkit': ['android-support-webkit', 'webkit'], |
| 71 | 'com.android.support:customview': ['android-support-customview', 'customview'], |
| 72 | 'com.android.support:textclassifier': ['android-support-textclassifier', 'textclassifier'], |
| 73 | 'com.android.support:swiperefreshlayout': ['android-support-swiperefreshlayout', 'swiperefreshlayout'], |
| 74 | 'com.android.support:viewpager': ['android-support-viewpager', 'viewpager'], |
| 75 | 'com.android.support:coordinatorlayout': ['android-support-coordinatorlayout', 'coordinatorlayout'], |
| 76 | 'com.android.support:asynclayoutinflater': ['android-support-asynclayoutinflater', 'asynclayoutinflater'], |
| 77 | 'com.android.support:support-content': ['android-support-support-content', 'support-content'], |
| 78 | 'com.android.support:documentfile': ['android-support-documentfile', 'documentfile'], |
| 79 | 'com.android.support:drawerlayout': ['android-support-drawerlayout', 'drawerlayout'], |
| 80 | 'com.android.support:localbroadcastmanager': ['android-support-localbroadcastmanager', 'localbroadcastmanager'], |
| 81 | 'com.android.support:print': ['android-support-print', 'print'], |
| 82 | 'com.android.support:slidingpanelayout': ['android-support-slidingpanelayout', 'slidingpanelayout'], |
| 83 | 'com.android.support:interpolator': ['android-support-interpolator', 'interpolator'], |
| 84 | 'com.android.support:cursoradapter': ['android-support-cursoradapter', 'cursoradapter'], |
| 85 | 'com.android.support:loader': ['android-support-loader', 'loader'], |
| 86 | 'com.android.support:contentpaging': ['android-support-contentpaging', 'contentpaging'], |
| 87 | 'com.android.support:recyclerview-selection': ['android-support-recyclerview-selection', 'recyclerview-selection'], |
| 88 | 'com.android.support:car': ['android-support-car', 'car'], |
| 89 | 'com.android.support:slices-core': ['android-slices-core', 'slices-core'], |
| 90 | 'com.android.support:slices-view': ['android-slices-view', 'slices-view'], |
| 91 | 'com.android.support:slices-builders': ['android-slices-builders', 'slices-builders'], |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 92 | |
| 93 | # Multidex |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 94 | 'com.android.support:multidex': ['android-support-multidex', 'multidex/library'], |
| 95 | 'com.android.support:multidex-instrumentation': ['android-support-multidex-instrumentation', 'multidex/instrumentation'], |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 96 | |
| 97 | # Constraint Layout |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 98 | 'com.android.support.constraint:constraint-layout': ['android-support-constraint-layout', 'constraint-layout'], |
| 99 | 'com.android.support.constraint:constraint-layout-solver': ['android-support-constraint-layout-solver', 'constraint-layout-solver'], |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 100 | |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 101 | # Architecture Components |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 102 | 'android.arch.core:runtime': ['android-arch-core-runtime', 'arch-core/runtime'], |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 103 | 'android.arch.core:common': ['android-arch-core-common', 'arch-core/common'], |
| 104 | 'android.arch.lifecycle:common': ['android-arch-lifecycle-common', 'arch-lifecycle/common'], |
| 105 | 'android.arch.lifecycle:common-java8': ['android-arch-lifecycle-common-java8', 'arch-lifecycle/common-java8'], |
| 106 | 'android.arch.lifecycle:extensions': ['android-arch-lifecycle-extensions', 'arch-lifecycle/extensions'], |
| 107 | 'android.arch.lifecycle:livedata': ['android-arch-lifecycle-livedata', 'arch-lifecycle/livedata'], |
| 108 | 'android.arch.lifecycle:livedata-core': ['android-arch-lifecycle-livedata-core', 'arch-lifecycle/livedata-core'], |
| 109 | 'android.arch.lifecycle:runtime': ['android-arch-lifecycle-runtime', 'arch-lifecycle/runtime'], |
| 110 | 'android.arch.lifecycle:viewmodel': ['android-arch-lifecycle-viewmodel', 'arch-lifecycle/viewmodel'], |
| 111 | 'android.arch.paging:common': ['android-arch-paging-common', 'arch-paging/common'], |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 112 | 'android.arch.paging:runtime': ['android-arch-paging-runtime', 'arch-paging/runtime'], |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 113 | 'android.arch.persistence:db': ['android-arch-persistence-db', 'arch-persistence/db'], |
| 114 | 'android.arch.persistence:db-framework': ['android-arch-persistence-db-framework', 'arch-persistence/db-framework'], |
| 115 | 'android.arch.persistence.room:common': ['android-arch-room-common', 'arch-room/common'], |
| 116 | 'android.arch.persistence.room:migration': ['android-arch-room-migration', 'arch-room/migration'], |
| 117 | 'android.arch.persistence.room:runtime': ['android-arch-room-runtime', 'arch-room/runtime'], |
| 118 | 'android.arch.persistence.room:testing': ['android-arch-room-testing', 'arch-room/testing'], |
| 119 | |
| 120 | # AndroidX |
| 121 | 'androidx.slice:slice-builders': ['androidx.slice_slice-builders', 'androidx/slice/slice-builders'], |
| 122 | 'androidx.slice:slice-core': ['androidx.slice_slice-core', 'androidx/slice/slice-core'], |
| 123 | 'androidx.slice:slice-view': ['androidx.slice_slice-view', 'androidx/slice/slice-view'], |
| 124 | 'androidx.vectordrawable:vectordrawable-animated': ['androidx.vectordrawable_vectordrawable-animated', 'androidx/vectordrawable/vectordrawable-animated'], |
| 125 | 'androidx.annotation:annotation': ['androidx.annotation_annotation', 'androidx/annotation/annotation', 'jar'], |
| 126 | 'androidx.asynclayoutinflater:asynclayoutinflater': ['androidx.asynclayoutinflater_asynclayoutinflater', 'androidx/asynclayoutinflater/asynclayoutinflater'], |
| 127 | 'androidx.car:car': ['androidx.car_car', 'androidx/car/car'], |
| 128 | 'androidx.collection:collection': ['androidx.collection_collection', 'androidx/collection/collection', 'jar'], |
| 129 | 'androidx.core:core': ['androidx.core_core', 'androidx/core/core'], |
| 130 | 'androidx.contentpaging:contentpaging': ['androidx.contentpaging_contentpaging', 'androidx/contentpaging/contentpaging'], |
| 131 | 'androidx.coordinatorlayout:coordinatorlayout': ['androidx.coordinatorlayout_coordinatorlayout', 'androidx/coordinatorlayout/coordinatorlayout'], |
| 132 | 'androidx.legacy:legacy-support-core-ui': ['androidx.legacy_legacy-support-core-ui', 'androidx/legacy/legacy-support-core-ui'], |
| 133 | 'androidx.legacy:legacy-support-core-utils': ['androidx.legacy_legacy-support-core-utils', 'androidx/legacy/legacy-support-core-utils'], |
| 134 | 'androidx.cursoradapter:cursoradapter': ['androidx.cursoradapter_cursoradapter', 'androidx/cursoradapter/cursoradapter'], |
| 135 | 'androidx.browser:browser': ['androidx.browser_browser', 'androidx/browser/browser'], |
| 136 | 'androidx.customview:customview': ['androidx.customview_customview', 'androidx/customview/customview'], |
| 137 | 'androidx.documentfile:documentfile': ['androidx.documentfile_documentfile', 'androidx/documentfile/documentfile'], |
| 138 | 'androidx.drawerlayout:drawerlayout': ['androidx.drawerlayout_drawerlayout', 'androidx/drawerlayout/drawerlayout'], |
| 139 | 'androidx.dynamicanimation:dynamicanimation': ['androidx.dynamicanimation_dynamicanimation', 'androidx/dynamicanimation/dynamicanimation'], |
| 140 | 'androidx.emoji:emoji': ['androidx.emoji_emoji', 'androidx/emoji/emoji'], |
| 141 | 'androidx.emoji:emoji-appcompat': ['androidx.emoji_emoji-appcompat', 'androidx/emoji/emoji-appcompat'], |
| 142 | 'androidx.emoji:emoji-bundled': ['androidx.emoji_emoji-bundled', 'androidx/emoji/emoji-bundled'], |
| 143 | 'androidx.exifinterface:exifinterface': ['androidx.exifinterface_exifinterface', 'androidx/exifinterface/exifinterface'], |
| 144 | 'androidx.fragment:fragment': ['androidx.fragment_fragment', 'androidx/fragment/fragment'], |
| 145 | 'androidx.heifwriter:heifwriter': ['androidx.heifwriter_heifwriter', 'androidx/heifwriter/heifwriter'], |
| 146 | 'androidx.interpolator:interpolator': ['androidx.interpolator_interpolator', 'androidx/interpolator/interpolator'], |
| 147 | 'androidx.loader:loader': ['androidx.loader_loader', 'androidx/loader/loader'], |
| 148 | 'androidx.localbroadcastmanager:localbroadcastmanager': ['androidx.localbroadcastmanager_localbroadcastmanager', 'androidx/localbroadcastmanager/localbroadcastmanager'], |
| 149 | 'androidx.media:media': ['androidx.media_media', 'androidx/media/media'], |
| 150 | 'androidx.percentlayout:percentlayout': ['androidx.percentlayout_percentlayout', 'androidx/percentlayout/percentlayout'], |
| 151 | 'androidx.print:print': ['androidx.print_print', 'androidx/print/print'], |
| 152 | 'androidx.recommendation:recommendation': ['androidx.recommendation_recommendation', 'androidx/recommendation/recommendation'], |
| 153 | 'androidx.recyclerview:recyclerview-selection': ['androidx.recyclerview_recyclerview-selection', 'androidx/recyclerview/recyclerview-selection'], |
| 154 | 'androidx.slidingpanelayout:slidingpanelayout': ['androidx.slidingpanelayout_slidingpanelayout', 'androidx/slidingpanelayout/slidingpanelayout'], |
| 155 | 'androidx.swiperefreshlayout:swiperefreshlayout': ['androidx.swiperefreshlayout_swiperefreshlayout', 'androidx/swiperefreshlayout/swiperefreshlayout'], |
| 156 | 'androidx.textclassifier:textclassifier': ['androidx.textclassifier_textclassifier', 'androidx/textclassifier/textclassifier'], |
| 157 | 'androidx.transition:transition': ['androidx.transition_transition', 'androidx/transition/transition'], |
| 158 | 'androidx.tvprovider:tvprovider': ['androidx.tvprovider_tvprovider', 'androidx/tvprovider/tvprovider'], |
| 159 | 'androidx.legacy:legacy-support-v13': ['androidx.legacy_legacy-support-v13', 'androidx/legacy/legacy-support-v13'], |
| 160 | 'androidx.legacy:legacy-preference-v14': ['androidx.legacy_legacy-preference-v14', 'androidx/legacy/legacy-preference-v14'], |
| 161 | 'androidx.leanback:leanback': ['androidx.leanback_leanback', 'androidx/leanback/leanback'], |
| 162 | 'androidx.leanback:leanback-preference': ['androidx.leanback_leanback-preference', 'androidx/leanback/leanback-preference'], |
| 163 | 'androidx.legacy:legacy-support-v4': ['androidx.legacy_legacy-support-v4', 'androidx/legacy/legacy-support-v4'], |
| 164 | 'androidx.appcompat:appcompat': ['androidx.appcompat_appcompat', 'androidx/appcompat/appcompat'], |
| 165 | 'androidx.cardview:cardview': ['androidx.cardview_cardview', 'androidx/cardview/cardview'], |
| 166 | 'androidx.gridlayout:gridlayout': ['androidx.gridlayout_gridlayout', 'androidx/gridlayout/gridlayout'], |
| 167 | 'androidx.mediarouter:mediarouter': ['androidx.mediarouter_mediarouter', 'androidx/mediarouter/mediarouter'], |
| 168 | 'androidx.palette:palette': ['androidx.palette_palette', 'androidx/palette/palette'], |
| 169 | 'androidx.preference:preference': ['androidx.preference_preference', 'androidx/preference/preference'], |
| 170 | 'androidx.recyclerview:recyclerview': ['androidx.recyclerview_recyclerview', 'androidx/recyclerview/recyclerview'], |
| 171 | 'androidx.vectordrawable:vectordrawable': ['androidx.vectordrawable_vectordrawable', 'androidx/vectordrawable/vectordrawable'], |
| 172 | 'androidx.viewpager:viewpager': ['androidx.viewpager_viewpager', 'androidx/viewpager/viewpager'], |
| 173 | 'androidx.wear:wear': ['androidx.wear_wear', 'androidx/wear/wear'], |
| 174 | 'androidx.webkit:webkit': ['androidx.webkit_webkit', 'androidx/webkit/webkit'], |
| 175 | |
| 176 | # AndroidX for Multidex |
| 177 | 'androidx.multidex:multidex': ['androidx-multidex_multidex', 'androidx/multidex/multidex'], |
| 178 | 'androidx.multidex:multidex-instrumentation': ['androidx-multidex_multidex-instrumentation', 'androidx/multidex/multidex-instrumentation'], |
| 179 | |
| 180 | # AndroidX for Constraint Layout |
| 181 | 'androidx.constraintlayout:constraintlayout': ['androidx-constraintlayout_constraintlayout', 'androidx/constraintlayout/constraintlayout'], |
| 182 | 'androidx.constraintlayout:constraintlayout-solver': ['androidx-constraintlayout_constraintlayout-solver', 'androidx/constraintlayout/constraintlayout-solver'], |
| 183 | |
| 184 | # AndroidX for Architecture Components |
| 185 | 'androidx.arch.core:core-common': ['androidx.arch.core_core-common', 'androidx/arch/core/core-common'], |
| 186 | 'androidx.arch.core:core-runtime': ['androidx.arch.core_core-runtime', 'androidx/arch/core/core-runtime'], |
| 187 | 'androidx.lifecycle:lifecycle-common': ['androidx.lifecycle_lifecycle-common', 'androidx/lifecycle/lifecycle-common'], |
| 188 | 'androidx.lifecycle:lifecycle-common-java8': ['androidx.lifecycle_lifecycle-common-java8', 'androidx/lifecycle/lifecycle-common-java8'], |
| 189 | 'androidx.lifecycle:lifecycle-extensions': ['androidx.lifecycle_lifecycle-extensions', 'androidx/lifecycle/lifecycle-extensions'], |
| 190 | 'androidx.lifecycle:lifecycle-livedata': ['androidx.lifecycle_lifecycle-livedata', 'androidx/lifecycle/lifecycle-livedata'], |
| 191 | 'androidx.lifecycle:lifecycle-livedata-core': ['androidx.lifecycle_lifecycle-livedata-core', 'androidx/lifecycle/lifecycle-livedata-core'], |
| 192 | 'androidx.lifecycle:lifecycle-runtime': ['androidx.lifecycle_lifecycle-runtime', 'androidx/lifecycle/lifecycle-runtime'], |
| 193 | 'androidx.lifecycle:lifecycle-viewmodel': ['androidx.lifecycle_lifecycle-viewmodel', 'androidx/lifecycle/lifecycle-viewmodel'], |
| 194 | 'androidx.paging:paging-common': ['androidx.paging_paging-common', 'androidx/paging/paging-common'], |
| 195 | 'androidx.paging:paging-runtime': ['androidx.paging_paging-runtime', 'androidx/paging/paging-runtime'], |
| 196 | 'androidx.sqlite:sqlite': ['androidx.sqlite_sqlite', 'androidx/sqlite/sqlite'], |
| 197 | 'androidx.sqlite:sqlite-framework': ['androidx.sqlite_sqlite-framework', 'androidx/sqlite/sqlite-framework'], |
| 198 | 'androidx.room:room-common': ['androidx.room_room-common', 'androidx/room/room-common'], |
| 199 | 'androidx.room:room-migration': ['androidx.room_room-migration', 'androidx/room/room-migration'], |
| 200 | 'androidx.room:room-runtime': ['androidx.room_room-runtime', 'androidx/room/room-runtime'], |
| 201 | 'androidx.room:room-testing': ['androidx.room_room-testing', 'androidx/room/room-testing'], |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 202 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 203 | # Lifecycle |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 204 | # Missing dependencies: |
| 205 | # - auto-common |
| 206 | # - javapoet |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 207 | #'android.arch.lifecycle:compiler': ['android-arch-lifecycle-compiler', 'arch-lifecycle/compiler'], |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 208 | # Missing dependencies: |
| 209 | # - reactive-streams |
| 210 | #'android.arch.lifecycle:reactivestreams': ['android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams'], |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 211 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 212 | # Room |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 213 | # Missing dependencies: |
| 214 | # - auto-common |
| 215 | # - javapoet |
| 216 | # - antlr4 |
| 217 | # - kotlin-metadata |
| 218 | # - commons-codec |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 219 | #'android.arch.persistence.room:compiler': ['android-arch-room-compiler', 'arch-room/compiler'], |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 220 | # Missing dependencies: |
| 221 | # - rxjava |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 222 | #'android.arch.persistence.room:rxjava2': ['android-arch-room-rxjava2', 'arch-room/rxjava2'], |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 223 | |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 224 | # Third-party dependencies |
| 225 | 'com.google.android:flexbox': ['flexbox', 'flexbox'], |
| 226 | |
| 227 | # Support Library Material Design Components |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 228 | 'com.android.support:design': ['android-support-design', 'design'], |
| 229 | 'com.android.support:design-animation': ['android-support-design-animation', 'design-animation'], |
| 230 | 'com.android.support:design-bottomnavigation': ['android-support-design-bottomnavigation', 'design-bottomnavigation'], |
| 231 | 'com.android.support:design-bottomsheet': ['android-support-design-bottomsheet', 'design-bottomsheet'], |
| 232 | 'com.android.support:design-button': ['android-support-design-button', 'design-button'], |
| 233 | 'com.android.support:design-canvas': ['android-support-design-canvas', 'design-canvas'], |
| 234 | 'com.android.support:design-card': ['android-support-design-card', 'design-card'], |
| 235 | 'com.android.support:design-chip': ['android-support-design-chip', 'design-chip'], |
| 236 | 'com.android.support:design-circularreveal': ['android-support-design-circularreveal', 'design-circularreveal'], |
| 237 | 'com.android.support:design-circularreveal-cardview': ['android-support-design-circularreveal-cardview', 'design-circularreveal-cardview'], |
| 238 | 'com.android.support:design-circularreveal-coordinatorlayout': ['android-support-design-circularreveal-coordinatorlayout', 'design-circularreveal-coordinatorlayout'], |
| 239 | 'com.android.support:design-color': ['android-support-design-color', 'design-color'], |
| 240 | 'com.android.support:design-dialog': ['android-support-design-dialog', 'design-dialog'], |
| 241 | 'com.android.support:design-drawable': ['android-support-design-drawable', 'design-drawable'], |
| 242 | 'com.android.support:design-expandable': ['android-support-design-expandable', 'design-expandable'], |
| 243 | 'com.android.support:design-floatingactionbutton': ['android-support-design-floatingactionbutton', 'design-floatingactionbutton'], |
| 244 | 'com.android.support:design-internal': ['android-support-design-internal', 'design-internal'], |
| 245 | 'com.android.support:design-math': ['android-support-design-math', 'design-math'], |
| 246 | 'com.android.support:design-resources': ['android-support-design-resources', 'design-resources'], |
| 247 | 'com.android.support:design-ripple': ['android-support-design-ripple', 'design-ripple'], |
| 248 | 'com.android.support:design-snackbar': ['android-support-design-snackbar', 'design-snackbar'], |
| 249 | 'com.android.support:design-stateful': ['android-support-design-stateful', 'design-stateful'], |
| 250 | 'com.android.support:design-textfield': ['android-support-design-textfield', 'design-textfield'], |
| 251 | 'com.android.support:design-theme': ['android-support-design-theme', 'design-theme'], |
| 252 | 'com.android.support:design-transformation': ['android-support-design-transformation', 'design-transformation'], |
| 253 | 'com.android.support:design-typography': ['android-support-design-typography', 'design-typography'], |
| 254 | 'com.android.support:design-widget': ['android-support-design-widget', 'design-widget'], |
| 255 | 'com.android.support:design-navigation': ['android-support-design-navigation', 'design-navigation'], |
| 256 | 'com.android.support:design-tabs': ['android-support-design-tabs', 'design-tabs'], |
| 257 | 'com.android.support:design-bottomappbar': ['android-support-design-bottomappbar', 'design-bottomappbar'], |
| 258 | 'com.android.support:design-shape': ['android-support-design-shape', 'design-shape'], |
Alan Viverette | a59082b | 2018-02-22 10:27:46 -0500 | [diff] [blame] | 259 | |
Jeff Gaston | fa7c7e8 | 2018-04-06 13:35:48 -0400 | [diff] [blame] | 260 | # Androidx Material Design Components |
| 261 | 'com.google.android.material:material': ['androidx.material_material', 'com/google/android/material/material'], |
| 262 | |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 263 | # Intermediate-AndroidX Material Design Components |
| 264 | 'com.android.temp.support:design': ['androidx.design_design', 'com/android/temp/support/design/design'], |
| 265 | 'com.android.temp.support:design-animation': ['androidx.design_design-animation', 'com/android/temp/support/design/design-animation'], |
| 266 | 'com.android.temp.support:design-bottomnavigation': ['androidx.design_design-bottomnavigation', 'com/android/temp/support/design/design-bottomnavigation'], |
| 267 | 'com.android.temp.support:design-bottomsheet': ['androidx.design_design-bottomsheet', 'com/android/temp/support/design/design-bottomsheet'], |
| 268 | 'com.android.temp.support:design-button': ['androidx.design_design-button', 'com/android/temp/support/design/design-button'], |
| 269 | 'com.android.temp.support:design-canvas': ['androidx.design_design-canvas', 'com/android/temp/support/design/design-canvas'], |
| 270 | 'com.android.temp.support:design-card': ['androidx.design_design-card', 'com/android/temp/support/design/design-card'], |
| 271 | 'com.android.temp.support:design-chip': ['androidx.design_design-chip', 'com/android/temp/support/design/design-chip'], |
| 272 | 'com.android.temp.support:design-circularreveal': ['androidx.design_design-circularreveal', 'com/android/temp/support/design/design-circularreveal'], |
| 273 | 'com.android.temp.support:design-circularreveal-cardview': ['androidx.design_design-circularreveal-cardview', 'com/android/temp/support/design/design-circularreveal-cardview'], |
| 274 | 'com.android.temp.support:design-circularreveal-coordinatorlayout': ['androidx.design_design-circularreveal-coordinatorlayout', 'com/android/temp/support/design/design-circularreveal-coordinatorlayout'], |
| 275 | 'com.android.temp.support:design-color': ['androidx.design_design-color', 'com/android/temp/support/design/design-color'], |
| 276 | 'com.android.temp.support:design-dialog': ['androidx.design_design-dialog', 'com/android/temp/support/design/design-dialog'], |
| 277 | 'com.android.temp.support:design-drawable': ['androidx.design_design-drawable', 'com/android/temp/support/design/design-drawable'], |
| 278 | 'com.android.temp.support:design-expandable': ['androidx.design_design-expandable', 'com/android/temp/support/design/design-expandable'], |
| 279 | 'com.android.temp.support:design-floatingactionbutton': ['androidx.design_design-floatingactionbutton', 'com/android/temp/support/design/design-floatingactionbutton'], |
| 280 | 'com.android.temp.support:design-internal': ['androidx.design_design-internal', 'com/android/temp/support/design/design-internal'], |
| 281 | 'com.android.temp.support:design-math': ['androidx.design_design-math', 'com/android/temp/support/design/design-math'], |
| 282 | 'com.android.temp.support:design-resources': ['androidx.design_design-resources', 'com/android/temp/support/design/design-resources'], |
| 283 | 'com.android.temp.support:design-ripple': ['androidx.design_design-ripple', 'com/android/temp/support/design/design-ripple'], |
| 284 | 'com.android.temp.support:design-snackbar': ['androidx.design_design-snackbar', 'com/android/temp/support/design/design-snackbar'], |
| 285 | 'com.android.temp.support:design-stateful': ['androidx.design_design-stateful', 'com/android/temp/support/design/design-stateful'], |
| 286 | 'com.android.temp.support:design-textfield': ['androidx.design_design-textfield', 'com/android/temp/support/design/design-textfield'], |
| 287 | 'com.android.temp.support:design-theme': ['androidx.design_design-theme', 'com/android/temp/support/design/design-theme'], |
| 288 | 'com.android.temp.support:design-transformation': ['androidx.design_design-transformation', 'com/android/temp/support/design/design-transformation'], |
| 289 | 'com.android.temp.support:design-typography': ['androidx.design_design-typography', 'com/android/temp/support/design/design-typography'], |
| 290 | 'com.android.temp.support:design-widget': ['androidx.design_design-widget', 'com/android/temp/support/design/design-widget'], |
| 291 | 'com.android.temp.support:design-navigation': ['androidx.design_design-navigation', 'com/android/temp/support/design/design-navigation'], |
| 292 | 'com.android.temp.support:design-tabs': ['androidx.design_design-tabs', 'com/android/temp/support/design/design-tabs'], |
| 293 | 'com.android.temp.support:design-bottomappbar': ['androidx.design_design-bottomappbar', 'com/android/temp/support/design/design-bottomappbar'], |
| 294 | 'com.android.temp.support:design-shape': ['androidx.design_design-shape', 'com/android/temp/support/design/design-shape'], |
| 295 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | # Always remove these files. |
| 299 | blacklist_files = [ |
| 300 | 'annotations.zip', |
| 301 | 'public.txt', |
| 302 | 'R.txt', |
Alan Viverette | 44ad4e4 | 2017-08-09 17:45:00 -0400 | [diff] [blame] | 303 | 'AndroidManifest.xml', |
Alan Viverette | f48d9b4 | 2017-08-17 14:45:46 -0400 | [diff] [blame] | 304 | os.path.join('libs','noto-emoji-compat-java.jar') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 305 | ] |
| 306 | |
Alan Viverette | 44ad4e4 | 2017-08-09 17:45:00 -0400 | [diff] [blame] | 307 | 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] | 308 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 309 | |
| 310 | class MavenLibraryInfo: |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 311 | 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] | 312 | self.key = key |
| 313 | self.group_id = group_id |
| 314 | self.artifact_id = artifact_id |
| 315 | self.version = version |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 316 | self.dir = dir |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 317 | self.repo_dir = repo_dir |
| 318 | self.file = file |
| 319 | |
| 320 | |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 321 | def print_e(*args, **kwargs): |
| 322 | print(*args, file=sys.stderr, **kwargs) |
| 323 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 324 | |
| 325 | def touch(fname, times=None): |
| 326 | with open(fname, 'a'): |
| 327 | os.utime(fname, times) |
| 328 | |
| 329 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 330 | def path(*path_parts): |
| 331 | return reduce((lambda x, y: os.path.join(x, y)), path_parts) |
| 332 | |
| 333 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 334 | def flatten(list): |
| 335 | return reduce((lambda x, y: "%s %s" % (x, y)), list) |
| 336 | |
| 337 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 338 | def rm(path): |
| 339 | if os.path.isdir(path): |
| 340 | rmtree(path) |
| 341 | elif os.path.exists(path): |
| 342 | os.remove(path) |
| 343 | |
| 344 | |
| 345 | def mv(src_path, dst_path): |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 346 | if os.path.exists(dst_path): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 347 | rm(dst_path) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 348 | if not os.path.exists(os.path.dirname(dst_path)): |
| 349 | os.makedirs(os.path.dirname(dst_path)) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 350 | os.rename(src_path, dst_path) |
| 351 | |
| 352 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 353 | def detect_artifacts(maven_repo_dirs): |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 354 | maven_lib_info = {} |
| 355 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 356 | # Find the latest revision for each artifact, remove others |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 357 | for repo_dir in maven_repo_dirs: |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 358 | for root, dirs, files in os.walk(repo_dir): |
| 359 | for file in files: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 360 | if file[-4:] == ".pom": |
| 361 | # Read the POM (hack hack hack). |
| 362 | group_id = '' |
| 363 | artifact_id = '' |
| 364 | version = '' |
| 365 | file = os.path.join(root, file) |
| 366 | with open(file) as pom_file: |
| 367 | for line in pom_file: |
| 368 | if line[:11] == ' <groupId>': |
| 369 | group_id = line[11:-11] |
| 370 | elif line[:14] == ' <artifactId>': |
| 371 | artifact_id = line[14:-14] |
| 372 | elif line[:11] == ' <version>': |
| 373 | version = line[11:-11] |
| 374 | if group_id == '' or artifact_id == '' or version == '': |
| 375 | print_e('Failed to find Maven artifact data in ' + file) |
| 376 | continue |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 377 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 378 | # Locate the artifact. |
| 379 | artifact_file = file[:-4] |
| 380 | if os.path.exists(artifact_file + '.jar'): |
| 381 | artifact_file = artifact_file + '.jar' |
| 382 | elif os.path.exists(artifact_file + '.aar'): |
| 383 | artifact_file = artifact_file + '.aar' |
| 384 | else: |
| 385 | print_e('Failed to find artifact for ' + artifact_file) |
| 386 | continue |
| 387 | |
| 388 | # Make relative to root. |
| 389 | artifact_file = artifact_file[len(root) + 1:] |
| 390 | |
| 391 | # Find the mapping. |
| 392 | group_artifact = group_id + ':' + artifact_id |
Jeff Gaston | 3e622ba | 2018-03-26 23:24:46 -0400 | [diff] [blame] | 393 | if group_artifact in maven_to_make: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 394 | key = group_artifact |
Jeff Gaston | 3e622ba | 2018-03-26 23:24:46 -0400 | [diff] [blame] | 395 | elif artifact_id in maven_to_make: |
| 396 | key = artifact_id |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 397 | else: |
| 398 | print_e('Failed to find artifact mapping for ' + group_artifact) |
| 399 | continue |
| 400 | |
| 401 | # Store the latest version. |
| 402 | version = LooseVersion(version) |
| 403 | if key not in maven_lib_info \ |
| 404 | or version > maven_lib_info[key].version: |
| 405 | maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version, |
| 406 | root, repo_dir, artifact_file) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 407 | |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 408 | return maven_lib_info |
| 409 | |
| 410 | |
Jeff Gaston | 1cc0609 | 2018-03-28 15:51:02 -0400 | [diff] [blame] | 411 | def transform_maven_repos(maven_repo_dirs, transformed_dir, extract_res=True, include_static_deps=False): |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 412 | cwd = os.getcwd() |
| 413 | |
| 414 | # Use a temporary working directory. |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 415 | maven_lib_info = detect_artifacts(maven_repo_dirs) |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 416 | working_dir = temp_dir |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 417 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 418 | if not maven_lib_info: |
| 419 | print_e('Failed to detect artifacts') |
| 420 | return False |
| 421 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 422 | # extract some files (for example, AndroidManifest.xml) from any relevant artifacts |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 423 | for info in maven_lib_info.values(): |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 424 | transform_maven_lib(working_dir, info, extract_res) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 425 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 426 | # generate a single Android.mk that specifies to use all of the above artifacts |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 427 | makefile = os.path.join(working_dir, 'Android.mk') |
| 428 | with open(makefile, 'w') as f: |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 429 | args = ["pom2mk", "-sdk-version", "current"] |
Jeff Gaston | 1cc0609 | 2018-03-28 15:51:02 -0400 | [diff] [blame] | 430 | if include_static_deps: |
| 431 | args.append("-static-deps") |
Jeff Gaston | 7ec1d8f | 2018-03-27 00:25:12 -0400 | [diff] [blame] | 432 | rewriteNames = [name for name in maven_to_make if ":" in name] + [name for name in maven_to_make if ":" not in name] |
| 433 | args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name][0] for name in rewriteNames]) |
Jeff Gaston | 7ec1d8f | 2018-03-27 00:25:12 -0400 | [diff] [blame] | 434 | args.extend(["."]) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 435 | subprocess.check_call(args, stdout=f, cwd=working_dir) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 436 | |
Jeff Gaston | f12f3ce | 2018-03-23 16:41:24 -0400 | [diff] [blame] | 437 | global rerun_extract_deps |
| 438 | rerun_extract_deps = True |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 439 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 440 | # Replace the old directory. |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 441 | output_dir = os.path.join(cwd, transformed_dir) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 442 | mv(working_dir, output_dir) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 443 | return True |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 444 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 445 | # 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] | 446 | def transform_maven_lib(working_dir, artifact_info, extract_res): |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 447 | # Move library into working dir |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame^] | 448 | 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] | 449 | mv(artifact_info.dir, new_dir) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 450 | |
| 451 | for dirpath, dirs, files in os.walk(new_dir): |
| 452 | for f in files: |
| 453 | if '-sources.jar' in f: |
| 454 | os.remove(os.path.join(dirpath, f)) |
| 455 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 456 | matcher = artifact_pattern.match(artifact_info.file) |
| 457 | maven_lib_name = artifact_info.key |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 458 | maven_lib_vers = matcher.group(2) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 459 | maven_lib_type = artifact_info.file[-3:] |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 460 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 461 | make_lib_name = maven_to_make[artifact_info.key][0] |
| 462 | make_dir_name = maven_to_make[artifact_info.key][1] |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 463 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 464 | artifact_file = os.path.join(new_dir, artifact_info.file) |
| 465 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 466 | if extract_res: |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 467 | target_dir = os.path.join(working_dir, make_dir_name) |
| 468 | if not os.path.exists(target_dir): |
| 469 | os.makedirs(target_dir) |
| 470 | |
| 471 | if maven_lib_type == "aar": |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 472 | process_aar(artifact_file, target_dir) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 473 | |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 474 | with zipfile.ZipFile(artifact_file) as zip: |
| 475 | manifests_dir = os.path.join(working_dir, "manifests") |
| 476 | zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name)) |
Dan Willemsen | d677b60 | 2017-11-08 22:13:17 -0800 | [diff] [blame] | 477 | |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 478 | print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 479 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 480 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 481 | def process_aar(artifact_file, target_dir): |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 482 | # Extract AAR file to target_dir. |
| 483 | with zipfile.ZipFile(artifact_file) as zip: |
| 484 | zip.extractall(target_dir) |
| 485 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 486 | # Remove classes.jar |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 487 | classes_jar = os.path.join(target_dir, "classes.jar") |
| 488 | if os.path.exists(classes_jar): |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 489 | os.remove(classes_jar) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 490 | |
| 491 | # Remove or preserve empty dirs. |
| 492 | for root, dirs, files in os.walk(target_dir): |
| 493 | for dir in dirs: |
| 494 | dir_path = os.path.join(root, dir) |
| 495 | if not os.listdir(dir_path): |
| 496 | os.rmdir(dir_path) |
| 497 | |
| 498 | # Remove top-level cruft. |
| 499 | for file in blacklist_files: |
| 500 | file_path = os.path.join(target_dir, file) |
| 501 | if os.path.exists(file_path): |
| 502 | os.remove(file_path) |
| 503 | |
Alan Viverette | f17c940 | 2017-07-19 12:57:40 -0400 | [diff] [blame] | 504 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 505 | def fetch_artifact(target, build_id, artifact_path): |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 506 | print('Fetching %s from %s...' % (artifact_path, target)) |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 507 | fetch_cmd = [FETCH_ARTIFACT, '--bid', str(build_id), '--target', target, artifact_path] |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 508 | try: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 509 | subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 510 | except subprocess.CalledProcessError: |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 511 | 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] | 512 | print_e('Please make sure you are authenticated for build server access!') |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 513 | return None |
| 514 | return artifact_path |
| 515 | |
| 516 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 517 | def fetch_artifacts(target, build_id, artifact_dict): |
| 518 | for artifact, target_path in artifact_dict.items(): |
| 519 | artifact_path = fetch_artifact(target, build_id.url_id, artifact) |
| 520 | if not artifact_path: |
| 521 | return False |
| 522 | mv(artifact_path, target_path) |
| 523 | return True |
| 524 | |
| 525 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 526 | def extract_artifact(artifact_path): |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 527 | # Unzip the repo archive into a separate directory. |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 528 | repo_dir = os.path.basename(artifact_path)[:-4] |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 529 | with zipfile.ZipFile(artifact_path) as zipFile: |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 530 | zipFile.extractall(repo_dir) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 531 | return repo_dir |
| 532 | |
| 533 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 534 | def fetch_and_extract(target, build_id, file, artifact_path=None): |
| 535 | if not artifact_path: |
| 536 | artifact_path = fetch_artifact(target, build_id, file) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 537 | if not artifact_path: |
| 538 | return None |
| 539 | return extract_artifact(artifact_path) |
| 540 | |
| 541 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 542 | def update_support(target, build_id, local_file): |
| 543 | if build_id: |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 544 | repo_file = 'top-of-tree-m2repository-dejetified-%s.zip' % build_id.fs_id |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 545 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None) |
| 546 | else: |
| 547 | repo_dir = fetch_and_extract(target, None, None, local_file) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 548 | if not repo_dir: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 549 | print_e('Failed to extract Support Library repository') |
Alan Viverette | f48d9b4 | 2017-08-17 14:45:46 -0400 | [diff] [blame] | 550 | return False |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 551 | |
| 552 | # Transform the repo archive into a Makefile-compatible format. |
Jeff Gaston | 1cc0609 | 2018-03-28 15:51:02 -0400 | [diff] [blame] | 553 | return transform_maven_repos([repo_dir], support_dir, extract_res=True, include_static_deps=True) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 554 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 555 | |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 556 | def update_androidx(target, target_toolkit, build_id, local_file): |
| 557 | if build_id: |
| 558 | repo_file = 'top-of-tree-m2repository-%s.zip' % build_id.fs_id |
| 559 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None) |
| 560 | else: |
| 561 | repo_dir = fetch_and_extract(target, None, None, local_file) |
| 562 | if not repo_dir: |
| 563 | print_e('Failed to extract AndroidX repository') |
| 564 | return False |
| 565 | |
| 566 | if build_id: |
| 567 | repo_file2 = 'top-of-tree-m2repository-%s.zip' % build_id.fs_id |
| 568 | repo_dir2 = fetch_and_extract(target_toolkit, build_id.url_id, repo_file2, None) |
| 569 | else: |
| 570 | repo_dir2 = fetch_and_extract(target_toolkit, None, None, local_file) |
| 571 | if not repo_dir2: |
| 572 | print_e('Failed to extract AndroidX app-toolkit repository') |
| 573 | return False |
| 574 | |
| 575 | # Transform the repo archive into a Makefile-compatible format. |
| 576 | return transform_maven_repos([repo_dir, repo_dir2], androidx_dir, extract_res=False) |
| 577 | |
| 578 | |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 579 | def update_jetifier(target, build_id): |
| 580 | repo_file = 'jetifier-standalone.zip' |
| 581 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file) |
| 582 | if not repo_dir: |
| 583 | print_e('Failed to extract Jetifier') |
| 584 | return False |
| 585 | |
| 586 | rm(jetifier_dir) |
Jeff Gaston | 553a437 | 2018-03-29 18:34:22 -0400 | [diff] [blame] | 587 | mv(os.path.join(repo_dir, 'jetifier-standalone'), jetifier_dir) |
| 588 | os.chmod(os.path.join(jetifier_dir, 'bin', 'jetifier-standalone'), 0o755) |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 589 | return True |
| 590 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 591 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 592 | def update_toolkit(target, build_id): |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 593 | repo_dir = fetch_and_extract(target, build_id.url_id, \ |
| 594 | 'top-of-tree-m2repository-dejetified-%s.zip' % build_id.fs_id) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 595 | if not repo_dir: |
| 596 | print_e('Failed to extract App Toolkit repository') |
| 597 | return False |
| 598 | |
| 599 | # Transform the repo archive into a Makefile-compatible format. |
Jeff Gaston | 1cc0609 | 2018-03-28 15:51:02 -0400 | [diff] [blame] | 600 | return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'app-toolkit'), extract_res=True, include_static_deps=True) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 601 | |
| 602 | |
| 603 | def update_constraint(target, build_id): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 604 | layout_dir = fetch_and_extract(target, build_id.url_id, |
| 605 | 'com.android.support.constraint-constraint-layout-%s.zip' % build_id.fs_id) |
| 606 | solver_dir = fetch_and_extract(target, build_id.url_id, |
| 607 | 'com.android.support.constraint-constraint-layout-solver-%s.zip' % build_id.fs_id) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 608 | if not layout_dir or not solver_dir: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 609 | print_e('Failed to extract Constraint Layout repositories') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 610 | return False |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 611 | |
| 612 | # Passing False here is an inelegant solution, but it means we can replace |
| 613 | # the top-level directory without worrying about other child directories. |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 614 | return transform_maven_repos([layout_dir, solver_dir], |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 615 | os.path.join(extras_dir, 'constraint-layout'), extract_res=False) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 616 | |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame^] | 617 | def update_constraint_x(local_file): |
| 618 | repo_dir = extract_artifact(local_file) |
| 619 | if not repo_dir: |
| 620 | print_e('Failed to extract Constraint Layout X') |
| 621 | return False |
| 622 | return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'constraint-layout-x'), extract_res=False) |
| 623 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 624 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 625 | def update_design(file): |
| 626 | design_dir = extract_artifact(file) |
| 627 | if not design_dir: |
| 628 | print_e('Failed to extract Design Library repositories') |
| 629 | return False |
| 630 | |
| 631 | # Don't bother extracting resources -- this should only be used with AAPT2. |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 632 | return transform_maven_repos([design_dir], |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 633 | os.path.join(extras_dir, 'material-design'), extract_res=False) |
| 634 | |
| 635 | |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 636 | def update_material(file): |
| 637 | design_dir = extract_artifact(file) |
| 638 | if not design_dir: |
| 639 | print_e('Failed to extract intermediate-AndroidX Design Library repositories') |
| 640 | return False |
| 641 | |
| 642 | # Don't bother extracting resources -- this should only be used with AAPT2. |
| 643 | return transform_maven_repos([design_dir], |
| 644 | os.path.join(extras_dir, 'material-design-x'), extract_res=False) |
| 645 | |
| 646 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 647 | def extract_to(zip_file, filename, parent_path): |
| 648 | zip_path = next(filter(lambda path: filename in path, zip_file.namelist())) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 649 | src_path = zip_file.extract(zip_path) |
| 650 | dst_path = path(parent_path, filename) |
| 651 | mv(src_path, dst_path) |
| 652 | |
| 653 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 654 | # This is a dict from an sdk level to an "artifact dict". The artifact dict |
| 655 | # maps from artifact name to the respective package it stubs. |
| 656 | # TODO(hansson): standardize the artifact names and remove this dict. |
| 657 | sdk_artifacts_dict = { |
| 658 | 'core': { |
| 659 | 'core.current.stubs.jar': 'android.jar', |
| 660 | }, |
| 661 | 'public': { |
| 662 | 'android.test.base.stubs.jar': 'android.test.base.jar', |
| 663 | 'android.test.runner.stubs.jar': 'android.test.runner.jar', |
| 664 | 'android.test.mock.stubs.jar': 'android.test.mock.jar', |
| 665 | 'org.apache.http.legacy.jar': 'org.apache.http.legacy.jar', |
| 666 | }, |
| 667 | 'system': { |
| 668 | 'android_system.jar': 'android.jar', |
| 669 | 'android.test.mock.stubs_system.jar': 'android.test.mock.jar', |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | |
| 674 | # TODO(hansson): Remove this method once the tools support the new structure. |
| 675 | def update_framework_current_legacy(build_id): |
| 676 | sdk_artifact = 'sdk-repo-darwin-platforms-%s.zip' % build_id.fs_id |
| 677 | artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, sdk_artifact) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 678 | if not artifact_path: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 679 | return False |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 680 | |
| 681 | with zipfile.ZipFile(artifact_path) as zipFile: |
| 682 | paths = zipFile.namelist() |
| 683 | |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 684 | filenames = ['android.jar', 'uiautomator.jar', 'framework.aidl', |
| 685 | 'optional/android.test.base.jar', 'optional/android.test.mock.jar', |
| 686 | 'optional/android.test.runner.jar'] |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 687 | |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 688 | for filename in filenames: |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 689 | extract_to(zipFile, filename, current_path) |
Jiyong Park | b773d29 | 2018-01-30 23:33:19 +0900 | [diff] [blame] | 690 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 691 | # There's no system version of framework.aidl, so use the public one. |
| 692 | extract_to(zipFile, 'framework.aidl', system_path) |
Jiyong Park | b773d29 | 2018-01-30 23:33:19 +0900 | [diff] [blame] | 693 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 694 | artifact_dict = { |
| 695 | 'core.current.stubs.jar': path(current_path, 'core.jar'), |
| 696 | 'android_system.jar': path(system_path, 'android.jar'), |
| 697 | 'android.test.mock.stubs_system.jar': path(system_path, 'optional/android.test.mock.jar'), |
| 698 | } |
| 699 | return fetch_artifacts(framework_sdk_target, build_id, artifact_dict) |
| 700 | |
| 701 | |
| 702 | def update_framework(build_id, sdk_dir): |
| 703 | for api_level in ['core', 'public', 'system']: |
| 704 | target_dir = path(sdk_dir, api_level) |
| 705 | artifact_to_filename = sdk_artifacts_dict[api_level] |
| 706 | artifact_to_path = {artifact: path(target_dir, filename) |
| 707 | for (artifact, filename) in artifact_to_filename.items()} |
| 708 | |
| 709 | if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path): |
| 710 | return False |
| 711 | |
| 712 | if api_level == 'public': |
| 713 | # Fetch a few artifacts from the public sdk. |
| 714 | artifact = 'sdk-repo-darwin-platforms-%s.zip' % build_id.fs_id |
| 715 | artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, artifact) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 716 | if not artifact_path: |
| 717 | return False |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 718 | |
| 719 | with zipfile.ZipFile(artifact_path) as zipFile: |
| 720 | for filename in ['android.jar', 'framework.aidl', 'uiautomator.jar']: |
| 721 | extract_to(zipFile, filename, target_dir) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 722 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 723 | return True |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 724 | |
| 725 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 726 | def finalize_sdk(build_id, sdk_version): |
| 727 | target_finalize_dir = '%d' % sdk_version |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 728 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 729 | extra_finalize_artifacts = { |
| 730 | 'public_api.txt': path(target_finalize_dir, 'public/api/android.txt'), |
| 731 | 'system-api.txt': path(target_finalize_dir, 'system/api/android.txt'), |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 732 | } |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 733 | return fetch_artifacts(framework_sdk_target, build_id, extra_finalize_artifacts) \ |
| 734 | and update_framework(build_id, target_finalize_dir) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 735 | |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 736 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 737 | def update_framework_current(build_id): |
| 738 | return update_framework(build_id, current_path) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 739 | |
| 740 | |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 741 | def update_buildtools(target, arch, build_id): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 742 | artifact_path = fetch_and_extract(target, build_id.url_id, |
| 743 | "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id)) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 744 | if not artifact_path: |
| 745 | return False |
| 746 | |
| 747 | top_level_dir = os.listdir(artifact_path)[0] |
| 748 | src_path = os.path.join(artifact_path, top_level_dir) |
| 749 | dst_path = path(buildtools_dir, arch) |
| 750 | mv(src_path, dst_path) |
| 751 | |
| 752 | # Move all top-level files to /bin and make them executable |
| 753 | bin_path = path(dst_path, 'bin') |
| 754 | top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path)) |
| 755 | for file in top_level_files: |
| 756 | src_file = path(dst_path, file) |
| 757 | dst_file = path(bin_path, file) |
| 758 | mv(src_file, dst_file) |
| 759 | os.chmod(dst_file, 0o755) |
| 760 | |
| 761 | # Remove renderscript |
| 762 | rm(path(dst_path, 'renderscript')) |
| 763 | |
| 764 | return True |
| 765 | |
| 766 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 767 | def append(text, more_text): |
| 768 | if text: |
| 769 | return "%s, %s" % (text, more_text) |
| 770 | return more_text |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 771 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 772 | |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 773 | class buildId(object): |
| 774 | def __init__(self, url_id, fs_id): |
| 775 | # id when used in build server urls |
| 776 | self.url_id = url_id |
| 777 | # id when used in build commands |
| 778 | self.fs_id = fs_id |
| 779 | |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 780 | def getBuildId(args): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 781 | # must be in the format 12345 or P12345 |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 782 | source = args.source |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 783 | number_text = source[:] |
| 784 | presubmit = False |
| 785 | if number_text.startswith("P"): |
| 786 | presubmit = True |
| 787 | number_text = number_text[1:] |
| 788 | if not number_text.isnumeric(): |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 789 | return None |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 790 | url_id = source |
| 791 | fs_id = url_id |
| 792 | if presubmit: |
| 793 | fs_id = "0" |
| 794 | args.file = False |
| 795 | return buildId(url_id, fs_id) |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 796 | |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 797 | def getFile(args): |
| 798 | source = args.source |
| 799 | if not source.isnumeric(): |
| 800 | return args.source |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 801 | return None |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 802 | |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 803 | |
| 804 | def script_relative(rel_path): |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 805 | return os.path.join(script_dir, rel_path) |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 806 | |
| 807 | |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 808 | def uncommittedChangesExist(): |
| 809 | try: |
| 810 | # Make sure we don't overwrite any pending changes. |
| 811 | diffCommand = "cd " + git_dir + " && git diff --quiet" |
| 812 | subprocess.check_call(diffCommand, shell=True) |
| 813 | subprocess.check_call(diffCommand + " --cached", shell=True) |
| 814 | return False |
| 815 | except subprocess.CalledProcessError: |
| 816 | return True |
| 817 | |
| 818 | |
Jeff Gaston | a7fba9b | 2018-03-26 23:48:51 -0400 | [diff] [blame] | 819 | rm(temp_dir) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 820 | parser = argparse.ArgumentParser( |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 821 | description=('Update current prebuilts')) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 822 | parser.add_argument( |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 823 | 'source', |
| 824 | help='Build server build ID or local Maven ZIP file') |
| 825 | parser.add_argument( |
| 826 | '-d', '--design', action="store_true", |
| 827 | help='If specified, updates only the Design Library') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 828 | parser.add_argument( |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 829 | '-m', '--material', action="store_true", |
| 830 | help='If specified, updates only the intermediate-AndroidX Design Library') |
| 831 | parser.add_argument( |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 832 | '-c', '--constraint', action="store_true", |
| 833 | help='If specified, updates only Constraint Layout') |
| 834 | parser.add_argument( |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame^] | 835 | '--constraint_x', action="store_true", |
| 836 | help='If specified, updates Constraint Layout X') |
| 837 | parser.add_argument( |
Alan Viverette | 5bfe05b | 2017-06-06 14:21:29 -0400 | [diff] [blame] | 838 | '-s', '--support', action="store_true", |
| 839 | help='If specified, updates only the Support Library') |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 840 | parser.add_argument( |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 841 | '-x', '--androidx', action="store_true", |
| 842 | help='If specified, updates only AndroidX') |
| 843 | parser.add_argument( |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 844 | '-j', '--jetifier', action="store_true", |
| 845 | help='If specified, updates only Jetifier') |
| 846 | parser.add_argument( |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 847 | '-t', '--toolkit', action="store_true", |
| 848 | help='If specified, updates only the App Toolkit') |
| 849 | parser.add_argument( |
Alan Viverette | 5bfe05b | 2017-06-06 14:21:29 -0400 | [diff] [blame] | 850 | '-p', '--platform', action="store_true", |
| 851 | help='If specified, updates only the Android Platform') |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 852 | parser.add_argument( |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 853 | '-f', '--finalize_sdk', type=int, |
| 854 | help='If specified, imports the source build as the specified finalized SDK version') |
| 855 | parser.add_argument( |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 856 | '-b', '--buildtools', action="store_true", |
| 857 | help='If specified, updates only the Build Tools') |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 858 | parser.add_argument( |
| 859 | '--commit-first', action="store_true", |
| 860 | help='If specified, then if uncommited changes exist, commit before continuing') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 861 | args = parser.parse_args() |
Jeff Gaston | 56fe276 | 2018-02-06 14:54:37 -0500 | [diff] [blame] | 862 | args.file = True |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 863 | if not args.source: |
| 864 | 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] | 865 | sys.exit(1) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 866 | if not (args.support or args.platform or args.constraint or args.toolkit or args.buildtools \ |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 867 | or args.design or args.jetifier or args.androidx or args.material \ |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame^] | 868 | or args.finalize_sdk or args.constraint_x): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 869 | parser.error("You must specify at least one target to update") |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 870 | sys.exit(1) |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame^] | 871 | if (args.support or args.constraint or args.constraint_x or args.toolkit or args.design or args.material or args.androidx) \ |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 872 | and which('pom2mk') is None: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 873 | parser.error("Cannot find pom2mk in path; please run lunch to set up build environment") |
| 874 | sys.exit(1) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 875 | |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 876 | if uncommittedChangesExist(): |
| 877 | if args.commit_first: |
| 878 | subprocess.check_call("cd " + git_dir + " && git add -u", shell=True) |
| 879 | subprocess.check_call("cd " + git_dir + " && git commit -m 'save working state'", shell=True) |
| 880 | |
| 881 | if uncommittedChangesExist(): |
Anton Hansson | 10861a0 | 2018-04-06 13:57:08 +0100 | [diff] [blame] | 882 | 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] | 883 | sys.exit(1) |
| 884 | |
| 885 | try: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 886 | components = None |
| 887 | if args.constraint: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 888 | if update_constraint('studio', getBuildId(args)): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 889 | components = append(components, 'Constraint Layout') |
| 890 | else: |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame^] | 891 | print_e('Failed to update Constraint Layout, aborting...') |
| 892 | sys.exit(1) |
| 893 | if args.constraint_x: |
| 894 | if update_constraint_x(getFile(args)): |
| 895 | components = append(components, 'Constraint Layout X') |
| 896 | else: |
| 897 | print_e('Failed to update Constraint Layout X, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 898 | sys.exit(1) |
| 899 | if args.support: |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 900 | if update_support('support_library', getBuildId(args), getFile(args)): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 901 | components = append(components, 'Support Library') |
| 902 | else: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 903 | print_e('Failed to update Support Library, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 904 | sys.exit(1) |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 905 | if args.androidx: |
| 906 | if update_androidx('support_library', 'support_library_app_toolkit', \ |
| 907 | getBuildId(args), getFile(args)): |
| 908 | components = append(components, 'AndroidX') |
| 909 | else: |
| 910 | print_e('Failed to update AndroidX, aborting...') |
| 911 | sys.exit(1) |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 912 | if args.jetifier: |
| 913 | if update_jetifier('support_library', getBuildId(args)): |
| 914 | components = append(components, 'Jetifier') |
| 915 | else: |
| 916 | print_e('Failed to update Jetifier, aborting...') |
| 917 | sys.exit(1) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 918 | if args.toolkit: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 919 | if update_toolkit('support_library_app_toolkit', getBuildId(args)): |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 920 | components = append(components, 'App Toolkit') |
| 921 | else: |
| 922 | print_e('Failed to update App Toolkit, aborting...') |
| 923 | sys.exit(1) |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 924 | if args.platform: |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 925 | build_id = getBuildId(args) |
| 926 | if update_framework_current_legacy(build_id) and update_framework_current(build_id): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 927 | components = append(components, 'platform SDK') |
| 928 | else: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 929 | print_e('Failed to update platform SDK, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 930 | sys.exit(1) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 931 | if args.finalize_sdk: |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 932 | if finalize_sdk(getBuildId(args), args.finalize_sdk): |
| 933 | subprocess.check_call(['git', 'add', "%d" % args.finalize_sdk]) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 934 | components = append(components, 'finalized SDK %d' % args.finalize_sdk) |
| 935 | else: |
| 936 | print_e('Failed to finalize SDK %d, aborting...' % args.finalize_sdk) |
| 937 | sys.exit(1) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 938 | if args.design: |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 939 | if update_design(getFile(args)): |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 940 | components = append(components, 'Design Library') |
| 941 | else: |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 942 | print_e('Failed to update Design Library, aborting...') |
| 943 | sys.exit(1) |
| 944 | if args.material: |
| 945 | if update_material(getFile(args)): |
| 946 | components = append(components, 'intermediate-AndroidX Design Library') |
| 947 | else: |
| 948 | print_e('Failed to update intermediate-AndroidX Design Library, aborting...') |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 949 | sys.exit(1) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 950 | if args.buildtools: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 951 | if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \ |
| 952 | and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \ |
| 953 | and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 954 | components = append(components, 'build tools') |
| 955 | else: |
| 956 | print_e('Failed to update build tools, aborting...') |
| 957 | sys.exit(1) |
Jeff Gaston | f12f3ce | 2018-03-23 16:41:24 -0400 | [diff] [blame] | 958 | if rerun_extract_deps: |
Jeff Gaston | b70daa9 | 2018-03-29 20:10:22 -0400 | [diff] [blame] | 959 | depsfile = os.path.join(current_path, 'fix_dependencies.mk') |
Jeff Gaston | f12f3ce | 2018-03-23 16:41:24 -0400 | [diff] [blame] | 960 | with open(depsfile, 'w') as f: |
Jeff Gaston | b70daa9 | 2018-03-29 20:10:22 -0400 | [diff] [blame] | 961 | cwd=os.getcwd() |
Jeff Gaston | 7bb9309 | 2018-04-09 18:16:27 -0400 | [diff] [blame] | 962 | subprocess.check_call( |
Anton Hansson | 10861a0 | 2018-04-06 13:57:08 +0100 | [diff] [blame] | 963 | './update_prebuilts/extract_deps.py current/*/Android.mk current/extras/*/Android.mk', |
Jeff Gaston | 7bb9309 | 2018-04-09 18:16:27 -0400 | [diff] [blame] | 964 | stdout=f, cwd=cwd, shell=True) |
Jeff Gaston | b70daa9 | 2018-03-29 20:10:22 -0400 | [diff] [blame] | 965 | subprocess.check_call(['git', 'add', depsfile]) |
| 966 | |
Jeff Gaston | f12f3ce | 2018-03-23 16:41:24 -0400 | [diff] [blame] | 967 | |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 968 | |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 969 | subprocess.check_call(['git', 'add', current_path, system_path, api_path, system_api_path, |
| 970 | buildtools_dir]) |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 971 | if not args.source.isnumeric(): |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 972 | src_msg = "local Maven ZIP" |
| 973 | else: |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 974 | src_msg = "build %s" % (getBuildId(args).url_id) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 975 | 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] | 976 | subprocess.check_call(['git', 'commit', '-m', msg]) |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 977 | print('Remember to test this change before uploading it to Gerrit!') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 978 | |
| 979 | finally: |
| 980 | # Revert all stray files, including the downloaded zip. |
| 981 | try: |
| 982 | with open(os.devnull, 'w') as bitbucket: |
| 983 | subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket) |
| 984 | subprocess.check_call( |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame^] | 985 | ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!', '--allow-empty'], stdout=bitbucket) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 986 | subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket) |
| 987 | except subprocess.CalledProcessError: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 988 | print_e('ERROR: Failed cleaning up, manual cleanup required!!!') |