X-Git-Url: https://git.ralfj.de/auto-debuild.git/blobdiff_plain/42fcdf2dd90a74c4c932c4517eeb10e2c8b6299e..7bfd35d131a80134f8bc028971ae977b176b0b4b:/auto_debuild.py?ds=inline diff --git a/auto_debuild.py b/auto_debuild.py index a708798..f7ed9e0 100755 --- a/auto_debuild.py +++ b/auto_debuild.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # auto-debuild - Automatic Generation of Debian Packages # Copyright (C) 2012 Ralf Jung # @@ -16,7 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import os, shutil, stat, time, subprocess, sys, shlex, tempfile, argparse +import os, shutil, stat, time, subprocess, sys, shlex, tempfile, argparse, multiprocessing from collections import OrderedDict # a dict with some useful additional getters which can convert types and handle one-element lists like their single member @@ -103,9 +103,7 @@ class RulesFile: def write(self, f): print("#!/usr/bin/make -f", file=f) print(file=f) - print(".PHONY: build", file=f) # there may be a directory called "build" - print(file=f) - print("build %:", file=f) # need to mention "build" here again explicitly so PHONY takes effect + print("%:", file=f) # write proper dh call dh = self.dh if self.dhWith: @@ -138,6 +136,7 @@ def automakeRules(r, config): # and HOST_GNU_TYPE are equal, and if they are not, add a --host parameter) r.dh += ["--buildsystem=autoconf", "--builddirectory="+config.getstr('buildDir')] r.rules['auto_configure'] = [ + (safeCall(*config['autogen']) + " && " if 'autogen' in config else '') + safeCall("mkdir", "-p", buildDir), safeCall("cd", buildDir) + " && " + 'BUILD_TYPE=$$(dpkg-architecture -qDEB_BUILD_GNU_TYPE) && ' + # doing the expansion beforehand ensures that we cancel if it fails @@ -177,25 +176,23 @@ def commandInBuildEnv(config, command): def getArchitecture(config): cmd = commandInBuildEnv(config, ['dpkg-architecture', '-qDEB_HOST_ARCH']) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE) - res = p.communicate()[0] # get only stdout - if p.returncode != 0: raise Exception("Querying dpkg for the architecture failed") - return res[0:len(res)-1] # chop of the \n at the end + output = subprocess.check_output(cmd) + return output.decode('utf-8').strip('\n') # chop off the \n at the end def writeDependency(f, name, list): if len(list): print(name+": "+', '.join(list), file=f) +# actual work functions def deleteDebianFolder(): if os.path.islink('debian'): target = os.readlink('debian') if os.path.exists(target): shutil.rmtree(target) os.remove('debian') - else: + elif os.path.exists('debian'): shutil.rmtree('debian') -# actual work functions def createDebianFiles(config): if not isinstance(config, ConfigDict): config = ConfigDict(config) @@ -208,8 +205,7 @@ def createDebianFiles(config): buildSystem = buildSystems[config.getstr('buildSystem')] # get the data immediately version = config.getstr('version') # version name excluding epoch (used for filenames) fullVersion = str(config.getint('epoch'))+':'+version if 'epoch' in config else version # version name including epoch - dbgPackage = config.getbool('dbgPackage', False) - parallelJobs = config.getint('parallelJobs', 2) + parallelJobs = config.getint('parallelJobs', multiprocessing.cpu_count()) packageArchitecture = config.getstr('architecture', 'any') withPython2 = config.getbool('withPython2', False) withSIP = config.getbool('withSIP', False) @@ -277,18 +273,8 @@ def createDebianFiles(config): writeDependency(f, "Replaces", config.get('binaryReplaces', []) + config.get('binaryBreaksReplaces', [])) print("Description:",sourceName,"(auto-debuild)", file=f) print(" Package auto-generated by auto-debuild.", file=f) - files.append(os.path.join(debDir, "%s_%s_%s.deb" % (binaryName, version, arch))) - # debug package - if dbgPackage: - print(file=f) - print("Package:",binaryName+"-dbg", file=f) - print("Section: debug", file=f) - print("Priority: extra", file=f) - print("Architecture:",packageArchitecture, file=f) - writeDependency(f, "Depends", ["${misc:Depends}", binaryName+" (= ${binary:Version})"]) - print("Description:",sourceName,"debug smbols (auto-debuild)", file=f) - print(" Package containing debug symbols for "+sourceName+", auto-generated by auto-debuild.", file=f) - files.append(os.path.join(debDir, "%s-dbg_%s_%s.deb" % (binaryName, version, arch))) + files.append(os.path.join(debDir, "{}_{}_{}.deb".format(binaryName, version, arch))) + files.append(os.path.join(debDir, "{}-dbgsym_{}_{}.deb".format(binaryName, version, arch))) # shim packages for shim in config.get('binaryShims', []): print(file=f) @@ -299,7 +285,7 @@ def createDebianFiles(config): writeDependency(f, "Depends", ["${misc:Depends}", binaryName+" (= ${binary:Version})"]) print("Description:",sourceName,"shim for",shim,"(auto-debuild)", file=f) print(" Package pretending to be "+shim+", auto-generated by auto-debuild.", file=f) - files.append(os.path.join(debDir, "%s_%s_%s.deb" % (shim, version, arch))) + files.append(os.path.join(debDir, "{}_{}_{}.deb".format(shim, version, arch))) # install file with open('debian/'+binaryName+'.install', 'w') as f: for line in config.get('binaryInstallFiles', []): @@ -343,10 +329,6 @@ def createDebianFiles(config): buildSystem.ruleMaker(r, config) # global rules r.env["DEB_BUILD_OPTIONS"] = 'parallel='+str(parallelJobs) - if not dbgPackage: - # disable debug information - r.env["DEB_CFLAGS_APPEND"] = '-g0' - r.env["DEB_CXXFLAGS_APPEND"] = '-g0' r.dh += ['--parallel'] if withPython2: r.dhWith.add('python2') @@ -359,9 +341,6 @@ def createDebianFiles(config): # installation rule if 'binarySkipFiles' in config: r.rules['auto_install'].append(safeCall('cd', 'debian/'+binaryName) + " && " + safeCall('rm', *config.get('binarySkipFiles'))) - # debug packages - if dbgPackage: - r.rules['strip'] = [safeCall('dh_strip', '--dbg-package='+binaryName+"-dbg")] # put debug files in appropriate package # make the doc folder of the other packages a symlink (dbg, shims) r.rules['installdocs'] = [safeCall('dh_installdocs', '--link-doc='+binaryName)] # wait after configuration? @@ -402,10 +381,10 @@ if __name__ == "__main__": deleteDebianFolder() files = createDebianFiles(config) # check if a file is overwritten - for file in files: - if os.path.exists(file): - if input("Do you want to overwrite %s (y/N)? " % file).lower() != "y": - sys.exit(1) + overwritten_files = list(filter(lambda file: os.path.exists(file), files)) + if overwritten_files: + if input("Do you want to overwrite {} (y/N)? ".format(', '.join(overwritten_files))).lower() != "y": + sys.exit(1) # run compilation buildDebianPackage(config) # install files