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='Build KDE')
8 parser.add_argument("-c, --config",
9 dest="config", default="config.py",
10 help="kdebuildpy config file")
11 parser.add_argument("--reconfigure",
12 action="store_true", dest="reconfigure",
13 help="Force configuration to be run")
14 parser.add_argument("--phases", choices=["update", "configure", "compile"], nargs='*', metavar='PHASE',
15 dest="phases", default=["update", "configure", "compile"],
16 help="For each module, run the given phases in the given order. Possible phases are: update, configure, compile")
17 parser.add_argument("--resume-from", metavar='MODULE',
19 help="Resume building from the given repository")
20 parser.add_argument("modules", metavar='MODULE', nargs='*',
21 help="Manually specify modules to be built")
22 args = parser.parse_args()
25 config = imp.load_source('config', args.config)
26 os.remove(args.config+'c') # remove compiled python file
27 projects = OrderedDict() # all projects
28 workProjects = [] # projects we work on
32 def __init__(self, folder, module):
34 self.name = module['name']
36 vcsName = module.get('vcs', 'kde+git')
37 if vcsName == 'kde+git':
38 self.vcs = vcs.KDEGit(self.sourceFolder(), module['name'], module['version'])
39 elif vcsName == 'kde+svn':
40 self.vcs = vcs.KDESVN(self.sourceFolder(), module['svn-path'])
42 raise Exception("Unknown VCS type "+vcsName)
44 buildSystemName = module.get('build-system', 'cmake')
45 if buildSystemName == 'cmake':
46 self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), config)
48 raise Exception("Unknown build system type "+buildSystemName)
50 def sourceFolder(self):
51 return os.path.join(self.folder, self.name)
53 def buildFolder(self):
54 return os.path.join(config.buildDir, self.sourceFolder())
56 # return the position of the given item in the list
57 def findInList(list, item):
58 for i in xrange(len(list)):
61 raise Exception("%s not found in list" % str(item))
63 # populate list of projects
64 def loadProjects(modules, folder=''):
65 for module in modules:
66 if 'folder' in module: # a subpath
67 loadProjects(module['modules'], os.path.join(folder, module['folder']))
68 else: # a proper project
69 if module['name'] in projects:
70 raise Exception("Duplicate module name "+module['name'])
71 projects[module['name']] = Project(folder, module)
73 # now check what we have to do
74 loadProjects(config.modules)
76 if args.resume_from is not None:
77 raise Exception("Can not use --resume-from and manually specify modules")
78 for module in args.modules:
79 if not module in projects:
80 raise Exception("Project %s does not exist" % module)
81 workProjects.append(projects[module])
82 elif args.resume_from is None:
83 workProjects = projects.values() # all the projects
85 if not args.resume_from in projects:
86 raise Exception("Project %s does not exist" % args.resume_from)
87 startWith = projects[args.resume_from]
88 startIndex = findInList(projects.values(), startWith)
89 workProjects = projects.values()[startIndex:]
92 for project in workProjects:
94 for phase in args.phases:
97 elif phase == 'configure':
98 project.buildSystem.configure(force=args.reconfigure)
99 elif phase == 'compile':
100 project.buildSystem.build()
101 project.buildSystem.install()
103 raise Exception("Invalid phase "+phase)
104 except (subprocess.CalledProcessError, KeyboardInterrupt) as e:
107 if isinstance(e, KeyboardInterrupt): # str(e) would be the empty string
108 print >> sys.stderr, "Interruped by user while processing %s" % (project.name)
110 print >> sys.stderr, "Error while processing %s: %s" % (project.name, str(e))