build: Only create a single build environment

I was using a debug and a release environment for programs, that way
both versions of tests could be checked.  Instead, it'll be simpler to
only use a single environment and then control debug information using
CONFIG_DEBUG.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2013-07-07 21:17:27 -04:00 committed by Anna Schumaker
parent e13b4afa60
commit 13a0d25e8f
4 changed files with 46 additions and 40 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
*.run
*.test
*.tar.gz
.*
ocarina.bin
.sconsign.dblite
bin/

24
config
View File

@ -7,23 +7,17 @@ CONFIG_DEBUG = True
Export("CONFIG_VERSION", "CONFIG_DEBUG")
# Set up default environments
def get_env(flags):
e = Environment(CCFLAGS = flags)
e.Append(CPPPATH = os.path.abspath("include"))
e.Append(CXXCOMSTR = "C++ $TARGET")
e.Append(LINKCOMSTR = "Linking $TARGET")
return e
CONFIG_RELEASE = [ "-O2" ]
CONFIG_DEBUG = [ "-Wall", "-Werror", "-g", "-DCONFIG_DEBUG" ]
release = get_env(CONFIG_RELEASE)
debug = get_env(CONFIG_DEBUG)
env = release
# Set up default environment
CONFIG_ENV = [ "-O2" ]
if CONFIG_DEBUG == True:
env = debug
Export("release", "debug", "env", "CONFIG_RELEASE", "CONFIG_DEBUG")
CONFIG_ENV = [ "-Wall", "-Werror", "-g", "-DCONFIG_DEBUG" ]
env = Environment( CCFLAGS = CONFIG_ENV )
env.Append(CPPPATH = os.path.abspath("include"))
env.Append(CXXCOMSTR = "C++ $TARGET")
env.Append(LINKCOMSTR = "Linking $TARGET")
Export("env", "CONFIG_ENV")

View File

@ -1,8 +1,9 @@
#!/usr/bin/python
Import("release", "debug", "CONFIG_VERSION", "CONFIG_RELEASE", "CONFIG_DEBUG")
Import("env", "CONFIG_DEBUG", "CONFIG_VERSION", "CONFIG_ENV")
CONFIG_RELEASE += [ "-DCONFIG_VERSION='\"%s\"'" % CONFIG_VERSION ]
CONFIG_DEBUG += [ "-DCONFIG_VERSION='\"%s-debug\"'" % CONFIG_VERSION ]
if CONFIG_DEBUG:
CONFIG_ENV += [ "-DCONFIG_VERSION='\"%s-debug\"'" % CONFIG_VERSION ]
else:
CONFIG_ENV += [ "-DCONFIG_VERSION='\"%s\"'" % CONFIG_VERSION ]
release.Replace(CCFLAGS = CONFIG_RELEASE)
debug.Replace(CCFLAGS = CONFIG_DEBUG)
env.Replace(CCFLAGS = CONFIG_ENV)

View File

@ -1,34 +1,44 @@
#!/usr/bin/python
Import("release", "debug")
Import("env", "CONFIG_DEBUG")
CMD = "tests/%s/%s.test"
OUT = "tests/%s/%s.run"
GOOD = "tests/%s/%s.good"
if CONFIG_DEBUG:
GOOD = "tests/%s/%s-debug.good"
def run_test(group, name):
cmd = "tests/%s/%s.test" % (group, name)
out = "tests/%s/%s.run" % (group, name)
good = "tests/%s/%s.good" % (group, name)
test = Command(out, None,
cmd = CMD % (group, name)
out = OUT % (group, name)
good = GOOD % (group, name)
return Command("%s.run" % name, None,
[ "%s > %s" % (cmd, out),
"diff -u %s %s" % (out, good)
"diff -u %s %s" % (out, good),
]
)
return test
def make_test(group, src, name, env):
obj = env.StaticObject(name, src)
prog = env.Program("%s.test" % name, obj)
test = run_test(group, name)
Depends(test, prog)
Alias("tests", [obj, prog])
Alias("tests/%s" % group, [obj, prog])
Alias("tests/%s/%s" % (group, name), [obj, prog])
def Test(group, src):
def Test(group, src, config = []):
name, extension = src.rsplit(".", 1)
make_test(group, src, name, release)
make_test(group, src, "%s-debug" % name, debug)
lib = SConscript("../../lib/Sconscript", variant_dir = ".%s" % name)
prog = env.Program("%s.test" % name, [ src ] + lib)
test = run_test(group, name)
Depends(test, prog)
AlwaysBuild(test)
Alias("tests", [ prog, test ])
Alias("tests/%s" % group, [ prog, test ])
Alias("tests/%s/%s" % (group, name), [ prog, test ])
Export("Test")
# Read SConscript files
basic = SConscript("basic/Sconscript")
file = SConscript("file/Sconscript")
Default("tests")