Skip to content

Commit

Permalink
Merge pull request #10004 from /issues/17937
Browse files Browse the repository at this point in the history
Support function-like definitions in check_chromium_src.py
  • Loading branch information
mariospr authored Sep 8, 2021
2 parents 4d08ddb + 49608f4 commit 46be407
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
#undef __x86_64__
#endif

#include "../../../../../../../third_party/ethash/src/lib/keccak/keccak.c"
#include "../../../../../../../../brave/third_party/ethash/src/lib/keccak/keccak.c"
37 changes: 27 additions & 10 deletions script/check_chromium_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
BRAVE_CHROMIUM_SRC = os.path.join(BRAVE_SRC, 'chromium_src')
CHROMIUM_SRC = os.path.abspath(os.path.dirname(BRAVE_SRC))

NORMAL_DEFINITIONS_REGEXP = r'#define[\s\\]+([a-zA-Z0-9_]+[^\s\(]*)(?:[ \t]+\\\s*|[ \t])+([a-zA-Z0-9_]+[^\s\(]*)'
FUNCTION_LIKE_DEFINITIONS_REGEXP = r'#define[\s\\]+([a-zA-Z0-9_]+)[\s\\]*\(.*?\)(?:[ \t]+\\\s*|[ \t])([a-zA-Z0-9_]*[\s\\]*\(.*?\))'

EXCLUDES = [
'CPPLINT.cfg',
Expand Down Expand Up @@ -107,19 +109,34 @@ def do_check_defines(override_filepath, original_filepath):
attempts to find the <TARGET> in the |original_filepath|.
"""
with open(override_filepath, mode='r', encoding='utf-8') as override_file:
for line in override_file:
line_match = re.search(r'^#define\s*(\S*)\s*(\S*)', line)
if not line_match:
continue
target = line_match.group(1)
replacement = line_match.group(2)
content = override_file.read()
matches = []

# Search for all matches for normal definitions
# e.g. #define FooBar FooBar_ChromiumImpl
normal_matches = re.findall(NORMAL_DEFINITIONS_REGEXP, content)
matches += [{'value': m, 'is_func': False} for m in normal_matches]

# Search for all matches for function-like definitions
# e.g. #define FooBar(P1, P2) FooBar_ChromiumImpl(P1, P2, p3)
function_matches = re.findall(FUNCTION_LIKE_DEFINITIONS_REGEXP,
content, flags=re.DOTALL)
matches += [{'value': m, 'is_func': True} for m in function_matches]

if not matches:
return

for match in matches:
target = match['value'][0]
replacement = match['value'][1]

if not replacement:
continue

# Adjust target name for BUILDFLAG_INTERNAL_*() cases.
if target.startswith('BUILDFLAG_INTERNAL_'):
buildflag_match = re.search(r'BUILDFLAG_INTERNAL_(\S*)\(\)',
target)
# Adjust target name for BUILDFLAG_INTERNAL_*() cases for
# function-like matches.
if match['is_func'] and target.startswith('BUILDFLAG_INTERNAL_'):
buildflag_match = re.search(r'BUILDFLAG_INTERNAL_(\S*)', target)
target = buildflag_match.group(1)

# Report ERROR if target can't be found in the original file.
Expand Down

0 comments on commit 46be407

Please sign in to comment.