Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/56753 )

Change subject: scons: Turn all global sticky variables into variant ones.
......................................................................

scons: Turn all global sticky variables into variant ones.

Saved option files are processed twice, once to load the value of the
EXTRAS variable, and then again once variables have been set up by
SConsopts.

Change-Id: Id8d49051c8fe684142a68259c470ed7c86bdab53
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/56753
Reviewed-by: Andreas Sandberg <andreas.sandb...@arm.com>
Maintainer: Gabe Black <gabe.bl...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
A SConsopts
M SConstruct
M src/SConscript
3 files changed, 132 insertions(+), 82 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass




diff --git a/SConsopts b/SConsopts
new file mode 100644
index 0000000..bb2de86
--- /dev/null
+++ b/SConsopts
@@ -0,0 +1,53 @@
+# Copyright (c) 2013, 2015-2020 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 os.path
+
+from gem5_scons import warning
+
+Import('*')
+
+sticky_vars.AddVariables(
+    ('BATCH', 'Use batch pool for build and tests', False),
+    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
+    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
+    ('USE_EFENCE', 'Link with Electric Fence malloc debugger', False),
+    )
diff --git a/SConstruct b/SConstruct
index 000e526..beecd03 100755
--- a/SConstruct
+++ b/SConstruct
@@ -243,49 +243,12 @@

 ########################################################################
 #
-# Set up global sticky variables... these are common to an entire build
-# tree (not specific to a particular build like X86)
-#
-########################################################################
-
-global_vars_file = os.path.join(build_root, 'variables.global')
-
-global_vars = Variables(global_vars_file, args=ARGUMENTS)
-
-global_vars.AddVariables(
-    ('BATCH', 'Use batch pool for build and tests', False),
-    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
-    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
-    ('EXTRAS', 'Add extra directories to the compilation', '')
-    )
-
-# Update main environment with values from ARGUMENTS & global_vars_file
-global_vars.Update(main)
-Help('''
-Global build variables:
-{help}
-'''.format(help=global_vars.GenerateHelpText(main)), append=True)
-
-# Save sticky variable settings back to current variables file
-global_vars.Save(global_vars_file, main)
-
-
-########################################################################
-#
 # Set up various paths.
 #
 ########################################################################

-# Parse EXTRAS variable to build list of all directories where we're
-# look for sources etc.  This list is exported as extras_dir_list.
 base_dir = Dir('#src').abspath
-if main['EXTRAS']:
-    extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':'))
-else:
-    extras_dir_list = []
-
 Export('base_dir')
-Export('extras_dir_list')

 # the ext directory should be on the #includes path
 main.Append(CPPPATH=[Dir('ext')])
@@ -454,25 +417,11 @@
         warning("Don't know how to enable %s sanitizer(s) for your "
                 "compiler." % sanitizers)

-# Do this after we save setting back, or else we'll tack on an
-# extra 'qdo' every time we run scons.
-if main['BATCH']:
-    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
-    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
-    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
-    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
-    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
-
 if sys.platform == 'cygwin':
     # cygwin has some header file issues...
     main.Append(CCFLAGS=["-Wno-uninitialized"])


-# Cache build files in the supplied directory.
-if main['M5_BUILD_CACHE']:
-    print('Using build cache located at', main['M5_BUILD_CACHE'])
-    CacheDir(main['M5_BUILD_CACHE'])
-
 if not GetOption('no_compress_debug'):
     with gem5_scons.Configure(main) as conf:
         if not conf.CheckCxxFlag('-gz'):
@@ -625,32 +574,8 @@
     sticky_vars = Variables(args=ARGUMENTS)
     Export('sticky_vars')

