diff --git a/.gitignore b/.gitignore index 24214ff0..678692e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ *.o *.sw* -#*.pyc *.run *.test *.glade~ gui/#* -gui/ocarina +bin/ .sconsign.dblite diff --git a/config b/config index ae05fb0c..c75a177a 100644 --- a/config +++ b/config @@ -4,7 +4,6 @@ import os # Configuration variables CONFIG_VERSION = 6.0 CONFIG_DEBUG = True -#CONFIG_TESTING = False # Set up default environment @@ -18,51 +17,18 @@ env.Append(CXXCOMSTR = "C++ $TARGET") env.Append(LINKCOMSTR = "Linking $TARGET") -# Class to store configuration data -class Config: - # Set up reasonable defaults - def __init__(self): - self.VERSION = CONFIG_VERSION - self.DEBUG = CONFIG_DEBUG - self.CCFLAGS = CONFIG_CCFLAGS - self.reset(); +def use_package(name): + env.ParseConfig("pkg-config --cflags --libs %s" % name) - def package(self, name): - env.ParseConfig("pkg-config --cflags --libs %s" % name) - - def reconfigure(self): - env.Replace( CCFLAGS = self.CCFLAGS ) - if self.TEST == True: - env.Append( CCFLAGS = [ "-DCONFIG_TEST" ]) - - def reset(self, TEST = False, ALL = False): - self.AUDIO = ALL - self.CALLBACK = ALL - self.DATABASE = ALL - self.DECK = ALL - self.FILE = ALL - self.FILTER = ALL - self.IDLE = ALL - self.LIBRARY = ALL - self.PLAYLIST = ALL - self.PLAYQUEUE = ALL - self.TEST = TEST - self.reconfigure() - -CONFIG = Config() -Export("env", "CONFIG") +Export("env", "use_package", "CONFIG_DEBUG", "CONFIG_VERSION") -# Import SConscript files include = SConscript("include/Sconscript") -design = SConscript("design/Sconscript") - -#gui = SConscript("gui/Sconscript") - -#Default("gui") -#if CONFIG_TESTING == True: -# tests = SConscript("tests/Sconscript") -# Depends(gui, tests) +lib = SConscript("lib/Sconscript") tests = SConscript("tests/Sconscript") -Default("tests") + +gui = SConscript("gui/Sconscript") + +ocarina = env.Program("bin/ocarina", lib + gui) +Default(ocarina) diff --git a/gui/Sconscript b/gui/Sconscript index f7253909..268611ad 100644 --- a/gui/Sconscript +++ b/gui/Sconscript @@ -1,7 +1,7 @@ #!/usr/bin/python -Import("env", "CONFIG") +Import("use_package") -CONFIG.package("gtkmm-3.0") +use_package("gtkmm-3.0") res = Glob("*.cpp") Return("res") diff --git a/include/Sconscript b/include/Sconscript index c67ea6a0..6ea804e1 100644 --- a/include/Sconscript +++ b/include/Sconscript @@ -1,9 +1,8 @@ #!/usr/bin/python -Import("CONFIG") +Import("env", "CONFIG_DEBUG", "CONFIG_VERSION") -if CONFIG.DEBUG: - CONFIG.CCFLAGS += [ "-DCONFIG_VERSION='\"%s-debug\"'" % CONFIG.VERSION ] -else: - CONFIG.CCFLAGS += [ "-DCONFIG_VERSION='\"%s\"'" % CONFIG.VERSION ] +version = str(CONFIG_VERSION) +if CONFIG_DEBUG == True: + version += "-debug" -CONFIG.reconfigure() +env.Append( CCFLAGS = [ "-DCONFIG_VERSION='\"%s\"'" % version ] ) diff --git a/lib/Sconscript b/lib/Sconscript index 28b4f2d5..9bc77cf7 100644 --- a/lib/Sconscript +++ b/lib/Sconscript @@ -1,62 +1,8 @@ #!/usr/bin/python -Import("env", "CONFIG") +Import("use_package") -class Module: - def __init__(self, source = None, package = "", depends = []): - self.depends = depends - self.package = package - self.source = source +use_package("gstreamer-1.0") +use_package("taglib") - -modules = { -########################### -# # -# Define new modules here # -# # -########################### - - "AUDIO" : Module("audio.cpp", package = "gstreamer-1.0", depends = [ "DECK" ]), - "CALLBACK" : Module("callback.cpp"), - "DATABASE" : Module("database.cpp", depends = [ "FILE" ]), - "DECK" : Module("deck.cpp", depends = [ "PLAYQUEUE" ]), - "FILE" : Module("file.cpp", package = "glib-2.0"), - "FILTER" : Module("filter.cpp", depends = [ "DATABASE" ]), - "IDLE" : Module("idle.cpp"), - "LIBRARY" : Module("library.cpp", package = "taglib", depends = [ "CALLBACK", "DATABASE", "FILTER", "IDLE" ]), - "PLAYLIST" : Module("playlist.cpp", depends = [ "DATABASE" ]), - "PLAYQUEUE" : Module("playqueue.cpp", depends = [ "LIBRARY" ]), - -########################### -########################### -} - - -build = [] -enabled = [] - -def resolve(name): - CONFIG.__dict__[name] = True - mod = modules[name] - - if mod.package != "": - CONFIG.package(mod.package) - - res = [ env.Object(mod.source) ] - - for dep in mod.depends: - if CONFIG.__dict__.get(dep) == False: - res += resolve(dep) - - return res - - - -for key in modules.keys(): - if CONFIG.__dict__[key] == True: - enabled += [key] - -for mod in enabled: - build += resolve(mod) - - -Return("build") +res = Glob("*.cpp") +Return("res") diff --git a/tests/Sconscript b/tests/Sconscript index d1bb1128..f0a20aec 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -1,71 +1,11 @@ #!/usr/bin/python -import os, subprocess, shutil -import xdg.BaseDirectory -Import("env", "CONFIG") +Import("env") +src = SConscript("src/Sconscript") +test = Command("tests.out", [], "./tests/test") -GOOD = "%s.good" +AlwaysBuild(test) +Depends(test, src) -def run_test(target, source, env): - res = str(target[0]) - out = open(res, 'w') - ret = subprocess.call("%s" % source[0], stdout = out, stderr = out) - out.close() - - if ret != 0: - print "Test returns: ", ret - - if (len(source) == 2): - good = str(source[1]) - if (subprocess.call("diff -u %s %s" % (good, res), shell = True) != 0): - print - Exit(1) - else: - for line in open( str(target[0]) ): - print line.rstrip() - print - - if ret != 0: - Exit(1) - -def Test(group, src, gui = False): - name, extension = src.rsplit(".", 1) - mods = [ src ] - - mods += SConscript("../../lib/Sconscript") - if gui == True: - mods += SConscript("../../gui/Sconscript") - prog = env.Program("%s.test" % name, mods) - - 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) - - Alias("tests", [ prog, test ]) - Alias("tests/%s" % group, [ prog, test ]) - Alias("tests/%s/%s" % (group, name), [ prog, test ]) - -Export("Test") - -# -# Clean up leftover test data -# -def rm_test_dir(dir): - dir = os.path.join(dir, "ocarina-test") - if os.path.exists(dir): - shutil.rmtree(dir) -rm_test_dir(xdg.BaseDirectory.xdg_config_home); -rm_test_dir(xdg.BaseDirectory.xdg_data_home); - -# -# Read SConscript files -# -scripts = [ "print", "file", "database", "index", "filter", "idle", "playlist", - "library", "playqueue", "deck", "audio", "gui" ] -for s in scripts: - CONFIG.reset(TEST = True) - SConscript("%s/Sconscript" % s) +#scripts = [ "print", "file", "database", "index", "filter", "idle", "playlist", +# "library", "playqueue", "deck", "audio", "gui" ] diff --git a/tests/print/.gitignore b/tests/print/.gitignore deleted file mode 100644 index 9c29f432..00000000 --- a/tests/print/.gitignore +++ /dev/null @@ -1 +0,0 @@ -print.good diff --git a/tests/print/Sconscript b/tests/print/Sconscript deleted file mode 100644 index 11915ac2..00000000 --- a/tests/print/Sconscript +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/python -Import("Test", "CONFIG") - -out = open("print.good", 'w') -if CONFIG.DEBUG == True: - out.write("%s-debug\n" % CONFIG.VERSION) - out.write("%s-debug\n" % CONFIG.VERSION) -else: - out.write("%s\n" % CONFIG.VERSION) - out.write("%s\n" % CONFIG.VERSION) -out.close() - -Test("basic", "print.cpp") diff --git a/tests/run_test b/tests/run_test new file mode 100755 index 00000000..7a7b19b4 --- /dev/null +++ b/tests/run_test @@ -0,0 +1,13 @@ +#!/bin/bash +# Copyright (c) Anna Schumaker. + +VERSION=$(cat ../config | grep ^CONFIG_VERSION | awk -F= '{print $2}' | tr -d ' ') +DEBUG=$(cat ../config | grep ^CONFIG_DEBUG | awk -F= '{print $2}' | tr -d ' ') + +function utility +{ + echo src/$1 +} + +echo -n "Running test '$1' ... " +. tests/$1 diff --git a/tests/src/Sconscript b/tests/src/Sconscript new file mode 100644 index 00000000..7779c018 --- /dev/null +++ b/tests/src/Sconscript @@ -0,0 +1,8 @@ +#!/usr/bin/python +Import("env") + +def compile_utility(name): + return env.Program(name, "%s.cpp" % name) + +build = compile_utility("version") +Return("build") diff --git a/tests/src/version b/tests/src/version new file mode 100755 index 00000000..bede8ee8 Binary files /dev/null and b/tests/src/version differ diff --git a/tests/print/print.cpp b/tests/src/version.cpp similarity index 62% rename from tests/print/print.cpp rename to tests/src/version.cpp index aa8a5a13..faa6d393 100644 --- a/tests/print/print.cpp +++ b/tests/src/version.cpp @@ -1,6 +1,6 @@ /* * Copyright 2013 (c) Anna Schumaker. - * Prints version info to the screen when compiled in debug mode + * Prints out version info */ #include #include @@ -8,6 +8,5 @@ int main(int argc, char **argv) { print("%s\n", get_version()); - dprint("%s\n", get_version()); return 0; } diff --git a/tests/test b/tests/test new file mode 100755 index 00000000..616dd660 --- /dev/null +++ b/tests/test @@ -0,0 +1,10 @@ +#!/bin/bash +# Copyright 2014 (c) Anna Schumaker. + +cd $(dirname $0) + +[ $? == 0 ] && tests=$(ls tests/) || tests="$*" + +for t in $tests; do + ./run_test $t +done diff --git a/tests/tests/version b/tests/tests/version new file mode 100755 index 00000000..34a2dc2c --- /dev/null +++ b/tests/tests/version @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright 2014 (c) Anna Schumaker. + +expected=$VERSION +[ $DEBUG == "True" ] && expected="$expected-debug" + +cmd=$(utility version) +actual=$($cmd) + +if [ $expected == $actual ]; then + echo "Success!" + exit 0 +fi + +echo "FAILED =(" +echo "Expected output: $expected" +echo "Actual output: $actual"