Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/40858 )

Change subject: scons: Extract the gem5 specific Configure call to its own file.
......................................................................

scons: Extract the gem5 specific Configure call to its own file.

This modularizes that fairly generic code and pulls it out of the main
SConstruct file.

Change-Id: I5f5edc866af43753b4e0a9cc63774ded0fffe06b
---
M SConstruct
M site_scons/gem5_scons/__init__.py
A site_scons/gem5_scons/configure.py
3 files changed, 146 insertions(+), 93 deletions(-)



diff --git a/SConstruct b/SConstruct
index 7ec4d77..b57131d 100755
--- a/SConstruct
+++ b/SConstruct
@@ -126,6 +126,7 @@
           help='Build systemc tests')

 from gem5_scons import Transform, error, warning, summarize_warnings
+import gem5_scons

 ########################################################################
 #
@@ -498,81 +499,9 @@
     warning('While checking protoc version:', str(e))
     main['HAVE_PROTOC'] = False

-def CheckCxxFlag(context, flag, autoadd=True):
-    context.Message("Checking for compiler %s support... " % flag)
-    last_cxxflags = context.env['CXXFLAGS']
-    context.env.Append(CXXFLAGS=[flag])
-    ret = context.TryCompile('', '.cc')
-    if not autoadd:
-        context.env['CXXFLAGS'] = last_cxxflags
-    context.Result(ret)
-    return ret
-
-def CheckLinkFlag(context, flag, autoadd=True, set_for_shared=True):
-    context.Message("Checking for linker %s support... " % flag)
-    last_linkflags = context.env['LINKFLAGS']
-    context.env.Append(LINKFLAGS=[flag])
-    ret = context.TryLink('int main(int, char *[]) { return 0; }', '.cc')
-    if not autoadd:
-        context.env['LINKFLAGS'] = last_linkflags
-    if set_for_shared:
-        assert(autoadd)
-        context.env.Append(SHLINKFLAGS=[flag])
-    context.Result(ret)
-    return ret
-
-# Add a custom Check function to test for structure members.
-def CheckMember(context, include, decl, member, include_quotes="<>"):
-    context.Message("Checking for member %s in %s..." %
-                    (member, decl))
-    text = """
-#include %(header)s
-int main(){
-  %(decl)s test;
-  (void)test.%(member)s;
-  return 0;
-};
-""" % { "header" : include_quotes[0] + include + include_quotes[1],
-        "decl" : decl,
-        "member" : member,
-        }
-
-    ret = context.TryCompile(text, extension=".cc")
-    context.Result(ret)
-    return ret
-
-def CheckPythonLib(context):
-    context.Message('Checking Python version... ')
-    ret = context.TryRun(r"""
-#include <pybind11/embed.h>
-
-int
-main(int argc, char **argv) {
-    pybind11::scoped_interpreter guard{};
-    pybind11::exec(
-        "import sys\n"
-        "vi = sys.version_info\n"
- "sys.stdout.write('%i.%i.%i' % (vi.major, vi.minor, vi.micro));\n");
-    return 0;
-}
-    """, extension=".cc")
-    context.Result(ret[1] if ret[0] == 1 else 0)
-    if ret[0] == 0:
-        return None
-    else:
-        return tuple(map(int, ret[1].split(".")))
-
 # Platform-specific configuration.  Note again that we assume that all
 # builds under a given build root run on the same host platform.
-conf = Configure(main,
-                 conf_dir = joinpath(build_root, '.scons_config'),
-                 log_file = joinpath(build_root, 'scons_config.log'),
-                 custom_tests = {
-        'CheckMember' : CheckMember,
-        'CheckPythonLib' : CheckPythonLib,
-        'CheckCxxFlag' : CheckCxxFlag,
-        'CheckLinkFlag' : CheckLinkFlag,
-        })
+conf = gem5_scons.Configure(main)

 # We should compile a 64 bit binary on Mac OS X/Darwin
 if sys.platform == "darwin":
@@ -581,25 +510,6 @@
     main.Append(LINKFLAGS=['-arch', 'x86_64'])
     main.Append(ASFLAGS=['-arch', 'x86_64'])

-# Recent versions of scons substitute a "Null" object for Configure()
-# when configuration isn't necessary, e.g., if the "--help" option is
-# present.  Unfortuantely this Null object always returns false,
-# breaking all our configuration checks.  We replace it with our own
-# more optimistic null object that returns True instead.
-if not conf:
-    def NullCheck(*args, **kwargs):
-        return True
-
-    class NullConf:
-        def __init__(self, env):
-            self.env = env
-        def Finish(self):
-            return self.env
-        def __getattr__(self, mname):
-            return NullCheck
-
-    conf = NullConf(main)
-
 # Cache build files in the supplied directory.
 if main['M5_BUILD_CACHE']:
     print('Using build cache located at', main['M5_BUILD_CACHE'])
