diff options
-rw-r--r-- | meta/lib/oe/package_manager.py | 58 | ||||
-rw-r--r-- | meta/lib/oe/rootfs.py | 64 |
2 files changed, 59 insertions, 63 deletions
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py index b95b3b96a8..61df06d4f0 100644 --- a/meta/lib/oe/package_manager.py +++ b/meta/lib/oe/package_manager.py | |||
@@ -349,6 +349,54 @@ class PackageManager(object, metaclass=ABCMeta): | |||
349 | shutil.copytree(postinst_intercepts_dir, self.intercepts_dir) | 349 | shutil.copytree(postinst_intercepts_dir, self.intercepts_dir) |
350 | 350 | ||
351 | @abstractmethod | 351 | @abstractmethod |
352 | def _handle_intercept_failure(self, failed_script): | ||
353 | pass | ||
354 | |||
355 | def _postpone_to_first_boot(self, postinst_intercept_hook): | ||
356 | with open(postinst_intercept_hook) as intercept: | ||
357 | registered_pkgs = None | ||
358 | for line in intercept.read().split("\n"): | ||
359 | m = re.match("^##PKGS:(.*)", line) | ||
360 | if m is not None: | ||
361 | registered_pkgs = m.group(1).strip() | ||
362 | break | ||
363 | |||
364 | if registered_pkgs is not None: | ||
365 | bb.note("If an image is being built, the postinstalls for the following packages " | ||
366 | "will be postponed for first boot: %s" % | ||
367 | registered_pkgs) | ||
368 | |||
369 | # call the backend dependent handler | ||
370 | self._handle_intercept_failure(registered_pkgs) | ||
371 | |||
372 | |||
373 | def run_intercepts(self): | ||
374 | intercepts_dir = self.intercepts_dir | ||
375 | |||
376 | bb.note("Running intercept scripts:") | ||
377 | os.environ['D'] = self.target_rootfs | ||
378 | os.environ['STAGING_DIR_NATIVE'] = self.d.getVar('STAGING_DIR_NATIVE') | ||
379 | for script in os.listdir(intercepts_dir): | ||
380 | script_full = os.path.join(intercepts_dir, script) | ||
381 | |||
382 | if script == "postinst_intercept" or not os.access(script_full, os.X_OK): | ||
383 | continue | ||
384 | |||
385 | if script == "delay_to_first_boot": | ||
386 | self._postpone_to_first_boot(script_full) | ||
387 | continue | ||
388 | |||
389 | bb.note("> Executing %s intercept ..." % script) | ||
390 | |||
391 | try: | ||
392 | output = subprocess.check_output(script_full, stderr=subprocess.STDOUT) | ||
393 | if output: bb.note(output.decode("utf-8")) | ||
394 | except subprocess.CalledProcessError as e: | ||
395 | bb.warn("The postinstall intercept hook '%s' failed, details in log.do_rootfs" % script) | ||
396 | bb.note("Exit code %d. Output:\n%s" % (e.returncode, e.output.decode("utf-8"))) | ||
397 | self._postpone_to_first_boot(script_full) | ||
398 | |||
399 | @abstractmethod | ||
352 | def update(self): | 400 | def update(self): |
353 | """ | 401 | """ |
354 | Update the package manager package database. | 402 | Update the package manager package database. |
@@ -897,6 +945,14 @@ class RpmPM(PackageManager): | |||
897 | open(saved_script_name, 'w').write(output) | 945 | open(saved_script_name, 'w').write(output) |
898 | os.chmod(saved_script_name, 0o755) | 946 | os.chmod(saved_script_name, 0o755) |
899 | 947 | ||
948 | def _handle_intercept_failure(self, registered_pkgs): | ||
949 | rpm_postinsts_dir = self.target_rootfs + self.d.expand('${sysconfdir}/rpm-postinsts/') | ||
950 | bb.utils.mkdirhier(rpm_postinsts_dir) | ||
951 | |||
952 | # Save the package postinstalls in /etc/rpm-postinsts | ||
953 | for pkg in registered_pkgs.split(): | ||
954 | self.save_rpmpostinst(pkg) | ||
955 | |||
900 | def extract(self, pkg): | 956 | def extract(self, pkg): |
901 | output = self._invoke_dnf(["repoquery", "--queryformat", "%{location}", pkg]) | 957 | output = self._invoke_dnf(["repoquery", "--queryformat", "%{location}", pkg]) |
902 | pkg_name = output.splitlines()[-1] | 958 | pkg_name = output.splitlines()[-1] |
@@ -1000,6 +1056,8 @@ class OpkgDpkgPM(PackageManager): | |||
1000 | 1056 | ||
1001 | return tmp_dir | 1057 | return tmp_dir |
1002 | 1058 | ||
1059 | def _handle_intercept_failure(self, registered_pkgs): | ||
1060 | self.mark_packages("unpacked", registered_pkgs.split()) | ||
1003 | 1061 | ||
1004 | class OpkgPM(OpkgDpkgPM): | 1062 | class OpkgPM(OpkgDpkgPM): |
1005 | def __init__(self, d, target_rootfs, config_file, archs, task_name='target'): | 1063 | def __init__(self, d, target_rootfs, config_file, archs, task_name='target'): |
diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py index 600a685d68..f8f717c050 100644 --- a/meta/lib/oe/rootfs.py +++ b/meta/lib/oe/rootfs.py | |||
@@ -92,10 +92,6 @@ class Rootfs(object, metaclass=ABCMeta): | |||
92 | self.d.getVar('PACKAGE_FEED_ARCHS')) | 92 | self.d.getVar('PACKAGE_FEED_ARCHS')) |
93 | 93 | ||
94 | 94 | ||
95 | @abstractmethod | ||
96 | def _handle_intercept_failure(self, failed_script): | ||
97 | pass | ||
98 | |||
99 | """ | 95 | """ |
100 | The _cleanup() method should be used to clean-up stuff that we don't really | 96 | The _cleanup() method should be used to clean-up stuff that we don't really |
101 | want to end up on target. For example, in the case of RPM, the DB locks. | 97 | want to end up on target. For example, in the case of RPM, the DB locks. |
@@ -197,7 +193,7 @@ class Rootfs(object, metaclass=ABCMeta): | |||
197 | 193 | ||
198 | execute_pre_post_process(self.d, rootfs_post_install_cmds) | 194 | execute_pre_post_process(self.d, rootfs_post_install_cmds) |
199 | 195 | ||
200 | self._run_intercepts() | 196 | self.pm.run_intercepts() |
201 | 197 | ||
202 | execute_pre_post_process(self.d, post_process_cmds) | 198 | execute_pre_post_process(self.d, post_process_cmds) |
203 | 199 | ||
@@ -283,50 +279,6 @@ class Rootfs(object, metaclass=ABCMeta): | |||
283 | # Remove the package manager data files | 279 | # Remove the package manager data files |
284 | self.pm.remove_packaging_data() | 280 | self.pm.remove_packaging_data() |
285 | 281 | ||
286 | def _postpone_to_first_boot(self, postinst_intercept_hook): | ||
287 | with open(postinst_intercept_hook) as intercept: | ||
288 | registered_pkgs = None | ||
289 | for line in intercept.read().split("\n"): | ||
290 | m = re.match("^##PKGS:(.*)", line) | ||
291 | if m is not None: | ||
292 | registered_pkgs = m.group(1).strip() | ||
293 | break | ||
294 | |||
295 | if registered_pkgs is not None: | ||
296 | bb.note("The postinstalls for the following packages " | ||
297 | "will be postponed for first boot: %s" % | ||
298 | registered_pkgs) | ||
299 | |||
300 | # call the backend dependent handler | ||
301 | self._handle_intercept_failure(registered_pkgs) | ||
302 | |||
303 | |||
304 | def _run_intercepts(self): | ||
305 | intercepts_dir = self.pm.intercepts_dir | ||
306 | |||
307 | bb.note("Running intercept scripts:") | ||
308 | os.environ['D'] = self.image_rootfs | ||
309 | os.environ['STAGING_DIR_NATIVE'] = self.d.getVar('STAGING_DIR_NATIVE') | ||
310 | for script in os.listdir(intercepts_dir): | ||
311 | script_full = os.path.join(intercepts_dir, script) | ||
312 | |||
313 | if script == "postinst_intercept" or not os.access(script_full, os.X_OK): | ||
314 | continue | ||
315 | |||
316 | if script == "delay_to_first_boot": | ||
317 | self._postpone_to_first_boot(script_full) | ||
318 | continue | ||
319 | |||
320 | bb.note("> Executing %s intercept ..." % script) | ||
321 | |||
322 | try: | ||
323 | output = subprocess.check_output(script_full, stderr=subprocess.STDOUT) | ||
324 | if output: bb.note(output.decode("utf-8")) | ||
325 | except subprocess.CalledProcessError as e: | ||
326 | bb.warn("The postinstall intercept hook '%s' failed, details in log.do_rootfs" % script) | ||
327 | bb.note("Exit code %d. Output:\n%s" % (e.returncode, e.output.decode("utf-8"))) | ||
328 | self._postpone_to_first_boot(script_full) | ||
329 | |||
330 | def _run_ldconfig(self): | 282 | def _run_ldconfig(self): |
331 | if self.d.getVar('LDCONFIGDEPEND'): | 283 | if self.d.getVar('LDCONFIGDEPEND'): |
332 | bb.note("Executing: ldconfig -r" + self.image_rootfs + "-c new -v") | 284 | bb.note("Executing: ldconfig -r" + self.image_rootfs + "-c new -v") |
@@ -519,14 +471,6 @@ class RpmRootfs(Rootfs): | |||
519 | self._log_check_warn() | 471 | self._log_check_warn() |
520 | self._log_check_error() | 472 | self._log_check_error() |
521 | 473 | ||
522 | def _handle_intercept_failure(self, registered_pkgs): | ||
523 | rpm_postinsts_dir = self.image_rootfs + self.d.expand('${sysconfdir}/rpm-postinsts/') | ||
524 | bb.utils.mkdirhier(rpm_postinsts_dir) | ||
525 | |||
526 | # Save the package postinstalls in /etc/rpm-postinsts | ||
527 | for pkg in registered_pkgs.split(): | ||
528 | self.pm.save_rpmpostinst(pkg) | ||
529 | |||
530 | def _cleanup(self): | 474 | def _cleanup(self): |
531 | self.pm._invoke_dnf(["clean", "all"]) | 475 | self.pm._invoke_dnf(["clean", "all"]) |
532 | 476 | ||
@@ -707,9 +651,6 @@ class DpkgRootfs(DpkgOpkgRootfs): | |||
707 | src_postinst_dir = self.d.expand("${IMAGE_ROOTFS}/var/lib/dpkg/info") | 651 | src_postinst_dir = self.d.expand("${IMAGE_ROOTFS}/var/lib/dpkg/info") |
708 | return self._save_postinsts_common(dst_postinst_dir, src_postinst_dir) | 652 | return self._save_postinsts_common(dst_postinst_dir, src_postinst_dir) |
709 | 653 | ||
710 | def _handle_intercept_failure(self, registered_pkgs): | ||
711 | self.pm.mark_packages("unpacked", registered_pkgs.split()) | ||
712 | |||
713 | def _log_check(self): | 654 | def _log_check(self): |
714 | self._log_check_warn() | 655 | self._log_check_warn() |
715 | self._log_check_error() | 656 | self._log_check_error() |
@@ -978,9 +919,6 @@ class OpkgRootfs(DpkgOpkgRootfs): | |||
978 | src_postinst_dir = self.d.expand("${IMAGE_ROOTFS}${OPKGLIBDIR}/opkg/info") | 919 | src_postinst_dir = self.d.expand("${IMAGE_ROOTFS}${OPKGLIBDIR}/opkg/info") |
979 | return self._save_postinsts_common(dst_postinst_dir, src_postinst_dir) | 920 | return self._save_postinsts_common(dst_postinst_dir, src_postinst_dir) |
980 | 921 | ||
981 | def _handle_intercept_failure(self, registered_pkgs): | ||
982 | self.pm.mark_packages("unpacked", registered_pkgs.split()) | ||
983 | |||
984 | def _log_check(self): | 922 | def _log_check(self): |
985 | self._log_check_warn() | 923 | self._log_check_warn() |
986 | self._log_check_error() | 924 | self._log_check_error() |