lib: Improve dependency resolution

Rather than doing everything in tedious if blocks written in any order,
I instead resolve dependencies using a much simpler loop.  At the moment
each module only depends on a single other module, so this will have to
be extended if I ever need multiple-dependency resolution.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-09-29 22:00:35 -04:00 committed by Anna Schumaker
parent 1f9ff4ae2d
commit 38f97fb85b
1 changed files with 42 additions and 19 deletions

View File

@ -1,33 +1,56 @@
#!/usr/bin/python
Import("env", "CONFIG")
class Module:
def __init__(self, source = None, package = "", depends = ""):
self.depends = depends
self.package = package
self.source = source
modules = {
###########################
# #
# Define new modules here #
# #
###########################
"DATABASE" : Module("database.cpp", depends = "FILE"),
"FILE" : Module("file.cpp", package = "glib-2.0"),
"FILTER" : Module("filter.cpp", depends = "INDEX"),
"GROUP" : Module("group.cpp", depends = "INDEX"),
"IDLE" : Module("idle.cpp"),
"INDEX" : Module("index.cpp", depends = "FILE"),
###########################
###########################
}
build = []
enabled = []
if CONFIG.FILTER:
CONFIG.INDEX = True
build += [ env.Object("filter.cpp") ]
def resolve(name):
CONFIG.__dict__[name] = True
mod = modules[name]
if CONFIG.GROUP:
CONFIG.INDEX = True
build += [ env.Object("group.cpp") ]
if mod.package != "":
CONFIG.package(mod.package)
####################
res = [ env.Object(mod.source) ]
if CONFIG.__dict__.get(mod.depends) == False:
res += resolve(mod.depends)
if CONFIG.DATABASE:
CONFIG.FILE = True
build += [ env.Object("database.cpp") ]
return res
if CONFIG.INDEX:
CONFIG.FILE = True
build += [ env.Object("index.cpp") ]
####################
if CONFIG.FILE:
CONFIG.package("glib-2.0")
build += [ env.Object("file.cpp") ]
for key in modules.keys():
if CONFIG.__dict__[key] == True:
enabled += [key]
for mod in enabled:
build += resolve(mod)
if CONFIG.IDLE:
build += [ env.Object("idle.cpp") ]
Return("build")