Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/6224

Change subject: scons: Track and reuse object nodes for a given source file.
......................................................................

scons: Track and reuse object nodes for a given source file.

scons gets upset if two different environments are used to set up a
particular object file. This change adds two dicts to the SourceFile
class, one for static and one for shared object files, which are keyed
off of the appropriate suffix. If a suffix hasn't been set up yet,
a new node of the appropriate type is set up and stored in the cache,
and then whatever is in the cache (new or old) is returned.

Change-Id: Ice4b4fc728b438a4d3316c3ff6667c0480d2a6d7
---
M src/SConscript
1 file changed, 24 insertions(+), 12 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index 73e9f82..b274804 100755
--- a/src/SConscript
+++ b/src/SConscript
@@ -124,6 +124,21 @@
             if issubclass(base, SourceFile):
                 base.all.append(self)

+        self.static_objs = {}
+        self.shared_objs = {}
+
+    def static(self, env):
+        suffix = env['OBJSUFFIX']
+        if not suffix in self.static_objs:
+            self.static_objs[suffix] = env.StaticObject(self.tnode)
+        return self.static_objs[suffix]
+
+    def shared(self, env):
+        suffix = env['SHOBJSUFFIX']
+        if not suffix in self.shared_objs:
+            self.shared_objs[suffix] = env.SharedObject(self.tnode)
+        return self.shared_objs[suffix]
+
     @property
     def filename(self):
         return str(self.tnode)
@@ -960,9 +975,6 @@
     new_env.Label = label
     new_env.Append(**kwargs)

-    make_static = lambda source: new_env.StaticObject(source.tnode)
-    make_shared = lambda source: new_env.SharedObject(source.tnode)
-
     lib_sources = Source.all.with_tag('gem5 lib')

     # Without Python, leave out all Python content from the library
@@ -974,16 +986,16 @@
     shared_objs = []

     for s in lib_sources.with_tag(Source.ungrouped_tag):
-        static_objs.append(make_static(s))
-        shared_objs.append(make_shared(s))
+        static_objs.append(s.static(new_env))
+        shared_objs.append(s.shared(new_env))

     for group in Source.source_groups:
         srcs = lib_sources.with_tag(Source.link_group_tag(group))
         if not srcs:
             continue

-        group_static = [ make_static(s) for s in srcs ]
-        group_shared = [ make_shared(s) for s in srcs ]
+        group_static = [ s.static(new_env) for s in srcs ]
+        group_shared = [ s.shared(new_env) for s in srcs ]

         # If partial linking is disabled, add these sources to the build
         # directly, and short circuit this loop.
@@ -1004,11 +1016,11 @@
         partial = env.PartialShared(target=target, source=group_shared)
         shared_objs.extend(partial)

-    static_date = make_static(date_source)
+    static_date = date_source.static(new_env)
     new_env.Depends(static_date, static_objs)
     static_objs.extend(static_date)

-    shared_date = make_shared(date_source)
+    shared_date = date_source.shared(new_env)
     new_env.Depends(shared_date, shared_objs)
     shared_objs.extend(shared_date)

@@ -1018,11 +1030,11 @@
     shared_lib = new_env.SharedLibrary(libname, shared_objs)

     # Now link a stub with main() and the static library.
-    main_objs = [ make_static(s) for s in Source.all.with_tag('main') ]
+    main_objs = [ s.static(new_env) for s in Source.all.with_tag('main') ]

     for test in UnitTest.all:
         test_sources = Source.all.with_tag(str(test.target))
-        test_objs = [ make_static(s) for s in test_sources ]
+        test_objs = [ s.static(new_env) for s in test_sources ]
         if test.main:
             test_objs += main_objs
         path = 'unittest/%s.%s' % (test.target, label)
@@ -1033,7 +1045,7 @@
     gtest_env.Append(CPPFLAGS=gtest_env['GTEST_CPPFLAGS'])
     for test in GTest.all:
         test_sources = Source.all.with_tag(str(test.target))
- test_objs = [ gtest_env.StaticObject(s.tnode) for s in test_sources ]
+        test_objs = [ s.static(gtest_env) for s in test_sources ]
         gtest_env.Program(test.dir.File('%s.%s' % (test.target, label)),
                           test_objs)


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

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice4b4fc728b438a4d3316c3ff6667c0480d2a6d7
Gerrit-Change-Number: 6224
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to