forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_illegal_imports.py
45 lines (35 loc) · 1.13 KB
/
android_illegal_imports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import os
import subprocess
import sys
ANDROID_LOG_CLASS = 'android.util.Log'
FLUTTER_LOG_CLASS = 'io.flutter.Log'
def main():
parser = argparse.ArgumentParser(description='Checks Flutter Android library for forbidden imports')
parser.add_argument('--stamp', type=str, required=True)
parser.add_argument('--files', type=str, required=True, nargs='+')
args = parser.parse_args()
open(args.stamp, 'a').close()
bad_files = []
for file in args.files:
if file.endswith(os.path.join('io', 'flutter', 'Log.java')):
continue
with open(file) as f:
if ANDROID_LOG_CLASS in f.read():
bad_files.append(file)
if bad_files:
print('')
print('Illegal import %s detected in the following files:' % ANDROID_LOG_CLASS)
for bad_file in bad_files:
print(' - ' + bad_file)
print('Use %s instead.' % FLUTTER_LOG_CLASS)
print('')
return 1
return 0
if __name__ == '__main__':
sys.exit(main())