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

Side by Side Diff: PRESUBMIT.py

Issue 2304883002: Update PRESUBMIT.py to handle GN. (Closed)
Patch Set: Updated comments. Created 4 years, 3 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 | « no previous file | 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 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 1 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
2 # 2 #
3 # Use of this source code is governed by a BSD-style license 3 # Use of this source code is governed by a BSD-style license
4 # that can be found in the LICENSE file in the root of the source 4 # that can be found in the LICENSE file in the root of the source
5 # tree. An additional intellectual property rights grant can be found 5 # tree. An additional intellectual property rights grant can be found
6 # in the file PATENTS. All contributing project authors may 6 # in the file PATENTS. All contributing project authors may
7 # be found in the AUTHORS file in the root of the source tree. 7 # be found in the AUTHORS file in the root of the source tree.
8 8
9 import json 9 import json
10 import os 10 import os
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 if pattern.search(contents): 248 if pattern.search(contents):
249 violating_files.append(f) 249 violating_files.append(f)
250 if violating_files: 250 if violating_files:
251 return [output_api.PresubmitError( 251 return [output_api.PresubmitError(
252 'Depending on rtc_base is not allowed. Change your dependency to ' 252 'Depending on rtc_base is not allowed. Change your dependency to '
253 'rtc_base_approved and possibly sanitize and move the desired source ' 253 'rtc_base_approved and possibly sanitize and move the desired source '
254 'file(s) to rtc_base_approved.\nChanged GYP files:', 254 'file(s) to rtc_base_approved.\nChanged GYP files:',
255 items=violating_files)] 255 items=violating_files)]
256 return [] 256 return []
257 257
258 def _CheckNoRtcBaseDepsGn(input_api, gn_files, output_api):
259 pattern = input_api.re.compile(r'base:rtc_base\s*"')
260 violating_files = []
261 for f in gn_files:
262 gn_exceptions = (
263 os.path.join('base_tests', 'BUILD.gn'),
264 os.path.join('desktop_capture', 'BUILD.gn'),
265 os.path.join('p2p', 'BUILD.gn'),
266 os.path.join('sdk', 'BUILD.gn'),
267 os.path.join('webrtc_test_common', 'BUILD.gn'),
268 os.path.join('webrtc_tests', 'BUILD.gn'),
269
270 # TODO(ehmaldonado): Clean up references to rtc_base in these files.
271 # See https://bugs.chromium.org/p/webrtc/issues/detail?id=3806
272 os.path.join('webrtc', 'BUILD.gn'),
273 os.path.join('xmllite', 'BUILD.gn'),
274 os.path.join('xmpp', 'BUILD.gn'),
275 os.path.join('modules', 'BUILD.gn'),
276 os.path.join('audio_device', 'BUILD.gn'),
277 os.path.join('pc', 'BUILD.gn'),
278 )
279 if f.LocalPath().endswith(gn_exceptions):
280 continue
281 contents = input_api.ReadFile(f)
282 if pattern.search(contents):
283 violating_files.append(f)
284 if violating_files:
285 return [output_api.PresubmitError(
286 'Depending on rtc_base is not allowed. Change your dependency to '
287 'rtc_base_approved and possibly sanitize and move the desired source '
288 'file(s) to rtc_base_approved.\nChanged GN files:',
289 items=violating_files)]
290 return []
291
258 def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api): 292 def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
259 # Disallow referencing source files with paths above the GYP file location. 293 # Disallow referencing source files with paths above the GYP file location.
260 source_pattern = input_api.re.compile(r'\'sources\'.*?\[(.*?)\]', 294 source_pattern = input_api.re.compile(r'\'sources\'.*?\[(.*?)\]',
261 re.MULTILINE | re.DOTALL) 295 re.MULTILINE | re.DOTALL)
262 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'") 296 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
263 violating_gyp_files = set() 297 violating_gyp_files = set()
264 violating_source_entries = [] 298 violating_source_entries = []
265 for gyp_file in gyp_files: 299 for gyp_file in gyp_files:
266 if 'supplement.gypi' in gyp_file.LocalPath(): 300 if 'supplement.gypi' in gyp_file.LocalPath():
267 # Exclude supplement.gypi from this check, as the LSan and TSan 301 # Exclude supplement.gypi from this check, as the LSan and TSan
(...skipping 12 matching lines...) Expand all
280 return [output_api.PresubmitError( 314 return [output_api.PresubmitError(
281 'Referencing source files above the directory of the GYP file is not ' 315 'Referencing source files above the directory of the GYP file is not '
282 'allowed. Please introduce new GYP targets and/or GYP files in the ' 316 'allowed. Please introduce new GYP targets and/or GYP files in the '
283 'proper location instead.\n' 317 'proper location instead.\n'
284 'Invalid source entries:\n' 318 'Invalid source entries:\n'
285 '%s\n' 319 '%s\n'
286 'Violating GYP files:' % '\n'.join(violating_source_entries), 320 'Violating GYP files:' % '\n'.join(violating_source_entries),
287 items=violating_gyp_files)] 321 items=violating_gyp_files)]
288 return [] 322 return []
289 323
324 def _CheckNoSourcesAboveGn(input_api, gn_files, output_api):
325 # Disallow referencing source files with paths above the GN file location.
326 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
327 re.MULTILINE | re.DOTALL)
328 file_pattern = input_api.re.compile(r'"((\.\./.*?)|(//.*?))"')
329 violating_gn_files = set()
330 violating_source_entries = []
331 for gn_file in gn_files:
332 contents = input_api.ReadFile(gn_file)
333 for source_block_match in source_pattern.finditer(contents):
334 # Find all source list entries starting with ../ in the source block
335 # (exclude overrides entries).
336 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
337 source_file = file_list_match.group(1)
338 if 'overrides/' not in source_file:
339 violating_source_entries.append(source_file)
340 violating_gn_files.add(gn_file)
341 if violating_gn_files:
342 return [output_api.PresubmitError(
343 'Referencing source files above the directory of the GN file is not '
344 'allowed. Please introduce new GYP targets and/or GN files in the '
345 'proper location instead.\n'
346 'Invalid source entries:\n'
347 '%s\n'
348 'Violating GN files:' % '\n'.join(violating_source_entries),
349 items=violating_gn_files)]
350 return []
351
290 def _CheckGypChanges(input_api, output_api): 352 def _CheckGypChanges(input_api, output_api):
291 source_file_filter = lambda x: input_api.FilterSourceFile( 353 source_file_filter = lambda x: input_api.FilterSourceFile(
292 x, white_list=(r'.+\.(gyp|gypi)$',)) 354 x, white_list=(r'.+\.(gyp|gypi)$',))
293 355
294 gyp_files = [] 356 gyp_files = []
295 for f in input_api.AffectedSourceFiles(source_file_filter): 357 for f in input_api.AffectedSourceFiles(source_file_filter):
296 if f.LocalPath().startswith('webrtc'): 358 if f.LocalPath().startswith('webrtc'):
297 gyp_files.append(f) 359 gyp_files.append(f)
298 360
299 result = [] 361 result = []
300 if gyp_files: 362 if gyp_files:
301 result.append(output_api.PresubmitNotifyResult( 363 result.append(output_api.PresubmitNotifyResult(
302 'As you\'re changing GYP files: please make sure corresponding ' 364 'As you\'re changing GYP files: please make sure corresponding '
303 'BUILD.gn files are also updated.\nChanged GYP files:', 365 'BUILD.gn files are also updated.\nChanged GYP files:',
304 items=gyp_files)) 366 items=gyp_files))
305 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api)) 367 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
306 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api)) 368 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
307 return result 369 return result
308 370
371 def _CheckGnChanges(input_api, output_api):
372 source_file_filter = lambda x: input_api.FilterSourceFile(
373 x, white_list=(r'.+\.(gn|gni)$',))
374
375 gn_files = []
376 for f in input_api.AffectedSourceFiles(source_file_filter):
377 if f.LocalPath().startswith('webrtc'):
378 gn_files.append(f)
379
380 result = []
381 if gn_files:
382 result.append(output_api.PresubmitNotifyResult(
383 'As you\'re changing GN files: please make sure corresponding GYP'
384 'files are also updated.\nChanged GN files:',
385 items=gn_files))
386 result.extend(_CheckNoRtcBaseDepsGn(input_api, gn_files, output_api))
387 result.extend(_CheckNoSourcesAboveGn(input_api, gn_files, output_api))
388 return result
389
309 def _CheckUnwantedDependencies(input_api, output_api): 390 def _CheckUnwantedDependencies(input_api, output_api):
310 """Runs checkdeps on #include statements added in this 391 """Runs checkdeps on #include statements added in this
311 change. Breaking - rules is an error, breaking ! rules is a 392 change. Breaking - rules is an error, breaking ! rules is a
312 warning. 393 warning.
313 """ 394 """
314 # Copied from Chromium's src/PRESUBMIT.py. 395 # Copied from Chromium's src/PRESUBMIT.py.
315 396
316 # We need to wait until we have an input_api object and use this 397 # We need to wait until we have an input_api object and use this
317 # roundabout construct to import checkdeps because this file is 398 # roundabout construct to import checkdeps because this file is
318 # eval-ed and thus doesn't have __file__. 399 # eval-ed and thus doesn't have __file__.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( 563 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
483 input_api, output_api)) 564 input_api, output_api))
484 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( 565 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
485 input_api, output_api)) 566 input_api, output_api))
486 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner( 567 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
487 input_api, output_api)) 568 input_api, output_api))
488 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api)) 569 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
489 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 570 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
490 results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) 571 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
491 results.extend(_CheckGypChanges(input_api, output_api)) 572 results.extend(_CheckGypChanges(input_api, output_api))
573 results.extend(_CheckGnChanges(input_api, output_api))
492 results.extend(_CheckUnwantedDependencies(input_api, output_api)) 574 results.extend(_CheckUnwantedDependencies(input_api, output_api))
493 results.extend(_CheckJSONParseErrors(input_api, output_api)) 575 results.extend(_CheckJSONParseErrors(input_api, output_api))
494 results.extend(_RunPythonTests(input_api, output_api)) 576 results.extend(_RunPythonTests(input_api, output_api))
495 return results 577 return results
496 578
497 579
498 def CheckChangeOnUpload(input_api, output_api): 580 def CheckChangeOnUpload(input_api, output_api):
499 results = [] 581 results = []
500 results.extend(_CommonChecks(input_api, output_api)) 582 results.extend(_CommonChecks(input_api, output_api))
501 results.extend( 583 results.extend(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 for builder in masters[master]: 620 for builder in masters[master]:
539 if 'presubmit' in builder: 621 if 'presubmit' in builder:
540 # Do not trigger presubmit builders, since they're likely to fail 622 # Do not trigger presubmit builders, since they're likely to fail
541 # (e.g. OWNERS checks before finished code review), and we're running 623 # (e.g. OWNERS checks before finished code review), and we're running
542 # local presubmit anyway. 624 # local presubmit anyway.
543 pass 625 pass
544 else: 626 else:
545 try_config[master][builder] = ['defaulttests'] 627 try_config[master][builder] = ['defaulttests']
546 628
547 return try_config 629 return try_config
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698