SCons has a system of "tools", which basically detect versions of build tools (compilers, linkers, etc) and set up an environment with the appropriate build variable substitutions for that tool to be used. For instance, there would be a "tool" for gcc, and it would detect if gcc is present on the system, and if so would set the "CC" variable to "gcc". An actually tool as defined by SCons would be a lot more sophisticated than that and set more variables, but that's the basic idea. To help modularize the gem5 SConstruct file, I moved code which would set up git commit hooks into a "tool" which helped modularize it and reduce the size of SConstruct. This isn't quite right since, while the code does detect if git was used to check out the source (if there is a .git file at the root), it doesn't really modify the environment at all. It will also be invoked every time any environment is set up, although right now that will only be the DefaultEnvironment, what's used when loose functions like Builder or Command are called with, and the "main" environment which all the others are Clone-d from. Normally, when SCons sets up a new environment, either implicitly or when Environment() is called, it sets up a bunch of built in tools which are fixed within SCons itself. If you want, you can add a "tools" argument to Environment (or to the DefaultEnvironment() function) which will replace that list of tools. That can be used to make an environment use the new "git" tool, but it isn't automatic. SCons also lets you override default tools by creating your own with the same name as the default. To make loading the git tool automatic, I added an override "default" tool which, in addition to setting some defaults which should apply to all environments, also pulled in other tools, at that time "git" and "mercurial" (RIP). Unfortunately, that meant that today, apparently particularly with SCons version 4, *any* Environment would pull in "git", and all of "git"'s dependencies, even if SCons wasn't set up enough for those to work. To break that dependency, this change stops the default tool from automatically loading the git tool, although it does continue to set other defaults which have very minimal external dependencies. When creating the "main" Environment in the SConstruct, the "git" tool is now added in explicitly. Since the list of tools replaces the original and doesn't extend it, we have to add in "default" explicitly as well. Really, the "git" tool should be converted from the tool interface into something more appropriate, like perhaps a small module under site_scons which site_init.py can import and call. When that happens, main can be declared like normal again. While making this change, I also got rid of a few nonstandard additions to the main environment that were little used and not really necessary. When reading the SConstruct, it wasn't very obvious where those extra values were coming from, and they didn't really add any value. Change-Id: I574db42fc2196bf62fc13d6754357c753ceb9117 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38616 Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Reviewed-by: Yu-hsin Wang <yuhsingw@google.com> Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
85 lines
3.7 KiB
Python
85 lines
3.7 KiB
Python
# Copyright (c) 2013, 2015-2017 ARM Limited
|
|
# All rights reserved.
|
|
#
|
|
# The license below extends only to copyright in the software and shall
|
|
# not be construed as granting a license to any other intellectual
|
|
# property including but not limited to intellectual property relating
|
|
# to a hardware implementation of the functionality of the software
|
|
# licensed hereunder. You may use the software subject to the license
|
|
# terms below provided that you ensure that this notice is replicated
|
|
# unmodified and in its entirety in all distributions of the software,
|
|
# modified or unmodified, in source code or in binary form.
|
|
#
|
|
# Copyright (c) 2011 Advanced Micro Devices, Inc.
|
|
# Copyright (c) 2009 The Hewlett-Packard Development Company
|
|
# Copyright (c) 2004-2005 The Regents of The University of Michigan
|
|
# All rights reserved.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted provided that the following conditions are
|
|
# met: redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer;
|
|
# redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution;
|
|
# neither the name of the copyright holders nor the names of its
|
|
# contributors may be used to endorse or promote products derived from
|
|
# this software without specific prior written permission.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
import os
|
|
import sys
|
|
|
|
import SCons.Tool
|
|
import SCons.Tool.default
|
|
|
|
from gem5_python_paths import extra_python_paths
|
|
|
|
def common_config(env):
|
|
# export TERM so that clang reports errors in color
|
|
use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH',
|
|
'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PROTOC',
|
|
'PYTHONPATH', 'RANLIB', 'TERM' ])
|
|
|
|
use_prefixes = [
|
|
"ASAN_", # address sanitizer symbolizer path and settings
|
|
"CCACHE_", # ccache (caching compiler wrapper) configuration
|
|
"CCC_", # clang static analyzer configuration
|
|
"DISTCC_", # distcc (distributed compiler wrapper) config
|
|
"INCLUDE_SERVER_", # distcc pump server settings
|
|
"M5", # M5 configuration (e.g., path to kernels)
|
|
]
|
|
|
|
for key,val in sorted(os.environ.items()):
|
|
if key in use_vars or \
|
|
any([key.startswith(prefix) for prefix in use_prefixes]):
|
|
env['ENV'][key] = val
|
|
|
|
# Tell scons to avoid implicit command dependencies to avoid issues
|
|
# with the param wrappes being compiled twice (see
|
|
# https://github.com/SCons/scons/issues/2811
|
|
env['IMPLICIT_COMMAND_DEPENDENCIES'] = 0
|
|
env.Decider('MD5-timestamp')
|
|
|
|
# add useful python code PYTHONPATH so it can be used by subprocesses
|
|
# as well
|
|
env.AppendENVPath('PYTHONPATH', extra_python_paths)
|
|
|
|
def generate(env):
|
|
common_config(env)
|
|
SCons.Tool.default.generate(env)
|
|
|
|
def exists(env):
|
|
return 1
|