Package: git-buildpackage Version: 0.9.14 Severity: wishlist Tags: patch GNU make, since version 4.2 https://lists.gnu.org/archive/html/info-gnu/2016-05/msg00013.html, officially supports the file descriptors of the jobserver to subporcess, but gbp will close those file-descriptors since it uses the default settings of the subprocess module (which is to close all file descriptors except standard-in, -out, and -error).
I created a patch that in buildpackages looks for the '--jobserver-auth=<N>,<M>' flag in the environment variable $MAKEFLAGS, if that exists it sets those file descriptors as bein passed to the subprocess module. Below is the patch generated. The reason this is useful is because it enables multiple gbp jobs that are spawned from make to run in parallel and share a job-server. Note that this patch in itself will not enable this since the builder needs to support it as well. diff -Nru git-buildpackage-0.9.14/debian/changelog git-buildpackage-0.9.14+nmu1/debian/changelog --- git-buildpackage-0.9.14/debian/changelog 2019-03-21 09:33:34.000000000 +0000 +++ git-buildpackage-0.9.14+nmu1/debian/changelog 2019-04-25 10:25:15.000000000 +0000 @@ -1,3 +1,11 @@ +git-buildpackage (0.9.14+nmu1) UNRELEASED; urgency=medium + + * Non-maintainer upload. + * Made gbp buildpackage able to pass file-descriptors of an existing + GNU Make job-server. + + -- Kristofer Hansson <kristofer.hans...@icomera.com> Thu, 25 Apr 2019 10:25:15 +0000 + git-buildpackage (0.9.14) unstable; urgency=medium [ Michael Prokop ] diff -Nru git-buildpackage-0.9.14/gbp/command_wrappers.py git-buildpackage-0.9.14+nmu1/gbp/command_wrappers.py --- git-buildpackage-0.9.14/gbp/command_wrappers.py 2019-01-08 19:15:13.000000000 +0000 +++ git-buildpackage-0.9.14+nmu1/gbp/command_wrappers.py 2019-04-25 10:25:15.000000000 +0000 @@ -75,7 +75,7 @@ If cmd doesn't contain a path component it will be looked up in $PATH. """ - def __init__(self, cmd, args=[], shell=False, extra_env=None, cwd=None, + def __init__(self, cmd, args=[], shell=False, extra_env=None, cwd=None, pass_fds=(), capture_stderr=False, capture_stdout=False): self.cmd = cmd @@ -86,6 +86,7 @@ self.capture_stdout = capture_stdout self.capture_stderr = capture_stderr self.cwd = cwd + self.pass_fds = pass_fds if extra_env is not None: self.env = os.environ.copy() self.env.update(extra_env) @@ -145,7 +146,8 @@ env=self.env, preexec_fn=default_sigpipe, stdout=stdout_arg, - stderr=stderr_arg) + stderr=stderr_arg, + pass_fds=self.pass_fds) (self.stdout, self.stderr) = popen.communicate() if self.stdout is not None: self.stdout = self.stdout.decode() diff -Nru git-buildpackage-0.9.14/gbp/scripts/buildpackage.py git-buildpackage-0.9.14+nmu1/gbp/scripts/buildpackage.py --- git-buildpackage-0.9.14/gbp/scripts/buildpackage.py 2019-01-08 19:15:13.000000000 +0000 +++ git-buildpackage-0.9.14+nmu1/gbp/scripts/buildpackage.py 2019-04-25 10:25:15.000000000 +0000 @@ -335,6 +335,20 @@ return branch +def get_job_fds_from_env(): + makeflags = None + try: + makeflags = os.environ['MAKEFLAGS'] + except KeyError: + return () + + for flag in makeflags.split(' '): + if flag.startswith('--jobserver-auth='): + return tuple(flag.split('=')[1].split(',')) + else: + return () + + def build_parser(name, prefix=None): try: parser = GbpOptionParserDebian(command=os.path.basename(name), prefix=prefix) @@ -510,6 +524,7 @@ export_dir = os.path.join(output_dir, "%s-%s" % (source.sourcepkg, major)) build_dir = export_dir if options.export_dir else repo.path changes_file = changes_file_name(source, build_dir, options.builder, dpkg_args) + job_fds = get_job_fds_from_env() # Run preexport hook if options.export_dir and options.preexport: @@ -563,6 +578,7 @@ RunAtCommand(options.builder, [pipes.quote(arg) for arg in dpkg_args], shell=True, + pass_fds=job_fds, extra_env=Hook.md(build_env, {'GBP_BUILD_DIR': build_dir}) )(dir=build_dir)