make configuration more flexible and more readable
[mass-build.git] / kdebuildpy.py
index 720c96b73f259785176cc401d6830a090d5e44a0..d7e81588f15f4c36d4a06136566b4ab5309efa35 100755 (executable)
@@ -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: