Make config inherited
[mass-build.git] / mass_build.py
index ed47bacbf21bb3bbe0b004d5a3da8e5ef7853034..6bbba4c23d8429e9b48c618ac6c94fbc73246cd1 100755 (executable)
@@ -5,24 +5,24 @@ from collections import OrderedDict
 
 # an entire Project
 class Project:
-       def __init__(self, folder, projectConfig, globalConfig):
+       def __init__(self, folder, config):
                self.folder = folder
-               self.name = projectConfig['name']
+               self.name = config['name']
                # VCS
-               vcsName = projectConfig['vcs']
+               vcsName = config['vcs']
                if vcsName == 'git':
-                       self.vcs = vcs.Git(self.sourceFolder(), projectConfig['url'], projectConfig['version'])
+                       self.vcs = vcs.Git(self.sourceFolder(), config['url'], config['version'])
                elif vcsName == 'svn':
-                       self.vcs = vcs.SVN(self.sourceFolder(), projectConfig['url'], projectConfig.get('versionName'))
+                       self.vcs = vcs.SVN(self.sourceFolder(), config['url'], config.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)
+               if config.get('buildDeb', False):
+                       self.buildSystem = build_system.AutoDebuild(self.sourceFolder(), self.buildFolder(), config, self.vcs)
                else:
-                       buildSystemName = projectConfig['buildSystem']
+                       buildSystemName = config['buildSystem']
                        if buildSystemName == 'cmake':
-                               self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), projectConfig, globalConfig)
+                               self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), config)
                        else:
                                raise Exception("Unknown build system type "+buildSystemName)
        
@@ -70,16 +70,24 @@ def findInList(list, item):
                        return i
        raise Exception("%s not found in list" % str(item))
 
+# copy all items which don't exist below, except for those in the exclude list
+def inherit(subConfig, superConfig, exclude = ('name', 'projects')):
+       for name in superConfig.keys():
+               if (not name in subConfig) and (not name in exclude):
+                       subConfig[name] = superConfig[name]
+
 # populate list of projects, return list of projects in that folder
-def loadProjects(projects, folder=''):
+def loadProjects(config, folder=''):
        folderProjects = []
-       for projectConfig in projects:
-               if 'folder' in projectConfig: # a subpath
-                       folderProjects += loadProjects(projectConfig['projects'], os.path.join(folder, projectConfig['folder']))
+       for projectConfig in config['projects']:
+               assert 'name' in projectConfig # everything must have a name
+               inherit(projectConfig, config)
+               if 'projects' in projectConfig: # a subpath
+                       folderProjects += loadProjects(projectConfig, os.path.join(folder, projectConfig['name']))
                else: # a proper project
                        if projectConfig['name'] in allProjects:
-                               raise Exception("Duplicate project name "+project['name'])
-                       project = Project(folder, projectConfig, config)
+                               raise Exception("Duplicate project name "+projectConfig['name'])
+                       project = Project(folder, projectConfig)
                        allProjects[projectConfig['name']] = project
                        folderProjects.append(project)
        # store projects of this folder
@@ -89,7 +97,7 @@ def loadProjects(projects, folder=''):
        return folderProjects
 
 # now check what we have to do
-loadProjects(config['projects'])
+loadProjects(config)
 if args.projects:
        if args.resume_from is not None:
                raise Exception("Can not use --resume-from and manually specify projects")
@@ -99,7 +107,7 @@ if args.projects:
                elif name in allFolders:
                        workProjects += allFolders[name]
                else:
-                       raise Exception("Project or folder %s does not exist" % name)
+                       raise Exception("Project or folder%s does not exist" % name)
 elif args.resume_from is None:
        workProjects = projects.values() # all the projects
 else: