Clean up the build system
I'm taking a break from gui code to clean up the build system and update my unit tests. This patch updates how code is built, and reworks my "print" test to test version number instead. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
bfcc94de21
commit
871914ea90
|
@ -1,9 +1,8 @@
|
|||
*.o
|
||||
*.sw*
|
||||
#*.pyc
|
||||
*.run
|
||||
*.test
|
||||
*.glade~
|
||||
gui/#*
|
||||
gui/ocarina
|
||||
bin/
|
||||
.sconsign.dblite
|
||||
|
|
52
config
52
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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 ] )
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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" ]
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
print.good
|
|
@ -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")
|
|
@ -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
|
|
@ -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")
|
Binary file not shown.
|
@ -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 <print.h>
|
||||
#include <version.h>
|
||||
|
@ -8,6 +8,5 @@
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
print("%s\n", get_version());
|
||||
dprint("%s\n", get_version());
|
||||
return 0;
|
||||
}
|
|
@ -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
|
|
@ -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"
|
Loading…
Reference in New Issue