From c11370305021ffcb9eaf907d8374aa6e46df6b0f Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 18 Mar 2020 14:39:17 -0500 Subject: [PATCH] Add support for build-only packages Sometimes an element needs packages installed so that it can perform tasks but those package are not appropriate for the final image content. Add a "build-only" flag to package-install-squash which will cause package to be installed at the beginning of the phase and then uninstalled at the end of the phase. Change-Id: Ie01b795991710c93f6b669c8f14b57eb4412c1d5 --- diskimage_builder/elements/package-installs/README.rst | 7 +++++++ .../package-installs/bin/package-installs-squash | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/diskimage_builder/elements/package-installs/README.rst b/diskimage_builder/elements/package-installs/README.rst index 329d9c48b..4660b9753 100644 --- a/diskimage_builder/elements/package-installs/README.rst +++ b/diskimage_builder/elements/package-installs/README.rst @@ -30,6 +30,8 @@ example ``package-installs.yaml`` dib_python_version: 2 python3-dev: dib_python_version: 3 + libssl-dev: + build-only: True package-a: when: DIB_USE_PACKAGE_A = 1 package-b: @@ -60,6 +62,11 @@ Setting the installtype property causes the package only to be installed if the specified installtype would be used for the element. See the diskimage-builder docs for more information on installtypes. +Setting ``build-only`` will cause the package to be added both to the +list of packages to be installed and to the list of packages to be +uninstalled. This allows expressing build-time dependencies that should +not end up in the final image. + The ``arch`` property is a comma-separated list of architectures to install for. The ``not-arch`` is a comma-separated list of architectures the package should be excluded from. Either ``arch`` or diff --git a/diskimage_builder/elements/package-installs/bin/package-installs-squash b/diskimage_builder/elements/package-installs/bin/package-installs-squash index 04c31a4cf..7ba71dad1 100755 --- a/diskimage_builder/elements/package-installs/bin/package-installs-squash +++ b/diskimage_builder/elements/package-installs/bin/package-installs-squash @@ -113,9 +113,11 @@ def collect_data(data, objs, element_name): if not params: params = {} phase = params.get('phase', 'install.d') - install = "install" + installs = ["install"] if 'uninstall' in params: - install = "uninstall" + installs = ["uninstall"] + if 'build-only' in params: + installs = ["install", "uninstall"] # Filter out incorrect installtypes installtype = params.get('installtype', None) @@ -136,7 +138,8 @@ def collect_data(data, objs, element_name): continue if valid_installtype and valid_arch and valid_dib_python_version: - data[phase][install].append((pkg_name, element_name)) + for install in installs: + data[phase][install].append((pkg_name, element_name)) return data