1#!/usr/bin/env python3 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 19import 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 26def 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:]: 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" 46 47 # No matching files 48 if not os_specific_files: 49 sys.exit(0) 50 51 print("The following operating system specific files were found in your commit:\n\033[91m") 52 for filename in os_specific_files.values(): 53 print(filename) 54 print ("""\033[0m\nPlease make sure to import the corresponding prebuilts for missing platforms. 55If you imported a prebuilt similar to foo:bar:linux, try foo:bar:osx (or foo:bar:macos), 56and vice versa. 57If there is no corresponding prebuilt, or only adding a prebuilt for one platform is intended, run: 58\033[92mrepo upload --no-verify\033[0m 59to skip this warning.""") 60 sys.exit(1) 61 62 63if __name__ == "__main__": 64 main() 65