summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfergus.henderson <fergushenderson@users.noreply.github.com>2010-08-19 19:23:49 +0000
committerfergus.henderson <fergushenderson@users.noreply.github.com>2010-08-19 19:23:49 +0000
commitdc2c66bf523a70178fc486abcbdfa9c2a379dbb1 (patch)
tree48f351cb35736f61d160e46eab79e7a0fc22b83a
parentf07afd5a0d0150c3cb1b8559d668bbbd31ed1f2e (diff)
downloaddistcc-git-dc2c66bf523a70178fc486abcbdfa9c2a379dbb1.tar.gz
Apply --sysroot patch from Simon Baldwin <simonb@google.com>:
2010-08-18 Simon Baldwin <simonb@google.com> * include_server/compiler_defaults.py (_SystemSearchdirsGCC): Add a 'sysroot' parameter. Add --sysroot, if needed, to the gcc invocation that identifies search directories and default paths. Add debugging output. (SetSystemDirsDefaults): Add 'sysroot' parameter. Add another dictionary level to system_dirs_default for sysroot values. Add debugging output. * include_server/parse_command.py (ParseCommandArgs): Identify and handle arguments of the form '--opt=value'. Pass any --sysroot value to compiler_defaults.SetSystemDirsDefaults, use it in compiler_defaults.system_dirs_default lookups. (CPP_OPTIONS_APPEARING_AS_ASSIGNMENTS): New. * include_server/parse_command_test.py (Mock_SetSystemDirsDefaults): Add sysroot parameter, verify it on function calls. (ParseCommandUnitTest): Add --sysroot to mock gcc invocations.
-rwxr-xr-xinclude_server/compiler_defaults.py42
-rwxr-xr-xinclude_server/parse_command.py26
-rwxr-xr-xinclude_server/parse_command_test.py32
3 files changed, 69 insertions, 31 deletions
diff --git a/include_server/compiler_defaults.py b/include_server/compiler_defaults.py
index dbbb419..d0c27d5 100755
--- a/include_server/compiler_defaults.py
+++ b/include_server/compiler_defaults.py
@@ -155,13 +155,14 @@ def _MakeLinkFromMirrorToRealLocation(system_dir, client_root, system_links):
system_links.append(rooted_system_dir)
-def _SystemSearchdirsGCC(compiler, language, canonical_lookup):
+def _SystemSearchdirsGCC(compiler, sysroot, language, canonical_lookup):
"""Run gcc on empty file; parse output to figure out default paths.
This function works only for gcc, and only some versions at that.
Arguments:
compiler: a filepath (the first argument on the distcc command line)
+ sysroot: the --sysroot passed to the compiler ("" to disable)
language: 'c' or 'c++' or other item in basics.LANGUAGES
canonical_lookup: a function that maps strings to their realpaths
Returns:
@@ -184,8 +185,11 @@ def _SystemSearchdirsGCC(compiler, language, canonical_lookup):
# blah. blah.
#------------
- command = [compiler, "-x", language, "-v", "-c", "/dev/null", "-o",
- "/dev/null"]
+ command = [compiler]
+ if sysroot:
+ command += ["--sysroot=" + sysroot]
+ command += ["-x", language, "-v", "-c", "/dev/null", "-o", "/dev/null"]
+ Debug(DEBUG_DATA, "system search dirs command: %s" % command)
try:
# We clear the environment, because otherwise, directories
@@ -331,11 +335,12 @@ class CompilerDefaults(object):
self.system_links = []
self.client_root = client_root
- def SetSystemDirsDefaults(self, compiler, language, timer=None):
+ def SetSystemDirsDefaults(self, compiler, sysroot, language, timer=None):
"""Set instance variables according to compiler, and make symlink farm.
Arguments:
compiler: a filepath (the first argument on the distcc command line)
+ sysroot: the --sysroot passed to the compiler ("" to disable)
language: 'c' or 'c++' or other item in basics.LANGUAGES
timer: a basis.IncludeAnalyzerTimer or None
@@ -346,30 +351,35 @@ class CompilerDefaults(object):
"""
assert isinstance(compiler, str)
assert isinstance(language, str)
- Debug(DEBUG_TRACE, "SetSystemDirsDefaults with CC, LANG: %s, %s" %
- (compiler, language))
+ Debug(DEBUG_TRACE,
+ "SetSystemDirsDefaults with CC, SYSROOT, LANG: %s, %s, %s" %
+ (compiler, sysroot, language))
if compiler in self.system_dirs_default:
- if language in self.system_dirs_default[compiler]:
- return
+ if sysroot in self.system_dirs_default[compiler]:
+ if language in self.system_dirs_default[compiler][sysroot]:
+ return
+ else:
+ self.system_dirs_default[compiler][sysroot] = {}
else:
- self.system_dirs_default[compiler] = {}
+ self.system_dirs_default[compiler] = {sysroot: {}}
try:
if timer:
# We have to disable the timer because the select system call that is
# executed when calling the compiler through Popen gives up if presented
# with a SIGALRM.
timer.Stop()
- self.system_dirs_default[compiler][language] = (
- _SystemSearchdirsGCC(compiler, language, self.canonical_lookup))
+ self.system_dirs_default[compiler][sysroot][language] = (
+ _SystemSearchdirsGCC(compiler,
+ sysroot, language, self.canonical_lookup))
Debug(DEBUG_DATA,
- "system_dirs_default[%s][%s]: %s" %
- (compiler, language,
- self.system_dirs_default[compiler][language]))
+ "system_dirs_default[%s][%s][%s]: %s" %
+ (compiler, sysroot, language,
+ self.system_dirs_default[compiler][sysroot][language]))
# Now summarize what we know and add to system_dirs_default_all.
self.system_dirs_default_all |= (
- set(self.system_dirs_default[compiler][language]))
+ set(self.system_dirs_default[compiler][sysroot][language]))
# Construct the symlink farm for the compiler default dirs.
- for system_dir in self.system_dirs_default[compiler][language]:
+ for system_dir in self.system_dirs_default[compiler][sysroot][language]:
_MakeLinkFromMirrorToRealLocation(system_dir, self.client_root,
self.system_links)
finally:
diff --git a/include_server/parse_command.py b/include_server/parse_command.py
index e58f973..5b420ac 100755
--- a/include_server/parse_command.py
+++ b/include_server/parse_command.py
@@ -52,7 +52,7 @@ class ParseState:
self.language = 'none' # equivalent to commandline of '-x none'
self.isysroot = None
- self.sysroot = None
+ self.sysroot = ""
self.output_file = None
self.iprefix = ""
self.Dopts = []
@@ -109,8 +109,6 @@ CPP_OPTIONS_MAYBE_TWO_WORDS = {
'-imultilib': lambda ps, arg: _RaiseNotImplemented('-imultilib'),
'-isystem': lambda ps, arg: ps.before_system_dirs.append(arg),
'-iquote': lambda ps, arg: ps.quote_dirs.append(arg),
-# '--sysroot=': lambda ps, arg: ps.set_sysroot(arg),
- '--sysroot=': lambda ps, arg: None,
}
CPP_OPTIONS_MAYBE_TWO_WORDS_FIRST_LETTERS = ('M', 'i', '-')
# A "compile-time" check to make sure the first-letter list is up-to-date
@@ -139,6 +137,13 @@ CPP_OPTIONS_TWO_WORDS = {}
CPP_OPTIONS_TWO_WORDS.update(CPP_OPTIONS_MAYBE_TWO_WORDS)
CPP_OPTIONS_TWO_WORDS.update(CPP_OPTIONS_ALWAYS_TWO_WORDS)
+# These are the cpp options that a) are more than one letter long,
+# b) always take an argument, and c) have that argument separated from
+# the option by '='.
+CPP_OPTIONS_APPEARING_AS_ASSIGNMENTS = {
+ '--sysroot': lambda ps, arg: ps.set_sysroot(arg)
+}
+
# These are the cpp options that do not take an argument.
# (Note, most cpp options do not take an argument, but do not pertain to
# preprocessing, so we can ignore them. Those are dealt in the default
@@ -375,6 +380,16 @@ def ParseCommandArgs(args, current_dir, includepath_map, dir_map,
raise NotCoveredError("No argument found for option '%s'" % args[i])
continue
+ # Deal with the have-arg options that appear as if assignments
+ # ("--sysroot=/mumble").
+ if '=' in args[i]:
+ arg, value = args[i].split('=', 1)
+ action = CPP_OPTIONS_APPEARING_AS_ASSIGNMENTS.get(arg)
+ if action:
+ action(parse_state, value)
+ i += 1
+ continue
+
# Deal with the options that take no arguments ("-nostdinc").
action = CPP_OPTIONS_ONE_WORD.get(args[i])
if action:
@@ -432,7 +447,8 @@ def ParseCommandArgs(args, current_dir, includepath_map, dir_map,
parse_state.language = basics.TRANSLATION_UNIT_MAP[suffix]
assert parse_state.language in basics.LANGUAGES
- compiler_defaults.SetSystemDirsDefaults(compiler, parse_state.language, timer)
+ compiler_defaults.SetSystemDirsDefaults(compiler, parse_state.sysroot,
+ parse_state.language, timer)
def IndexDirs(dir_list):
"""Normalize directory names and index.
@@ -450,7 +466,7 @@ def ParseCommandArgs(args, current_dir, includepath_map, dir_map,
if not parse_state.nostdinc:
angle_dirs.extend(
IndexDirs(compiler_defaults.system_dirs_default
- [compiler][parse_state.language]))
+ [compiler][parse_state.sysroot][parse_state.language]))
angle_dirs.extend(IndexDirs(parse_state.after_system_dirs))
quote_dirs = IndexDirs(parse_state.quote_dirs)
diff --git a/include_server/parse_command_test.py b/include_server/parse_command_test.py
index 70ccfde..b7ef4e6 100755
--- a/include_server/parse_command_test.py
+++ b/include_server/parse_command_test.py
@@ -50,19 +50,26 @@ class ParseCommandUnitTest(unittest.TestCase):
mock_compiler = '/usr/crosstool/v8/gcc-4.1.0-glibc-2.2.2/blah/gcc'
self.mock_compiler = mock_compiler
+ mock_sysroot = '/usr/local/fake/sysroot'
+ self.mock_sysroot = mock_sysroot
- def Mock_SetSystemDirsDefaults(compiler, language, timer=None):
+ def Mock_SetSystemDirsDefaults(compiler, sysroot, language, timer=None):
if compiler != mock_compiler:
raise Exception, "compiler: %s, mock_compiler: %s" % (
compiler, mock_compiler)
+ if sysroot != mock_sysroot:
+ raise Exception, "sysroot: %s, mock_sysroot: %s" % (
+ sysroot, mock_sysroot)
self.compiler_defaults = lambda x: x
self.compiler_defaults.SetSystemDirsDefaults = Mock_SetSystemDirsDefaults
self.compiler_defaults.system_dirs_default_all = []
self.compiler_defaults.system_dirs_default = {}
- self.compiler_defaults.system_dirs_default[mock_compiler] = {}
- self.compiler_defaults.system_dirs_default[mock_compiler]['c'] = []
- self.compiler_defaults.system_dirs_default[mock_compiler]['c++'] = []
+ system_dirs_default = self.compiler_defaults.system_dirs_default
+ system_dirs_default[mock_compiler] = {}
+ system_dirs_default[mock_compiler][mock_sysroot] = {}
+ system_dirs_default[mock_compiler][mock_sysroot]['c'] = []
+ system_dirs_default[mock_compiler][mock_sysroot]['c++'] = []
def tearDown(self):
shutil.rmtree(self.tmp)
@@ -121,10 +128,12 @@ class ParseCommandUnitTest(unittest.TestCase):
quote_dirs, angle_dirs, include_files, filepath, _incl_clos_f, _d_opts = (
parse_command.ParseCommandArgs(
parse_command.ParseCommandLine(
- self.mock_compiler + " -isystem system -Imice -iquote/and -I/men a.c "
- " -include included_A.h "
- " -includeincluded_B.h "
- "-Xlinker W,l -L /ignored_by_us -o a.o"),
+ self.mock_compiler
+ + " --sysroot=" + self.mock_sysroot
+ + " -isystem system -Imice -iquote/and -I/men a.c "
+ + " -include included_A.h "
+ + " -includeincluded_B.h "
+ + "-Xlinker W,l -L /ignored_by_us -o a.o"),
os.getcwd(),
self.includepath_map,
self.directory_map,
@@ -144,7 +153,9 @@ class ParseCommandUnitTest(unittest.TestCase):
self.assertRaises(NotCoveredError,
parse_command.ParseCommandArgs,
parse_command.ParseCommandLine(
- self.mock_compiler +" -I- -iquote a.c"),
+ self.mock_compiler
+ + " --sysroot=" + self.mock_sysroot
+ + " -I- -iquote a.c"),
os.getcwd(),
self.includepath_map,
self.directory_map,
@@ -153,7 +164,8 @@ class ParseCommandUnitTest(unittest.TestCase):
quote_dirs, angle_dirs, include_files, filepath, _incl_cls_file, _d_opts = (
parse_command.ParseCommandArgs(parse_command.ParseCommandLine(
"/usr/crosstool/v8/gcc-4.1.0-glibc-2.2.2/blah/gcc"
- + " -fno-exceptions -funsigned-char -D__STDC_FORMAT_MACROS -g0"
+ + " --sysroot=/usr/local/fake/sysroot"
+ + " -fno-exceptions -funsigned-char -D__STDC_FORMAT_MACROS -g0"
+ " -D_REENTRANT -DCOMPILER_GCC3 -DCOMPILER_GCC4 -DARCH_PIII -DOS_LINUX"
+ " -fmessage-length=0 -fno-strict-aliasing -fno-tree-vrp -D_REENTRANT"
+ " -DHAS_vsnprintf"