Skip to content
Permalink
Browse files

Handle complex arguments, like assembler macros

The Linux kernel has started using statements like
-Wa,macros.s for including assembler with the code.

Handle these similar to the `-imacros` statement,
and send them to the compile server for processing.
  • Loading branch information...
afbjorklund committed Nov 9, 2018
1 parent bdcd546 commit 0caa4b03ddca12f084dd5bfe6775a5eeac7ec8e6
Showing with 36 additions and 1 deletion.
  1. +30 −0 include_server/parse_command.py
  2. +6 −1 include_server/parse_command_test.py
@@ -119,6 +119,22 @@ def _RaiseNotImplemented(name, comment=''):
for key in CPP_OPTIONS_MAYBE_TWO_WORDS.keys():
assert key[1] in CPP_OPTIONS_MAYBE_TWO_WORDS_FIRST_LETTERS

PATH_EXPR='[/a-zA-Z_0-9.]+' # regular expression for a partial file path

# These are the cpp options that require regular expressions, m is Match.
CPP_OPTIONS_REGULAR_EXPRESSIONS = {
'-Wa,(%s\.s)' % PATH_EXPR: lambda ps, m: ps.include_files.append(m.group(1)),
'-Wa,\[(%s\.s)\]' % PATH_EXPR: lambda ps, m: ps.include_files.append(m.group(1)),
}

CPP_OPTIONS_REGULAR_EXPRESSIONS_STARTS_WITH = '-Wa,'
for key in CPP_OPTIONS_REGULAR_EXPRESSIONS.keys():
assert key.startswith(CPP_OPTIONS_REGULAR_EXPRESSIONS_STARTS_WITH)

CPP_OPTIONS_REGULAR_EXPRESSIONS_COMPILED = {}
for key in CPP_OPTIONS_REGULAR_EXPRESSIONS.keys():
CPP_OPTIONS_REGULAR_EXPRESSIONS_COMPILED[key] = re.compile(key)

# These are the cpp options that a) are more than one letter long,
# b) always take an argument, and c) must have that argument as a
# separate word in argv.
@@ -415,6 +431,20 @@ def ParseCommandArgs(args, current_dir, includepath_map, dir_map,
if found_action: # what we really need here is a goto!
continue

# Deal with the complex options requiring regular expressions last.
if args[i].startswith(CPP_OPTIONS_REGULAR_EXPRESSIONS_STARTS_WITH):
found_action = False
for (option, action) in CPP_OPTIONS_REGULAR_EXPRESSIONS.items():
r = CPP_OPTIONS_REGULAR_EXPRESSIONS_COMPILED[option]
m = r.match(args[i])
if action and m is not None:
action(parse_state, m)
i += 1
found_action = True
break
if found_action:
continue

# Whatever is left must be a one-word option (that is, an option
# without an arg) that it's safe to ignore.
i += 1
@@ -133,6 +133,10 @@ def test_ParseCommandArgs(self):
+ " -isystem system -Imice -iquote/and -I/men a.c "
+ " -include included_A.h "
+ " -includeincluded_B.h "
+ " -Wa,macros_A.s "
+ " -Wa,[macros_B.s] "
+ " -Wa,arch/x86/kernel/macros.s -Wa,- "
+ " -Wa,other_directive "
+ "-Xlinker W,l -L /ignored_by_us -o a.o"),
os.getcwd(),
self.includepath_map,
@@ -146,7 +150,8 @@ def test_ParseCommandArgs(self):
filepath),
(('/and', 'mice', '/men', 'system'),
('mice', '/men', 'system'),
["included_A.h", "included_B.h"],
["included_A.h", "included_B.h",
"macros_A.s", "macros_B.s", "arch/x86/kernel/macros.s"],
'a.c'))


0 comments on commit 0caa4b0

Please sign in to comment.
You can’t perform that action at this time.