@@ -33,12 +33,14 @@ def test_thinlto_file(self):
33
33
corpus ._load_and_parse_command (
34
34
module_path = module_path , has_thinlto = False ),
35
35
['-cc1' , '-foo' , '-bar=baz' , '-x' , 'ir' , module_path + '.bc' ])
36
+ data = ['-cc1' , '-foo' , '-bar=baz' , '-fthinlto-index=some/path/here' ]
37
+ argfile = self .create_tempfile (content = '\0 ' .join (data ), file_path = 'hi.cmd' )
36
38
self .assertEqual (
37
39
corpus ._load_and_parse_command (
38
40
module_path = module_path , has_thinlto = True ), [
39
- '-cc1' , '-foo' , '-bar=baz' , '-x' , 'ir' , module_path + '.bc' ,
40
- '-fthinlto-index=' + module_path + '.thinlto.bc' , '-mllvm ' ,
41
- '-thinlto-assume-merged'
41
+ '-cc1' , '-foo' , '-bar=baz' ,
42
+ '-fthinlto-index=' + module_path + '.thinlto.bc' , '-x' , 'ir ' ,
43
+ module_path + '.bc' , '-mllvm' , '-thinlto-assume-merged'
42
44
])
43
45
44
46
def test_deletion (self ):
@@ -70,6 +72,54 @@ def test_addition(self):
70
72
additional_flags = additional_flags ),
71
73
['-cc1' , '-x' , 'ir' , module_path + '.bc' , '-fix-all-bugs' ])
72
74
75
+ def test_replacement (self ):
76
+ replace_flags = {'-replace-me' : '{context.full_path_prefix}.replaced' }
77
+ data = ['-cc1' ]
78
+ argfile = self .create_tempfile (content = '\0 ' .join (data ), file_path = 'hi.cmd' )
79
+ module_path = argfile .full_path [:- 4 ]
80
+ # if we expect to be able to replace a flag, and it's not in the original
81
+ # cmdline, raise.
82
+ self .assertRaises (
83
+ ValueError ,
84
+ corpus ._load_and_parse_command ,
85
+ module_path = module_path ,
86
+ has_thinlto = False ,
87
+ replace_flags = replace_flags )
88
+ data = ['-cc1' , '-replace-me=some_value' ]
89
+ argfile = self .create_tempfile (content = '\0 ' .join (data ), file_path = 'hi.cmd' )
90
+ # the flag can be replaced in non-thinlto cases; and in the case of thinlto
91
+ # it does not interfere with the thinlto one
92
+ self .assertEqual (
93
+ corpus ._load_and_parse_command (
94
+ module_path = module_path ,
95
+ has_thinlto = False ,
96
+ replace_flags = replace_flags ), [
97
+ '-cc1' , '-replace-me=' + module_path + '.replaced' , '-x' , 'ir' ,
98
+ module_path + '.bc'
99
+ ])
100
+ # variant without '='
101
+ data = ['-cc1' , '-replace-me' , 'some_value' ]
102
+ argfile = self .create_tempfile (content = '\0 ' .join (data ), file_path = 'hi.cmd' )
103
+ self .assertEqual (
104
+ corpus ._load_and_parse_command (
105
+ module_path = module_path ,
106
+ has_thinlto = False ,
107
+ replace_flags = replace_flags ), [
108
+ '-cc1' , '-replace-me' , module_path + '.replaced' , '-x' , 'ir' ,
109
+ module_path + '.bc'
110
+ ])
111
+ data = ['-cc1' , '-replace-me' , 'some_value' , '-fthinlto-index=blah' ]
112
+ argfile = self .create_tempfile (content = '\0 ' .join (data ), file_path = 'hi.cmd' )
113
+ self .assertEqual (
114
+ corpus ._load_and_parse_command (
115
+ module_path = module_path ,
116
+ has_thinlto = True ,
117
+ replace_flags = replace_flags ), [
118
+ '-cc1' , '-replace-me' , module_path + '.replaced' ,
119
+ '-fthinlto-index=' + module_path + '.thinlto.bc' , '-x' , 'ir' ,
120
+ module_path + '.bc' , '-mllvm' , '-thinlto-assume-merged'
121
+ ])
122
+
73
123
def test_modification (self ):
74
124
delete_compilation_flags = ('-split-dwarf-file' , '-split-dwarf-output' ,
75
125
'-fthinlto-index' , '-fprofile-sample-use' ,
@@ -166,23 +216,27 @@ def test_get_with_thinlto(self):
166
216
tempdir .create_file (
167
217
'2.cmd' , content = '\0 ' .join (['-cc1' , '-fthinlto-index=abc' ]))
168
218
169
- ms_list = corpus ._build_modulespecs_from_datapath (
219
+ self .assertRaises (
220
+ ValueError ,
221
+ corpus ._build_modulespecs_from_datapath ,
170
222
tempdir .full_path ,
171
223
additional_flags = ('-add' ,),
172
224
delete_flags = ('-fthinlto-index' ,))
225
+ ms_list = corpus ._build_modulespecs_from_datapath (
226
+ tempdir .full_path , additional_flags = ('-add' ,))
173
227
self .assertEqual (len (ms_list ), 2 )
174
228
ms1 = ms_list [0 ]
175
229
ms2 = ms_list [1 ]
176
230
self .assertEqual (ms1 .name , '1' )
177
231
self .assertEqual (ms1 .exec_cmd ,
178
- ('-cc1' , '-x' , 'ir' , tempdir .full_path + '/1.bc' ,
179
- '-fthinlto-index=' + tempdir .full_path + '/1.thinlto .bc' ,
232
+ ('-cc1' , '-fthinlto-index=' + tempdir .full_path +
233
+ '/1.thinlto.bc' , '-x' , 'ir' , tempdir .full_path + '/1.bc' ,
180
234
'-mllvm' , '-thinlto-assume-merged' , '-add' ))
181
235
182
236
self .assertEqual (ms2 .name , '2' )
183
237
self .assertEqual (ms2 .exec_cmd ,
184
- ('-cc1' , '-x' , 'ir' , tempdir .full_path + '/2.bc' ,
185
- '-fthinlto-index=' + tempdir .full_path + '/2.thinlto .bc' ,
238
+ ('-cc1' , '-fthinlto-index=' + tempdir .full_path +
239
+ '/2.thinlto.bc' , '-x' , 'ir' , tempdir .full_path + '/2.bc' ,
186
240
'-mllvm' , '-thinlto-assume-merged' , '-add' ))
187
241
188
242
def test_get_with_override (self ):
@@ -203,9 +257,7 @@ def test_get_with_override(self):
203
257
tempdir .create_file ('2.cmd' , content = '\0 ' .join (['-fthinlto-index=abc' ]))
204
258
205
259
ms_list = corpus ._build_modulespecs_from_datapath (
206
- tempdir .full_path ,
207
- additional_flags = ('-add' ,),
208
- delete_flags = ('-fthinlto-index' ,))
260
+ tempdir .full_path , additional_flags = ('-add' ,))
209
261
self .assertEqual (len (ms_list ), 2 )
210
262
ms1 = ms_list [0 ]
211
263
ms2 = ms_list [1 ]
0 commit comments