summaryrefslogtreecommitdiffstats
path: root/meta-oe/classes/systemd.bbclass
diff options
context:
space:
mode:
authorAndreas Müller <schnitzeltony@googlemail.com>2012-02-22 14:22:53 +0100
committerKoen Kooi <koen@dominion.thruhere.net>2012-02-23 16:46:31 +0100
commit4c66cea57941e0048c5635e5b0ef7ec430d2f828 (patch)
tree3b019ab1273ef0f5de6edbeb2131ed6cfee5199f /meta-oe/classes/systemd.bbclass
parent916b26ef7d8c3779616763ceca144380bd6c058c (diff)
downloadmeta-openembedded-4c66cea57941e0048c5635e5b0ef7ec430d2f828.tar.gz
systemd.bbclass: automatically extend FILES_* for systemd packages
* Add files found in SYSTEMD_SERVICE and add service files referenced by 'Also=' (and 'Conflicts=' in case of one service for links to /dev/null) recursively. * For *.socket files the corresponding '*.service' and '*@.service are packed * In case a file set in SYSTEMD_SERVICE does not exist, build is aborted with an error message. Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com> Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
Diffstat (limited to 'meta-oe/classes/systemd.bbclass')
-rw-r--r--meta-oe/classes/systemd.bbclass60
1 files changed, 60 insertions, 0 deletions
diff --git a/meta-oe/classes/systemd.bbclass b/meta-oe/classes/systemd.bbclass
index e13f09dc3..c712e17c3 100644
--- a/meta-oe/classes/systemd.bbclass
+++ b/meta-oe/classes/systemd.bbclass
@@ -126,9 +126,69 @@ python populate_packages_prepend () {
126 rdepends.append("systemd") 126 rdepends.append("systemd")
127 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d) 127 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
128 128
129 # add files to FILES_*-systemd if existent and not already done
130 def systemd_append_file(pkg_systemd, file_append):
131 appended = False
132 if os.path.exists('${D}' + file_append):
133 var_name = "FILES_" + pkg_systemd
134 files = d.getVar(var_name, 0) or ""
135 if file_append not in files.split():
136 d.setVar(var_name, "%s %s" % (files, file_append))
137 appended = True
138 return appended
139
140 # add systemd files to FILES_*-systemd, parse for Also= and follow recursive
141 def systemd_add_files_and_parse(pkg_systemd, path, service, keys):
142 # avoid infinite recursion
143 if systemd_append_file(pkg_systemd, path + service):
144 fullpath = '${D}' + path + service
145 if service.find('.socket') != -1:
146 # for *.socket add *.service and *@.service
147 service_base = service.replace('.socket', '')
148 systemd_add_files_and_parse(pkg_systemd, path, service_base + '.service', keys)
149 systemd_add_files_and_parse(pkg_systemd, path, service_base + '@.service', keys)
150 for key in keys.split():
151 # recurse all dependencies found in keys ('Also';'Conflicts';..) and add to files
152 cmd = "grep %s %s | sed 's,%s=,,g' | tr ',' '\\n'" % (key, fullpath, key)
153 pipe = os.popen(cmd, 'r')
154 line = pipe.readline()
155 while line:
156 line = line.replace('\n', '')
157 systemd_add_files_and_parse(pkg_systemd, path, line, keys)
158 line = pipe.readline()
159 pipe.close()
160
161 # check service-files and call systemd_add_files_and_parse for each entry
162 def systemd_check_services():
163 searchpaths = '/etc/systemd/system/ /lib/systemd/system/ /usr/lib/systemd/system/'
164 systemd_packages = d.getVar('SYSTEMD_PACKAGES', 1)
165 has_exactly_one_service = len(systemd_packages.split()) == 1
166 if has_exactly_one_service:
167 systemd_services = d.getVar('SYSTEMD_SERVICE' + "_" + systemd_packages, 1) or d.getVar('SYSTEMD_SERVICE', 1)
168 has_exactly_one_service = len(systemd_services.split()) == 1
169
170 keys = 'Also' # Conflicts??
171 if has_exactly_one_service:
172 # single service gets also the /dev/null dummies
173 keys = 'Also Conflicts'
174 # scan for all in SYSTEMD_SERVICE[]
175 for pkg_systemd in systemd_packages.split():
176 systemd_services = d.getVar('SYSTEMD_SERVICE' + "_" + pkg_systemd, 1) or d.getVar('SYSTEMD_SERVICE', 1)
177 for service in systemd_services.split():
178 path_found = ''
179 for path in searchpaths.split():
180 if os.path.exists('${D}' + path + service):
181 path_found = path
182 if path_found != '':
183 systemd_add_files_and_parse(pkg_systemd, path_found, service, keys)
184 else:
185 raise bb.build.FuncFailed, "\n\nFor package %s SYSTEMD_SERVICE-entry %s does not exist" % \
186 (pkg_systemd, service)
187
129 188
130 # run all modifications once when creating package 189 # run all modifications once when creating package
131 if os.path.exists('${D}'): 190 if os.path.exists('${D}'):
132 for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split(): 191 for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
133 systemd_generate_package_scripts(pkg_systemd) 192 systemd_generate_package_scripts(pkg_systemd)
193 systemd_check_services()
134} 194}