SConscript (12757:114f34a90feb) SConscript (12797:fc61ae2a54bd)
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

--- 297 unchanged lines hidden (view full) ---

306 modname,ext = self.extname
307 assert ext == 'proto'
308
309 # Currently, we stick to generating the C++ headers, so we
310 # only need to track the source and header.
311 self.cc_file = File(modname + '.pb.cc')
312 self.hh_file = File(modname + '.pb.h')
313
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

--- 297 unchanged lines hidden (view full) ---

306 modname,ext = self.extname
307 assert ext == 'proto'
308
309 # Currently, we stick to generating the C++ headers, so we
310 # only need to track the source and header.
311 self.cc_file = File(modname + '.pb.cc')
312 self.hh_file = File(modname + '.pb.h')
313
314class UnitTest(object):
315 '''Create a UnitTest'''
316
314
315exectuable_classes = []
316class ExecutableMeta(type):
317 '''Meta class for Executables.'''
317 all = []
318 all = []
318 def __init__(self, target, *srcs_and_filts, **kwargs):
319
320 def __init__(cls, name, bases, d):
321 if not d.pop('abstract', False):
322 ExecutableMeta.all.append(cls)
323 super(ExecutableMeta, cls).__init__(name, bases, d)
324
325 cls.all = []
326
327class Executable(object):
328 '''Base class for creating an executable from sources.'''
329 __metaclass__ = ExecutableMeta
330
331 abstract = True
332
333 def __init__(self, target, *srcs_and_filts):
319 '''Specify the target name and any sources. Sources that are
320 not SourceFiles are evalued with Source().'''
334 '''Specify the target name and any sources. Sources that are
335 not SourceFiles are evalued with Source().'''
336 super(Executable, self).__init__()
337 self.all.append(self)
338 self.target = target
321
322 isFilter = lambda arg: isinstance(arg, SourceFilter)
323 self.filters = filter(isFilter, srcs_and_filts)
324 sources = filter(lambda a: not isFilter(a), srcs_and_filts)
325
326 srcs = SourceList()
327 for src in sources:
328 if not isinstance(src, SourceFile):
329 src = Source(src, tags=[])
330 srcs.append(src)
331
332 self.sources = srcs
339
340 isFilter = lambda arg: isinstance(arg, SourceFilter)
341 self.filters = filter(isFilter, srcs_and_filts)
342 sources = filter(lambda a: not isFilter(a), srcs_and_filts)
343
344 srcs = SourceList()
345 for src in sources:
346 if not isinstance(src, SourceFile):
347 src = Source(src, tags=[])
348 srcs.append(src)
349
350 self.sources = srcs
333 self.target = target
334 self.main = kwargs.get('main', False)
335 self.all.append(self)
336 self.dir = Dir('.')
337
351 self.dir = Dir('.')
352
338class GTest(UnitTest):
353 def path(self, env):
354 return self.dir.File(self.target + '.' + env['EXE_SUFFIX'])
355
356 def srcs_to_objs(self, env, sources):
357 return list([ s.static(env) for s in sources ])
358
359 @classmethod
360 def declare_all(cls, env):
361 return list([ instance.declare(env) for instance in cls.all ])
362
363 def declare(self, env, objs=None):
364 if objs is None:
365 objs = self.srcs_to_objs(env, self.sources)
366
367 if env['STRIP_EXES']:
368 stripped = self.path(env)
369 unstripped = env.File(str(stripped) + '.unstripped')
370 if sys.platform == 'sunos5':
371 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
372 else:
373 cmd = 'strip $SOURCE -o $TARGET'
374 env.Program(unstripped, objs)
375 return env.Command(stripped, unstripped,
376 MakeAction(cmd, Transform("STRIP")))
377 else:
378 return env.Program(self.path(env), objs)
379
380class UnitTest(Executable):
381 '''Create a UnitTest'''
382 def __init__(self, target, *srcs_and_filts, **kwargs):
383 super(UnitTest, self).__init__(target, *srcs_and_filts)
384
385 self.main = kwargs.get('main', False)
386
387 def declare(self, env):
388 sources = list(self.sources)
389 for f in self.filters:
390 sources = Source.all.apply_filter(f)
391 objs = self.srcs_to_objs(env, sources) + env['STATIC_OBJS']
392 if self.main:
393 objs += env['MAIN_OBJS']
394 return super(UnitTest, self).declare(env, objs)
395
396class GTest(Executable):
339 '''Create a unit test based on the google test framework.'''
340 all = []
397 '''Create a unit test based on the google test framework.'''
398 all = []
341 def __init__(self, *args, **kwargs):
342 super(GTest, self).__init__(*args, **kwargs)
399 def __init__(self, *srcs_and_filts, **kwargs):
400 super(GTest, self).__init__(*srcs_and_filts)
401
343 self.skip_lib = kwargs.pop('skip_lib', False)
344
402 self.skip_lib = kwargs.pop('skip_lib', False)
403
404 @classmethod
405 def declare_all(cls, env):
406 env = env.Clone()
407 env.Append(LIBS=env['GTEST_LIBS'])
408 env.Append(CPPFLAGS=env['GTEST_CPPFLAGS'])
409 env['GTEST_LIB_SOURCES'] = Source.all.with_tag('gtest lib')
410 env['GTEST_OUT_DIR'] = \
411 Dir(env['BUILDDIR']).Dir('unittests.' + env['EXE_SUFFIX'])
412 return super(GTest, cls).declare_all(env)
413
414 def declare(self, env):
415 sources = list(self.sources)
416 if not self.skip_lib:
417 sources += env['GTEST_LIB_SOURCES']
418 for f in self.filters:
419 sources += Source.all.apply_filter(f)
420 objs = self.srcs_to_objs(env, sources)
421
422 binary = super(GTest, self).declare(env, objs)
423
424 out_dir = env['GTEST_OUT_DIR']
425 xml_file = out_dir.Dir(str(self.dir)).File(self.target + '.xml')
426 AlwaysBuild(env.Command(xml_file, binary,
427 "${SOURCES[0]} --gtest_output=xml:${TARGETS[0]}"))
428
429 return binary
430
431class Gem5(Executable):
432 '''Create a gem5 executable.'''
433
434 def __init__(self, target):
435 super(Gem5, self).__init__(target)
436
437 def declare(self, env):
438 objs = env['MAIN_OBJS'] + env['STATIC_OBJS']
439 return super(Gem5, self).declare(env, objs)
440
441
345# Children should have access
346Export('Source')
347Export('PySource')
348Export('SimObject')
349Export('ProtoBuf')
442# Children should have access
443Export('Source')
444Export('PySource')
445Export('SimObject')
446Export('ProtoBuf')
447Export('Executable')
350Export('UnitTest')
351Export('GTest')
352
353########################################################################
354#
355# Debug Flags
356#
357debug_flags = {}

--- 645 unchanged lines hidden (view full) ---

1003#
1004# Define binaries. Each different build type (debug, opt, etc.) gets
1005# a slightly different build environment.
1006#
1007
1008# List of constructed environments to pass back to SConstruct
1009date_source = Source('base/date.cc', tags=[])
1010
448Export('UnitTest')
449Export('GTest')
450
451########################################################################
452#
453# Debug Flags
454#
455debug_flags = {}

--- 645 unchanged lines hidden (view full) ---

1101#
1102# Define binaries. Each different build type (debug, opt, etc.) gets
1103# a slightly different build environment.
1104#
1105
1106# List of constructed environments to pass back to SConstruct
1107date_source = Source('base/date.cc', tags=[])
1108
1109gem5_binary = Gem5('gem5')
1110
1011# Function to create a new build environment as clone of current
1012# environment 'env' with modified object suffix and optional stripped
1013# binary. Additional keyword arguments are appended to corresponding
1014# build environment vars.
1015def makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs):
1016 # SCons doesn't know to append a library suffix when there is a '.' in the
1017 # name. Use '_' instead.
1018 libname = 'gem5_' + label
1111# Function to create a new build environment as clone of current
1112# environment 'env' with modified object suffix and optional stripped
1113# binary. Additional keyword arguments are appended to corresponding
1114# build environment vars.
1115def makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs):
1116 # SCons doesn't know to append a library suffix when there is a '.' in the
1117 # name. Use '_' instead.
1118 libname = 'gem5_' + label
1019 exename = 'gem5.' + label
1020 secondary_exename = 'm5.' + label
1021
1022 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
1023 new_env.Label = label
1024 new_env.Append(**kwargs)
1025
1026 lib_sources = Source.all.with_tag('gem5 lib')
1027

--- 39 unchanged lines hidden (view full) ---

1067 static_date = date_source.static(new_env)
1068 new_env.Depends(static_date, static_objs)
1069 static_objs.extend(static_date)
1070
1071 shared_date = date_source.shared(new_env)
1072 new_env.Depends(shared_date, shared_objs)
1073 shared_objs.extend(shared_date)
1074
1119 secondary_exename = 'm5.' + label
1120
1121 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
1122 new_env.Label = label
1123 new_env.Append(**kwargs)
1124
1125 lib_sources = Source.all.with_tag('gem5 lib')
1126

--- 39 unchanged lines hidden (view full) ---

