Louis Pullen-Freilich | afc60aa | 2021-05-05 17:12:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Louis Pullen-Freilich | 7bcaeba | 2019-04-06 20:52:59 +0100 | [diff] [blame] | 2 | |
| 3 | # |
| 4 | # Copyright 2019, The Android Open Source Project |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | import sys |
| 20 | |
| 21 | #### #### |
| 22 | # This preupload script ensures that when an operating system specific (linux / |
| 23 | # osx) prebuilt is added to prebuilts/ the same prebuilt is available on both platforms. |
| 24 | #### #### |
| 25 | |
| 26 | def main(): |
| 27 | # Dict of file names without their platform name mapped to the full name |
| 28 | # E.g foo/bar-linux.jar would be split into foo/bar-.jar : foo/bar-linux.jar |
| 29 | os_specific_files = {} |
| 30 | |
| 31 | for filename in sys.argv[1:]: |
David Saff | 6ccbea7 | 2021-09-01 11:03:00 -0400 | [diff] [blame] | 32 | |
| 33 | # This technique makes sure that platform-specific files come in pairs. Those will usually |
| 34 | # be either osx/linux or macos/linux. Technically, if a osx/macos pair came through, we would |
| 35 | # let it through, but that seems unlikely |
| 36 | |
| 37 | for platform in ["macos", "osx", "linux"]: |
| 38 | if platform in filename: |
| 39 | stripped_filename = filename.replace(platform, "") |
| 40 | if stripped_filename in os_specific_files.keys(): |
| 41 | # Corresponding platform pair, so no need to track |
| 42 | os_specific_files.pop(stripped_filename) |
| 43 | else: |
| 44 | os_specific_files[stripped_filename] = filename |
| 45 | break # don't get hung up if file contains "macosx" |
Louis Pullen-Freilich | 7bcaeba | 2019-04-06 20:52:59 +0100 | [diff] [blame] | 46 | |
| 47 | # No matching files |
| 48 | if not os_specific_files: |
| 49 | sys.exit(0) |
| 50 | |
Louis Pullen-Freilich | afc60aa | 2021-05-05 17:12:38 +0100 | [diff] [blame] | 51 | print("The following operating system specific files were found in your commit:\n\033[91m") |
Louis Pullen-Freilich | 7bcaeba | 2019-04-06 20:52:59 +0100 | [diff] [blame] | 52 | for filename in os_specific_files.values(): |
Louis Pullen-Freilich | afc60aa | 2021-05-05 17:12:38 +0100 | [diff] [blame] | 53 | print(filename) |
| 54 | print ("""\033[0m\nPlease make sure to import the corresponding prebuilts for missing platforms. |
David Saff | 6ccbea7 | 2021-09-01 11:03:00 -0400 | [diff] [blame] | 55 | If you imported a prebuilt similar to foo:bar:linux, try foo:bar:osx (or foo:bar:macos), |
| 56 | and vice versa. |
Louis Pullen-Freilich | 7bcaeba | 2019-04-06 20:52:59 +0100 | [diff] [blame] | 57 | If there is no corresponding prebuilt, or only adding a prebuilt for one platform is intended, run: |
| 58 | \033[92mrepo upload --no-verify\033[0m |
Louis Pullen-Freilich | afc60aa | 2021-05-05 17:12:38 +0100 | [diff] [blame] | 59 | to skip this warning.""") |
Louis Pullen-Freilich | 7bcaeba | 2019-04-06 20:52:59 +0100 | [diff] [blame] | 60 | sys.exit(1) |
| 61 | |
| 62 | |
| 63 | if __name__ == "__main__": |
| 64 | main() |