From a8ac802d74cf0b3092849a2adc9bd2a0a2a257e5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 27 Jul 2012 14:36:01 +0200 Subject: [PATCH] Properly escape folder names, add support for custom build directory --- auto_debuild.py | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/auto_debuild.py b/auto_debuild.py index eda72e3..efc36eb 100755 --- a/auto_debuild.py +++ b/auto_debuild.py @@ -2,18 +2,36 @@ import os, stat, time, subprocess, sys from collections import OrderedDict +# some utility functions +def safeCall(args): + res = "" + for arg in args: + assert arg.find("'") < 0 # ' is not supported + if len(res): res += " " + res += "'"+arg+"'" + return res + # abstract representation of rules file class RulesFile: def __init__(self): - self.env = [] + self.env = {} self.dh = [] self.rules = OrderedDict() + def env2str(self): + res = "" + for name in self.env: # we rely on the name being sane (i.e., no special characters) + val = self.env[name] + assert val.find("'") < 0 # ' is not supported + if len(res): res += " " + res += name+"='"+val+"'" + return res + def write(self, f): print >>f, "#!/usr/bin/make -f" print >>f, "" print >>f, "%:" - print >>f, '\t'+' '.join(self.env)+' dh $@',' '.join(self.dh) + print >>f, '\t'+self.env2str()+' dh $@ '+safeCall(self.dh) for rule in self.rules: print >>f, "" print >>f, "override_dh_"+rule+":" @@ -22,13 +40,16 @@ class RulesFile: # build-system specific part of rules file def cmakeRules(config): + buildDir = config.get('buildDir', 'build.dir') # "build" is not a good idea, as that's also the name of a target... + srcDir = os.getcwd() r = RulesFile() - r.dh += ["--buildsystem=cmake", "--builddirectory=build.dir"] # dh parameters: "build" is not a good idea, as that's also the name of a target... + r.dh += ["--buildsystem=cmake", "--builddirectory="+buildDir] # dh parameters r.rules['auto_configure'] = [ - 'mkdir -p build.dir', - "cd build.dir && cmake .. -DCMAKE_INSTALL_PREFIX=/usr "+' '.join(config.get('cmakeParameters', [])) + safeCall(["mkdir", "-p", buildDir]), + safeCall(["cd", buildDir]) + " && " + + safeCall(["cmake", srcDir, "-DCMAKE_INSTALL_PREFIX=/usr"] + config.get('cmakeParameters', [])) ] - r.rules['auto_clean'] = ['rm -f build.dir/CMakeCache.txt'] # clean old cmake cache + r.rules['auto_clean'] = [safeCall(['rm', '-f', os.path.join(buildDir, 'CMakeCache.txt')])] # clean old cmake cache return r def automakeRules(config): @@ -133,12 +154,15 @@ def createDebianFiles(config): else: raise Exception("Invalid build system "+buildSystem) # global rules - r.env += ["DEB_BUILD_OPTIONS='parallel=2'"] - if not dbgPackage: r.env += ["DEB_CFLAGS_APPEND='-g0'", "DEB_CXXFLAGS_APPEND='-g0'"] # disable debug information + r.env["DEB_BUILD_OPTIONS"] = 'parallel=2' + if not dbgPackage: + # disable debug information + r.env["DEB_CFLAGS_APPEND"] = '-g0' + r.env["DEB_CXXFLAGS_APPEND"] = '-g0' r.dh += ['--parallel'] - r.rules['builddeb'] = ['dh_builddeb --destdir='+debDir] # passing this gobally to dh results in weird problems (like stuff being installed there, and not in the package...) + r.rules['builddeb'] = [safeCall(['dh_builddeb', "--destdir="+debDir])] # passing this gobally to dh results in weird problems (like stuff being installed there, and not in the package...) r.rules['auto_test'] = [] - r.rules['auto_install'] = ['dh_auto_install --destdir=debian/'+binaryName] # install everything into the binary package + r.rules['auto_install'] = [safeCall(['dh_auto_install', '--destdir=debian/'+binaryName])] # install everything into the binary package # for debug packages if dbgPackage: r.rules['strip'] = ['dh_strip --dbg-package='+binaryName+"-dbg"] # put debug files in appropriate package -- 2.30.2