systemd bbclass: replace all tabs with 4 spaces

Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
This commit is contained in:
Koen Kooi
2012-07-19 11:06:40 +00:00
parent 4c0420d830
commit 3770f2bbee
+151 -151
View File
@@ -27,51 +27,51 @@ systemctl disable ${SYSTEMD_SERVICE}
} }
def get_package_var(d, var, pkg): def get_package_var(d, var, pkg):
val = (d.getVar('%s_%s' % (var, pkg), d, 1) or "").strip() val = (d.getVar('%s_%s' % (var, pkg), d, 1) or "").strip()
if val == "": if val == "":
val = (d.getVar(var, d, 1) or "").strip() val = (d.getVar(var, d, 1) or "").strip()
return val return val
def systemd_after_parse(d): def systemd_after_parse(d):
def systemd_check_vars(): def systemd_check_vars():
if d.getVar('BB_WORKERCONTEXT', True) is not None: if d.getVar('BB_WORKERCONTEXT', True) is not None:
return return
bb_filename = d.getVar('FILE') bb_filename = d.getVar('FILE')
packages = d.getVar('PACKAGES', 1) packages = d.getVar('PACKAGES', 1)
# check SYSTEMD_PACKAGES # check SYSTEMD_PACKAGES
systemd_pkgs = d.getVar('SYSTEMD_PACKAGES', 1) or "" systemd_pkgs = d.getVar('SYSTEMD_PACKAGES', 1) or ""
if systemd_pkgs == "": if systemd_pkgs == "":
raise bb.build.FuncFailed, "\n\n%s inherits systemd but doesn't set SYSTEMD_PACKAGES" % bb_filename raise bb.build.FuncFailed, "\n\n%s inherits systemd but doesn't set SYSTEMD_PACKAGES" % bb_filename
for pkg_systemd in systemd_pkgs.split(): for pkg_systemd in systemd_pkgs.split():
if pkg_systemd.find("-systemd") == -1: if pkg_systemd.find("-systemd") == -1:
if pkg_systemd != d.getVar('PN', 1): if pkg_systemd != d.getVar('PN', 1):
raise bb.build.FuncFailed, \ raise bb.build.FuncFailed, \
"\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN}" % \ "\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN}" % \
(bb_filename, pkg_systemd) (bb_filename, pkg_systemd)
else: else:
pkg_systemd_base = pkg_systemd.replace('-systemd', '') pkg_systemd_base = pkg_systemd.replace('-systemd', '')
if pkg_systemd_base not in packages: if pkg_systemd_base not in packages:
raise bb.build.FuncFailed, \ raise bb.build.FuncFailed, \
"\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN}" % \ "\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN}" % \
( bb_filename, pkg_systemd) ( bb_filename, pkg_systemd)
# prepend systemd-packages not already included # prepend systemd-packages not already included
def systemd_create_package(pkg_systemd): def systemd_create_package(pkg_systemd):
packages = d.getVar('PACKAGES', 1) packages = d.getVar('PACKAGES', 1)
if not pkg_systemd in packages: if not pkg_systemd in packages:
packages = "%s %s" % (pkg_systemd, packages) packages = "%s %s" % (pkg_systemd, packages)
d.setVar('PACKAGES', packages) d.setVar('PACKAGES', packages)
bpn = d.getVar('BPN', 1) bpn = d.getVar('BPN', 1)
if bpn + "-native" != d.getVar('PN', 1) and \ if bpn + "-native" != d.getVar('PN', 1) and \
bpn + "-cross" != d.getVar('PN', 1) and \ bpn + "-cross" != d.getVar('PN', 1) and \
bpn + "-nativesdk" != d.getVar('PN', 1): bpn + "-nativesdk" != d.getVar('PN', 1):
systemd_check_vars() systemd_check_vars()
for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split(): for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
systemd_create_package(pkg_systemd) systemd_create_package(pkg_systemd)
python __anonymous() { python __anonymous() {
@@ -81,103 +81,103 @@ python __anonymous() {
# automatically install all *.service and *.socket supplied in recipe's SRC_URI # automatically install all *.service and *.socket supplied in recipe's SRC_URI
do_install_append() { do_install_append() {
for service in `find ${WORKDIR} -maxdepth 1 -name '*.service' -o -name '*.socket'` ; do for service in `find ${WORKDIR} -maxdepth 1 -name '*.service' -o -name '*.socket'` ; do
# ensure installing systemd-files only (e.g not avahi *.service) # ensure installing systemd-files only (e.g not avahi *.service)
if grep -q '\[Unit\]' $service ; then if grep -q '\[Unit\]' $service ; then
install -d ${D}${systemd_unitdir}/system install -d ${D}${systemd_unitdir}/system
install -m 644 $service ${D}${systemd_unitdir}/system install -m 644 $service ${D}${systemd_unitdir}/system
fi fi
done done
} }
python populate_packages_prepend () { python populate_packages_prepend () {
def systemd_generate_package_scripts(pkg): def systemd_generate_package_scripts(pkg):
bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg) bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg)
localdata = bb.data.createCopy(d) localdata = bb.data.createCopy(d)
overrides = bb.data.getVar("OVERRIDES", localdata, 1) overrides = bb.data.getVar("OVERRIDES", localdata, 1)
bb.data.setVar("OVERRIDES", "%s:%s" % (pkg, overrides), localdata) bb.data.setVar("OVERRIDES", "%s:%s" % (pkg, overrides), localdata)
bb.data.update_data(localdata) bb.data.update_data(localdata)
""" """
systemd postinst is appended here because pkg_postinst may require to systemd postinst is appended here because pkg_postinst may require to
execute on the target. Not doing so may cause systemd postinst invoked execute on the target. Not doing so may cause systemd postinst invoked
twice to cause unwanted warnings. twice to cause unwanted warnings.
""" """
postinst = bb.data.getVar('pkg_postinst', localdata, 1) postinst = bb.data.getVar('pkg_postinst', localdata, 1)
if not postinst: if not postinst:
postinst = '#!/bin/sh\n' postinst = '#!/bin/sh\n'
postinst += bb.data.getVar('systemd_postinst', localdata, 1) postinst += bb.data.getVar('systemd_postinst', localdata, 1)
bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
prerm = bb.data.getVar('pkg_prerm', localdata, 1) prerm = bb.data.getVar('pkg_prerm', localdata, 1)
if not prerm: if not prerm:
prerm = '#!/bin/sh\n' prerm = '#!/bin/sh\n'
prerm += bb.data.getVar('systemd_prerm', localdata, 1) prerm += bb.data.getVar('systemd_prerm', localdata, 1)
bb.data.setVar('pkg_prerm_%s' % pkg, prerm, d) bb.data.setVar('pkg_prerm_%s' % pkg, prerm, d)
postrm = bb.data.getVar('pkg_postrm', localdata, 1) postrm = bb.data.getVar('pkg_postrm', localdata, 1)
if not postrm: if not postrm:
postrm = '#!/bin/sh\n' postrm = '#!/bin/sh\n'
postrm += bb.data.getVar('systemd_postrm', localdata, 1) postrm += bb.data.getVar('systemd_postrm', localdata, 1)
bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d) bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d)
# add files to FILES_*-systemd if existent and not already done # add files to FILES_*-systemd if existent and not already done
def systemd_append_file(pkg_systemd, file_append): def systemd_append_file(pkg_systemd, file_append):
appended = False appended = False
if os.path.exists('${D}' + file_append): if os.path.exists('${D}' + file_append):
var_name = "FILES_" + pkg_systemd var_name = "FILES_" + pkg_systemd
files = d.getVar(var_name, 0) or "" files = d.getVar(var_name, 0) or ""
if file_append not in files.split(): if file_append not in files.split():
d.setVar(var_name, "%s %s" % (files, file_append)) d.setVar(var_name, "%s %s" % (files, file_append))
appended = True appended = True
return appended return appended
# add systemd files to FILES_*-systemd, parse for Also= and follow recursive # add systemd files to FILES_*-systemd, parse for Also= and follow recursive
def systemd_add_files_and_parse(pkg_systemd, path, service, keys): def systemd_add_files_and_parse(pkg_systemd, path, service, keys):
# avoid infinite recursion # avoid infinite recursion
if systemd_append_file(pkg_systemd, path + service): if systemd_append_file(pkg_systemd, path + service):
fullpath = '${D}' + path + service fullpath = '${D}' + path + service
if service.find('.socket') != -1: if service.find('.socket') != -1:
# for *.socket add *.service and *@.service # for *.socket add *.service and *@.service
service_base = service.replace('.socket', '') service_base = service.replace('.socket', '')
systemd_add_files_and_parse(pkg_systemd, path, service_base + '.service', keys) systemd_add_files_and_parse(pkg_systemd, path, service_base + '.service', keys)
systemd_add_files_and_parse(pkg_systemd, path, service_base + '@.service', keys) systemd_add_files_and_parse(pkg_systemd, path, service_base + '@.service', keys)
for key in keys.split(): for key in keys.split():
# recurse all dependencies found in keys ('Also';'Conflicts';..) and add to files # recurse all dependencies found in keys ('Also';'Conflicts';..) and add to files
cmd = "grep %s %s | sed 's,%s=,,g' | tr ',' '\\n'" % (key, fullpath, key) cmd = "grep %s %s | sed 's,%s=,,g' | tr ',' '\\n'" % (key, fullpath, key)
pipe = os.popen(cmd, 'r') pipe = os.popen(cmd, 'r')
line = pipe.readline() line = pipe.readline()
while line: while line:
line = line.replace('\n', '') line = line.replace('\n', '')
systemd_add_files_and_parse(pkg_systemd, path, line, keys) systemd_add_files_and_parse(pkg_systemd, path, line, keys)
line = pipe.readline() line = pipe.readline()
pipe.close() pipe.close()
# check service-files and call systemd_add_files_and_parse for each entry # check service-files and call systemd_add_files_and_parse for each entry
def systemd_check_services(): def systemd_check_services():
searchpaths = '/etc/systemd/system/ /lib/systemd/system/ /usr/lib/systemd/system/' searchpaths = '/etc/systemd/system/ /lib/systemd/system/ /usr/lib/systemd/system/'
systemd_packages = d.getVar('SYSTEMD_PACKAGES', 1) systemd_packages = d.getVar('SYSTEMD_PACKAGES', 1)
has_exactly_one_service = len(systemd_packages.split()) == 1 has_exactly_one_service = len(systemd_packages.split()) == 1
if has_exactly_one_service: if has_exactly_one_service:
has_exactly_one_service = len(get_package_var(d, 'SYSTEMD_SERVICE', systemd_packages).split()) == 1 has_exactly_one_service = len(get_package_var(d, 'SYSTEMD_SERVICE', systemd_packages).split()) == 1
keys = 'Also' # Conflicts?? keys = 'Also' # Conflicts??
if has_exactly_one_service: if has_exactly_one_service:
# single service gets also the /dev/null dummies # single service gets also the /dev/null dummies
keys = 'Also Conflicts' keys = 'Also Conflicts'
# scan for all in SYSTEMD_SERVICE[] # scan for all in SYSTEMD_SERVICE[]
for pkg_systemd in systemd_packages.split(): for pkg_systemd in systemd_packages.split():
for service in get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd).split(): for service in get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd).split():
path_found = '' path_found = ''
for path in searchpaths.split(): for path in searchpaths.split():
if os.path.exists('${D}' + path + service): if os.path.exists('${D}' + path + service):
path_found = path path_found = path
if path_found != '': if path_found != '':
systemd_add_files_and_parse(pkg_systemd, path_found, service, keys) systemd_add_files_and_parse(pkg_systemd, path_found, service, keys)
else: else:
raise bb.build.FuncFailed, "\n\nFor package %s SYSTEMD_SERVICE-entry %s does not exist" % \ raise bb.build.FuncFailed, "\n\nFor package %s SYSTEMD_SERVICE-entry %s does not exist" % \
(pkg_systemd, service) (pkg_systemd, service)
""" Setup rdepends / rrecommmends as: """ Setup rdepends / rrecommmends as:
----------------------------- -----------------------------
| pkg_systemd_base: 'foo' | | pkg_systemd_base: 'foo' |
@@ -190,33 +190,33 @@ python populate_packages_prepend () {
------------------------------/ ------------------------------/
| pkg_systemd: 'foo-systemd' | | pkg_systemd: 'foo-systemd' |
------------------------------ ------------------------------
""" """
def systemd_add_rdepends_rrecommends(pkg_systemd): def systemd_add_rdepends_rrecommends(pkg_systemd):
# RDEPENDS_${pkg_systemd} += pkg_systemd_base systemd # RDEPENDS_${pkg_systemd} += pkg_systemd_base systemd
rdepends = d.getVar('RDEPENDS_' + pkg_systemd, 1) or "" rdepends = d.getVar('RDEPENDS_' + pkg_systemd, 1) or ""
rdepends_arr = rdepends.split() rdepends_arr = rdepends.split()
if not 'systemd' in rdepends_arr: if not 'systemd' in rdepends_arr:
rdepends = '%s %s' % (rdepends, 'systemd') rdepends = '%s %s' % (rdepends, 'systemd')
pkg_systemd_base = pkg_systemd.replace('-systemd', '') pkg_systemd_base = pkg_systemd.replace('-systemd', '')
# no automatism for: # no automatism for:
# recipes setting rdepends themselves AND # recipes setting rdepends themselves AND
# not rdepending myself AND # not rdepending myself AND
# avoid double entries # avoid double entries
if len(rdepends_arr) == 0 and pkg_systemd != '${PN}' and not pkg_systemd_base in rdepends: if len(rdepends_arr) == 0 and pkg_systemd != '${PN}' and not pkg_systemd_base in rdepends:
rdepends = '%s %s' % (rdepends, pkg_systemd_base) rdepends = '%s %s' % (rdepends, pkg_systemd_base)
d.setVar('RDEPENDS_' + pkg_systemd, rdepends) d.setVar('RDEPENDS_' + pkg_systemd, rdepends)
# RRECOMMENDS_${pkg_systemd_base} += pkg_systemd systemd # RRECOMMENDS_${pkg_systemd_base} += pkg_systemd systemd
rrecommends = d.getVar('RRECOMMENDS_' + pkg_systemd_base, 1) or "" rrecommends = d.getVar('RRECOMMENDS_' + pkg_systemd_base, 1) or ""
# not rrecommending myself AND avoid double entries # not rrecommending myself AND avoid double entries
if pkg_systemd != pkg_systemd_base and not pkg_systemd in rrecommends.split(): if pkg_systemd != pkg_systemd_base and not pkg_systemd in rrecommends.split():
rrecommends = '%s %s' % (rrecommends, pkg_systemd) rrecommends = '%s %s' % (rrecommends, pkg_systemd)
d.setVar('RRECOMMENDS_' + pkg_systemd_base, rrecommends) d.setVar('RRECOMMENDS_' + pkg_systemd_base, rrecommends)
# run all modifications once when creating package # run all modifications once when creating package
if os.path.exists('${D}'): if os.path.exists('${D}'):
for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split(): for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
if get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd) != "": if get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd) != "":
systemd_generate_package_scripts(pkg_systemd) systemd_generate_package_scripts(pkg_systemd)
systemd_add_rdepends_rrecommends(pkg_systemd) systemd_add_rdepends_rrecommends(pkg_systemd)
systemd_check_services() systemd_check_services()
} }