diff --git a/site_scons/gem5_scons/__init__.py b/site_scons/gem5_scons/__init__.py
index 708002f..9d62c47 100644
--- a/site_scons/gem5_scons/__init__.py
+++ b/site_scons/gem5_scons/__init__.py
@@ -43,6 +43,7 @@
 import textwrap

 from gem5_scons.util import get_termcap
+from gem5_scons.configure import Configure
 import SCons.Script

 termcap = get_termcap()
@@ -200,4 +201,4 @@
     print_message('Error: ', termcap.Red, message, **kwargs)
     SCons.Script.Exit(1)

-__all__ = ['Transform', 'warning', 'error']
+__all__ = ['Configure', 'Transform', 'warning', 'error']
diff --git a/site_scons/gem5_scons/configure.py b/site_scons/gem5_scons/configure.py
new file mode 100644
index 0000000..e539c73
--- /dev/null
+++ b/site_scons/gem5_scons/configure.py
@@ -0,0 +1,142 @@
+# 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 SCons.Script
+
+def CheckCxxFlag(context, flag, autoadd=True):
+    context.Message("Checking for compiler %s support... " % flag)
+    last_cxxflags = context.env['CXXFLAGS']
+    context.env.Append(CXXFLAGS=[flag])
+    ret = context.TryCompile('', '.cc')
+    if not autoadd:
+        context.env['CXXFLAGS'] = last_cxxflags
+    context.Result(ret)
+    return ret
+
+def CheckLinkFlag(context, flag, autoadd=True, set_for_shared=True):
+    context.Message("Checking for linker %s support... " % flag)
+    last_linkflags = context.env['LINKFLAGS']
+    context.env.Append(LINKFLAGS=[flag])
+    ret = context.TryLink('int main(int, char *[]) { return 0; }', '.cc')
+    if not autoadd:
+        context.env['LINKFLAGS'] = last_linkflags
+    if set_for_shared:
+        assert(autoadd)
+        context.env.Append(SHLINKFLAGS=[flag])
+    context.Result(ret)
+    return ret
+
+# Add a custom Check function to test for structure members.
+def CheckMember(context, include, decl, member, include_quotes="<>"):
+    context.Message("Checking for member %s in %s..." %
+                    (member, decl))
+    text = """
+#include %(header)s
+int main(){
+  %(decl)s test;
+  (void)test.%(member)s;
+  return 0;
+};
+""" % { "header" : include_quotes[0] + include + include_quotes[1],
+        "decl" : decl,
+        "member" : member,
+        }
+
+    ret = context.TryCompile(text, extension=".cc")
+    context.Result(ret)
+    return ret
+
+def CheckPythonLib(context):
+    context.Message('Checking Python version... ')
+    ret = context.TryRun(r"""
+#include <pybind11/embed.h>
+
+int
+main(int argc, char **argv) {
+    pybind11::scoped_interpreter guard{};
+    pybind11::exec(
+        "import sys\n"
+        "vi = sys.version_info\n"
+ "sys.stdout.write('%i.%i.%i' % (vi.major, vi.minor, vi.micro));\n");
+    return 0;
+}
+    """, extension=".cc")
+    context.Result(ret[1] if ret[0] == 1 else 0)
+    if ret[0] == 0:
+        return None
+    else:
+        return tuple(map(int, ret[1].split(".")))
+
+def Configure(env, *args, **kwargs):
+    kwargs.setdefault('conf_dir',
+            os.path.join(env['BUILDROOT'], '.scons_config'))
+    kwargs.setdefault('log_file',
+            os.path.join(env['BUILDROOT'], 'scons_config.log'))
+    kwargs.setdefault('custom_tests', {})
+    kwargs['custom_tests'].update({
+            'CheckMember' : CheckMember,
+            'CheckPythonLib' : CheckPythonLib,
+            'CheckCxxFlag' : CheckCxxFlag,
+            'CheckLinkFlag' : CheckLinkFlag,
+    })
+    conf = SCons.Script.Configure(env, *args, **kwargs)
+
+    # Recent versions of scons substitute a "Null" object for Configure()
+    # when configuration isn't necessary, e.g., if the "--help" option is
+    # present.  Unfortuantely this Null object always returns false,
+    # breaking all our configuration checks.  We replace it with our own
+    # more optimistic null object that returns True instead.
+    if not conf:
+        def NullCheck(*args, **kwargs):
+            return True
+
+        class NullConf:
+            def __init__(self, env):
+                self.env = env
+            def Finish(self):
+                return self.env
+            def __getattr__(self, mname):
+                return NullCheck
+
+        conf = NullConf(main)
+
+    return conf

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40858
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: I5f5edc866af43753b4e0a9cc63774ded0fffe06b
Gerrit-Change-Number: 40858
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to