This has two purposes. First, SCons assumes that once you call Configure, you won't set up the environment the Configure is based on until after you get the environment back from it again with conf.Finish(). We get away with this when the cache mode for config tests is not "force", since Configure just reuses the environment we pass in, and any changes we make are immediately communicated between the two. If the cache mode *is* "force" though, SCons modifies the decider so that everything the conf environment goes to build looks like it's out of date. It does that by cloning the original environment, and then using that clone to do its tests. That causes a problem because we have a long lived "conf" object and make further changes to main, and since the two environments are now separate the one in conf doesn't see those updates. Second, and more subtly, we export our "main" and "env" environments so that other SConsopts and SConscript files can use them and define things in them. The way Configure is designed, if the config caching mode is "force", then it will create a new environment, and then that environment will replace what the, for instance, "main" variable points to when "main = conf.Finish()" is executed. Unfortunately, if we've already Export()-ed main, we've exported what the "main" variable pointed to at that time. Our view of "main" will track with the value that conf.Finish() returned, but since that construction environment is mearly derived from the main we Exported and not actually the same thing, they have diverged at that point and will behave independently. To solve both of these problems, this change modifies the gem5_scons.Configure() method so that it's a context manager instead of a regular function. As before, it will call Configure for us and create a configuration context, which it will yield as the "with" value. When the context exits, all the variables in the context Finish() returns will be shoved back into the original context with Replace(). This isn't perfect since variables which were deleted in the environment (probably very rare in practice) will not exist and so will not overwrite the still existent variable in the original dict. This has several advantages. The environment never splits into two copies which continue on independently. It makes the lifetime of a configuration context short, which is good because behavior during that time is tricky and unintuitive. It also makes the scope of the context very clear, so that you won't miss the fact that you're in a special setting and need to pay attention to what environment you're modifying. Also, this keeps the conceptual overhead of configuration localized to where the configuration is happening. In parts of the SConscripts which are not doing anything with conf, etc, they don't have to modify their behavior since no configuration context is active. This change is based on this change from Hanhwi Jang who identified this problem and proposed an initial solution: https://gem5-review.googlesource.com/c/public/gem5/+/44265 Change-Id: Iae0a292d6b375c5da98619f31392ca1de6216fcd Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44389 Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br> Reviewed-by: Hanhwi Jang <jang.hanhwi@gmail.com> Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com>
39 lines
1.9 KiB
Plaintext
39 lines
1.9 KiB
Plaintext
# Copyright 2020 Google, Inc.
|
|
#
|
|
# 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('*')
|
|
|
|
from gem5_scons import warning
|
|
|
|
import gem5_scons
|
|
|
|
with gem5_scons.Configure(main) as conf:
|
|
if conf.CheckLibWithHeader([None, 'execinfo'], 'execinfo.h', 'C',
|
|
'char temp; backtrace_symbols_fd((void *)&temp, 0, 0);'):
|
|
conf.env['BACKTRACE_IMPL'] = 'glibc'
|
|
else:
|
|
conf.env['BACKTRACE_IMPL'] = 'none'
|
|
warning("No suitable back trace implementation found.")
|