1 import os, shutil, subprocess
3 '''A build system must have a "build" method with an optional "reconfigure" parameter.'''
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=False):
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 subprocess.check_call(['cmake', self.sourceFolder, '-DCMAKE_BUILD_TYPE='+self.config['buildType'],
22 '-DCMAKE_INSTALL_PREFIX='+self.config['installDir']]+self.config.get('cmakeParameters', []))
23 os.unsetenv('PKG_CONFIG_PATH')
24 # if asked to do so, wait
25 if self.config['waitAfterConfig']:
26 raw_input('Configuration done. Hit "Enter" to build the project. ')
28 subprocess.check_call(self.config['buildCmdPrefix'] + ['make', '-j'+str(self.config['jobs'])])
30 subprocess.check_call(self.config['installCmdPrefix'] + ['make', 'install'])
32 # if auto-debuild is available, provide a wrapper for it
36 def __init__(self, sourceFolder, buildFolder, config, vcs):
37 self.sourceFolder = os.path.abspath(sourceFolder)
38 self.buildFolder = os.path.abspath(buildFolder)
39 self.debFolder = os.path.abspath(config['debDir'])
43 def build(self, reconfigure=False): # reconfigure is ignored (we always do a reconfiguration)
44 # create auto-debuild configuration
46 'sourceName': self.config['name'],
47 'buildSystem': self.config['buildSystem'],
48 'debDir': self.debFolder,
49 'buildDir': self.buildFolder,
50 'name': self.config['debName'],
51 'email': self.config['debEMail'],
52 'parallelJobs': self.config['jobs'],
53 'version': self.vcs.version(),
55 if autoDebuildConfig['version'] is None:
56 raise Exception("VCS did not provide us with a proper version number, please fix this")
57 # copy some more optional configuration
58 for option in ('waitAfterConfig', 'dbgPackage', 'section', 'withPython2', 'binarySkipFiles', 'binaryInstallFiles',
59 'buildDepends', 'binaryDepends', 'binaryRecommends', 'binaryProvides', 'binaryConflicts',
60 'alternatives', 'cmakeParameters', 'automakeParameters'):
61 if option in self.config:
62 autoDebuildConfig[option] = self.config[option]
64 os.chdir(self.sourceFolder)
65 if os.path.isdir('debian'): # clean previous build attempts
66 shutil.rmtree('debian')
67 files = auto_debuild.createDebianFiles(autoDebuildConfig)
69 auto_debuild.buildDebianPackage(autoDebuildConfig)
71 if self.config.get('debInstall', True):
72 subprocess.check_call(['sudo', 'dpkg', '--install'] + files)
75 #print "auto_debuild not found, disabling auto-debuild system"