From c65e0bdb2adac2e71accbdf8affa00f7eaa73e14 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sun, 7 Jul 2013 22:27:26 -0400 Subject: [PATCH] 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 --- config | 25 +++++++++++++++++++---- include/Sconscript | 10 +++++----- tests/Sconscript | 50 +++++++++++++++++++++++++++------------------- 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/config b/config index 1124b626..01bc45f3 100644 --- a/config +++ b/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") diff --git a/include/Sconscript b/include/Sconscript index a8e22d51..cc356d82 100644 --- a/include/Sconscript +++ b/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() diff --git a/tests/Sconscript b/tests/Sconscript index aa25d9b4..403cc1df 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -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")