-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind-repo-files.py
executable file
·86 lines (64 loc) · 2.36 KB
/
find-repo-files.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
import os
import os.path
import sys
import subprocess
import json
import collections
def run(cmd, **extra):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, **extra)
(stdout, stderr) = p.communicate()
if p.returncode:
print >>sys.stderr, 'Command failed', cmd
print >>sys.stderr, 'Return code', p.returncode
print >>sys.stderr, stdout
print >>sys.stderr, '---'
print >>sys.stderr, stderr
sys.exit(p.returncode)
return stdout
config = json.load(open(sys.argv[1]))
tree_name = sys.argv[2]
repo_path = config['trees'][tree_name]['files_path']
stdout = run('git ls-files --recurse-submodules', shell=True, cwd=repo_path)
lines = stdout.split('\n')
files = []
js = []
idl = []
ipdl = []
dirs = collections.OrderedDict()
ipdl_dirs = collections.OrderedDict()
for line in lines:
path = line.strip()
if not path:
continue
fullpath = os.path.join(repo_path, path)
elts = path.split('/')
for i in range(len(elts)):
sub = '/'.join(elts[:i])
if sub and sub not in dirs:
dirs[sub] = True
files.append(path + '\n')
(_, ext) = os.path.splitext(path)
if ext == '.idl':
# This file causes problems because an IDL file of the same
# name exists in browser/, android/, and other places, and
# they all end up in dist/include.
if not path.endswith('nsIShellService.idl'):
idl.append(path + '\n')
if ext == '.ipdl' or ext == '.ipdlh':
if 'ipc/ipdl/test' in path or 'accessible/ipc/win' in path or 'widget/win' in path:
continue
ipdl.append(path + '\n')
dir = '/'.join(elts[:-1])
ipdl_dirs[dir] = True
if 'js/src/tests' in path or 'jit-test' in path:
continue
if ext in ['.js', '.jsm', '.xml', '.xul', '.inc']:
js.append(path + '\n')
index_path = config['trees'][tree_name]['index_path']
open(os.path.join(index_path, 'repo-files'), 'w').writelines(files)
open(os.path.join(index_path, 'repo-dirs'), 'w').writelines([ d + '\n' for d in dirs ])
open(os.path.join(index_path, 'js-files'), 'w').writelines(js)
open(os.path.join(index_path, 'idl-files'), 'w').writelines(idl)
open(os.path.join(index_path, 'ipdl-files'), 'w').writelines(ipdl)
open(os.path.join(index_path, 'ipdl-includes'), 'w').write(' '.join([ '-I ' + d for d in ipdl_dirs ]))