-    # Sticky variables that should be exported to #defines in config/*.hh
-    # (see src/SConscript).
-    export_vars = []
-    Export('export_vars')
-
-    # Walk the tree and execute all SConsopts scripts that wil add to the
-    # above variables
-    if GetOption('verbose'):
-        print("Reading SConsopts")
-    for bdir in [ base_dir ] + extras_dir_list:
-        if not isdir(bdir):
-            error("Directory '%s' does not exist." % bdir)
-        for root, dirs, files in os.walk(bdir):
-            if 'SConsopts' in files:
-                if GetOption('verbose'):
-                    print("Reading", os.path.join(root, 'SConsopts'))
-                SConscript(os.path.join(root, 'SConsopts'),
-                        exports={'main': env})
-
-    # Call any callbacks which the SConsopts files registered.
-    for cb in after_sconsopts_callbacks:
-        cb()
-
-    # Add any generic sticky variables here.
-    sticky_vars.Add(BoolVariable('USE_EFENCE',
-        'Link with Electric Fence malloc debugger', False))
+    # EXTRAS is special since it affects what SConsopts need to be read.
+ sticky_vars.Add(('EXTRAS', 'Add extra directories to the compilation', ''))

     # Set env variables according to the build directory config.
     sticky_vars.files = []
@@ -693,7 +618,48 @@
                   % (current_vars_file, ' or '.join(default_vars_files)))
             Exit(1)

-    # Apply current variable settings to env
+    # Apply current settings for EXTRAS to env.
+    sticky_vars.Update(env)
+
+    # Parse EXTRAS variable to build list of all directories where we're
+    # look for sources etc.  This list is exported as extras_dir_list.
+    if env['EXTRAS']:
+        extras_dir_list = makePathListAbsolute(env['EXTRAS'].split(':'))
+    else:
+        extras_dir_list = []
+
+    Export('extras_dir_list')
+
+    # Sticky variables that should be exported to #defines in config/*.hh
+    # (see src/SConscript).
+    export_vars = []
+    Export('export_vars')
+
+    # Walk the tree and execute all SConsopts scripts that wil add to the
+    # above variables
+    if GetOption('verbose'):
+        print("Reading SConsopts")
+
+    def trySConsopts(dir):
+        sconsopts_path = os.path.join(dir, 'SConsopts')
+        if not isfile(sconsopts_path):
+            return
+        if GetOption('verbose'):
+            print("Reading", sconsopts_path)
+        SConscript(sconsopts_path, exports={'main': env})
+
+    trySConsopts(Dir('#').abspath)
+    for bdir in [ base_dir ] + extras_dir_list:
+        if not isdir(bdir):
+            error("Directory '%s' does not exist." % bdir)
+        for root, dirs, files in os.walk(bdir):
+            trySConsopts(root)
+
+    # Call any callbacks which the SConsopts files registered.
+    for cb in after_sconsopts_callbacks:
+        cb()
+
+    # Update env for new variables added by the SConsopts.
     sticky_vars.Update(env)

     Help('''
@@ -702,13 +668,24 @@
 '''.format(dir=variant_dir, help=sticky_vars.GenerateHelpText(env)),
          append=True)

-    # Process variable settings.
-    if env['USE_EFENCE']:
-        env.Append(LIBS=['efence'])
-
     # Save sticky variable settings back to current variables file
     sticky_vars.Save(current_vars_file, env)

+    # Do this after we save setting back, or else we'll tack on an
+    # extra 'qdo' every time we run scons.
+    if env['BATCH']:
+        env['CC']     = env['BATCH_CMD'] + ' ' + env['CC']
+        env['CXX']    = env['BATCH_CMD'] + ' ' + env['CXX']
+        env['AS']     = env['BATCH_CMD'] + ' ' + env['AS']
+        env['AR']     = env['BATCH_CMD'] + ' ' + env['AR']
+        env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB']
+
+    # Cache build files in the supplied directory.
+    if env['M5_BUILD_CACHE']:
+        print('Using build cache located at', env['M5_BUILD_CACHE'])
+        CacheDir(env['M5_BUILD_CACHE'])
+
+
     env.Append(CCFLAGS='$CCFLAGS_EXTRA')
     env.Append(LINKFLAGS='$LINKFLAGS_EXTRA')

diff --git a/src/SConscript b/src/SConscript
index f905b1f..64f1318 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -57,6 +57,9 @@

 Import('*')

+if env['USE_EFENCE']:
+    env.Append(LIBS=['efence'])
+
 # Children need to see the environment
 Export('env')


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56753
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Id8d49051c8fe684142a68259c470ed7c86bdab53
Gerrit-Change-Number: 56753
Gerrit-PatchSet: 10
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to