From: Ralf Jung Date: Tue, 19 Jun 2012 16:03:51 +0000 (+0200) Subject: make configuration more flexible and more readable X-Git-Url: https://git.ralfj.de/mass-build.git/commitdiff_plain/546c80d1c559cb94223f9c459db719d143df7291?ds=inline make configuration more flexible and more readable --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/build_system.py b/build_system.py index 5035e68..e18d9ff 100644 --- a/build_system.py +++ b/build_system.py @@ -14,7 +14,7 @@ class CMake: self.installCmdPrefix = config.installCmdPrefix def configure(self, force=False): - print "Configuring",self.folder + print "Configuring",self.sourceFolder if not os.path.exists(self.buildFolder): os.makedirs(self.buildFolder) os.chdir(self.buildFolder) # check if we actually need to work @@ -27,11 +27,13 @@ class CMake: os.unsetenv('PKG_CONFIG_PATH') def build(self): - print "Building",self.folder + print "Building",self.sourceFolder os.chdir(self.buildFolder) subprocess.check_call(self.buildCmdPrefix + ['make', '-j'+str(self.jobs)]) def install(self): - print "Installing",self.folder + print "Installing",self.sourceFolder os.chdir(self.buildFolder) subprocess.check_call(self.installCmdPrefix + ['make', 'install']) + +# TODO: class Debian, which creates & install a debian package diff --git a/config.py.sample b/config.py.sample index 3aa886c..e406591 100644 --- a/config.py.sample +++ b/config.py.sample @@ -5,27 +5,34 @@ buildType = 'Debug' jobs = 2 buildCmdPrefix = ['nice'] installCmdPrefix = [] +# helper function for the modules +defaultGitVersion = 'origin/master' # or 'origin/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): + return {'name':name, 'vcs':'kde+git', 'version':version} +def KDESvnModule(name, svnPath=defaultSvnVersion): + return {'name':name, 'vcs':'kde+svn', 'svn-path':svnPath+'/'+name} # the modules we are interested in -KDEBranch = 'KDE/4.8' modules = [ - # KDE core -# {'type': 'kde+svn', 'in-folder': 'kde', 'name': 'oxygen-icons', 'svn-path': 'tags/KDE/4.8.2/oxygen-icons'}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kdelibs', 'version': 'origin/'+KDEBranch}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kactivities', 'version': 'origin/'+KDEBranch}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kdepimlibs', 'version': 'origin/'+KDEBranch}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kde-runtime', 'version': 'origin/'+KDEBranch}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kde-workspace', 'version': 'origin/'+KDEBranch}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kde-baseapps', 'version': 'origin/'+KDEBranch}, -# {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kdepim-runtime', 'version': 'origin/'+KDEBranch}, - # KDE applications -# {'type': 'kde+svn', 'in-folder': 'kde', 'name': 'kde-wallpapers', 'svn-path': 'branches/'+KDEBranch+'/kde-wallpapers'}, - {'type': 'kde+svn', 'in-folder': 'kde', 'name': 'kdenetwork', 'svn-path': 'branches/'+KDEBranch+'/kdenetwork'}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'konsole', 'version': 'origin/'+KDEBranch}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kate', 'version': 'origin/'+KDEBranch}, - {'type': 'kde+git', 'in-folder': 'kde', 'name': 'kwallet', 'version': 'origin/'+KDEBranch}, - # Extragear applications, addons -# {'type': 'kde+git', 'in-folder': 'extragear', 'name': 'polkit-kde-agent-1', 'version': 'v0.99.0'}, - {'type': 'kde+git', 'in-folder': 'extragear', 'name': 'networkmanagement', 'version': 'v0.9.0.1'}, -# {'type': 'kde+git', 'in-folder': 'extragear', 'name': 'kdevplatform', 'version': 'v1.2.3'}, -# {'type': 'kde+git', 'in-folder': 'extragear', 'name': 'kdevelop', 'version': 'v4.2.3'}, + # KDE SC + {'folder': 'kde', 'modules': [ + # KDE core + KDESvnModule('oxygen-icons', '/trunk/kdesupport/oxygen-icons'), # released within the SC, but located in kdesupport... + KDEGitModule('kdelibs'), + KDEGitModule('kactivities'), + KDEGitModule('kdepimlibs'), + KDEGitModule('kde-runtime'), + KDEGitModule('kde-workspace'), + KDEGitModule('kde-baseapps'), + KDEGitModule('kdepim-runtime'), + # KDE applications + KDESvnModule('kde-wallpapers'), + KDEGitModule('konsole'), + KDEGitModule('kate'), + KDEGitModule('kwallet'), + ]}, + # Extragear + {'folder': 'extragear', 'modules': [ + KDEGitModule('networkmanagement', 'v0.9.0.3') + ]}, ] diff --git a/kdebuildpy.py b/kdebuildpy.py index 720c96b..d7e8158 100755 --- a/kdebuildpy.py +++ b/kdebuildpy.py @@ -23,29 +23,34 @@ args = parser.parse_args() # load config config = imp.load_source('config', args.config) +projects = OrderedDict() # all projects +workProjects = [] # projects we work on -# template for a KDE project: combine git/svn with cmake -def sourceFolder(module): - return os.path.join(module['in-folder'], module['name']) -def buildFolder(module): - return os.path.join(config.buildDir, sourceFolder(module)) - -class KDEGitProject(vcs.Git, build_system.CMake): - def __init__(self, module): - vcs.Git.__init__(self, sourceFolder(module),'kde:'+module['name'], module['version']) - build_system.CMake.__init__(self, sourceFolder(module), buildFolder(module), config) - self.name = module['name'] - -class KDESVNProject(vcs.SVN, build_system.CMake): - def __init__(self, module): - vcs.SVN.__init__(self, sourceFolder(module), 'svn://svn.kde.org/home/kde/'+module['svn-path']) - build_system.CMake.__init__(self, sourceFolder(module), buildFolder(module), config) +# an entire Project +class Project: + def __init__(self, folder, module): + self.folder = folder self.name = module['name'] - -moduleTypes = { - 'kde+git': KDEGitProject, - 'kde+svn': KDESVNProject -} + # VCS + vcsName = module.get('vcs', 'kde+git') + if vcsName == 'kde+git': + self.vcs = vcs.KDEGit(self.sourceFolder(), module['name'], module['version']) + elif vcsName == 'kde+svn': + self.vcs = vcs.KDESVN(self.sourceFolder(), module['svn-path']) + else: + raise Exception("Unknown VCS type "+vcsName) + # build system + buildSystemName = module.get('build-system', 'cmake') + if buildSystemName == 'cmake': + self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), 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): @@ -54,17 +59,18 @@ def findInList(list, item): return i raise Exception("%s not found in list" % str(item)) -# collect list of projects (separate run, since the actual compilation will change the working directory!) -projects = OrderedDict() -for module in config.modules: - if module['name'] in projects: - raise Exception("Duplicate module name "+module['name']) - if not module['type'] in moduleTypes: - raise Exception("Invalid module type "+module['type']) - projects[module['name']] = moduleTypes[module['type']](module) # create module of proper type +# populate list of projects +def loadProjects(modules, folder=''): + for module in modules: + if 'folder' in module: # a subpath + loadProjects(module['modules'], os.path.join(folder, module['folder'])) + else: # a proper project + if module['name'] in projects: + raise Exception("Duplicate module name "+module['name']) + projects[module['name']] = Project(folder, module) # now check what we have to do -workProjects = [] +loadProjects(config.modules) if args.modules: if args.resume_from is not None: raise Exception("Can not use --resume-from and manually specify modules") @@ -72,7 +78,8 @@ if args.modules: if not module in projects: raise Exception("Project %s does not exist" % module) workProjects.append(projects[module]) -elif args.resume_from is None: workProjects = projects.values() # all the projects +elif args.resume_from is None: + workProjects = projects.values() # all the projects else: if not args.resume_from in projects: raise Exception("Project %s does not exist" % args.resume_from) @@ -85,12 +92,12 @@ for project in workProjects: try: for phase in args.phases: if phase == 'update': - project.update() + project.vcs.update() elif phase == 'configure': - project.configure(force=args.reconfigure) + project.buildSystem.configure(force=args.reconfigure) elif phase == 'compile': - project.build() - project.install() + project.buildSystem.build() + project.buildSystem.install() else: raise Exception("Invalid phase "+phase) except (subprocess.CalledProcessError, KeyboardInterrupt) as e: diff --git a/vcs.py b/vcs.py index 994f03b..8acb571 100644 --- a/vcs.py +++ b/vcs.py @@ -47,6 +47,10 @@ class Git: print "(keeping local patches around)", print +class KDEGit(Git): + def __init__(self, folder, name, commit): + Git.__init__(self, folder, 'kde:'+name, commit) + # Fetch updates via SVN class SVN: def __init__(self, folder, svnPath): @@ -60,3 +64,7 @@ class SVN: subprocess.check_call(['svn', 'switch', self.svnPath]) # and update to the URL we got else: subprocess.check_call(['svn', 'co', self.svnPath, self.folder])# just download it + +class KDESVN(SVN): + def __init__(self, folder, svnPath): + SVN.__init__(self, folder, 'svn://svn.kde.org/home/kde/'+svnPath)