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