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
|
#!/usr/bin/python
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# Configuration variables
|
||||||
CONFIG_VERSION = 6.0
|
CONFIG_VERSION = 6.0
|
||||||
CONFIG_DEBUG = True
|
CONFIG_DEBUG = True
|
||||||
|
|
||||||
Export("CONFIG_VERSION", "CONFIG_DEBUG")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Set up default environment
|
# Set up default environment
|
||||||
CONFIG_ENV = [ "-O2" ]
|
CONFIG_ENV = [ "-O2" ]
|
||||||
|
@ -17,9 +15,28 @@ env = Environment( CCFLAGS = CONFIG_ENV )
|
||||||
env.Append(CPPPATH = os.path.abspath("include"))
|
env.Append(CPPPATH = os.path.abspath("include"))
|
||||||
env.Append(CXXCOMSTR = "C++ $TARGET")
|
env.Append(CXXCOMSTR = "C++ $TARGET")
|
||||||
env.Append(LINKCOMSTR = "Linking $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
|
# Import SConscript files
|
||||||
include = SConscript("include/Sconscript")
|
include = SConscript("include/Sconscript")
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
Import("env", "CONFIG_DEBUG", "CONFIG_VERSION", "CONFIG_ENV")
|
Import("CONFIG")
|
||||||
|
|
||||||
if CONFIG_DEBUG:
|
if CONFIG.DEBUG:
|
||||||
CONFIG_ENV += [ "-DCONFIG_VERSION='\"%s-debug\"'" % CONFIG_VERSION ]
|
CONFIG.ENV += [ "-DCONFIG_VERSION='\"%s-debug\"'" % CONFIG.VERSION ]
|
||||||
else:
|
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
|
#!/usr/bin/python
|
||||||
Import("env", "CONFIG_DEBUG")
|
import os, subprocess
|
||||||
|
Import("env", "CONFIG")
|
||||||
|
|
||||||
|
|
||||||
CMD = "tests/%s/%s.test"
|
GOOD = "%s.good"
|
||||||
OUT = "tests/%s/%s.run"
|
if CONFIG.DEBUG:
|
||||||
GOOD = "tests/%s/%s.good"
|
GOOD = "%s-debug.good"
|
||||||
if CONFIG_DEBUG:
|
|
||||||
GOOD = "tests/%s/%s-debug.good"
|
|
||||||
|
|
||||||
|
|
||||||
def run_test(group, name):
|
def run_test(target, source, env):
|
||||||
cmd = CMD % (group, name)
|
res = str(target[0])
|
||||||
out = OUT % (group, name)
|
out = open(res, 'w')
|
||||||
good = GOOD % (group, name)
|
ret = subprocess.call("%s" % source[0], stdout = out)
|
||||||
|
out.close()
|
||||||
|
|
||||||
return Command("%s.run" % name, None,
|
if (len(source) == 2) and (ret == 0):
|
||||||
[ "%s > %s" % (cmd, out),
|
good = str(source[1])
|
||||||
"diff -u %s %s" % (out, good),
|
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)
|
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)
|
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)
|
Depends(test, prog)
|
||||||
AlwaysBuild(test)
|
AlwaysBuild(test)
|
||||||
|
@ -38,7 +46,9 @@ Export("Test")
|
||||||
|
|
||||||
|
|
||||||
# Read SConscript files
|
# Read SConscript files
|
||||||
basic = SConscript("basic/Sconscript")
|
scripts = [ "basic", "file" ]
|
||||||
file = SConscript("file/Sconscript")
|
for s in scripts:
|
||||||
|
CONFIG.reset()
|
||||||
|
SConscript("%s/Sconscript" % s)
|
||||||
|
|
||||||
Default("tests")
|
Default("tests")
|
||||||
|
|
Loading…
Reference in New Issue