1 import os, shutil, subprocess
3 '''A build system has three methods: "configure" (with optionak "force" parameter), "build" and "install"'''
5 # Compile, build, and install cmake projects:
7 def __init__(self, sourceFolder, buildFolder, module, config):
8 self.sourceFolder = os.path.abspath(sourceFolder)
9 self.buildFolder = os.path.abspath(buildFolder)
10 self.installDir = config['installDir']
11 self.buildType = config['buildType']
12 self.jobs = config['jobs']
13 self.buildCmdPrefix = config['buildCmdPrefix']
14 self.installCmdPrefix = config['installCmdPrefix']
15 self.waitAfterConfig = config.get('waitAfterConfig', False)
18 def build(self, reconfigure=False):
19 # Make sure we have a build directory
20 if not os.path.exists(self.buildFolder): os.makedirs(self.buildFolder)
21 os.chdir(self.buildFolder)
22 # In case of reconfiguration, delete cache file if it exists
23 cacheFile = 'CMakeCache.txt'
24 if os.path.exists(cacheFile) and reconfigure: os.remove(cacheFile)
26 os.putenv('PKG_CONFIG_PATH', os.path.join(self.installDir, 'lib', 'pkgconfig')) # I found no way to do this within cmake
27 subprocess.check_call(['cmake', self.sourceFolder, '-DCMAKE_BUILD_TYPE='+self.buildType,
28 '-DCMAKE_INSTALL_PREFIX='+self.installDir]+self.module.get('cmakeParameters', []))
29 os.unsetenv('PKG_CONFIG_PATH')
30 # if asked to do so, wait
31 if self.waitAfterConfig:
32 raw_input('Configuration done. Hit "Enter" to build the module. ')
34 subprocess.check_call(self.buildCmdPrefix + ['make', '-j'+str(self.jobs)])
36 subprocess.check_call(self.installCmdPrefix + ['make', 'install'])
38 # if auto-debuild is available, provide a wrapper for it
42 def __init__(self, sourceFolder, buildFolder, module, vcs, config):
43 self.sourceFolder = os.path.abspath(sourceFolder)
44 self.buildFolder = os.path.abspath(buildFolder)
45 self.jobs = config['jobs']
46 self.debDir = os.path.abspath(config['debDir'])
47 self.debName = config['debName']
48 self.debEMail = config['debEMail']
49 self.waitAfterConfig = config.get('waitAfterConfig', False)
53 def build(self, reconfigure=False): # reconfigure is ignored (we always do a reconfiguration)
54 # create auto-debuild configuration
56 'sourceName': self.module['name'],
57 'buildSystem': self.module['buildSystem'],
58 'debDir': self.debDir,
59 'buildDir': self.buildFolder,
61 'email': self.debEMail,
62 'parallelJobs': self.jobs,
63 'version': self.vcs.version(),
64 'waitAfterConfig': self.waitAfterConfig,
66 if autoDebuildConfig['version'] is None:
67 raise Exception("VCS did not provide us with a proper version number, please fix this")
68 # copy some more optional configuration
69 for option in ('dbgPackage', 'section', 'withPython2', 'binarySkipFiles', 'binaryInstallFiles',
70 'buildDepends', 'binaryDepends', 'binaryRecommends', 'binaryProvides', 'binaryConflicts',
71 'cmakeParameters', 'automakeParameters'):
72 if option in self.module:
73 autoDebuildConfig[option] = self.module[option]
75 os.chdir(self.sourceFolder)
76 if os.path.isdir('debian'): # clean previous build attempts
77 shutil.rmtree('debian')
78 files = auto_debuild.createDebianFiles(autoDebuildConfig)
80 auto_debuild.buildDebianPackage(autoDebuildConfig)
82 subprocess.check_call(['sudo', 'dpkg', '--install'] + files)
85 #print "auto_debuild not found, disabling auto-debuild system"