blob: b93f6d2695b0bc1d2f40cf39dcd70d1487d6cf07 [file] [log] [blame]
Louis Pullen-Freilichafc60aa2021-05-05 17:12:38 +01001#!/usr/bin/env python3
Louis Pullen-Freilich7bcaeba2019-04-06 20:52:59 +01002
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:]:
David Saff6ccbea72021-09-01 11:03:00 -040032
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-Freilich7bcaeba2019-04-06 20:52:59 +010046
47 # No matching files
48 if not os_specific_files:
49 sys.exit(0)
50
Louis Pullen-Freilichafc60aa2021-05-05 17:12:38 +010051 print("The following operating system specific files were found in your commit:\n\033[91m")
Louis Pullen-Freilich7bcaeba2019-04-06 20:52:59 +010052 for filename in os_specific_files.values():
Louis Pullen-Freilichafc60aa2021-05-05 17:12:38 +010053 print(filename)
54 print ("""\033[0m\nPlease make sure to import the corresponding prebuilts for missing platforms.
David Saff6ccbea72021-09-01 11:03:00 -040055If you imported a prebuilt similar to foo:bar:linux, try foo:bar:osx (or foo:bar:macos),
56and vice versa.
Louis Pullen-Freilich7bcaeba2019-04-06 20:52:59 +010057If 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-Freilichafc60aa2021-05-05 17:12:38 +010059to skip this warning.""")
Louis Pullen-Freilich7bcaeba2019-04-06 20:52:59 +010060 sys.exit(1)
61
62
63if __name__ == "__main__":
64 main()