diff --git a/build_library/board_options.sh b/build_library/board_options.sh index efe70954a8..baa18f8fd9 100644 --- a/build_library/board_options.sh +++ b/build_library/board_options.sh @@ -14,23 +14,6 @@ ARCH=$(get_board_arch ${BOARD}) # What cross-build are we targeting? . "${BOARD_ROOT}/etc/portage/make.conf" || die -# check if any of the given use flags are enabled for a pkg -pkg_use_enabled() { - local pkg="${1}"; shift - - # for every flag argument, turn it into a regexp that matches it as - # either '+${flag}' or '(+${flag})' - local -a grep_args=() - local flag - for flag; do - grep_args+=( -e '^(\?+'"${flag}"')\?$' ) - done - local -i rv=0 - - equery-"${BOARD}" --quiet uses --forced-masked "${pkg}" | grep --quiet "${grep_args[@]}" || rv=$? - return ${rv} -} - # Usage: pkg_version [installed|binary|ebuild] some-pkg/name # Prints: some-pkg/name-1.2.3 # Note: returns 0 even if the package was not found. diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index 2153c4162c..3a66b97322 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -19,6 +19,7 @@ fi BUILD_DIR="${FLAGS_output_root}/${BOARD}/${IMAGE_SUBDIR}" OUTSIDE_OUTPUT_DIR="../build/images/${BOARD}/${IMAGE_SUBDIR}" +source "${BUILD_LIBRARY_DIR}/pkg_util.sh" || exit 1 source "${BUILD_LIBRARY_DIR}/reports_util.sh" || exit 1 source "${BUILD_LIBRARY_DIR}/sbsign_util.sh" || exit 1 @@ -685,7 +686,7 @@ EOF fi # Build the selinux policy - if pkg_use_enabled coreos-base/coreos selinux; then + if is_selinux_enabled "${BOARD}"; then info "Building selinux mcs policy" sudo chroot "${root_fs_dir}" bash -s <<'EOF' cd /usr/share/selinux/mcs @@ -725,7 +726,7 @@ EOF # SELinux: Label the root filesystem for using 'file_contexts'. # The labeling has to be done before moving /etc to /usr/share/flatcar/etc to prevent wrong labels for these files and as # the relabeling on boot would cause upcopies in the overlay. - if pkg_use_enabled coreos-base/coreos selinux; then + if is_selinux_enabled "${BOARD}"; then # -D - set or update any directory SHA1 digests # -E - treat conflicting specifications as errors # -F - force reset of context to match file_context diff --git a/build_library/pkg_util.sh b/build_library/pkg_util.sh new file mode 100644 index 0000000000..4865ba7316 --- /dev/null +++ b/build_library/pkg_util.sh @@ -0,0 +1,30 @@ +# Copyright (c) 2025 The Flatcar Maintainers. All rights reserved. +# Use of this source code is governed by the Apache 2.0 license. + +# check if any of the given use flags are enabled for a pkg +pkg_use_enabled() { + local board=${1}; shift + local pkg=${1}; shift + + # for every flag argument, turn it into a regexp that matches it as + # either '+${flag}' or '(+${flag})' + local -a grep_args=() + local flag + for flag; do + grep_args+=( -e '^(\?+'"${flag}"')\?$' ) + done + local -i rv=0 + local equery='equery' + if [[ -n ${board} ]]; then + equery+="-${board}" + fi + + "${equery}" --quiet uses --forced-masked "${pkg}" | grep --quiet "${grep_args[@]}" || rv=$? + return ${rv} +} + +is_selinux_enabled() { + local board=${1}; shift + + pkg_use_enabled "${board}" coreos-base/coreos selinux +}