Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathformat-command-lines.py
More file actions
Latest commit
87 lines (73 loc) · 2.47 KB
/
Copy pathformat-command-lines.py
File metadata and controls
87 lines (73 loc) · 2.47 KB
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
86
87
importos
importsys
importerrno
iflen(sys.argv) <2:
sys.stderr.write('Usage: %s <file> <modes> [<replacements> ...]'%sys.argv[0])
sys.exit(1)
input_file=sys.argv[1]
modes=sys.argv[2].split(',') # format-calls, apply-replacements
format_calls='format-calls'inmodes
apply_replacements='apply-replacements'inmodes
replacement_args= []
iflen(sys.argv) >2:
replacement_args=sys.argv[3:]
defshow(line):
try:
sys.stdout.write(line)
sys.stdout.flush()
exceptIOErrorase:
ife.errno==errno.EPIPE:
input.close()
sys.exit(0)
input=open(input_file, 'r')
command_line_counter=0
ifapply_replacements:
replacements= [] # a list because we want to keep order
forarginreplacement_args:
rep=arg.split('=')
iflen(rep) ==2:
replacements.append((rep[0], rep[1]))
else:
sys.stderr.write('WARNING: invalid replacement: %s\n'%arg)
ifreplacements:
print('===\n=== Replacements made by ye\n===\n')
fororig, repinreplacements:
print('%s => %s'% (orig, rep))
print('\n'+'='*80+'\n')
whileTrue:
build_line=input.readline()
ifnotbuild_line:
break
ifapply_replacements:
fororig, repinreplacements:
build_line=build_line.replace(orig, rep)
ifformat_calls:
tokens=build_line.split()
iflen(tokens) >0:
prev=None
first_token=tokens[0]
filename=os.path.basename(first_token)
if (filename.endswith('gcc') or
filename.endswith('g++') or
filename.endswith('xgcc') or
filename.endswith('clang') or
filename.endswith('clang++') or
filename.endswith('javac')):
command_line_counter+=1
dashes='-'*15
print('%s[ command line %s ]%s'% (dashes, command_line_counter, dashes))
lines= [first_token]
fortokenintokens[1:]:
ifprevin ['-o', '-isystem']:
lines[-1] +=' '+token
else:
lines.append(token)
prev=token
show(lines[0] +'\n')
forlineinlines[1:]:
show(' '+line+'\n')
else:
show(build_line)
else:
show(build_line)
input.close()