Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: test/analyzer/gyptest-analyzer.py

Issue 1402813002: Change analyzer to search for build_targets from supplied targets (Closed) Base URL: https://chromium.googlesource.com/external/gyp@master
Patch Set: make targets same as build_targets Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pylib/gyp/generator/analyzer.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2014 Google Inc. All rights reserved. 2 # Copyright (c) 2014 Google Inc. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Tests for analyzer 6 """Tests for analyzer
7 """ 7 """
8 8
9 import json 9 import json
10 import TestGyp 10 import TestGyp
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 args += CommonArgs() 62 args += CommonArgs()
63 test.run_gyp('test3.gyp', *args, **kw) 63 test.run_gyp('test3.gyp', *args, **kw)
64 64
65 65
66 def run_analyzer4(*args, **kw): 66 def run_analyzer4(*args, **kw):
67 """Same as run_analyzer(), but passes in test3.gyp instead of test.gyp.""" 67 """Same as run_analyzer(), but passes in test3.gyp instead of test.gyp."""
68 args += CommonArgs() 68 args += CommonArgs()
69 test.run_gyp('test4.gyp', *args, **kw) 69 test.run_gyp('test4.gyp', *args, **kw)
70 70
71 71
72 def EnsureContains(targets=set(), matched=False, build_targets=set()): 72 def EnsureContains(matched=False, build_targets=set()):
73 """Verifies output contains |targets|.""" 73 """Verifies output contains |build_targets|."""
74 result = _ReadOutputFileContents() 74 result = _ReadOutputFileContents()
75 if result.get('error', None): 75 if result.get('error', None):
76 print 'unexpected error', result.get('error') 76 print 'unexpected error', result.get('error')
77 test.fail_test() 77 test.fail_test()
78 78
79 if result.get('invalid_targets', None): 79 if result.get('invalid_targets', None):
80 print 'unexpected invalid_targets', result.get('invalid_targets') 80 print 'unexpected invalid_targets', result.get('invalid_targets')
81 test.fail_test() 81 test.fail_test()
82 82
83 # TODO(sky): nuke when get rid of targets.
84 targets = build_targets
83 actual_targets = set(result['targets']) 85 actual_targets = set(result['targets'])
84 if actual_targets != targets: 86 if actual_targets != targets:
85 print 'actual targets:', actual_targets, '\nexpected targets:', targets 87 print 'actual targets:', actual_targets, '\nexpected targets:', targets
86 test.fail_test() 88 test.fail_test()
87 89
88 actual_build_targets = set(result['build_targets']) 90 actual_build_targets = set(result['build_targets'])
89 if actual_build_targets != build_targets: 91 if actual_build_targets != build_targets:
90 print 'actual build_targets:', actual_build_targets, \ 92 print 'actual build_targets:', actual_build_targets, \
91 '\nexpected build_targets:', build_targets 93 '\nexpected build_targets:', build_targets
92 test.fail_test() 94 test.fail_test()
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 actual_invalid_targets = set(result['invalid_targets']) 143 actual_invalid_targets = set(result['invalid_targets'])
142 if actual_invalid_targets != expected_invalid_targets: 144 if actual_invalid_targets != expected_invalid_targets:
143 print 'actual invalid_targets:', actual_invalid_targets, \ 145 print 'actual invalid_targets:', actual_invalid_targets, \
144 '\nexpected :', expected_invalid_targets 146 '\nexpected :', expected_invalid_targets
145 test.fail_test() 147 test.fail_test()
146 148
147 149
148 # Two targets, A and B (both static_libraries) and A depends upon B. If a file 150 # Two targets, A and B (both static_libraries) and A depends upon B. If a file
149 # in B changes, then both A and B are output. It is not strictly necessary that 151 # in B changes, then both A and B are output. It is not strictly necessary that
150 # A is compiled in this case, only B. 152 # A is compiled in this case, only B.
151 _CreateConfigFile(['b.c'], []) 153 _CreateConfigFile(['b.c'], ['a'])
152 test.run_gyp('static_library_test.gyp', *CommonArgs()) 154 test.run_gyp('static_library_test.gyp', *CommonArgs())
153 EnsureContains(matched=True, build_targets={'a' ,'b'}) 155 EnsureContains(matched=True, build_targets={'a' ,'b'})
154 156
155 # Verifies config_path must be specified. 157 # Verifies config_path must be specified.
156 test.run_gyp('test.gyp') 158 test.run_gyp('test.gyp')
157 EnsureStdoutContains('Must specify files to analyze via config_path') 159 EnsureStdoutContains('Must specify files to analyze via config_path')
158 160
159 # Verifies config_path must point to a valid file. 161 # Verifies config_path must point to a valid file.
160 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file', 162 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file',
161 '-Ganalyzer_output_path=analyzer_output') 163 '-Ganalyzer_output_path=analyzer_output')
162 EnsureError('Unable to open file bogus_file') 164 EnsureError('Unable to open file bogus_file')
163 165
164 # Verify 'invalid_targets' is present when bad target is specified. 166 # Verify 'invalid_targets' is present when bad target is specified.
165 _CreateConfigFile(['exe2.c'], ['bad_target']) 167 _CreateConfigFile(['exe2.c'], ['bad_target', 'all', 'exe2'])
166 run_analyzer() 168 run_analyzer()
167 EnsureInvalidTargets({'bad_target'}) 169 EnsureInvalidTargets({'bad_target'})
168 170
169 # Verifies config_path must point to a valid json file. 171 # Verifies config_path must point to a valid json file.
170 _CreateBogusConfigFile() 172 _CreateBogusConfigFile()
171 run_analyzer() 173 run_analyzer()
172 EnsureError('Unable to parse config file test_file') 174 EnsureError('Unable to parse config file test_file')
173 175
174 # Trivial test of a source. 176 # Trivial test of a source.
175 _CreateConfigFile(['foo.c'], []) 177 _CreateConfigFile(['foo.c'], ['all', 'exe2'])
176 run_analyzer() 178 run_analyzer()
177 EnsureContains(matched=True, build_targets={'exe'}) 179 EnsureContains(matched=True, build_targets={'exe'})
178 180
179 # Conditional source that is excluded. 181 # Conditional source that is excluded.
180 _CreateConfigFile(['conditional_source.c'], []) 182 _CreateConfigFile(['conditional_source.c'], ['all', 'exe2'])
181 run_analyzer() 183 run_analyzer()
182 EnsureContains(matched=False) 184 EnsureContains(matched=False)
183 185
184 # Conditional source that is included by way of argument. 186 # Conditional source that is included by way of argument.
185 _CreateConfigFile(['conditional_source.c'], []) 187 _CreateConfigFile(['conditional_source.c'], ['all', 'exe2'])
186 run_analyzer('-Dtest_variable=1') 188 run_analyzer('-Dtest_variable=1')
187 EnsureContains(matched=True, build_targets={'exe'}) 189 EnsureContains(matched=True, build_targets={'exe'})
188 190
189 # Two unknown files. 191 # Two unknown files.
190 _CreateConfigFile(['unknown1.c', 'unoknow2.cc'], []) 192 _CreateConfigFile(['unknown1.c', 'unoknow2.cc'], ['all', 'exe2'])
191 run_analyzer() 193 run_analyzer()
192 EnsureContains() 194 EnsureContains()
193 195
194 # Two unknown files. 196 # Two unknown files.
195 _CreateConfigFile(['unknown1.c', 'subdir/subdir_sourcex.c'], []) 197 _CreateConfigFile(['unknown1.c', 'subdir/subdir_sourcex.c'], ['all', 'exe2'])
196 run_analyzer() 198 run_analyzer()
197 EnsureContains() 199 EnsureContains()
198 200
199 # Included dependency 201 # Included dependency
200 _CreateConfigFile(['unknown1.c', 'subdir/subdir_source.c'], []) 202 _CreateConfigFile(['unknown1.c', 'subdir/subdir_source.c'], ['all', 'exe2'])
201 run_analyzer() 203 run_analyzer()
202 EnsureContains(matched=True, build_targets={'exe', 'exe3'}) 204 EnsureContains(matched=True, build_targets={'exe', 'exe3'})
203 205
204 # Included inputs to actions. 206 # Included inputs to actions.
205 _CreateConfigFile(['action_input.c'], []) 207 _CreateConfigFile(['action_input.c'], ['all', 'exe2'])
206 run_analyzer() 208 run_analyzer()
207 EnsureContains(matched=True, build_targets={'exe'}) 209 EnsureContains(matched=True, build_targets={'exe'})
208 210
209 # Don't consider outputs. 211 # Don't consider outputs.
210 _CreateConfigFile(['action_output.c'], []) 212 _CreateConfigFile(['action_output.c'], ['all', 'exe2'])
211 run_analyzer() 213 run_analyzer()
212 EnsureContains(matched=False) 214 EnsureContains(matched=False)
213 215
214 # Rule inputs. 216 # Rule inputs.
215 _CreateConfigFile(['rule_input.c'], []) 217 _CreateConfigFile(['rule_input.c'], ['all', 'exe2'])
216 run_analyzer() 218 run_analyzer()
217 EnsureContains(matched=True, build_targets={'exe'}) 219 EnsureContains(matched=True, build_targets={'exe'})
218 220
219 # Ignore path specified with PRODUCT_DIR. 221 # Ignore path specified with PRODUCT_DIR.
220 _CreateConfigFile(['product_dir_input.c'], []) 222 _CreateConfigFile(['product_dir_input.c'], ['all', 'exe2'])
221 run_analyzer() 223 run_analyzer()
222 EnsureContains(matched=False) 224 EnsureContains(matched=False)
223 225
224 # Path specified via a variable. 226 # Path specified via a variable.
225 _CreateConfigFile(['subdir/subdir_source2.c'], []) 227 _CreateConfigFile(['subdir/subdir_source2.c'], ['all', 'exe2'])
226 run_analyzer() 228 run_analyzer()
227 EnsureContains(matched=True, build_targets={'exe'}) 229 EnsureContains(matched=True, build_targets={'exe'})
228 230
229 # Verifies paths with // are fixed up correctly. 231 # Verifies paths with // are fixed up correctly.
230 _CreateConfigFile(['parent_source.c'], []) 232 _CreateConfigFile(['parent_source.c'], ['all', 'exe2'])
231 run_analyzer() 233 run_analyzer()
232 EnsureContains(matched=True, build_targets={'exe', 'exe3'}) 234 EnsureContains(matched=True, build_targets={'exe', 'exe3'})
233 235
234 # Verifies relative paths are resolved correctly. 236 # Verifies relative paths are resolved correctly.
235 _CreateConfigFile(['subdir/subdir_source.h'], []) 237 _CreateConfigFile(['subdir/subdir_source.h'], ['all', 'exe2'])
236 run_analyzer() 238 run_analyzer()
237 EnsureContains(matched=True, build_targets={'exe'}) 239 EnsureContains(matched=True, build_targets={'exe'})
238 240
239 # Verifies relative paths in inputs are resolved correctly. 241 # Verifies relative paths in inputs are resolved correctly.
240 _CreateConfigFile(['rel_path1.h'], []) 242 _CreateConfigFile(['rel_path1.h'], ['all', 'exe2'])
241 run_analyzer() 243 run_analyzer()
242 EnsureContains(matched=True, build_targets={'exe'}) 244 EnsureContains(matched=True, build_targets={'exe'})
243 245
244 # Various permutations when passing in targets. 246 # Various permutations when passing in targets.
245 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe', 'exe3']) 247 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'],
248 ['exe', 'exe3', 'all', 'exe2'])
246 run_analyzer() 249 run_analyzer()
247 EnsureContains(matched=True, targets={'exe3'}, build_targets={'exe2', 'exe3'}) 250 EnsureContains(matched=True, build_targets={'exe2', 'exe3'})
248 251
249 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe']) 252 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'],
253 ['exe', 'all', 'exe2'])
250 run_analyzer() 254 run_analyzer()
251 EnsureContains(matched=True, build_targets={'exe2', 'exe3'}) 255 EnsureContains(matched=True, build_targets={'exe2', 'exe3'})
252 256
253 # Verifies duplicates are ignored. 257 # Verifies duplicates are ignored.
254 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe', 'exe']) 258 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'],
259 ['exe', 'exe', 'all', 'exe2'])
255 run_analyzer() 260 run_analyzer()
256 EnsureContains(matched=True, build_targets={'exe2', 'exe3'}) 261 EnsureContains(matched=True, build_targets={'exe2', 'exe3'})
257 262
258 _CreateConfigFile(['exe2.c'], ['exe']) 263 _CreateConfigFile(['exe2.c'], ['exe', 'all', 'exe2'])
259 run_analyzer() 264 run_analyzer()
260 EnsureContains(matched=True, build_targets={'exe2'}) 265 EnsureContains(matched=True, build_targets={'exe2'})
261 266
262 _CreateConfigFile(['exe2.c'], []) 267 _CreateConfigFile(['exe2.c'], ['all', 'exe2'])
263 run_analyzer() 268 run_analyzer()
264 EnsureContains(matched=True, build_targets={'exe2'}) 269 EnsureContains(matched=True, build_targets={'exe2'})
265 270
266 _CreateConfigFile(['subdir/subdir2b_source.c', 'exe2.c'], []) 271 _CreateConfigFile(['subdir/subdir2b_source.c', 'exe2.c'], ['all', 'exe2'])
267 run_analyzer() 272 run_analyzer()
268 EnsureContains(matched=True, build_targets={'exe2', 'exe3'}) 273 EnsureContains(matched=True, build_targets={'exe2', 'exe3'})
269 274
270 _CreateConfigFile(['subdir/subdir2b_source.c'], ['exe3']) 275 _CreateConfigFile(['subdir/subdir2b_source.c'], ['exe3', 'all', 'exe2'])
271 run_analyzer() 276 run_analyzer()
272 EnsureContains(matched=True, targets={'exe3'}, build_targets={'exe3'}) 277 EnsureContains(matched=True, build_targets={'exe3'})
273 278
274 _CreateConfigFile(['exe2.c'], []) 279 _CreateConfigFile(['foo.c'], ['all', 'exe2'])
275 run_analyzer()
276 EnsureContains(matched=True, build_targets={'exe2'})
277
278 _CreateConfigFile(['foo.c'], [])
279 run_analyzer() 280 run_analyzer()
280 EnsureContains(matched=True, build_targets={'exe'}) 281 EnsureContains(matched=True, build_targets={'exe'})
281 282
282 # Assertions when modifying build (gyp/gypi) files, especially when said files 283 # Assertions when modifying build (gyp/gypi) files, especially when said files
283 # are included. 284 # are included.
284 _CreateConfigFile(['subdir2/d.cc'], ['exe', 'exe2', 'foo', 'exe3']) 285 _CreateConfigFile(['subdir2/d.cc'], ['exe', 'exe2', 'foo', 'exe3'])
285 run_analyzer2() 286 run_analyzer2()
286 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) 287 EnsureContains(matched=True, build_targets={'exe'})
287 288
288 _CreateConfigFile(['subdir2/subdir.includes.gypi'], 289 _CreateConfigFile(['subdir2/subdir.includes.gypi'],
289 ['exe', 'exe2', 'foo', 'exe3']) 290 ['exe', 'exe2', 'foo', 'exe3'])
290 run_analyzer2() 291 run_analyzer2()
291 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) 292 EnsureContains(matched=True, build_targets={'exe'})
292 293
293 _CreateConfigFile(['subdir2/subdir.gyp'], ['exe', 'exe2', 'foo', 'exe3']) 294 _CreateConfigFile(['subdir2/subdir.gyp'], ['exe', 'exe2', 'foo', 'exe3'])
294 run_analyzer2() 295 run_analyzer2()
295 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) 296 EnsureContains(matched=True, build_targets={'exe'})
296 297
297 _CreateConfigFile(['test2.includes.gypi'], ['exe', 'exe2', 'foo', 'exe3']) 298 _CreateConfigFile(['test2.includes.gypi'], ['exe', 'exe2', 'foo', 'exe3'])
298 run_analyzer2() 299 run_analyzer2()
299 EnsureContains(matched=True, targets={'exe', 'exe2', 'exe3'}, 300 EnsureContains(matched=True, build_targets={'exe', 'exe2', 'exe3'})
300 build_targets={'exe', 'exe2', 'exe3'})
301 301
302 # Verify modifying a file included makes all targets dirty. 302 # Verify modifying a file included makes all targets dirty.
303 _CreateConfigFile(['common.gypi'], ['exe', 'exe2', 'foo', 'exe3']) 303 _CreateConfigFile(['common.gypi'], ['exe', 'exe2', 'foo', 'exe3'])
304 run_analyzer2('-Icommon.gypi') 304 run_analyzer2('-Icommon.gypi')
305 EnsureMatchedAll({'exe', 'exe2', 'foo', 'exe3'}) 305 EnsureMatchedAll({'exe', 'exe2', 'foo', 'exe3'})
306 306
307 # Assertions from test3.gyp. 307 # Assertions from test3.gyp.
308 _CreateConfigFile(['d.c', 'f.c'], ['a']) 308 _CreateConfigFile(['d.c', 'f.c'], ['a', 'all'])
309 run_analyzer3()
310 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b'})
311
312 _CreateConfigFile(['f.c'], ['a'])
313 run_analyzer3()
314 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b'})
315
316 _CreateConfigFile(['f.c'], [])
317 run_analyzer3() 309 run_analyzer3()
318 EnsureContains(matched=True, build_targets={'a', 'b'}) 310 EnsureContains(matched=True, build_targets={'a', 'b'})
319 311
320 _CreateConfigFile(['c.c', 'e.c'], []) 312 _CreateConfigFile(['f.c'], ['a', 'all'])
313 run_analyzer3()
314 EnsureContains(matched=True, build_targets={'a', 'b'})
315
316 _CreateConfigFile(['f.c'], ['all'])
317 run_analyzer3()
318 EnsureContains(matched=True, build_targets={'a', 'b'})
319
320 _CreateConfigFile(['c.c', 'e.c'], ['all'])
321 run_analyzer3() 321 run_analyzer3()
322 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'e'}) 322 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'e'})
323 323
324 _CreateConfigFile(['d.c'], ['a']) 324 _CreateConfigFile(['d.c'], ['a', 'all'])
325 run_analyzer3() 325 run_analyzer3()
326 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b'}) 326 EnsureContains(matched=True, build_targets={'a', 'b'})
327 327
328 _CreateConfigFile(['a.c'], ['a', 'b']) 328 _CreateConfigFile(['a.c'], ['a', 'b', 'all'])
329 run_analyzer3()
330 EnsureContains(matched=True, targets={'a'}, build_targets={'a'})
331
332 _CreateConfigFile(['a.c'], ['a', 'b'])
333 run_analyzer3()
334 EnsureContains(matched=True, targets={'a'}, build_targets={'a'})
335
336 _CreateConfigFile(['d.c'], ['a', 'b'])
337 run_analyzer3()
338 EnsureContains(matched=True, targets={'a', 'b'}, build_targets={'a', 'b'})
339
340 _CreateConfigFile(['f.c'], ['a'])
341 run_analyzer3()
342 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b'})
343
344 _CreateConfigFile(['a.c'], ['a'])
345 run_analyzer3()
346 EnsureContains(matched=True, targets={'a'}, build_targets={'a'})
347
348 _CreateConfigFile(['a.c'], [])
349 run_analyzer3() 329 run_analyzer3()
350 EnsureContains(matched=True, build_targets={'a'}) 330 EnsureContains(matched=True, build_targets={'a'})
351 331
352 _CreateConfigFile(['d.c'], []) 332 _CreateConfigFile(['a.c'], ['a', 'b', 'all'])
333 run_analyzer3()
334 EnsureContains(matched=True, build_targets={'a'})
335
336 _CreateConfigFile(['d.c'], ['a', 'b', 'all'])
337 run_analyzer3()
338 EnsureContains(matched=True, build_targets={'a', 'b'})
339
340 _CreateConfigFile(['f.c'], ['a', 'all'])
341 run_analyzer3()
342 EnsureContains(matched=True, build_targets={'a', 'b'})
343
344 _CreateConfigFile(['a.c'], ['a', 'all'])
345 run_analyzer3()
346 EnsureContains(matched=True, build_targets={'a'})
347
348 _CreateConfigFile(['a.c'], ['all'])
349 run_analyzer3()
350 EnsureContains(matched=True, build_targets={'a'})
351
352 _CreateConfigFile(['d.c'], ['all'])
353 run_analyzer3() 353 run_analyzer3()
354 EnsureContains(matched=True, build_targets={'a', 'b'}) 354 EnsureContains(matched=True, build_targets={'a', 'b'})
355 355
356 # Assertions around test4.gyp. 356 # Assertions around test4.gyp.
357 _CreateConfigFile(['f.c'], []) 357 _CreateConfigFile(['f.c'], ['a', 'e', 'h'])
358 run_analyzer4() 358 run_analyzer4()
359 EnsureContains(matched=True, build_targets={'e', 'f'}) 359 EnsureContains(matched=True, build_targets={'e', 'f'})
360 360
361 _CreateConfigFile(['d.c'], []) 361 _CreateConfigFile(['d.c'], ['a', 'e', 'h'])
362 run_analyzer4() 362 run_analyzer4()
363 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'd'}) 363 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'd'})
364 364
365 _CreateConfigFile(['i.c'], []) 365 _CreateConfigFile(['i.c'], ['a', 'e', 'h'])
366 run_analyzer4() 366 run_analyzer4()
367 EnsureContains(matched=True, build_targets={'h', 'i'}) 367 EnsureContains(matched=True, build_targets={'h', 'i'})
368 368
369 test.pass_test() 369 test.pass_test()
OLDNEW
« no previous file with comments | « pylib/gyp/generator/analyzer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698