summaryrefslogtreecommitdiff
path: root/include_server
diff options
context:
space:
mode:
authorAnders F Björklund <anders.f.bjorklund@gmail.com>2018-11-09 19:00:13 +0100
committerAnders F Björklund <anders.f.bjorklund@gmail.com>2018-11-10 08:35:17 +0100
commit0caa4b03ddca12f084dd5bfe6775a5eeac7ec8e6 (patch)
treef04ec8d99db21ad06b4503a9ea091879b3c6a8ac /include_server
parentbdcd546564a3e6b196838d5a6c09e7cfbad83b91 (diff)
downloaddistcc-git-0caa4b03ddca12f084dd5bfe6775a5eeac7ec8e6.tar.gz
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.
Diffstat (limited to 'include_server')
-rwxr-xr-xinclude_server/parse_command.py30
-rwxr-xr-xinclude_server/parse_command_test.py7
2 files changed, 36 insertions, 1 deletions
diff --git a/include_server/parse_command.py b/include_server/parse_command.py
index cd02d01..b0b284d 100755
--- a/include_server/parse_command.py
+++ b/include_server/parse_command.py
@@ -119,6 +119,22 @@ CPP_OPTIONS_MAYBE_TWO_WORDS_FIRST_LETTERS = ('M', 'i', '-', 'a', 't')
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
diff --git a/include_server/parse_command_test.py b/include_server/parse_command_test.py
index 91a5b3a..718c3b8 100755
--- a/include_server/parse_command_test.py
+++ b/include_server/parse_command_test.py
@@ -133,6 +133,10 @@ class ParseCommandUnitTest(unittest.TestCase):
+ " -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 @@ class ParseCommandUnitTest(unittest.TestCase):
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'))