2 import vcs, build_system, imp
3 import argparse, os, sys, subprocess
4 from collections import OrderedDict
6 # read command-line arguments
7 parser = argparse.ArgumentParser(description='Update and build a bunch of stuff')
8 parser.add_argument("-c, --config",
9 dest="config", default="mass-build.conf",
10 help="mass-build config file")
11 parser.add_argument("--reconfigure",
12 action="store_true", dest="reconfigure",
13 help="Force configuration to be run")
14 parser.add_argument("--reset-source",
15 action="store_true", dest="reset_source",
16 help="Reset sourcecode to the given version (removes local changes!)")
17 parser.add_argument("--no-update",
18 action="store_false", dest="update",
19 help="Do not update modules before compilation")
20 parser.add_argument("--resume-from", metavar='MODULE',
22 help="Resume building from the given repository")
23 parser.add_argument("modules", metavar='MODULE', nargs='*',
24 help="Manually specify modules to be built")
25 args = parser.parse_args()
27 if args.reset_source and not args.update:
28 raise Exception("When no update is performed, no reset to the given version can be done either")
31 config = imp.load_source('config', args.config).__dict__
32 os.remove(args.config+'c') # remove compiled python file
33 projects = OrderedDict() # all projects
34 workProjects = [] # projects we work on
38 def __init__(self, config, folder, module):
40 self.name = module['name']
42 vcsName = module['vcs']
44 self.vcs = vcs.Git(self.sourceFolder(), module['url'], module['version'])
45 elif vcsName == 'svn':
46 self.vcs = vcs.SVN(self.sourceFolder(), module['url'], module.get('versionName'))
48 raise Exception("Unknown VCS type "+vcsName)
50 if config.get('buildDeb', False):
51 self.buildSystem = build_system.AutoDebuild(self.sourceFolder(), self.buildFolder(), module, self.vcs, config)
53 buildSystemName = module['buildSystem']
54 if buildSystemName == 'cmake':
55 self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), module, config)
57 raise Exception("Unknown build system type "+buildSystemName)
59 def sourceFolder(self):
60 return os.path.join(self.folder, self.name)
62 def buildFolder(self):
63 return os.path.join(config['buildDir'], self.sourceFolder())
65 # return the position of the given item in the list
66 def findInList(list, item):
67 for i in xrange(len(list)):
70 raise Exception("%s not found in list" % str(item))
72 # populate list of projects
73 def loadProjects(config, modules, folder=''):
74 for module in modules:
75 if 'folder' in module: # a subpath
76 loadProjects(config, module['modules'], os.path.join(folder, module['folder']))
77 else: # a proper project
78 if module['name'] in projects:
79 raise Exception("Duplicate module name "+module['name'])
80 projects[module['name']] = Project(config, folder, module)
82 # now check what we have to do
83 loadProjects(config, config['modules'])
85 if args.resume_from is not None:
86 raise Exception("Can not use --resume-from and manually specify modules")
87 for module in args.modules:
88 if not module in projects:
89 raise Exception("Project %s does not exist" % module)
90 workProjects.append(projects[module])
91 elif args.resume_from is None:
92 workProjects = projects.values() # all the projects
94 if not args.resume_from in projects:
95 raise Exception("Project %s does not exist" % args.resume_from)
96 startWith = projects[args.resume_from]
97 startIndex = findInList(projects.values(), startWith)
98 workProjects = projects.values()[startIndex:]
101 for project in workProjects:
104 print "Updating module",project.sourceFolder()
105 project.vcs.update(forceVersion=args.reset_source)
106 print "Building module",project.sourceFolder()
107 project.buildSystem.build(reconfigure=args.reconfigure)
109 except (subprocess.CalledProcessError, KeyboardInterrupt) as e:
112 if isinstance(e, KeyboardInterrupt): # str(e) would be the empty string
113 print >> sys.stderr, "Interruped by user while processing %s" % (project.name)
115 print >> sys.stderr, "Error while processing %s: %s" % (project.name, str(e))