@@ -68,7 +68,6 @@ def main():
68
68
update_or_generate_group .add_argument ("--update" , help = "Update the file in-place" , action = "store_true" )
69
69
update_or_generate_group .add_argument ("--opts" , help = "other options" ,
70
70
action = "store" , default = '' , type = str )
71
-
72
71
args = parser .parse_args ()
73
72
74
73
if not args .source :
@@ -80,19 +79,31 @@ def main():
80
79
print ("clang binary specified not present." )
81
80
return - 1
82
81
83
- filters = set (args .filters .split (',' )) if args .filters else set ()
84
-
85
- note = "// NOTE: CHECK lines have been autogenerated by " \
86
- "gen_ast_dump_json_test.py"
87
-
88
- if (args .filters ):
89
- note += "\n // using --filters=" + args .filters
90
-
82
+ note_firstline = "// NOTE: CHECK lines have been autogenerated by " \
83
+ "gen_ast_dump_json_test.py"
84
+ filters_line_prefix = "// using --filters="
85
+ note = note_firstline
86
+
91
87
cmd = [clang_binary , "-cc1" ]
92
88
if args .update :
93
89
# When updating the first line of the test must be a RUN: line
94
90
with open (args .source , "r" ) as srcf :
95
91
first_line = srcf .readline ()
92
+ filters_line_next = False
93
+ filters_line = None
94
+ for i , line in enumerate (srcf .readlines ()):
95
+ if filters_line_next :
96
+ # print("Filters line: '", line.rstrip(), "'", sep="")
97
+ if line .startswith (filters_line_prefix ):
98
+ filters_line = line [len (filters_line_prefix ):].rstrip ()
99
+ break
100
+ if line .startswith (note_firstline ):
101
+ filters_line_next = True
102
+ # print("Found autogenerated disclaimer at line", i + 1)
103
+ if not args .filters and filters_line :
104
+ args .filters = filters_line
105
+ print ("Inferred filters as '" + args .filters + "'" )
106
+
96
107
if "RUN: %clang_cc1 " not in first_line :
97
108
sys .exit ("When using --update the first line of the input file must contain RUN: %clang_cc1" )
98
109
clang_start = first_line .find ("%clang_cc1" ) + len ("%clang_cc1" )
@@ -115,6 +126,12 @@ def main():
115
126
using_ast_dump_filter = any ('ast-dump-filter' in arg for arg in cmd )
116
127
cmd .append (args .source )
117
128
print ("Will run" , cmd )
129
+ filters = set ()
130
+ if args .filters :
131
+ note += "\n " + filters_line_prefix + args .filters
132
+ filters = set (args .filters .split (',' ))
133
+ print ("Will use the following filters:" , filters )
134
+
118
135
119
136
try :
120
137
json_str = subprocess .check_output (cmd )
@@ -147,7 +164,7 @@ def main():
147
164
with open (args .source , "r" ) as srcf :
148
165
for line in srcf .readlines ():
149
166
# copy up to the note:
150
- if line .rstrip () == note :
167
+ if line .rstrip () == note_firstline :
151
168
break
152
169
f .write (line )
153
170
f .write (note + "\n " )
0 commit comments