build: Change CONFIG_* variables into a class
The class is in charge of resetting fields at will, and will be able to maintain everything easier than if I were to do it by hand. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
13a0d25e8f
commit
c65e0bdb2a
25
config
25
config
|
@ -1,12 +1,10 @@
|
|||
#!/usr/bin/python
|
||||
import os
|
||||
|
||||
# Configuration variables
|
||||
CONFIG_VERSION = 6.0
|
||||
CONFIG_DEBUG = True
|
||||
|
||||
Export("CONFIG_VERSION", "CONFIG_DEBUG")
|
||||
|
||||
|
||||
|
||||
# Set up default environment
|
||||
CONFIG_ENV = [ "-O2" ]
|
||||
|
@ -17,9 +15,28 @@ 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")
|
||||
|
||||
|
||||
# Class to store configuration data
|
||||
class Config:
|
||||
# Set up reasonable defaults
|
||||
def __init__(self):
|
||||
self.VERSION = CONFIG_VERSION
|
||||
self.DEBUG = CONFIG_DEBUG
|
||||
self.ENV = CONFIG_ENV
|
||||
self.FILE = False
|
||||
|
||||
def reconfigure(self):
|
||||
env.Replace( CCFLAGS = self.ENV )
|
||||
if self.FILE: env.Append( CCFLAGS = "-DCONFIG_FILE" )
|
||||
|
||||
def reset(self):
|
||||
self.FILE = False
|
||||
self.reconfigure()
|
||||
|
||||
CONFIG = Config()
|
||||
Export("env", "CONFIG")
|
||||
|
||||
|
||||
# Import SConscript files
|
||||
include = SConscript("include/Sconscript")
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#!/usr/bin/python
|
||||
Import("env", "CONFIG_DEBUG", "CONFIG_VERSION", "CONFIG_ENV")
|
||||
Import("CONFIG")
|
||||
|
||||
if CONFIG_DEBUG:
|
||||
CONFIG_ENV += [ "-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 ]
|
||||
CONFIG.ENV += [ "-DCONFIG_VERSION='\"%s\"'" % CONFIG.VERSION ]
|
||||
|
||||
env.Replace(CCFLAGS = CONFIG_ENV)
|
||||
CONFIG.reconfigure()
|
||||
|
|
|
@ -1,31 +1,39 @@
|
|||
#!/usr/bin/python
|
||||
Import("env", "CONFIG_DEBUG")
|
||||
import os, subprocess
|
||||
Import("env", "CONFIG")
|
||||
|
||||
|
||||
CMD = "tests/%s/%s.test"
|
||||
OUT = "tests/%s/%s.run"
|
||||
GOOD = "tests/%s/%s.good"
|
||||
if CONFIG_DEBUG:
|
||||
GOOD = "tests/%s/%s-debug.good"
|
||||
GOOD = "%s.good"
|
||||
if CONFIG.DEBUG:
|
||||
GOOD = "%s-debug.good"
|
||||
|
||||
|
||||
def run_test(group, name):
|
||||
cmd = CMD % (group, name)
|
||||
out = OUT % (group, name)
|
||||
good = GOOD % (group, name)
|
||||
def run_test(target, source, env):
|
||||
res = str(target[0])
|
||||
out = open(res, 'w')
|
||||
ret = subprocess.call("%s" % source[0], stdout = out)
|
||||
out.close()
|
||||
|
||||
return Command("%s.run" % name, None,
|
||||
[ "%s > %s" % (cmd, out),
|
||||
"diff -u %s %s" % (out, good),
|
||||
]
|
||||
)
|
||||
if (len(source) == 2) and (ret == 0):
|
||||
good = str(source[1])
|
||||
if (subprocess.call("diff -u %s %s" % (res, good), shell = True) != 0):
|
||||
print
|
||||
else:
|
||||
for line in open( str(target[0]) ):
|
||||
print line.strip()
|
||||
print
|
||||
|
||||
def Test(group, src, config = []):
|
||||
def Test(group, src):
|
||||
name, extension = src.rsplit(".", 1)
|
||||
CONFIG.reconfigure()
|
||||
|
||||
lib = SConscript("../../lib/Sconscript", variant_dir = ".%s" % name)
|
||||
lib = SConscript("../../lib/Sconscript")
|
||||
prog = env.Program("%s.test" % name, [ src ] + lib)
|
||||
test = run_test(group, name)
|
||||
|
||||
src_files = [ "%s.test" % name ]
|
||||
if os.path.exists(GOOD % name):
|
||||
src_files += [ GOOD % name ]
|
||||
test = Command("%s.run" % name, src_files, run_test)
|
||||
|
||||
Depends(test, prog)
|
||||
AlwaysBuild(test)
|
||||
|
@ -38,7 +46,9 @@ Export("Test")
|
|||
|
||||
|
||||
# Read SConscript files
|
||||
basic = SConscript("basic/Sconscript")
|
||||
file = SConscript("file/Sconscript")
|
||||
scripts = [ "basic", "file" ]
|
||||
for s in scripts:
|
||||
CONFIG.reset()
|
||||
SConscript("%s/Sconscript" % s)
|
||||
|
||||
Default("tests")
|
||||
|
|
Loading…
Reference in New Issue