import os, shutil, subprocess
-'''A build system has three methods: "configure" (with optionak "force" parameter), "build" and "install"'''
+'''A build system must have a "build" method with an optional "reconfigure" parameter.'''
# Compile, build, and install cmake projects:
class CMake:
- def __init__(self, sourceFolder, buildFolder, module, config):
+ def __init__(self, sourceFolder, buildFolder, projectConfig, globalConfig):
self.sourceFolder = os.path.abspath(sourceFolder)
self.buildFolder = os.path.abspath(buildFolder)
- self.installDir = config['installDir']
- self.buildType = config['buildType']
- self.jobs = config['jobs']
- self.buildCmdPrefix = config['buildCmdPrefix']
- self.installCmdPrefix = config['installCmdPrefix']
- self.waitAfterConfig = config.get('waitAfterConfig', False)
- self.module = module
+ self.installDir = globalConfig['installDir']
+ self.buildType = globalConfig['buildType']
+ self.jobs = globalConfig['jobs']
+ self.buildCmdPrefix = globalConfig['buildCmdPrefix']
+ self.installCmdPrefix = globalConfig['installCmdPrefix']
+ self.waitAfterConfig = globalConfig.get('waitAfterConfig', False)
+ self.projectConfig = projectConfig
def build(self, reconfigure=False):
# Make sure we have a build directory
# Run cmake
os.putenv('PKG_CONFIG_PATH', os.path.join(self.installDir, 'lib', 'pkgconfig')) # I found no way to do this within cmake
subprocess.check_call(['cmake', self.sourceFolder, '-DCMAKE_BUILD_TYPE='+self.buildType,
- '-DCMAKE_INSTALL_PREFIX='+self.installDir]+self.module.get('cmakeParameters', []))
+ '-DCMAKE_INSTALL_PREFIX='+self.installDir]+self.projectConfig.get('cmakeParameters', []))
os.unsetenv('PKG_CONFIG_PATH')
# if asked to do so, wait
if self.waitAfterConfig:
- raw_input('Configuration done. Hit "Enter" to build the module. ')
+ raw_input('Configuration done. Hit "Enter" to build the project. ')
# run compilation
subprocess.check_call(self.buildCmdPrefix + ['make', '-j'+str(self.jobs)])
# run installation
try:
import auto_debuild
class AutoDebuild:
- def __init__(self, sourceFolder, buildFolder, module, vcs, config):
+ def __init__(self, sourceFolder, buildFolder, projectConfig, vcs, globalConfig):
self.sourceFolder = os.path.abspath(sourceFolder)
self.buildFolder = os.path.abspath(buildFolder)
- self.jobs = config['jobs']
- self.debDir = os.path.abspath(config['debDir'])
- self.debName = config['debName']
- self.debEMail = config['debEMail']
- self.waitAfterConfig = config.get('waitAfterConfig', False)
- self.module = module
+ self.jobs = globalConfig['jobs']
+ self.debDir = os.path.abspath(globalConfig['debDir'])
+ self.debName = globalConfig['debName']
+ self.debEMail = globalConfig['debEMail']
+ self.waitAfterConfig = globalConfig.get('waitAfterConfig', False)
+ self.projectConfig = projectConfig
self.vcs = vcs
def build(self, reconfigure=False): # reconfigure is ignored (we always do a reconfiguration)
# create auto-debuild configuration
autoDebuildConfig = {
- 'sourceName': self.module['name'],
- 'buildSystem': self.module['buildSystem'],
+ 'sourceName': self.projectConfig['name'],
+ 'buildSystem': self.projectConfig['buildSystem'],
'debDir': self.debDir,
'buildDir': self.buildFolder,
'name': self.debName,
for option in ('dbgPackage', 'section', 'withPython2', 'binarySkipFiles', 'binaryInstallFiles',
'buildDepends', 'binaryDepends', 'binaryRecommends', 'binaryProvides', 'binaryConflicts',
'cmakeParameters', 'automakeParameters'):
- if option in self.module:
- autoDebuildConfig[option] = self.module[option]
+ if option in self.projectConfig:
+ autoDebuildConfig[option] = self.projectConfig[option]
# create Debian files
os.chdir(self.sourceFolder)
if os.path.isdir('debian'): # clean previous build attempts
import argparse, os, sys, subprocess
from collections import OrderedDict
+# an entire Project
+class Project:
+ def __init__(self, folder, projectConfig, globalConfig):
+ self.folder = folder
+ self.name = projectConfig['name']
+ # VCS
+ vcsName = projectConfig['vcs']
+ if vcsName == 'git':
+ self.vcs = vcs.Git(self.sourceFolder(), projectConfig['url'], projectConfig['version'])
+ elif vcsName == 'svn':
+ self.vcs = vcs.SVN(self.sourceFolder(), projectConfig['url'], projectConfig.get('versionName'))
+ else:
+ raise Exception("Unknown VCS type "+vcsName)
+ # build system
+ if globalConfig.get('buildDeb', False):
+ self.buildSystem = build_system.AutoDebuild(self.sourceFolder(), self.buildFolder(), projectConfig, self.vcs, globalConfig)
+ else:
+ buildSystemName = projectConfig['buildSystem']
+ if buildSystemName == 'cmake':
+ self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), projectConfig, globalConfig)
+ else:
+ raise Exception("Unknown build system type "+buildSystemName)
+
+ def sourceFolder(self):
+ return os.path.join(self.folder, self.name)
+
+ def buildFolder(self):
+ return os.path.join(config['buildDir'], self.sourceFolder())
+
# read command-line arguments
parser = argparse.ArgumentParser(description='Update and build a bunch of stuff')
parser.add_argument("-c, --config",
help="Reset sourcecode to the given version (removes local changes!)")
parser.add_argument("--no-update",
action="store_false", dest="update",
- help="Do not update modules before compilation")
-parser.add_argument("--resume-from", metavar='MODULE',
+ help="Do not update projects before compilation")
+parser.add_argument("--resume-from", metavar='PROJECT',
dest="resume_from",
- help="Resume building from the given repository")
-parser.add_argument("modules", metavar='MODULE', nargs='*',
- help="Manually specify modules to be built")
+ help="Resume building from the given project")
+parser.add_argument("projects", metavar='PROJECT', nargs='*',
+ help="Manually specify projects or folders to be built (project names take precedence)")
args = parser.parse_args()
# sanitize
if args.reset_source and not args.update:
# load config
config = imp.load_source('config', args.config).__dict__
os.remove(args.config+'c') # remove compiled python file
-projects = OrderedDict() # all projects
+allProjects = OrderedDict() # all projects
+allFolders = {} # all folders
workProjects = [] # projects we work on
-# an entire Project
-class Project:
- def __init__(self, config, folder, module):
- self.folder = folder
- self.name = module['name']
- # VCS
- vcsName = module['vcs']
- if vcsName == 'git':
- self.vcs = vcs.Git(self.sourceFolder(), module['url'], module['version'])
- elif vcsName == 'svn':
- self.vcs = vcs.SVN(self.sourceFolder(), module['url'], module.get('versionName'))
- else:
- raise Exception("Unknown VCS type "+vcsName)
- # build system
- if config.get('buildDeb', False):
- self.buildSystem = build_system.AutoDebuild(self.sourceFolder(), self.buildFolder(), module, self.vcs, config)
- else:
- buildSystemName = module['buildSystem']
- if buildSystemName == 'cmake':
- self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), module, config)
- else:
- raise Exception("Unknown build system type "+buildSystemName)
-
- def sourceFolder(self):
- return os.path.join(self.folder, self.name)
-
- def buildFolder(self):
- return os.path.join(config['buildDir'], self.sourceFolder())
-
# return the position of the given item in the list
def findInList(list, item):
for i in xrange(len(list)):
return i
raise Exception("%s not found in list" % str(item))
-# populate list of projects
-def loadProjects(config, modules, folder=''):
- for module in modules:
- if 'folder' in module: # a subpath
- loadProjects(config, module['modules'], os.path.join(folder, module['folder']))
+# populate list of projects, return list of projects in that folder
+def loadProjects(projects, folder=''):
+ folderProjects = []
+ for projectConfig in projects:
+ if 'folder' in projectConfig: # a subpath
+ folderProjects += loadProjects(projectConfig['projects'], os.path.join(folder, projectConfig['folder']))
else: # a proper project
- if module['name'] in projects:
- raise Exception("Duplicate module name "+module['name'])
- projects[module['name']] = Project(config, folder, module)
+ if projectConfig['name'] in allProjects:
+ raise Exception("Duplicate project name "+project['name'])
+ project = Project(folder, projectConfig, config)
+ allProjects[projectConfig['name']] = project
+ folderProjects.append(project)
+ # store projects of this folder
+ if folder in allFolders:
+ raise Exception("Duplicate folder name "+folder)
+ allFolders[folder] = folderProjects
+ return folderProjects
# now check what we have to do
-loadProjects(config, config['modules'])
-if args.modules:
+loadProjects(config['projects'])
+if args.projects:
if args.resume_from is not None:
- raise Exception("Can not use --resume-from and manually specify modules")
- for module in args.modules:
- if not module in projects:
- raise Exception("Project %s does not exist" % module)
- workProjects.append(projects[module])
+ raise Exception("Can not use --resume-from and manually specify projects")
+ for name in args.projects:
+ if name in allProjects:
+ workProjects.append(allProjects[name])
+ elif name in allFolders:
+ workProjects += allFolders[name]
+ else:
+ raise Exception("Project or folder%s does not exist" % name)
elif args.resume_from is None:
workProjects = projects.values() # all the projects
else:
- if not args.resume_from in projects:
+ if not args.resume_from in allProjects:
raise Exception("Project %s does not exist" % args.resume_from)
- startWith = projects[args.resume_from]
- startIndex = findInList(projects.values(), startWith)
- workProjects = projects.values()[startIndex:]
+ startWith = allProjects[args.resume_from]
+ startIndex = findInList(allProjects.values(), startWith)
+ workProjects = allProjects.values()[startIndex:]
# and do it!
for project in workProjects:
try:
if args.update:
- print "Updating module",project.sourceFolder()
+ print "Updating project",project.sourceFolder()
project.vcs.update(forceVersion=args.reset_source)
- print "Building module",project.sourceFolder()
+ print "Building project",project.sourceFolder()
project.buildSystem.build(reconfigure=args.reconfigure)
print
except (subprocess.CalledProcessError, KeyboardInterrupt) as e: # for some exceptions, a stackrace is usually pointless