Skip to content

Commit

Permalink
Linux: Detect host g++ version as well as target g++ version.
Browse files Browse the repository at this point in the history
BUG=360082

Review URL: https://codereview.chromium.org/247623003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265572 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thestig@chromium.org committed Apr 23, 2014
1 parent 17a659b commit 707ad51
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 21 deletions.
36 changes: 28 additions & 8 deletions build/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@
# TODO(glider): set clang to 1 earlier for ASan and TSan builds so
# that it takes effect here.
['clang==0 and asan==0 and lsan==0 and tsan==0 and msan==0', {
'binutils_version%': '<!pymod_do_main(compiler_version assembler)',
'binutils_version%': '<!pymod_do_main(compiler_version target assembler)',
}],
# On Android we know the binutils version in the toolchain.
['OS=="android"', {
Expand Down Expand Up @@ -1387,19 +1387,23 @@
['os_posix==1 and OS!="mac" and OS!="ios" and clang==0 and asan==0 and lsan==0 and tsan==0 and msan==0', {
'conditions': [
['OS=="android"', {
# We directly set the gcc_version since we know what we use.
# We directly set the gcc versions since we know what we use.
'conditions': [
['target_arch=="x64" or target_arch=="arm64"', {
'host_gcc_version%': 48,
'gcc_version%': 48,
}, {
'host_gcc_version%': 46,
'gcc_version%': 46,
}],
],
}, {
'gcc_version%': '<!pymod_do_main(compiler_version)',
'host_gcc_version%': '<!pymod_do_main(compiler_version host compiler)',
'gcc_version%': '<!pymod_do_main(compiler_version target compiler)',
}],
],
}, {
'host_gcc_version%': 0,
'gcc_version%': 0,
}],
['OS=="win" and "<!pymod_do_main(dir_exists <(windows_sdk_default_path))"=="True"', {
Expand Down Expand Up @@ -3850,13 +3854,29 @@
# TODO(mithro): Watch for clang support at following thread:
# http://clang-developers.42468.n3.nabble.com/Adding-fuse-ld-support-to-clang-td4032180.html
['gcc_version>=48', {
'cflags': [
'-fuse-ld=gold',
'target_conditions': [
['_toolset=="target"', {
'cflags': [
'-fuse-ld=gold',
],
'ldflags': [
'-fuse-ld=gold',
],
}],
],
'ldflags': [
'-fuse-ld=gold',
}],
['host_gcc_version>=48', {
'target_conditions': [
['_toolset=="host"', {
'cflags': [
'-fuse-ld=gold',
],
'ldflags': [
'-fuse-ld=gold',
],
}],
],
}]
}],
],
}],
['linux_use_bundled_binutils==1', {
Expand Down
59 changes: 46 additions & 13 deletions build/compiler_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@
compiler_version_cache = {} # Map from (compiler, tool) -> version.


def Usage(program_name):
print '%s MODE TOOL' % os.path.basename(program_name)
print 'MODE: host or target.'
print 'TOOL: assembler or compiler or linker.'
return 1


def ParseArgs(args):
if len(args) != 2:
raise Exception('Invalid number of arguments')
mode = args[0]
tool = args[1]
if mode not in ('host', 'target'):
raise Exception('Invalid mode: %s' % mode)
if tool not in ('assembler', 'compiler', 'linker'):
raise Exception('Invalid tool: %s' % tool)
return mode, tool


def GetEnvironFallback(var_list, default):
"""Look up an environment variable from a possible list of variable names."""
for var in var_list:
if var in os.environ:
return os.environ[var]
return default


def GetVersion(compiler, tool):
tool_output = tool_error = None
cache_key = (compiler, tool)
Expand Down Expand Up @@ -73,7 +100,13 @@ def GetVersion(compiler, tool):


def main(args):
ret_code, result = ExtractVersion(args)
try:
(mode, tool) = ParseArgs(args[1:])
except Exception, e:
sys.stderr.write(e.message + '\n\n')
return Usage(args[0])

ret_code, result = ExtractVersion(mode, tool)
if ret_code == 0:
print result
return ret_code
Expand All @@ -82,29 +115,29 @@ def main(args):
def DoMain(args):
"""Hook to be called from gyp without starting a separate python
interpreter."""
ret_code, result = ExtractVersion(args)
(mode, tool) = ParseArgs(args)
ret_code, result = ExtractVersion(mode, tool)
if ret_code == 0:
return result
raise Exception("Failed to extract compiler version for args: %s" % args)


def ExtractVersion(args):
tool = "compiler"
if len(args) == 1:
tool = args[0]
elif len(args) > 1:
print "Unknown arguments!"
def ExtractVersion(mode, tool):
# Check if various CXX environment variables exist and use them if they
# exist. The preferences and fallback order is a close approximation of
# GenerateOutputForConfig() in GYP's ninja generator.
# The main difference being not supporting GYP's make_global_settings.
environments = ['CXX_target', 'CXX']
if mode == 'host':
environments = ['CXX_host'] + environments;
compiler = GetEnvironFallback(environments, 'c++')

# Check if CXX environment variable exists and if it does use that
# compiler, otherwise check g++.
compiler = os.getenv("CXX", "g++")
if compiler:
compiler_version = GetVersion(compiler, tool)
if compiler_version != "":
return (0, compiler_version)

return (1, None)


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
sys.exit(main(sys.argv))

0 comments on commit 707ad51

Please sign in to comment.