mirror of
https://github.com/flatcar/scripts.git
synced 2026-01-17 06:22:18 +01:00
build_library: Move and fix pkg_use_enabled into
There were two problems with pkg_use_enabled: 1. It did not detect force-enabled or masked USE flags correctly - selinux USE flag is force-enabled and is shown in the output inside parentheses. 2. It was defined in board_options.sh which injects some command line flags and globals that are not related to the function. Since pkg_use_enabled was only used so far for checking the selinux USE flags, add a function is_selinux_enabled and use the newly added function in the currently only user of pkg_use_enabled. Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
This commit is contained in:
parent
4b14051100
commit
33e4c6573d
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
30
build_library/pkg_util.sh
Normal file
30
build_library/pkg_util.sh
Normal file
@ -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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user