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