1 #!/bin/false # invoke this with a specific python
3 import sys, shutil, os.path
4 from subprocess import Popen, PIPE
6 PYTHON = sys.executable
9 class SubprocessError(Exception):
12 def get_output(*cmd, **kwargs):
13 tolerate_stderr = kwargs.get("tolerate_stderr", False)
14 print " " + " ".join(cmd)
15 p = Popen(cmd, stdout=PIPE)
16 (out,err) = p.communicate()
19 print >>sys.stderr, err
20 raise SubprocessError("command %s exited with rc=%s", (cmd, rc))
21 if err and not tolerate_stderr:
22 print >>sys.stderr, "stderr:", err
23 raise SubprocessError("command emitted unexpected stderr")
27 def run(*cmd, **kwargs):
28 print " " + " ".join(cmd)
29 # if "stdin" in kwargs:
30 # stdin = kwargs.pop("stdin")
31 # p = Popen(cmd, stdin=PIPE, **kwargs)
32 # p.stdin.write(stdin)
35 # p = Popen(cmd, **kwargs)
36 p = Popen(cmd, **kwargs)
39 raise SubprocessError("command %s exited with rc=%s", (cmd, rc))
41 # the very first time you run setup.py, it will download+build darcsver and
42 # whatnot, emitting noise to stdout. Run it once (and throw away that junk)
43 # to avoid treating that noise as the package name.
44 run(PYTHON, "setup.py", "darcsver")
46 NAME = get_output(PYTHON, "setup.py", "--name").strip()
47 VERSION = get_output(PYTHON, "setup.py", "--version").strip()
49 TARBALL = "%s-%s.tar.gz" % (NAME, VERSION)
50 DEBIAN_TARBALL = "%s_%s.orig.tar.gz" % (NAME, VERSION)
51 BUILDDIR = "build/debian/%s-%s" % (NAME, VERSION)
53 run(PYTHON, "setup.py", "sdist", "--formats=gztar")
54 if os.path.exists("build/debian"):
55 shutil.rmtree("build/debian")
56 os.makedirs("build/debian")
57 shutil.copyfile("dist/%s" % TARBALL, "build/debian/%s" % DEBIAN_TARBALL)
58 run("tar", "xf", DEBIAN_TARBALL, cwd="build/debian")
60 # now modify the tree for debian packaging. This is an algorithmic way of
61 # applying the debian .diff, which factors out some of the similarities
62 # between various debian/ubuntu releases. Everything we do after this point
63 # will show up in the generated .diff, and thus form the debian-specific part
64 # of the source package.
65 DEBDIR = os.path.join(BUILDDIR, "debian")
68 # The 'aliases' section in setup.cfg causes problems, so get rid of it. We
69 # could get rid of the whole file, but 1: find_links is still sort of useful,
70 # and 2: dpkg-buildpackage prefers to ignore file removal (as opposed to
73 #os.unlink(os.path.join(BUILDDIR, "setup.cfg"))
74 SETUPCFG = os.path.join(BUILDDIR, "setup.cfg")
75 lines = open(SETUPCFG, "r").readlines()
76 f = open(SETUPCFG, "w")
78 if l.startswith("[aliases]"):
83 for n in ["compat", "control", "copyright", "pycompat", "rules"]:
84 fn = "misc/debian/%s.%s" % (n, ARCH)
85 if not os.path.exists(fn):
86 fn = "misc/debian/%s" % n
87 assert os.path.exists(fn)
89 shutil.copyfile(fn, os.path.join(DEBDIR, n))
91 os.chmod(os.path.join(DEBDIR, n), 0755) # +x
93 # We put "local package" on the first line of the changelog entry to suppress
94 # the lintian NMU warnings (since debchange's new entry's "author" will
95 # probably be different than the what the debian/control Maintainer: field
98 DISTRIBUTION_MAP = {"sid": "unstable"}
100 run("debchange", "--create",
102 "--newversion", VERSION+"-1",
103 "--distribution", DISTRIBUTION_MAP.get(ARCH, ARCH),
104 "local package: 'make deb' build", cwd=BUILDDIR)
106 # the package is ready to build. 'debuild' will produce the source package
107 # (.dsc+.diff.gz), then build the .deb and produce a .changes file ready for
108 # upload to an APT archive. The build log will go into a .build file.
110 run("debuild", "-uc", "-us", cwd=BUILDDIR)