SConscript (12370:945fbd508c87) | SConscript (12371:51ac71017cdb) |
---|---|
1# -*- mode:python -*- 2 3# Copyright (c) 2004-2005 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29# Authors: Nathan Binkert 30 31import array 32import bisect | 1# -*- mode:python -*- 2 3# Copyright (c) 2004-2005 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29# Authors: Nathan Binkert 30 31import array 32import bisect |
33import functools |
|
33import imp 34import marshal 35import os 36import re 37import subprocess 38import sys 39import zlib 40 --- 16 unchanged lines hidden (view full) --- 57from m5.util import code_formatter, compareVersions 58 59######################################################################## 60# Code for adding source files of various types 61# 62# When specifying a source file of some type, a set of tags can be 63# specified for that file. 64 | 34import imp 35import marshal 36import os 37import re 38import subprocess 39import sys 40import zlib 41 --- 16 unchanged lines hidden (view full) --- 58from m5.util import code_formatter, compareVersions 59 60######################################################################## 61# Code for adding source files of various types 62# 63# When specifying a source file of some type, a set of tags can be 64# specified for that file. 65 |
65class SourceList(list): 66 def with_tags_that(self, predicate): 67 '''Return a list of sources with tags that satisfy a predicate.''' 68 def match(source): 69 return predicate(source.tags) 70 return SourceList(filter(match, self)) | 66class SourceFilter(object): 67 def __init__(self, predicate): 68 self.predicate = predicate |
71 | 69 |
72 def with_any_tags(self, *tags): 73 '''Return a list of sources with any of the supplied tags.''' 74 return self.with_tags_that(lambda stags: len(set(tags) & stags) > 0) | 70 def __or__(self, other): 71 return SourceFilter(lambda tags: self.predicate(tags) or 72 other.predicate(tags)) |
75 | 73 |
76 def with_all_tags(self, *tags): 77 '''Return a list of sources with all of the supplied tags.''' 78 return self.with_tags_that(lambda stags: set(tags) <= stags) | 74 def __and__(self, other): 75 return SourceFilter(lambda tags: self.predicate(tags) and 76 other.predicate(tags)) |
79 | 77 |
80 def with_tag(self, tag): 81 '''Return a list of sources with the supplied tag.''' 82 return self.with_tags_that(lambda stags: tag in stags) | 78def with_tags_that(predicate): 79 '''Return a list of sources with tags that satisfy a predicate.''' 80 return SourceFilter(predicate) |
83 | 81 |
84 def without_tags(self, *tags): 85 '''Return a list of sources without any of the supplied tags.''' 86 return self.with_tags_that(lambda stags: len(set(tags) & stags) == 0) | 82def with_any_tags(*tags): 83 '''Return a list of sources with any of the supplied tags.''' 84 return SourceFilter(lambda stags: len(set(tags) & stags) > 0) |
87 | 85 |
88 def without_tag(self, tag): 89 '''Return a list of sources with the supplied tag.''' 90 return self.with_tags_that(lambda stags: tag not in stags) | 86def with_all_tags(*tags): 87 '''Return a list of sources with all of the supplied tags.''' 88 return SourceFilter(lambda stags: set(tags) <= stags) |
91 | 89 |
90def with_tag(tag): 91 '''Return a list of sources with the supplied tag.''' 92 return SourceFilter(lambda stags: tag in stags) 93 94def without_tags(*tags): 95 '''Return a list of sources without any of the supplied tags.''' 96 return SourceFilter(lambda stags: len(set(tags) & stags) == 0) 97 98def without_tag(tag): 99 '''Return a list of sources with the supplied tag.''' 100 return SourceFilter(lambda stags: tag not in stags) 101 102source_filter_factories = { 103 'with_tags_that': with_tags_that, 104 'with_any_tags': with_any_tags, 105 'with_all_tags': with_all_tags, 106 'with_tag': with_tag, 107 'without_tags': without_tags, 108 'without_tag': without_tag, 109} 110 111Export(source_filter_factories) 112 113class SourceList(list): 114 def apply_filter(self, f): 115 def match(source): 116 return f.predicate(source.tags) 117 return SourceList(filter(match, self)) 118 119 def __getattr__(self, name): 120 func = source_filter_factories.get(name, None) 121 if not func: 122 raise AttributeError 123 124 @functools.wraps(func) 125 def wrapper(*args, **kwargs): 126 return self.apply_filter(func(*args, **kwargs)) 127 return wrapper 128 |
|
92class SourceMeta(type): 93 '''Meta class for source files that keeps track of all files of a 94 particular type.''' 95 def __init__(cls, name, bases, dict): 96 super(SourceMeta, cls).__init__(name, bases, dict) 97 cls.all = SourceList() 98 99class SourceFile(object): --- 189 unchanged lines hidden (view full) --- 289 290 self.sources = srcs 291 self.target = target 292 self.main = kwargs.get('main', False) 293 self.all.append(self) 294 295class GTest(UnitTest): 296 '''Create a unit test based on the google test framework.''' | 129class SourceMeta(type): 130 '''Meta class for source files that keeps track of all files of a 131 particular type.''' 132 def __init__(cls, name, bases, dict): 133 super(SourceMeta, cls).__init__(name, bases, dict) 134 cls.all = SourceList() 135 136class SourceFile(object): --- 189 unchanged lines hidden (view full) --- 326 327 self.sources = srcs 328 self.target = target 329 self.main = kwargs.get('main', False) 330 self.all.append(self) 331 332class GTest(UnitTest): 333 '''Create a unit test based on the google test framework.''' |
297 | |
298 all = [] 299 def __init__(self, *args, **kwargs): | 334 all = [] 335 def __init__(self, *args, **kwargs): |
336 isFilter = lambda arg: isinstance(arg, SourceFilter) 337 self.filters = filter(isFilter, args) 338 args = filter(lambda a: not isFilter(a), args) |
|
300 super(GTest, self).__init__(*args, **kwargs) 301 self.dir = Dir('.') | 339 super(GTest, self).__init__(*args, **kwargs) 340 self.dir = Dir('.') |
341 self.skip_lib = kwargs.pop('skip_lib', False) |
|
302 303# Children should have access 304Export('Source') 305Export('PySource') 306Export('SimObject') 307Export('ProtoBuf') 308Export('UnitTest') 309Export('GTest') --- 734 unchanged lines hidden (view full) --- 1044 if test.main: 1045 test_objs += main_objs 1046 path = 'unittest/%s.%s' % (test.target, label) 1047 new_env.Program(path, test_objs + static_objs) 1048 1049 gtest_env = new_env.Clone() 1050 gtest_env.Append(LIBS=gtest_env['GTEST_LIBS']) 1051 gtest_env.Append(CPPFLAGS=gtest_env['GTEST_CPPFLAGS']) | 342 343# Children should have access 344Export('Source') 345Export('PySource') 346Export('SimObject') 347Export('ProtoBuf') 348Export('UnitTest') 349Export('GTest') --- 734 unchanged lines hidden (view full) --- 1084 if test.main: 1085 test_objs += main_objs 1086 path = 'unittest/%s.%s' % (test.target, label) 1087 new_env.Program(path, test_objs + static_objs) 1088 1089 gtest_env = new_env.Clone() 1090 gtest_env.Append(LIBS=gtest_env['GTEST_LIBS']) 1091 gtest_env.Append(CPPFLAGS=gtest_env['GTEST_CPPFLAGS']) |
1092 gtestlib_sources = Source.all.with_tag('gtest lib') |
|
1052 gtests = [] 1053 for test in GTest.all: | 1093 gtests = [] 1094 for test in GTest.all: |
1054 test_sources = Source.all.with_tag(str(test.target)) | 1095 test_sources = test.sources 1096 if not test.skip_lib: 1097 test_sources += gtestlib_sources 1098 for f in test.filters: 1099 test_sources += Source.all.apply_filter(f) |
1055 test_objs = [ s.static(gtest_env) for s in test_sources ] 1056 gtests.append(gtest_env.Program( 1057 test.dir.File('%s.%s' % (test.target, label)), test_objs)) 1058 1059 gtest_target = Dir(new_env['BUILDDIR']).File('unittests.%s' % label) 1060 AlwaysBuild(Command(gtest_target, gtests, gtests)) 1061 1062 progname = exename --- 125 unchanged lines hidden --- | 1100 test_objs = [ s.static(gtest_env) for s in test_sources ] 1101 gtests.append(gtest_env.Program( 1102 test.dir.File('%s.%s' % (test.target, label)), test_objs)) 1103 1104 gtest_target = Dir(new_env['BUILDDIR']).File('unittests.%s' % label) 1105 AlwaysBuild(Command(gtest_target, gtests, gtests)) 1106 1107 progname = exename --- 125 unchanged lines hidden --- |