From 8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 3 May 2018 13:42:47 +0200 Subject: BASELINE: Update Chromium to 66.0.3359.156 Change-Id: I0c9831ad39911a086b6377b16f995ad75a51e441 Reviewed-by: Michal Klocek --- chromium/v8/PRESUBMIT.py | 92 ++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 35 deletions(-) (limited to 'chromium/v8/PRESUBMIT.py') diff --git a/chromium/v8/PRESUBMIT.py b/chromium/v8/PRESUBMIT.py index b69e8f50891..e6dbb793956 100644 --- a/chromium/v8/PRESUBMIT.py +++ b/chromium/v8/PRESUBMIT.py @@ -153,6 +153,62 @@ def _CheckUnwantedDependencies(input_api, output_api): return results +def _CheckHeadersHaveIncludeGuards(input_api, output_api): + """Ensures that all header files have include guards.""" + file_inclusion_pattern = r'src/.+\.h' + + def FilterFile(affected_file): + black_list = (_EXCLUDED_PATHS + + input_api.DEFAULT_BLACK_LIST) + return input_api.FilterSourceFile( + affected_file, + white_list=(file_inclusion_pattern, ), + black_list=black_list) + + leading_src_pattern = input_api.re.compile(r'^src/') + dash_dot_slash_pattern = input_api.re.compile(r'[-./]') + def PathToGuardMacro(path): + """Guards should be of the form V8_PATH_TO_FILE_WITHOUT_SRC_H_.""" + x = input_api.re.sub(leading_src_pattern, 'v8_', path) + x = input_api.re.sub(dash_dot_slash_pattern, '_', x) + x = x.upper() + "_" + return x + + problems = [] + for f in input_api.AffectedSourceFiles(FilterFile): + local_path = f.LocalPath() + guard_macro = PathToGuardMacro(local_path) + guard_patterns = [ + input_api.re.compile(r'^#ifndef ' + guard_macro + '$'), + input_api.re.compile(r'^#define ' + guard_macro + '$'), + input_api.re.compile(r'^#endif // ' + guard_macro + '$')] + skip_check_pattern = input_api.re.compile( + r'^// PRESUBMIT_INTENTIONALLY_MISSING_INCLUDE_GUARD') + found_patterns = [ False, False, False ] + file_omitted = False + + for line in f.NewContents(): + for i in range(len(guard_patterns)): + if guard_patterns[i].match(line): + found_patterns[i] = True + if skip_check_pattern.match(line): + file_omitted = True + break + + if not file_omitted and not all(found_patterns): + problems.append( + '%s: Missing include guard \'%s\'' % (local_path, guard_macro)) + + if problems: + return [output_api.PresubmitError( + 'You added one or more header files without an appropriate\n' + 'include guard. Add the include guard {#ifndef,#define,#endif}\n' + 'triplet or omit the check entirely through the magic comment:\n' + '"// PRESUBMIT_INTENTIONALLY_MISSING_INCLUDE_GUARD".', problems)] + else: + return [] + + # TODO(mstarzinger): Similar checking should be made available as part of # tools/presubmit.py (note that tools/check-inline-includes.sh exists). def _CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api): @@ -230,44 +286,10 @@ def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): return [] -def _CheckMissingFiles(input_api, output_api): - """Runs verify_source_deps.py to ensure no files were added that are not in - GN. - """ - # We need to wait until we have an input_api object and use this - # roundabout construct to import checkdeps because this file is - # eval-ed and thus doesn't have __file__. - original_sys_path = sys.path - try: - sys.path = sys.path + [input_api.os_path.join( - input_api.PresubmitLocalPath(), 'tools')] - from verify_source_deps import missing_gn_files, missing_gyp_files - finally: - # Restore sys.path to what it was before. - sys.path = original_sys_path - - gn_files = missing_gn_files() - gyp_files = missing_gyp_files() - results = [] - if gn_files: - results.append(output_api.PresubmitError( - "You added one or more source files but didn't update the\n" - "corresponding BUILD.gn files:\n", - gn_files)) - if gyp_files: - results.append(output_api.PresubmitError( - "You added one or more source files but didn't update the\n" - "corresponding gyp files:\n", - gyp_files)) - return results - - def _CommonChecks(input_api, output_api): """Checks common to both upload and commit.""" results = [] results.extend(_CheckCommitMessageBugEntry(input_api, output_api)) - results.extend(input_api.canned_checks.CheckOwners( - input_api, output_api, source_file_filter=None)) results.extend(input_api.canned_checks.CheckPatchFormatted( input_api, output_api)) results.extend(input_api.canned_checks.CheckGenderNeutral( @@ -276,9 +298,9 @@ def _CommonChecks(input_api, output_api): results.extend(_CheckUnwantedDependencies(input_api, output_api)) results.extend( _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) + results.extend(_CheckHeadersHaveIncludeGuards(input_api, output_api)) results.extend( _CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api)) - results.extend(_CheckMissingFiles(input_api, output_api)) results.extend(_CheckJSONFiles(input_api, output_api)) results.extend(_CheckMacroUndefs(input_api, output_api)) results.extend(input_api.RunTests( -- cgit v1.2.1