1166 static_date = date_source.static(new_env)
1167 new_env.Depends(static_date, static_objs)
1168 static_objs.extend(static_date)
1169
1170 shared_date = date_source.shared(new_env)
1171 new_env.Depends(shared_date, shared_objs)
1172 shared_objs.extend(shared_date)
1173
1174 main_objs = [ s.static(new_env) for s in Source.all.with_tag('main') ]
1175
1075 # First make a library of everything but main() so other programs can
1076 # link against m5.
1077 static_lib = new_env.StaticLibrary(libname, static_objs)
1078 shared_lib = new_env.SharedLibrary(libname, shared_objs)
1079
1176 # First make a library of everything but main() so other programs can
1177 # link against m5.
1178 static_lib = new_env.StaticLibrary(libname, static_objs)
1179 shared_lib = new_env.SharedLibrary(libname, shared_objs)
1180
1080 # Now link a stub with main() and the static library.
1081 main_objs = [ s.static(new_env) for s in Source.all.with_tag('main') ]
1181 # Keep track of the object files generated so far so Executables can
1182 # include them.
1183 new_env['STATIC_OBJS'] = static_objs
1184 new_env['SHARED_OBJS'] = shared_objs
1185 new_env['MAIN_OBJS'] = main_objs
1082
1186
1083 for test in UnitTest.all:
1084 test_sources = list(test.sources)
1085 for f in test.filters:
1086 test_sources += Source.all.apply_filter(f)
1087 test_objs = [ s.static(new_env) for s in test_sources ]
1088 if test.main:
1089 test_objs += main_objs
1090 new_env.Program(test.dir.File('%s.%s' % (test.target, label)),
1091 test_objs + static_objs)
1187 new_env['STATIC_LIB'] = static_lib
1188 new_env['SHARED_LIB'] = shared_lib
1092
1189
1093 gtest_env = new_env.Clone()
1094 gtest_env.Append(LIBS=gtest_env['GTEST_LIBS'])
1095 gtest_env.Append(CPPFLAGS=gtest_env['GTEST_CPPFLAGS'])
1096 gtestlib_sources = Source.all.with_tag('gtest lib')
1097 gtest_out_dir = Dir(new_env['BUILDDIR']).Dir('unittests.%s' % label)
1098 for test in GTest.all:
1099 test_sources = list(test.sources)
1100 if not test.skip_lib:
1101 test_sources += gtestlib_sources
1102 for f in test.filters:
1103 test_sources += Source.all.apply_filter(f)
1104 test_objs = [ s.static(gtest_env) for s in test_sources ]
1105 test_binary = gtest_env.Program(
1106 test.dir.File('%s.%s' % (test.target, label)), test_objs)
1190 # Record some settings for building Executables.
1191 new_env['EXE_SUFFIX'] = label
1192 new_env['STRIP_EXES'] = strip
1107
1193
1108 AlwaysBuild(gtest_env.Command(
1109 gtest_out_dir.File("%s/%s.xml" % (test.dir, test.target)),
1110 test_binary, "${SOURCES[0]} --gtest_output=xml:${TARGETS[0]}"))
1194 for cls in ExecutableMeta.all:
1195 cls.declare_all(new_env)
1111
1196
1112 progname = exename
1113 if strip:
1114 progname += '.unstripped'
1197 new_env.M5Binary = File(gem5_binary.path(new_env))
1115
1198
1116 targets = new_env.Program(progname, main_objs + static_objs)
1117
1118 if strip:
1119 if sys.platform == 'sunos5':
1120 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
1121 else:
1122 cmd = 'strip $SOURCE -o $TARGET'
1123 targets = new_env.Command(exename, progname,
1124 MakeAction(cmd, Transform("STRIP")))
1125
1126 new_env.Command(secondary_exename, exename,
1199 new_env.Command(secondary_exename, new_env.M5Binary,
1127 MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
1128
1200 MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
1201
1129 new_env.M5Binary = targets[0]
1130
1131 # Set up regression tests.
1132 SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'),
1133 variant_dir=Dir('tests').Dir(new_env.Label),
1134 exports={ 'env' : new_env }, duplicate=False)
1135
1136# Start out with the compiler flags common to all compilers,
1137# i.e. they all use -g for opt and -g -pg for prof
1138ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],

--- 99 unchanged lines hidden ---
1202 # Set up regression tests.
1203 SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'),
1204 variant_dir=Dir('tests').Dir(new_env.Label),
1205 exports={ 'env' : new_env }, duplicate=False)
1206
1207# Start out with the compiler flags common to all compilers,
1208# i.e. they all use -g for opt and -g -pg for prof
1209ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],

--- 99 unchanged lines hidden ---