blob: 87b12335bf436f1320199e0484f6e9fb0f641cc0 [file] [log] [blame]
Andrew Bartholomew2639c502014-05-10 10:58:07 -04001#!/usr/bin/env python -E
The Android Open Source Project88b60792009-03-03 19:28:42 -08002
Anthony King91a1c642015-10-31 14:04:43 -04003from __future__ import print_function
4
The Android Open Source Project88b60792009-03-03 19:28:42 -08005import sys, os, re
6
7excludes = [r'.*?/\.obj.*?',
8 r'.*?~',
9 r'.*?\/.DS_Store',
10 r'.*?\/.gdb_history',
11 r'.*?\/buildspec.mk',
12 r'.*?/\..*?\.swp',
13 r'.*?/out/.*?',
14 r'.*?/install/.*?']
15
Anthony King91a1c642015-10-31 14:04:43 -040016excludes_compiled = list(map(re.compile, excludes))
The Android Open Source Project88b60792009-03-03 19:28:42 -080017
18def filter_excludes(str):
19 for e in excludes_compiled:
20 if e.match(str):
21 return False
22 return True
23
24def split_perforce_parts(s):
25 spaces = ((s.count(" ") + 1) / 3) * 2
26 pos = 0
27 while spaces > 0:
28 pos = s.find(" ", pos) + 1
29 spaces = spaces - 1
30 return s[pos:]
31
32def quotate(s):
33 return '"' + s + '"'
34
35class PerforceError(Exception):
36 def __init__(self,value):
37 self.value = value
38 def __str__(self):
39 return repr(self.value)
40
41
42def run(command, regex, filt):
43 def matchit(s):
44 m = regex_compiled.match(s)
45 if m:
46 return m.group(1)
47 else:
48 return ""
49 def filterit(s):
50 if filt_compiled.match(s):
51 return True
52 else:
53 return False
54
55 fd = os.popen(command);
56 lines = fd.readlines()
57 status = fd.close()
58 if status:
59 raise PerforceError("error calling " + command)
60
61 regex_compiled = re.compile(regex)
62 filt_compiled = re.compile(filt)
63
64 if len(lines) >= 1:
Anthony King91a1c642015-10-31 14:04:43 -040065 lines = list(filter(filterit, lines))
The Android Open Source Project88b60792009-03-03 19:28:42 -080066 if len(lines) >= 1:
Anthony King91a1c642015-10-31 14:04:43 -040067 return list(map(matchit, lines))
The Android Open Source Project88b60792009-03-03 19:28:42 -080068 return None
69
70try:
71 if len(sys.argv) == 1:
72 do_exclude = True
73 elif len(sys.argv) == 2 and sys.argv[1] == "-a":
74 do_exclude = False
75 else:
Anthony King91a1c642015-10-31 14:04:43 -040076 print("usage: checktree [-a]")
77 print(" -a don't filter common crud in the tree")
The Android Open Source Project88b60792009-03-03 19:28:42 -080078 sys.exit(1)
79
80 have = run("p4 have ...", r'[^#]+#[0-9]+ - (.*)', r'.*')
81
82 cwd = os.getcwd()
83 files = run("find . -not -type d", r'.(.*)', r'.*')
Anthony King91a1c642015-10-31 14:04:43 -040084 files = [cwd+s for s in files]
The Android Open Source Project88b60792009-03-03 19:28:42 -080085
86 added_depot_path = run("p4 opened ...", r'([^#]+)#.*', r'.*?#[0-9]+ - add .*');
87 added = []
88 if added_depot_path:
Anthony King91a1c642015-10-31 14:04:43 -040089 added_depot_path = list(map(quotate, added_depot_path))
The Android Open Source Project88b60792009-03-03 19:28:42 -080090
91 where = "p4 where " + " ".join(added_depot_path)
92 added = run(where, r'(.*)', r'.*')
Anthony King91a1c642015-10-31 14:04:43 -040093 added = list(map(split_perforce_parts, added))
The Android Open Source Project88b60792009-03-03 19:28:42 -080094
95 extras = []
96
97 # Python 2.3 -- still default on Mac OS X -- does not have set()
98 # Make dict's here to support the "in" operations below
99 have = dict().fromkeys(have, 1)
100 added = dict().fromkeys(added, 1)
101
102 for file in files:
103 if not file in have:
104 if not file in added:
105 extras.append(file)
106
107 if do_exclude:
108 extras = filter(filter_excludes, extras)
109
110 for s in extras:
Anthony King91a1c642015-10-31 14:04:43 -0400111 print(s.replace(" ", "\\ "))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800112
Anthony King91a1c642015-10-31 14:04:43 -0400113except PerforceError as e:
The Android Open Source Project88b60792009-03-03 19:28:42 -0800114 sys.exit(2)
115