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

Change subject: scons: Build up different environments for different binaries.
......................................................................

scons: Build up different environments for different binaries.

Rather than collect parameters describing what environments to use for
each binary, build up the environments themselves and skip the middle
man.

Change-Id: I57ff03a3522708396149b7d053dac014477859a7
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48131
Reviewed-by: Bobby R. Bruce <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/SConscript
1 file changed, 74 insertions(+), 95 deletions(-)

Approvals:
  Bobby R. Bruce: Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/SConscript b/src/SConscript
index 21df7ca..e8655a4 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1286,108 +1286,46 @@

 Gem5('gem5')

-# Function to create a new build environment as clone of current
-# environment 'env' with modified object suffix and optional stripped
-# binary.  Additional keyword arguments are appended to corresponding
-# build environment vars.
-def makeEnv(env, label, objsfx, **kwargs):
- # SCons doesn't know to append a library suffix when there is a '.' in the
-    # name.  Use '_' instead.
-    libname = 'gem5_' + label
+env['SHOBJSUFFIX'] = '${OBJSUFFIX}s'

-    new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
-    new_env.Append(**kwargs)
-
-    lib_sources = Source.all.with_tag(new_env, 'gem5 lib')
-
-    # Without Python, leave out all Python content from the library
-    # builds.  The option doesn't affect gem5 built as a program
-    if GetOption('without_python'):
-        lib_sources = lib_sources.without_tag(new_env, 'python')
-
-    static_objs = list([ s.static(new_env) for s in lib_sources ])
-    shared_objs = list([ s.shared(new_env) for s in lib_sources ])
-
-    static_date = date_source.static(new_env)
-    new_env.Depends(static_date, static_objs)
-    static_objs.extend(static_date)
-
-    shared_date = date_source.shared(new_env)
-    new_env.Depends(shared_date, shared_objs)
-    shared_objs.extend(shared_date)
-
-    main_objs = [ s.static(new_env) for s in
-            Source.all.with_tag(new_env, 'main') ]
-
-    # First make a library of everything but main() so other programs can
-    # link against m5.
-    static_lib = new_env.StaticLibrary(libname, static_objs)
-    shared_lib = new_env.SharedLibrary(libname, shared_objs)
-
-    # Keep track of the object files generated so far so Executables can
-    # include them.
-    new_env['STATIC_OBJS'] = static_objs
-    new_env['SHARED_OBJS'] = shared_objs
-    new_env['MAIN_OBJS'] = main_objs
-
-    new_env['STATIC_LIB'] = static_lib
-    new_env['SHARED_LIB'] = shared_lib
-
-    # Record some settings for building Executables.
-    new_env['EXE_SUFFIX'] = label
-
-    for cls in ExecutableMeta.all:
-        cls.declare_all(new_env)
-
-class EnvParams(object):
-    def __init__(self, label, obj, ccflags=None, cppdefines=None,
-            ldflags=None):
-        self.label = label
-        self.obj = obj
-        self.ccflags = ccflags if ccflags else []
-        self.cppdefines = cppdefines if cppdefines else []
-        self.ldflags = ldflags if ldflags else []
-
-# Start out with the compiler flags common to all compilers and linkers,
-# i.e. all compilers use -g for opt and -g -pg for prof, and all linkers use
-# -pg for prof, and -lprofiler for perf.
-env_params = {
- 'debug': EnvParams('debug', 'do', cppdefines=['DEBUG', 'TRACING_ON=1']), - 'opt': EnvParams('opt', 'o', ccflags=['-g'], cppdefines=['TRACING_ON=1']),
-    'fast': EnvParams('fast', 'fo', cppdefines=['NDEBUG', 'TRACING_ON=0']),
-    'prof': EnvParams('prof', 'po', ccflags=['-g', '-pg'],
- cppdefines=['NDEBUG', 'TRACING_ON=0'], ldflags=['-pg']),
-    # The -lprofile flag is surrounded by no-as-needed and as-needed as the
-    # binutils linker is too clever and simply doesn't link to the library
-    # otherwise.
-    'perf': EnvParams('perf', 'gpo', ccflags=['-g'],
-                      cppdefines=['NDEBUG', 'TRACING_ON=0'],
-                      ldflags=['-Wl,--no-as-needed', '-lprofiler',
-                               '-Wl,--as-needed'])
+envs = {
+    'debug': env.Clone(ENV_LABEL='debug', OBJSUFFIX='.do'),
+    'opt': env.Clone(ENV_LABEL='opt', OBJSUFFIX='.o'),
+    'fast': env.Clone(ENV_LABEL='fast', OBJSUFFIX='.fo'),
+    'prof': env.Clone(ENV_LABEL='prof', OBJSUFFIX='.po'),
+    'perf': env.Clone(ENV_LABEL='perf', OBJSUFFIX='.gpo')
 }

+envs['debug'].Append(CPPDEFINES=['DEBUG', 'TRACING_ON=1'])
+envs['opt'].Append(CCFLAGS=['-g'], CPPDEFINES=['TRACING_ON=1'])
+envs['fast'].Append(CPPDEFINES=['NDEBUG', 'TRACING_ON=0'])
+envs['prof'].Append(CCFLAGS=['-g', '-pg'], LDFLAGS=['-pg'],
+        CPPDEFINES=['NDEBUG', 'TRACING_ON=0'])
+envs['perf'].Append(CCFLAGS=['-g'], CPPDEFINES=['NDEBUG', 'TRACING_ON=0'],
+        LDFLAGS=['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed'])
+
 # For Link Time Optimization, the optimisation flags used to compile
 # individual files are decoupled from those used at link time
 # (i.e. you can compile with -O3 and perform LTO with -O0), so we need
 # to also update the linker flags based on the target.
 if env['GCC']:
     if sys.platform == 'sunos5':
-        env_params['debug'].ccflags += ['-gstabs+']
+        envs['debug'].Append(CCFLAGS=['-gstabs+'])
     else:
-        env_params['debug'].ccflags += ['-ggdb3']
-    env_params['debug'].ldflags += ['-O0']
+        envs['debug'].Append(CCFLAGS=['-ggdb3'])
+    envs['debug'].Append(LDFLAGS=['-O0'])
     # opt, fast, prof and perf all share the same cc flags, also add
     # the optimization to the ldflags as LTO defers the optimization
     # to link time
     for target in ['opt', 'fast', 'prof', 'perf']:
-        env_params[target].ccflags += ['-O3'] + env['LTO_CCFLAGS']
-        env_params[target].ldflags += ['-O3'] + env['LTO_LDFLAGS']
+        envs[target].Append(CCFLAGS=['-O3', '${LTO_CCFLAGS}'])
+        envs[target].Append(LDFLAGS=['-O3', '${LTO_LDFLAGS}'])

 elif env['CLANG']:
-    env_params['debug'].ccflags += ['-g', '-O0']
+    envs['debug'].Append(CCFLAGS=['-g', '-O0'])
     # opt, fast, prof and perf all share the same cc flags
     for target in ['opt', 'fast', 'prof', 'perf']:
-        env_params[target].ccflags += ['-O3']
+        envs[target].Append(CCFLAGS=['-O3'])
 else:
     error('Unknown compiler, please fix compiler options')

@@ -1400,18 +1338,59 @@
 target_exts = set({ os.path.splitext(t)[1] for t in BUILD_TARGETS })
 needed_envs = set()
 for ext in target_exts:
-    if ext:
-        ext = ext[1:]
- match = next((p for p in env_params.values() if ext in (p.label, p.obj)),
-                 None)
+    match = next((e for e in envs.values() if ext in (
+                    '.' + e['ENV_LABEL'], e['OBJSUFFIX'])), None)
     if match:
-        needed_envs.add(match)
+        needed_envs.add(match['ENV_LABEL'])
     else:
-        needed_envs |= set(env_params.values())
+        needed_envs |= set(envs.keys())
         break

-for params in needed_envs:
-    makeEnv(env, params.label, '.' + params.obj,
-            CCFLAGS = Split(params.ccflags),
-            CPPDEFINES = Split(params.cppdefines),
-            LINKFLAGS = Split(params.ldflags))
+
+# Function to create a new build environment as clone of current
+# environment 'env' with modified object suffix and optional stripped
+# binary.
+for env in (envs[e] for e in needed_envs):
+ # SCons doesn't know to append a library suffix when there is a '.' in the
+    # name.  Use '_' instead.
+    libname = 'gem5_${ENV_LABEL}'
+
+    lib_sources = Source.all.with_tag(env, 'gem5 lib')
+
+    # Without Python, leave out all Python content from the library
+    # builds.  The option doesn't affect gem5 built as a program
+    if GetOption('without_python'):
+        lib_sources = lib_sources.without_tag(env, 'python')
+
+    static_objs = list([ s.static(env) for s in lib_sources ])
+    shared_objs = list([ s.shared(env) for s in lib_sources ])
+
+    static_date = date_source.static(env)
+    env.Depends(static_date, static_objs)
+    static_objs.extend(static_date)
+
+    shared_date = date_source.shared(env)
+    env.Depends(shared_date, shared_objs)
+    shared_objs.extend(shared_date)
+
+    main_objs = [ s.static(env) for s in Source.all.with_tag(env, 'main') ]
+
+    # First make a library of everything but main() so other programs can
+    # link against m5.
+    static_lib = env.StaticLibrary(libname, static_objs)
+    shared_lib = env.SharedLibrary(libname, shared_objs)
+
+    # Keep track of the object files generated so far so Executables can
+    # include them.
+    env['STATIC_OBJS'] = static_objs
+    env['SHARED_OBJS'] = shared_objs
+    env['MAIN_OBJS'] = main_objs
+
+    env['STATIC_LIB'] = static_lib
+    env['SHARED_LIB'] = shared_lib
+
+    # Record some settings for building Executables.
+    env['EXE_SUFFIX'] = env['ENV_LABEL']
+
+    for cls in ExecutableMeta.all:
+        cls.declare_all(env)



2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/48131
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: I57ff03a3522708396149b7d053dac014477859a7
Gerrit-Change-Number: 48131
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
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