diff options
-rw-r--r-- | meta-systemd/classes/systemd.bbclass | 330 |
1 files changed, 165 insertions, 165 deletions
diff --git a/meta-systemd/classes/systemd.bbclass b/meta-systemd/classes/systemd.bbclass index 38b9ed5c03..dd9f326102 100644 --- a/meta-systemd/classes/systemd.bbclass +++ b/meta-systemd/classes/systemd.bbclass | |||
@@ -27,51 +27,51 @@ systemctl disable ${SYSTEMD_SERVICE} | |||
27 | } | 27 | } |
28 | 28 | ||
29 | def get_package_var(d, var, pkg): | 29 | def get_package_var(d, var, pkg): |
30 | val = (d.getVar('%s_%s' % (var, pkg), d, 1) or "").strip() | 30 | val = (d.getVar('%s_%s' % (var, pkg), d, 1) or "").strip() |
31 | if val == "": | 31 | if val == "": |
32 | val = (d.getVar(var, d, 1) or "").strip() | 32 | val = (d.getVar(var, d, 1) or "").strip() |
33 | return val | 33 | return val |
34 | 34 | ||
35 | def systemd_after_parse(d): | 35 | def systemd_after_parse(d): |
36 | def systemd_check_vars(): | 36 | def systemd_check_vars(): |
37 | if d.getVar('BB_WORKERCONTEXT', True) is not None: | 37 | if d.getVar('BB_WORKERCONTEXT', True) is not None: |
38 | return | 38 | return |
39 | 39 | ||
40 | bb_filename = d.getVar('FILE') | 40 | bb_filename = d.getVar('FILE') |
41 | packages = d.getVar('PACKAGES', 1) | 41 | packages = d.getVar('PACKAGES', 1) |
42 | 42 | ||
43 | # check SYSTEMD_PACKAGES | 43 | # check SYSTEMD_PACKAGES |
44 | systemd_pkgs = d.getVar('SYSTEMD_PACKAGES', 1) or "" | 44 | systemd_pkgs = d.getVar('SYSTEMD_PACKAGES', 1) or "" |
45 | if systemd_pkgs == "": | 45 | if systemd_pkgs == "": |
46 | raise bb.build.FuncFailed, "\n\n%s inherits systemd but doesn't set SYSTEMD_PACKAGES" % bb_filename | 46 | raise bb.build.FuncFailed, "\n\n%s inherits systemd but doesn't set SYSTEMD_PACKAGES" % bb_filename |
47 | for pkg_systemd in systemd_pkgs.split(): | 47 | for pkg_systemd in systemd_pkgs.split(): |
48 | if pkg_systemd.find("-systemd") == -1: | 48 | if pkg_systemd.find("-systemd") == -1: |
49 | if pkg_systemd != d.getVar('PN', 1): | 49 | if pkg_systemd != d.getVar('PN', 1): |
50 | raise bb.build.FuncFailed, \ | 50 | raise bb.build.FuncFailed, \ |
51 | "\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN}" % \ | 51 | "\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN}" % \ |
52 | (bb_filename, pkg_systemd) | 52 | (bb_filename, pkg_systemd) |
53 | else: | 53 | else: |
54 | pkg_systemd_base = pkg_systemd.replace('-systemd', '') | 54 | pkg_systemd_base = pkg_systemd.replace('-systemd', '') |
55 | if pkg_systemd_base not in packages: | 55 | if pkg_systemd_base not in packages: |
56 | raise bb.build.FuncFailed, \ | 56 | raise bb.build.FuncFailed, \ |
57 | "\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN}" % \ | 57 | "\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN}" % \ |
58 | ( bb_filename, pkg_systemd) | 58 | ( bb_filename, pkg_systemd) |
59 | 59 | ||
60 | # prepend systemd-packages not already included | 60 | # prepend systemd-packages not already included |
61 | def systemd_create_package(pkg_systemd): | 61 | def systemd_create_package(pkg_systemd): |
62 | packages = d.getVar('PACKAGES', 1) | 62 | packages = d.getVar('PACKAGES', 1) |
63 | if not pkg_systemd in packages: | 63 | if not pkg_systemd in packages: |
64 | packages = "%s %s" % (pkg_systemd, packages) | 64 | packages = "%s %s" % (pkg_systemd, packages) |
65 | d.setVar('PACKAGES', packages) | 65 | d.setVar('PACKAGES', packages) |
66 | 66 | ||
67 | 67 | ||
68 | bpn = d.getVar('BPN', 1) | 68 | bpn = d.getVar('BPN', 1) |
69 | if bpn + "-native" != d.getVar('PN', 1) and \ | 69 | if bpn + "-native" != d.getVar('PN', 1) and \ |
70 | bpn + "-cross" != d.getVar('PN', 1) and \ | 70 | bpn + "-cross" != d.getVar('PN', 1) and \ |
71 | bpn + "-nativesdk" != d.getVar('PN', 1): | 71 | bpn + "-nativesdk" != d.getVar('PN', 1): |
72 | systemd_check_vars() | 72 | systemd_check_vars() |
73 | for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split(): | 73 | for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split(): |
74 | systemd_create_package(pkg_systemd) | 74 | systemd_create_package(pkg_systemd) |
75 | 75 | ||
76 | 76 | ||
77 | python __anonymous() { | 77 | python __anonymous() { |
@@ -81,103 +81,103 @@ python __anonymous() { | |||
81 | # automatically install all *.service and *.socket supplied in recipe's SRC_URI | 81 | # automatically install all *.service and *.socket supplied in recipe's SRC_URI |
82 | do_install_append() { | 82 | do_install_append() { |
83 | for service in `find ${WORKDIR} -maxdepth 1 -name '*.service' -o -name '*.socket'` ; do | 83 | for service in `find ${WORKDIR} -maxdepth 1 -name '*.service' -o -name '*.socket'` ; do |
84 | # ensure installing systemd-files only (e.g not avahi *.service) | 84 | # ensure installing systemd-files only (e.g not avahi *.service) |
85 | if grep -q '\[Unit\]' $service ; then | 85 | if grep -q '\[Unit\]' $service ; then |
86 | install -d ${D}${systemd_unitdir}/system | 86 | install -d ${D}${systemd_unitdir}/system |
87 | install -m 644 $service ${D}${systemd_unitdir}/system | 87 | install -m 644 $service ${D}${systemd_unitdir}/system |
88 | fi | 88 | fi |
89 | done | 89 | done |
90 | } | 90 | } |
91 | 91 | ||
92 | python populate_packages_prepend () { | 92 | python populate_packages_prepend () { |
93 | def systemd_generate_package_scripts(pkg): | 93 | def systemd_generate_package_scripts(pkg): |
94 | bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg) | 94 | bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg) |
95 | localdata = bb.data.createCopy(d) | 95 | localdata = bb.data.createCopy(d) |
96 | overrides = bb.data.getVar("OVERRIDES", localdata, 1) | 96 | overrides = bb.data.getVar("OVERRIDES", localdata, 1) |
97 | bb.data.setVar("OVERRIDES", "%s:%s" % (pkg, overrides), localdata) | 97 | bb.data.setVar("OVERRIDES", "%s:%s" % (pkg, overrides), localdata) |
98 | bb.data.update_data(localdata) | 98 | bb.data.update_data(localdata) |
99 | 99 | ||
100 | """ | 100 | """ |
101 | systemd postinst is appended here because pkg_postinst may require to | 101 | systemd postinst is appended here because pkg_postinst may require to |
102 | execute on the target. Not doing so may cause systemd postinst invoked | 102 | execute on the target. Not doing so may cause systemd postinst invoked |
103 | twice to cause unwanted warnings. | 103 | twice to cause unwanted warnings. |
104 | """ | 104 | """ |
105 | postinst = bb.data.getVar('pkg_postinst', localdata, 1) | 105 | postinst = bb.data.getVar('pkg_postinst', localdata, 1) |
106 | if not postinst: | 106 | if not postinst: |
107 | postinst = '#!/bin/sh\n' | 107 | postinst = '#!/bin/sh\n' |
108 | postinst += bb.data.getVar('systemd_postinst', localdata, 1) | 108 | postinst += bb.data.getVar('systemd_postinst', localdata, 1) |
109 | bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) | 109 | bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) |
110 | 110 | ||
111 | prerm = bb.data.getVar('pkg_prerm', localdata, 1) | 111 | prerm = bb.data.getVar('pkg_prerm', localdata, 1) |
112 | if not prerm: | 112 | if not prerm: |
113 | prerm = '#!/bin/sh\n' | 113 | prerm = '#!/bin/sh\n' |
114 | prerm += bb.data.getVar('systemd_prerm', localdata, 1) | 114 | prerm += bb.data.getVar('systemd_prerm', localdata, 1) |
115 | bb.data.setVar('pkg_prerm_%s' % pkg, prerm, d) | 115 | bb.data.setVar('pkg_prerm_%s' % pkg, prerm, d) |
116 | 116 | ||
117 | postrm = bb.data.getVar('pkg_postrm', localdata, 1) | 117 | postrm = bb.data.getVar('pkg_postrm', localdata, 1) |
118 | if not postrm: | 118 | if not postrm: |
119 | postrm = '#!/bin/sh\n' | 119 | postrm = '#!/bin/sh\n' |
120 | postrm += bb.data.getVar('systemd_postrm', localdata, 1) | 120 | postrm += bb.data.getVar('systemd_postrm', localdata, 1) |
121 | bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d) | 121 | bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d) |
122 | 122 | ||
123 | # add files to FILES_*-systemd if existent and not already done | 123 | # add files to FILES_*-systemd if existent and not already done |
124 | def systemd_append_file(pkg_systemd, file_append): | 124 | def systemd_append_file(pkg_systemd, file_append): |
125 | appended = False | 125 | appended = False |
126 | if os.path.exists('${D}' + file_append): | 126 | if os.path.exists('${D}' + file_append): |
127 | var_name = "FILES_" + pkg_systemd | 127 | var_name = "FILES_" + pkg_systemd |
128 | files = d.getVar(var_name, 0) or "" | 128 | files = d.getVar(var_name, 0) or "" |
129 | if file_append not in files.split(): | 129 | if file_append not in files.split(): |
130 | d.setVar(var_name, "%s %s" % (files, file_append)) | 130 | d.setVar(var_name, "%s %s" % (files, file_append)) |
131 | appended = True | 131 | appended = True |
132 | return appended | 132 | return appended |
133 | 133 | ||
134 | # add systemd files to FILES_*-systemd, parse for Also= and follow recursive | 134 | # add systemd files to FILES_*-systemd, parse for Also= and follow recursive |
135 | def systemd_add_files_and_parse(pkg_systemd, path, service, keys): | 135 | def systemd_add_files_and_parse(pkg_systemd, path, service, keys): |
136 | # avoid infinite recursion | 136 | # avoid infinite recursion |
137 | if systemd_append_file(pkg_systemd, path + service): | 137 | if systemd_append_file(pkg_systemd, path + service): |
138 | fullpath = '${D}' + path + service | 138 | fullpath = '${D}' + path + service |
139 | if service.find('.socket') != -1: | 139 | if service.find('.socket') != -1: |
140 | # for *.socket add *.service and *@.service | 140 | # for *.socket add *.service and *@.service |
141 | service_base = service.replace('.socket', '') | 141 | service_base = service.replace('.socket', '') |
142 | systemd_add_files_and_parse(pkg_systemd, path, service_base + '.service', keys) | 142 | systemd_add_files_and_parse(pkg_systemd, path, service_base + '.service', keys) |
143 | systemd_add_files_and_parse(pkg_systemd, path, service_base + '@.service', keys) | 143 | systemd_add_files_and_parse(pkg_systemd, path, service_base + '@.service', keys) |
144 | for key in keys.split(): | 144 | for key in keys.split(): |
145 | # recurse all dependencies found in keys ('Also';'Conflicts';..) and add to files | 145 | # recurse all dependencies found in keys ('Also';'Conflicts';..) and add to files |
146 | cmd = "grep %s %s | sed 's,%s=,,g' | tr ',' '\\n'" % (key, fullpath, key) | 146 | cmd = "grep %s %s | sed 's,%s=,,g' | tr ',' '\\n'" % (key, fullpath, key) |
147 | pipe = os.popen(cmd, 'r') | 147 | pipe = os.popen(cmd, 'r') |
148 | line = pipe.readline() | 148 | line = pipe.readline() |
149 | while line: | 149 | while line: |
150 | line = line.replace('\n', '') | 150 | line = line.replace('\n', '') |
151 | systemd_add_files_and_parse(pkg_systemd, path, line, keys) | 151 | systemd_add_files_and_parse(pkg_systemd, path, line, keys) |
152 | line = pipe.readline() | 152 | line = pipe.readline() |
153 | pipe.close() | 153 | pipe.close() |
154 | 154 | ||
155 | # check service-files and call systemd_add_files_and_parse for each entry | 155 | # check service-files and call systemd_add_files_and_parse for each entry |
156 | def systemd_check_services(): | 156 | def systemd_check_services(): |
157 | searchpaths = '/etc/systemd/system/ /lib/systemd/system/ /usr/lib/systemd/system/' | 157 | searchpaths = '/etc/systemd/system/ /lib/systemd/system/ /usr/lib/systemd/system/' |
158 | systemd_packages = d.getVar('SYSTEMD_PACKAGES', 1) | 158 | systemd_packages = d.getVar('SYSTEMD_PACKAGES', 1) |
159 | has_exactly_one_service = len(systemd_packages.split()) == 1 | 159 | has_exactly_one_service = len(systemd_packages.split()) == 1 |
160 | if has_exactly_one_service: | 160 | if has_exactly_one_service: |
161 | has_exactly_one_service = len(get_package_var(d, 'SYSTEMD_SERVICE', systemd_packages).split()) == 1 | 161 | has_exactly_one_service = len(get_package_var(d, 'SYSTEMD_SERVICE', systemd_packages).split()) == 1 |
162 | 162 | ||
163 | keys = 'Also' # Conflicts?? | 163 | keys = 'Also' # Conflicts?? |
164 | if has_exactly_one_service: | 164 | if has_exactly_one_service: |
165 | # single service gets also the /dev/null dummies | 165 | # single service gets also the /dev/null dummies |
166 | keys = 'Also Conflicts' | 166 | keys = 'Also Conflicts' |
167 | # scan for all in SYSTEMD_SERVICE[] | 167 | # scan for all in SYSTEMD_SERVICE[] |
168 | for pkg_systemd in systemd_packages.split(): | 168 | for pkg_systemd in systemd_packages.split(): |
169 | for service in get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd).split(): | 169 | for service in get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd).split(): |
170 | path_found = '' | 170 | path_found = '' |
171 | for path in searchpaths.split(): | 171 | for path in searchpaths.split(): |
172 | if os.path.exists('${D}' + path + service): | 172 | if os.path.exists('${D}' + path + service): |
173 | path_found = path | 173 | path_found = path |
174 | if path_found != '': | 174 | if path_found != '': |
175 | systemd_add_files_and_parse(pkg_systemd, path_found, service, keys) | 175 | systemd_add_files_and_parse(pkg_systemd, path_found, service, keys) |
176 | else: | 176 | else: |
177 | raise bb.build.FuncFailed, "\n\nFor package %s SYSTEMD_SERVICE-entry %s does not exist" % \ | 177 | raise bb.build.FuncFailed, "\n\nFor package %s SYSTEMD_SERVICE-entry %s does not exist" % \ |
178 | (pkg_systemd, service) | 178 | (pkg_systemd, service) |
179 | 179 | ||
180 | """ Setup rdepends / rrecommmends as: | 180 | """ Setup rdepends / rrecommmends as: |
181 | 181 | ||
182 | ----------------------------- | 182 | ----------------------------- |
183 | | pkg_systemd_base: 'foo' | | 183 | | pkg_systemd_base: 'foo' | |
@@ -190,33 +190,33 @@ python populate_packages_prepend () { | |||
190 | ------------------------------/ | 190 | ------------------------------/ |
191 | | pkg_systemd: 'foo-systemd' | | 191 | | pkg_systemd: 'foo-systemd' | |
192 | ------------------------------ | 192 | ------------------------------ |
193 | """ | 193 | """ |
194 | def systemd_add_rdepends_rrecommends(pkg_systemd): | 194 | def systemd_add_rdepends_rrecommends(pkg_systemd): |
195 | # RDEPENDS_${pkg_systemd} += pkg_systemd_base systemd | 195 | # RDEPENDS_${pkg_systemd} += pkg_systemd_base systemd |
196 | rdepends = d.getVar('RDEPENDS_' + pkg_systemd, 1) or "" | 196 | rdepends = d.getVar('RDEPENDS_' + pkg_systemd, 1) or "" |
197 | rdepends_arr = rdepends.split() | 197 | rdepends_arr = rdepends.split() |
198 | if not 'systemd' in rdepends_arr: | 198 | if not 'systemd' in rdepends_arr: |
199 | rdepends = '%s %s' % (rdepends, 'systemd') | 199 | rdepends = '%s %s' % (rdepends, 'systemd') |
200 | pkg_systemd_base = pkg_systemd.replace('-systemd', '') | 200 | pkg_systemd_base = pkg_systemd.replace('-systemd', '') |
201 | # no automatism for: | 201 | # no automatism for: |
202 | # recipes setting rdepends themselves AND | 202 | # recipes setting rdepends themselves AND |
203 | # not rdepending myself AND | 203 | # not rdepending myself AND |
204 | # avoid double entries | 204 | # avoid double entries |
205 | if len(rdepends_arr) == 0 and pkg_systemd != '${PN}' and not pkg_systemd_base in rdepends: | 205 | if len(rdepends_arr) == 0 and pkg_systemd != '${PN}' and not pkg_systemd_base in rdepends: |
206 | rdepends = '%s %s' % (rdepends, pkg_systemd_base) | 206 | rdepends = '%s %s' % (rdepends, pkg_systemd_base) |
207 | d.setVar('RDEPENDS_' + pkg_systemd, rdepends) | 207 | d.setVar('RDEPENDS_' + pkg_systemd, rdepends) |
208 | # RRECOMMENDS_${pkg_systemd_base} += pkg_systemd systemd | 208 | # RRECOMMENDS_${pkg_systemd_base} += pkg_systemd systemd |
209 | rrecommends = d.getVar('RRECOMMENDS_' + pkg_systemd_base, 1) or "" | 209 | rrecommends = d.getVar('RRECOMMENDS_' + pkg_systemd_base, 1) or "" |
210 | # not rrecommending myself AND avoid double entries | 210 | # not rrecommending myself AND avoid double entries |
211 | if pkg_systemd != pkg_systemd_base and not pkg_systemd in rrecommends.split(): | 211 | if pkg_systemd != pkg_systemd_base and not pkg_systemd in rrecommends.split(): |
212 | rrecommends = '%s %s' % (rrecommends, pkg_systemd) | 212 | rrecommends = '%s %s' % (rrecommends, pkg_systemd) |
213 | d.setVar('RRECOMMENDS_' + pkg_systemd_base, rrecommends) | 213 | d.setVar('RRECOMMENDS_' + pkg_systemd_base, rrecommends) |
214 | 214 | ||
215 | # run all modifications once when creating package | 215 | # run all modifications once when creating package |
216 | if os.path.exists('${D}'): | 216 | if os.path.exists('${D}'): |
217 | for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split(): | 217 | for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split(): |
218 | if get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd) != "": | 218 | if get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd) != "": |
219 | systemd_generate_package_scripts(pkg_systemd) | 219 | systemd_generate_package_scripts(pkg_systemd) |
220 | systemd_add_rdepends_rrecommends(pkg_systemd) | 220 | systemd_add_rdepends_rrecommends(pkg_systemd) |
221 | systemd_check_services() | 221 | systemd_check_services() |
222 | } | 222 | } |