[go: nahoru, domu]

blob: 3d4c3e9ac04cab9ac5a844885dcfba2f7d0935d4 [file] [log] [blame]
Aurimas Liutikas8bd735d2019-11-14 13:11:11 -08001#!/usr/bin/python
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"""Script that will remind developers to run updateApi."""
20
21import argparse
Filip Pavlis1a467222019-11-28 18:00:53 +000022import os.path
Aurimas Liutikas8bd735d2019-11-14 13:11:11 -080023import sys
24
25
Filip Pavlis1a467222019-11-28 18:00:53 +000026
27WARNING_COLOR = '\033[33m'
Aurimas Liutikas8bd735d2019-11-14 13:11:11 -080028END_COLOR = '\033[0m'
29
Filip Pavlis1a467222019-11-28 18:00:53 +000030WARNING_NO_API_FILES = """
Aurimas Liutikas8bd735d2019-11-14 13:11:11 -080031{}**********************************************************************
32You changed library classes, but you have no current.txt changes.
33Did you forget to run ./gradlew updateApi?
34**********************************************************************{}
35""".format(WARNING_COLOR, END_COLOR)
36
Filip Pavlis1a467222019-11-28 18:00:53 +000037WARNING_OLD_API_FILES = """
38{}**********************************************************************
39Your current.txt is older than your current changes in library classes.
40Did you forget to re-run ./gradlew updateApi?
41**********************************************************************{}
42""".format(WARNING_COLOR, END_COLOR)
43
Aurimas Liutikas8bd735d2019-11-14 13:11:11 -080044
45def main(args=None):
Filip Pavlisab156412019-12-17 18:16:03 +000046 if not ('ENABLE_UPDATEAPI_WARNING' in os.environ):
47 sys.exit(0)
48
Aurimas Liutikas8bd735d2019-11-14 13:11:11 -080049 parser = argparse.ArgumentParser()
50 parser.add_argument('--file', '-f', nargs='*')
51 parser.set_defaults(format=False)
52 args = parser.parse_args()
53 api_files = [f for f in args.file
54 if f.endswith('.txt') and '/api/' in f]
Filip Pavlis1a467222019-11-28 18:00:53 +000055 source_files = [f for f in args.file
56 if (not "buildSrc/" in f and
57 "/src/main/" in f or
58 "/src/commonMain/" in f or
59 "/src/androidMain/" in f)]
60 if len(source_files) == 0:
Aurimas Liutikas8bd735d2019-11-14 13:11:11 -080061 sys.exit(0)
62
Filip Pavlis1a467222019-11-28 18:00:53 +000063 if len(api_files) == 0:
64 print(WARNING_NO_API_FILES)
65 sys.exit(77) # 77 is a warning code in repohooks
66
67 last_source_timestamp = max([os.path.getmtime(f) for f in source_files])
68 last_api_timestamp = max([os.path.getmtime(f) for f in api_files])
69
70 if last_source_timestamp > last_api_timestamp:
71 print(WARNING_OLD_API_FILES)
72 sys.exit(77) # 77 is a warning code in repohooks
Aurimas Liutikas8bd735d2019-11-14 13:11:11 -080073 sys.exit(0)
74
75if __name__ == '__main__':
76 main()