From: Ralf Jung Date: Sun, 12 Aug 2012 13:32:53 +0000 (+0200) Subject: module -> project; allow building all projects within a folder X-Git-Url: https://git.ralfj.de/mass-build.git/commitdiff_plain/c6f446c1a9af8dcdcfae87aae36656741aafca0c module -> project; allow building all projects within a folder --- diff --git a/build_system.py b/build_system.py index 14877d4..197d7ac 100644 --- a/build_system.py +++ b/build_system.py @@ -1,19 +1,19 @@ 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 @@ -25,11 +25,11 @@ class CMake: # 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 @@ -39,22 +39,22 @@ class CMake: 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, @@ -69,8 +69,8 @@ try: 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 diff --git a/mass-build.conf.kde.sample b/mass-build.conf.kde.sample index 875f5a4..535b6d4 100644 --- a/mass-build.conf.kde.sample +++ b/mass-build.conf.kde.sample @@ -5,7 +5,7 @@ buildType = 'Debug' jobs = 2 buildCmdPrefix = ['nice'] installCmdPrefix = [] -# helper function for the modules - per default, they assume an SC module +# helper function for the KDE modules - per default, they assume an SC module defaultGitVersion = 'origin/master' # or 'origin/KDE/4.8' or 'v4.8.4' defaultSvnVersion = 'trunk/KDE' # or 'branches/KDE/4.8' or 'tags/KDE/4.8.4' def KDEGitModule(name, version=defaultGitVersion, **module): @@ -22,12 +22,12 @@ def KDESvnModule(name, svnPath=defaultSvnVersion, **module): module['url'] = 'svn://svn.kde.org/home/kde/'+svnPath+'/'+name return module # the modules we are interested in -modules = [ +projects = [ # KDE support - {'folder': 'kdesupport', 'modules': [ + {'folder': 'kdesupport', 'projects': [ ]}, # KDE SC - {'folder': 'kde-sc', 'modules': [ + {'folder': 'kde-sc', 'projects': [ # KDE core KDESvnModule('oxygen-icons', '/trunk/kdesupport'), # released within the SC, but located in kdesupport... KDEGitModule('kdelibs'), @@ -44,7 +44,7 @@ modules = [ KDEGitModule('kwallet'), ]}, # Extragear - {'folder': 'extragear', 'modules': [ + {'folder': 'extragear', 'projects': [ KDEGitModule('networkmanagement', 'v0.9.0.4') ]}, ] diff --git a/mass_build.py b/mass_build.py index 11e5199..b53ab53 100755 --- a/mass_build.py +++ b/mass_build.py @@ -3,6 +3,35 @@ import vcs, build_system, imp 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", @@ -16,12 +45,12 @@ parser.add_argument("--reset-source", 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: @@ -30,38 +59,10 @@ 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)): @@ -69,41 +70,52 @@ def findInList(list, item): 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 diff --git a/vcs.py b/vcs.py index 0931beb..d20ebeb 100644 --- a/vcs.py +++ b/vcs.py @@ -1,6 +1,6 @@ import os, git, subprocess -'''A VCS must have an "update" method with an optional "force" parameter.''' +'''A VCS must have an "update" method with an optional "forceVersion" parameter, and a "version" method.''' # Fetch updates from git class Git: