Various distccd related improvements, mostly respect --verbose (#216)

I've done some refactoring while debugging #209.
* Unused file `pmb/build/crosscompiler.py` removed (that was a
  left over from `_pmb_build_in_native_chroot` hack
* Do verbose logging in distccd, when `pmbootstrap --verbose` is
  being invoked
* Restart distccd, when the commandline has changed (e.g. when the
  currently running version was not verbose, and the new one is
  verbose.) Prior to this change, it only got restarted, when the
  architecture changed (so it did not allow changing the job count
  on the fly for example).
* Insert missing whitespace in arguments help.
This commit is contained in:
Oliver Smith 2017-07-21 16:25:52 +00:00 committed by GitHub
parent cf0dc2a989
commit 56b34212f6
4 changed files with 67 additions and 72 deletions

View File

@ -1,32 +0,0 @@
"""
Copyright 2017 Oliver Smith
This file is part of pmbootstrap.
pmbootstrap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pmbootstrap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import pmb.config
import fnmatch
def init(args, arch):
packages = ["gcc-" + arch, "ccache-cross-symlinks"]
pmb.chroot.apk.install(args, packages)
def native_chroot(args, pkgname):
for pattern in pmb.config.crosscompile_supported:
if fnmatch.fnmatch(pkgname, pattern):
return True
return False

View File

@ -22,7 +22,6 @@ import logging
import pmb.build
import pmb.build.autodetect
import pmb.build.buildinfo
import pmb.build.crosscompiler
import pmb.chroot
import pmb.chroot.apk
import pmb.chroot.distccd

View File

@ -16,15 +16,19 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import configparser
import errno
import logging
import os
import errno
import pmb.chroot
import pmb.config
import pmb.chroot.apk
def get_running_pid(args):
"""
:returns: the running distccd's pid as integer or None
"""
pidfile = args.work + "/chroot_native/home/user/distccd.pid"
if not os.path.exists(pidfile):
return None
@ -33,23 +37,32 @@ def get_running_pid(args):
return int(lines[0][:-1])
def get_running_arch(args):
def get_running_info(args):
"""
:returns: the architecture string of the running distccd process (eg.
"armhf" or "aarch64") or "unknown" if the file does not exist.
:returns: A dictionary in the form of {"arch": .., "cmdline": "" }. arch is
the architecture (e.g. "armhf" or "aarch64"), and "cmdline" is the
saved value from the generate_cmdline() list, joined on space.
If the information can not be read, "arch" and "cmdline" are set to
"unknown".
The arch is used to print a nice stop message, the full cmdline is used to
check whether distccd needs to be restartet (e.g. because the arch has been
changed, or the verbose flag).
"""
file = args.work + "/chroot_native/tmp/distccd_running_arch"
if not os.path.exists(file):
return "unknown"
with open(file, "r") as handle:
lines = handle.readlines()
return lines[0][:-1]
info = configparser.ConfigParser()
path = args.work + "/chroot_native/tmp/distccd_running_info"
if os.path.exists(path):
info.read(path)
else:
info["distccd"] = {}
info["distccd"]["arch"] = "unknown"
info["distccd"]["cmdline"] = "unknown"
return info["distccd"]
def is_running(args):
"""
:returns: When not running: None
When running: the arch string, e.g. "armhf"
When running: result from get_running_info()
"""
# Get the PID
pid = get_running_pid(args)
@ -64,43 +77,58 @@ def is_running(args):
pmb.chroot.root(args, ["rm", "/home/user/distccd.pid"])
return False
elif err.errno == errno.EPERM: # access denied
return get_running_arch(args)
return get_running_info(args)
def generate_cmdline(args, arch):
"""
:returns: a dictionary suitable for pmb.chroot.user(), to start the distccd
with the cross-compiler in the path and all options set.
"""
path = "/usr/lib/gcc-cross-wrappers/" + arch + "/bin:" + pmb.config.chroot_path
ret = ["PATH=" + path,
"distccd",
"--pid-file", "/home/user/distccd.pid",
"--listen", "127.0.0.1",
"--allow", "127.0.0.1",
"--port", args.port_distccd,
"--log-file", "/home/user/distccd.log",
"--jobs", args.jobs,
"--nice", "19",
"--job-lifetime", "60",
"--daemon"
]
if args.verbose:
ret.append("--verbose")
return ret
def start(args, arch):
if is_running(args) == arch:
# Skip when already running with the same cmdline
cmdline = generate_cmdline(args, arch)
info = is_running(args)
if info and info["cmdline"] == " ".join(cmdline):
return
stop(args)
pmb.chroot.apk.install(args, ["distcc", "gcc-cross-wrappers"])
# Start daemon with cross-compiler in path
path = "/usr/lib/gcc-cross-wrappers/" + arch + "/bin:" + pmb.config.chroot_path
daemon = ["PATH=" + path,
"distccd",
"--pid-file", "/home/user/distccd.pid",
"--listen", "127.0.0.1",
"--allow", "127.0.0.1",
"--port", args.port_distccd,
"--log-file", "/home/user/distccd.log",
"--jobs", args.jobs,
"--nice", "19",
"--job-lifetime", "60",
"--daemon"
]
logging.info(
"(native) start distccd (" +
arch +
") on 127.0.0.1:" +
args.port_distccd)
pmb.chroot.user(args, daemon)
logging.info("(native) start distccd (" + arch + ") on 127.0.0.1:" +
args.port_distccd)
pmb.chroot.user(args, cmdline)
# Write down the running architecture
with open(args.work + "/chroot_native/tmp/distccd_running_arch", "w") as handle:
handle.write(arch + "\n")
# Write down the arch and cmdline (which also contains the relevant
# environment variables, /proc/$pid/cmdline does not!)
info = configparser.ConfigParser()
info["distccd"] = {}
info["distccd"]["arch"] = arch
info["distccd"]["cmdline"] = " ".join(cmdline)
with open(args.work + "/chroot_native/tmp/distccd_running_info", "w") as handle:
info.write(handle)
def stop(args):
arch = is_running(args)
if arch:
logging.info("(native) stop distccd (" + arch + ")")
info = is_running(args)
if info:
logging.info("(native) stop distccd (" + info["arch"] + ")")
pmb.chroot.user(args, ["kill", str(get_running_pid(args))])

View File

@ -108,7 +108,7 @@ def arguments():
parser.add_argument("-l", "--log", dest="log", default=None)
parser.add_argument("-v", "--verbose", dest="verbose",
action="store_true", help="write even more to the"
"logfile (this may reduce performance)")
" logfiles (this may reduce performance)")
parser.add_argument("-q", "--quiet", dest="quiet",
action="store_true", help="do not output any log messages")