Checks that the first include in each inline header ("*-inl.h") is the non-inl counterpart of that header, if that file exists.
(input_api, output_api)
| 370 | |
| 371 | |
| 372 | def _CheckInlineHeadersIncludeNonInlineHeadersFirst(input_api, output_api): |
| 373 | """Checks that the first include in each inline header ("*-inl.h") is the |
| 374 | non-inl counterpart of that header, if that file exists.""" |
| 375 | file_inclusion_pattern = r'.+-inl\.h' |
| 376 | include_error = ( |
| 377 | 'The first include of an -inl.h header should be the non-inl counterpart.' |
| 378 | ) |
| 379 | |
| 380 | def FilterFile(affected_file): |
| 381 | files_to_skip = _EXCLUDED_PATHS + input_api.DEFAULT_FILES_TO_SKIP + ( |
| 382 | # Exclude macro-assembler-<ARCH>-inl.h headers because they have special |
| 383 | # include rules (arch-specific macro assembler headers must be included |
| 384 | # via the general macro-assembler.h). |
| 385 | r'src[\\\/]codegen[\\\/].*[\\\/]macro-assembler-.*-inl\.h',) |
| 386 | return input_api.FilterSourceFile( |
| 387 | affected_file, |
| 388 | files_to_check=(file_inclusion_pattern,), |
| 389 | files_to_skip=files_to_skip) |
| 390 | |
| 391 | to_non_inl = lambda filename: filename[:-len("-inl.h")] + ".h" |
| 392 | problems = [] |
| 393 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 394 | if not os.path.isfile(to_non_inl(f.AbsoluteLocalPath())): |
| 395 | continue |
| 396 | non_inl_header = to_non_inl(f.LocalPath()).replace(os.sep, '/') |
| 397 | first_include = None |
| 398 | for line in f.NewContents(): |
| 399 | if line.startswith('#include '): |
| 400 | first_include = line |
| 401 | break |
| 402 | expected_include = f'#include "{non_inl_header}"' |
| 403 | if first_include is None: |
| 404 | problems.append(f'{f.LocalPath()}: should include {non_inl_header}\n' |
| 405 | ' found no includes in the file.') |
| 406 | elif not first_include.startswith(expected_include): |
| 407 | problems.append( |
| 408 | f'{f.LocalPath()}: should include {non_inl_header} first\n' |
| 409 | f' found: {first_include}') |
| 410 | |
| 411 | if problems: |
| 412 | return [output_api.PresubmitError(include_error, problems)] |
| 413 | else: |
| 414 | return [] |
| 415 | |
| 416 | |
| 417 | def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |