2 # Copyright 2009, Google Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 """Distcc support for SCons.
33 Since this modifies the C compiler strings, it must be specified after the
34 compiler tool in the tool list.
36 Distcc support can be enabled by specifying --distcc on the SCons command
44 from SCons
.compat
._scons
_optparse
import OptionConflictError
49 # NOTE: SCons requires the use of this name, which fails gpylint.
50 """SCons entry point for this tool."""
51 if not env
.Detect('distcc'):
55 SCons
.Script
.AddOption(
59 help='enable distcc support')
60 SCons
.Script
.Help(' --distcc Enable distcc suport.\n')
62 except (OptionConflictError
, optparse
.OptionConflictError
):
63 # The distcc tool can be specified for multiple platforms, but the
64 # --distcc option can only be added once. Ignore the error which
65 # results from trying to add it a second time.
68 # If distcc isn't enabled, stop now
69 if not env
.GetOption('distcc'):
72 # Copy DISTCC_HOSTS and HOME environment variables from system environment
73 for envvar
in ('DISTCC_HOSTS', 'HOME'):
74 value
= env
.get(envvar
, os
.environ
.get(envvar
))
76 print 'Warning: %s not set in environment; disabling distcc.' % envvar
78 env
['ENV'][envvar
] = value
80 # Set name of distcc tool
81 env
['DISTCC'] = 'distcc'
83 # Modify compilers we support
84 distcc_compilers
= env
.get('DISTCC_COMPILERS', ['cc', 'gcc', 'c++', 'g++'])
85 for compiler_var
in ('CC', 'CXX'):
86 compiler
= env
.get(compiler_var
)
87 if compiler
in distcc_compilers
:
88 if sys
.platform
== 'darwin':
89 # On Mac, distcc requires the full path to the compiler
90 compiler
= env
.WhereIs(compiler
)
91 env
[compiler_var
] = '$DISTCC ' + compiler