1 import os, shutil, subprocess
3 '''A build system must have a "build" method with parameters "reconfigure" and "waitAfterConfig".'''
5 # Compile, build, and install cmake projects:
7 def __init__(self, sourceFolder, buildFolder, config):
8 self.sourceFolder = os.path.abspath(sourceFolder)
9 self.buildFolder = os.path.abspath(buildFolder)
12 def build(self, reconfigure, waitAfterConfig):
13 # Make sure we have a build directory
14 if not os.path.exists(self.buildFolder): os.makedirs(self.buildFolder)
15 os.chdir(self.buildFolder)
16 # In case of reconfiguration, delete cache file if it exists
17 cacheFile = 'CMakeCache.txt'
18 if os.path.exists(cacheFile) and reconfigure: os.remove(cacheFile)
20 os.putenv('PKG_CONFIG_PATH', os.path.join(self.config['installDir'], 'lib', 'pkgconfig')) # I found no way to do this within cmake
21 os.putenv('CMAKE_PREFIX_PATH', self.config['installDir'])
22 subprocess.check_call(['cmake', self.sourceFolder, '-DCMAKE_BUILD_TYPE='+self.config['buildType'],
23 '-DCMAKE_INSTALL_PREFIX='+self.config['installDir']]+self.config.get('cmakeParameters', []))
24 os.unsetenv('PKG_CONFIG_PATH')
25 os.unsetenv('CMAKE_PREFIX_PATH')
26 # if asked to do so, wait
28 raw_input('Configuration done. Hit "Enter" to build the project. ')
30 subprocess.check_call(self.config.get('buildCmdPrefix', []) + ['make', '-j'+str(self.config['jobs'])])
32 subprocess.check_call(self.config.get('installCmdPrefix', []) + ['make', 'install'])
34 # if auto-debuild is available, provide a wrapper for it
38 def __init__(self, sourceFolder, buildFolder, config, vcs):
39 self.sourceFolder = os.path.abspath(sourceFolder)
40 self.buildFolder = os.path.abspath(buildFolder)
41 self.debFolder = os.path.abspath(config['debDir'])
45 def build(self, reconfigure, waitAfterConfig): # reconfigure is ignored (we always do a reconfiguration)
46 # create auto-debuild configuration
47 versionName = self.config['versionName'] if 'versionName' in self.config else self.vcs.version()
49 'sourceName': self.config['name'],
50 'buildSystem': self.config['buildSystem'],
51 'debDir': self.debFolder,
52 'buildDir': self.buildFolder,
53 'name': self.config['debName'],
54 'email': self.config['debEMail'],
55 'parallelJobs': self.config['jobs'],
56 'version': versionName,
57 'waitAfterConfig': waitAfterConfig,
59 if autoDebuildConfig['version'] is None:
60 raise Exception("VCS did not provide us with a proper version number, please fix this")
61 # copy some more optional configuration
62 for option in ('dbgPackage', 'section', 'withPython2', 'binarySkipFiles', 'binaryInstallFiles',
63 'buildDepends', 'binaryDepends', 'binaryRecommends', 'binaryProvides', 'binaryConflicts', 'binaryBreaks',
64 'binaryReplaces', 'binaryBreaksReplaces',
65 'alternatives', 'cmakeParameters', 'automakeParameters'):
66 if option in self.config:
67 autoDebuildConfig[option] = self.config[option]
69 os.chdir(self.sourceFolder)
70 if os.path.isdir('debian'): # clean previous build attempts
71 shutil.rmtree('debian')
72 files = auto_debuild.createDebianFiles(autoDebuildConfig)
74 auto_debuild.buildDebianPackage(autoDebuildConfig)
76 if self.config.get('debInstall', True):
77 subprocess.check_call(['sudo', 'dpkg', '--install'] + files)
80 #print "auto_debuild not found, disabling auto-debuild system"