module -> project; allow building all projects within a folder
authorRalf Jung <post@ralfj.de>
Sun, 12 Aug 2012 13:32:53 +0000 (15:32 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 12 Aug 2012 13:32:53 +0000 (15:32 +0200)
build_system.py
mass-build.conf.kde.sample
mass_build.py
vcs.py

index 14877d41562339beda7b861dc20288aede1a4a6e..197d7ac08feb3d84b83cb8aab89d151fa5bb690f 100644 (file)
@@ -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
index 875f5a43fbcd242102c3f1e35b850a729258b12e..535b6d4a3b302b02db9c6a83dbb34b1952aa6661 100644 (file)
@@ -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')
        ]},
 ]
index 11e519966e783aafea3ae3c357f8153d4e9ff604..b53ab53ee2c229335fa231a3d2defd93998e14d5 100755 (executable)
@@ -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 0931bebf7963958e1c499c074a8c6742daf4a7be..d20ebeb305100702cf2770d5f9d5aa6c5f6e9f4c 100644 (file)
--- 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: