diff options
author | Youngjae Cho <y0.cho@samsung.com> | 2024-08-21 11:28:46 +0900 |
---|---|---|
committer | Youngjae Cho <y0.cho@samsung.com> | 2024-08-21 14:02:37 +0900 |
commit | 021a7efecfe256c0f6e10ed21c774cca12ac1b93 (patch) | |
tree | 4ed04ab82689c18ea9a258e1fcaafab930c0e6e6 | |
parent | 34a417ba59b8fc76ddb0225dbb6cc794e0700c90 (diff) | |
download | rootstrap-checker-021a7efecfe256c0f6e10ed21c774cca12ac1b93.tar.gz rootstrap-checker-021a7efecfe256c0f6e10ed21c774cca12ac1b93.tar.bz2 rootstrap-checker-021a7efecfe256c0f6e10ed21c774cca12ac1b93.zip |
Add hal-rootstrap-checkeraccepted/tizen/base/x/20240826.005822accepted/tizen/base/20240823.063039
The hal-rootstrap-checker is mainly for screening packages out from
build that have dependencies to unmanaged, especially ABI incompatible,
packages. It operates after every %install stage of rpmbuild, aided by
rpm macro. Those managed/unmanaged packages can be configured by yaml
file described below.
The rpm-tizen_macros(defined at platform/upstream/rpm) has anchor point
%{?__hal_rootstrap_checker_install_post}
and this repository provides definition of that macro. And it leads
hal-rootstrap-checker.sh to be executed when rpmbuild confronts the
macro. See macros.hal-rootstrap-checker.
Note that, when the gbs build is triggered, the installation of this
repository is always followed by the execution of rpmbuild. Therefore,
it is guaranted for the rpmbuild to find hal-rootstrap-checker.sh and
its related stuffs such as configuration file and macro file. This
is possible because there are several packages preinstalled by build
system before running rpmbuild. And this hal-rootstrap-checker has
become one of that packages. See scm/meta/qb for the details.
The hal-rootstrap-checker.sh can be configured by yaml file with the
same name. The default one is
/etc/hal/rootstrap/hal-rootstrap-checker.yaml.
And there can be another one,
/etc/hal/rootstrap/rules.d/hal-rootstrap-checker.yaml,
which shades the default configuration, and it gives a way for applying
custom defined configuration.
For those details about configuration attributes, see the yaml file.
Overview:
> Triggering gbs build
|
|--> Preinstalling [...]
|--> Preinstalling hal-rootstrap-checker
| |-- /etc/hal/rootstrap/hal-rootstrap-checker.sh
| |-- /etc/hal/rootstrap/hal-rootstrap-checker.yaml
| |-- /etc/rpm/macros.hal-roostrap-checker
|
|--> Preinstalling rpm
|--> Preinstalling [...]
|
|--> Exec rpmbuild
|
|--> %prep
|--> %build
|--> [...]
|
|--> %install
|
|--> %{__spec_install_post}
| |--> %{?__hal_rootstrap_checker_install_post}
| (Overwritten by /etc/rpm/macros.hal-rootstrap-checker)
| |--> /etc/hal/rootstrap/hal-rootstrap-checker.sh
| |--> Stop rpmbuild if hal-rootstrap-checker
| blames that something not allowed dependencies
| have been specified. Otherwise, continue the
| remaining procedure.
|
|--> [...]
Change-Id: I2ae618dc82d8d2eb71cc675888833d94795337aa
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
-rw-r--r-- | README | 64 | ||||
-rw-r--r-- | packaging/hal-rootstrap-checker.sh | 279 | ||||
-rw-r--r-- | packaging/hal-rootstrap-checker.spec | 14 | ||||
-rw-r--r-- | packaging/hal-rootstrap-checker.yaml | 41 | ||||
-rw-r--r-- | packaging/macros.hal-rootstrap-checker | 3 |
5 files changed, 401 insertions, 0 deletions
@@ -0,0 +1,64 @@ +INTRODUCTION: + The hal-rootstrap-checker is mainly for screening packages out from + build that have dependencies to unmanaged, especially ABI incompatible, + packages. It operates after every %install stage of rpmbuild, aided by + rpm macro. Those managed/unmanaged packages can be configured by yaml + file described below. + +HOW IT WORKS: + The rpm-tizen_macro(defined at platform/upstream/rpm) has anchor point + %{?__hal_rootstrap_checker_install_post} + and this repository provides definition of that macro. And it leads + hal-rootstrap-checker.sh to be executed when rpmbuild confronts the + macro. See macros.hal-rootstrap-checker. + + Note that, when the gbs build is triggered, the installation of this + repository is always followed by the execution of rpmbuild. Therefore, + it is guaranteed for the rpmbuild to find hal-rootstrap-checker.sh and + its related stuffs such as configuration file and macro file. This + is possible because there are several packages preinstalled by build + system before running rpmbuild. And this hal-rootstrap-checker has + become one of that packages. See scm/meta/qb for the details. + +CONFIGURATION: + The hal-rootstrap-checker.sh can be configured by yaml file with the + same name. The default one is + /etc/hal/rootstrap/hal-rootstrap-checker.yaml + + And there can be another one, + /etc/hal/rootstrap/rules.d/hal-rootstrap-checker.yaml + which shades the default configuration, and it gives a way for applying + custom defined configuration. + + For those defails about configuration attributes, see the yaml file. + +OVERVIEW: + * Triggering gbs build + | + |--> Preinstalling [...] + |--> Preinstalling hal-rootstrap-checker + | |-- /etc/hal/rootstrap/hal-rootstrap-checker.sh + | |-- /etc/hal/rootstrap/hal-rootstrap-checker.yaml + | |-- /etc/rpm/macros.hal-roostrap-checker + | + |--> Preinstalling rpm + |--> Preinstalling [...] + | + |--> Exec rpmbuild + | + |--> %prep + |--> %build + |--> [...] + | + |--> %install + | + |--> %{__spec_install_post} + | |--> %{?__hal_rootstrap_checker_install_post} + | (Overwritten by /etc/rpm/macros.hal-rootstrap-checker) + | |--> /etc/hal/rootstrap/hal-rootstrap-checker.sh + | |--> Stop rpmbuild if hal-rootstrap-checker + | blames that something not allowed dependencies + | have been specified. Otherwise, continue the + | remaining procedure. + | + |--> [...] diff --git a/packaging/hal-rootstrap-checker.sh b/packaging/hal-rootstrap-checker.sh new file mode 100644 index 0000000..7ab0fb0 --- /dev/null +++ b/packaging/hal-rootstrap-checker.sh @@ -0,0 +1,279 @@ +#!/bin/bash + +# Disable pathname expansion by '*' or '?' +set -f + +IFS=";" + +# Message formatting +LINE_MAX_LENGTH=90 + +print_border() { + PLACEHOLDER=$(printf "%*s" "$LINE_MAX_LENGTH" " ") + echo ${PLACEHOLDER// /\#} +} + +print_message() { + MESSAGE_MAX_LENGTH=$(($LINE_MAX_LENGTH - 3)) + printf "# %-*s#\n" "$MESSAGE_MAX_LENGTH" "$1" +} + +print_not_allowed_warning() { + WARNING_TYPE=$1 + NOT_ALLOWED_LIST=$2 + ALLOWED_LIST=$3 + CHECK_ALWAYS=$4 + + print_border + print_border + + print_message "WARNING: There are not allowed $WARNING_TYPE. They might cause ABI break." + for NOT_ALLOWED in ${NOT_ALLOWED_LIST}; do + print_message "WARNING: - $NOT_ALLOWED" + done + + print_message "WARINIG:" + if [[ ! -z $ALLOWED_LIST ]]; then + print_message "WARNING: Use only allowed packages below for $WARNING_TYPE" + for ALLOWED in ${ALLOWED_LIST}; do + print_message "WARNING: - $ALLOWED" + done + else + print_message "WARNING: It is not allowed to specify $WARNING_TYPE" + fi + + if [[ $CHECK_ALWAYS == "no" ]]; then + print_message "WARNING:" + print_message "WARNING: Give parameter --define 'disable_hal_rootstrap_checker 1' to gbs build" + print_message "WARNING: to skip this check." + fi + + print_border + print_border +} + +# main +DISABLE_HAL_ROOTSTRAP_CHECKER=$1 +SOURCEDIR=$2 + +# Checker configuration filepath +HAL_ROOTSTRAP_CHECKER_CONF=/etc/hal/rootstrap/hal-rootstrap-checker.yaml +HAL_ROOTSTRAP_CHECKER_CONF_D=/etc/hal/rootstrap/rules.d/hal-rootstrap-checker.yaml + +# Checker configuration +TARGET_PACKAGE_NAME="" +EXCLUDED_TARGET_PACKAGE_NAME="" +ALLOWED_BUILDREQUIRES="" +ALLOWED_BUILDCONFLICTS="" +ALLOWED_REQUIRES="" +CHECK_ALWAYS="no" + +# Locate configuration file +CONFFILE="" +if [[ -s $HAL_ROOTSTRAP_CHECKER_CONF_D ]]; then + CONFFILE=$HAL_ROOTSTRAP_CHECKER_CONF_D +elif [[ -s $HAL_ROOTSTRAP_CHECKER_CONF ]]; then + CONFFILE=$HAL_ROOTSTRAP_CHECKER_CONF +else + echo "No configuration has been specified. Skipping test" + exit 0 +fi + +# Naive yaml parser for configuration file +KEY="" +while read LINE; do + # Trim comment(#) and whitespace + LINE=$(echo "$LINE" | sed 's/#.*//') + LINE=$(echo "$LINE" | sed 's/^[[:space:]]*\(.*\)[[:space:]]*$/\1/') + + if [[ -z "$LINE" ]]; then + continue + fi + + VALUE="" + if [[ "$LINE" =~ ^(.*):\ (.*)$ ]]; then # 'key: value' + KEY="${BASH_REMATCH[1]}" + VALUE="${BASH_REMATCH[2]}" + elif [[ "$LINE" =~ ^(.*):$ ]]; then # 'key:' + KEY="${BASH_REMATCH[1]}" + VALUE="" + elif [[ "$LINE" =~ ^-\ (.*)$ ]]; then # '- value' + VALUE="${BASH_REMATCH[1]}" + fi + + if [[ -z "$VALUE" ]]; then + continue + fi + + case $KEY in + target_package_name) + TARGET_PACKAGE_NAME+="$VALUE$IFS" + ;; + excluded_target_package_name) + EXCLUDED_TARGET_PACKAGE_NAME+="$VALUE$IFS" + ;; + allowed_buildrequires) + ALLOWED_BUILDREQUIRES+="$VALUE$IFS" + ;; + allowed_buildconflicts) + ALLOWED_BUILDCONFLICTS+="$VALUE$IFS" + ;; + allowed_requires) + ALLOWED_REQUIRES+="$VALUE$IFS" + ;; + check_always) + CHECK_ALWAYS="$VALUE" + ;; + *) + echo "Undefined key($KEY), skip the line: $LINE" + ;; + esac +done < $CONFFILE + +# Screen out packages that are not subject to the hal-rootstrap-checker +SPECFILE=$(find $SOURCEDIR -name *.spec) +if [[ $? != 0 ]]; then + echo "Cannot locate specfile for hal-rootstrap-checker" + exit 0 +fi + +CURRENT_PACKAGE_NAME=$(rpmspec -q --queryformat "[%{NAME}\n]" $SPECFILE | head -n 1) +PATTERN_MATCHED=0 +for PATTERN in $TARGET_PACKAGE_NAME; do + if [[ $CURRENT_PACKAGE_NAME == $PATTERN ]]; then + PATTERN_MATCHED=1 + break + fi +done + +if [[ $PATTERN_MATCHED == 0 ]]; then + exit 0 +fi + +PATTERN_MATCHED=0 +for PATTERN in $EXCLUDED_TARGET_PACKAGE_NAME; do + if [[ $CURRENT_PACKAGE_NAME == $PATTERN ]]; then + PATTERN_MATCHED=1 + break + fi +done + +if [[ $PATTERN_MATCHED == 1 ]]; then + print_border + print_border + + print_message "NOTICE: $CURRENT_PACKAGE_NAME is skipped from hal-rootstrap-checker" + print_message "NOTICE: as it has been specified at excluded_target_package_name." + + print_border + print_border + exit 0 +fi + +# Parse specfile: Get BuildRequires +SPECFILE_BUILDREQUIRES="" +while read -r LINE; do + if [[ -z $LINE ]]; then + continue + fi + SPECFILE_BUILDREQUIRES+="$LINE$IFS" +done <<< $(rpmspec -q --buildrequires $SPECFILE) + +# Parse specfile: Get BuildConflicts +SPECFILE_BUILDCONFLICTS="" +while read -r LINE; do + if [[ -z $LINE ]]; then + continue + fi + SPECFILE_BUILDCONFLICTS+="$LINE$IFS" +done <<< $(rpmspec -q --buildconflicts $SPECFILE) + +# Parse specfile: Get Requires +SPECFILE_REQUIRES="" +while read -r LINE; do + if [[ -z $LINE ]]; then + continue + fi + SPECFILE_REQUIRES+="$LINE$IFS" +done <<< $(rpmspec -q --queryformat "[%{REQUIRES}\n]" $SPECFILE) + +# Collect not allowed BuildRequires +SPECFILE_NOT_ALLOWED_BUILDREQUIRES="" +for BUILDREQUIRES in $SPECFILE_BUILDREQUIRES; do + IS_ALLOWED=0 + for ALLOWED_PATTERN in $ALLOWED_BUILDREQUIRES; do + if [[ $BUILDREQUIRES == $ALLOWED_PATTERN ]]; then + IS_ALLOWED=1 + break + fi + done + + if [[ $IS_ALLOWED == 0 ]]; then + SPECFILE_NOT_ALLOWED_BUILDREQUIRES+="$BUILDREQUIRES$IFS" + fi +done + +# Collect not allowed BuildConflicts +SPECFILE_NOT_ALLOWED_BUILDCONFLICTS="" +for BUILDCONFLICTS in $SPECFILE_BUILDCONFLICTS; do + IS_ALLOWED=0 + for ALLOWED_PATTERN in $ALLOWED_BUILDCONFLICTS; do + if [[ $BUILDCONFLICTS == $ALLOWED_PATTERN ]]; then + IS_ALLOWED=1 + break + fi + done + + if [[ $IS_ALLOWED == 0 ]]; then + SPECFILE_NOT_ALLOWED_BUILDCONFLICTS+="$BUILDCONFLICTS$IFS" + fi +done + +# Collect not allowed Requires +SPECFILE_NOT_ALLOWED_REQUIRES="" +for REQUIRES in $SPECFILE_REQUIRES; do + IS_ALLOWED=0 + for ALLOWED_PATTERN in $ALLOWED_REQUIRES; do + if [[ $REQUIRES == $ALLOWED_PATTERN ]]; then + IS_ALLOWED=1 + break + fi + done + + if [[ $IS_ALLOWED == 0 ]]; then + SPECFILE_NOT_ALLOWED_REQUIRES+="$REQUIRES$IFS" + fi +done + +# Check if there are not allowed BuildRequires +if [[ ! -z $SPECFILE_NOT_ALLOWED_BUILDREQUIRES ]]; then + print_not_allowed_warning "BuildRequires" \ + "$SPECFILE_NOT_ALLOWED_BUILDREQUIRES" \ + "$ALLOWED_BUILDREQUIRES" \ + "$CHECK_ALWAYS" +fi + +# Check if there are not allowed BuildConflicts +if [[ ! -z $SPECFILE_NOT_ALLOWED_BUILDCONFLICTS ]]; then + print_not_allowed_warning "BuildConflicts" \ + "$SPECFILE_NOT_ALLOWED_BUILDCONFLICTS" \ + "$ALLOWED_BUILDCONFLICTS" \ + "$CHECK_ALWAYS" +fi + +# Check if there are not allowed Requires +if [[ ! -z $SPECFILE_NOT_ALLOWED_REQUIRES ]]; then + print_not_allowed_warning "Requires" \ + "$SPECFILE_NOT_ALLOWED_REQUIRES" \ + "$ALLOWED_REQUIRES" \ + "$CHECK_ALWAYS" +fi + +# Check whether the test can be skipped +if [[ $DISABLE_HAL_ROOTSTRAP_CHECKER != 0 && $CHECK_ALWAYS == "no" ]]; then + exit 0 +fi + +if [[ ! -z $SPECFILE_NOT_ALLOWED_BUILDREQUIRES || ! -z $SPECFILE_NOT_ALLOWED_REQUIRES || ! -z $SPECFILE_NOT_ALLOWED_BUILDCONFLICTS ]]; then + exit 0 # Let them pass for now +fi diff --git a/packaging/hal-rootstrap-checker.spec b/packaging/hal-rootstrap-checker.spec index 67c596b..b174fec 100644 --- a/packaging/hal-rootstrap-checker.spec +++ b/packaging/hal-rootstrap-checker.spec @@ -5,6 +5,9 @@ Release: 1 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: hal-rootstrap-checker.manifest +Source2: hal-rootstrap-checker.sh +Source3: hal-rootstrap-checker.yaml +Source4: macros.hal-rootstrap-checker %description Package for hal rootstrap checker @@ -14,6 +17,17 @@ Package for hal rootstrap checker cp %{SOURCE1} . %install +rm -rf %{buildroot} + +mkdir -p %{buildroot}%{_sysconfdir}/hal/rootstrap +install -m 755 %{SOURCE2} %{buildroot}%{_sysconfdir}/hal/rootstrap +install -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/hal/rootstrap + +mkdir -p %{buildroot}%{_sysconfdir}/rpm +install -m 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/rpm %files %manifest %{name}.manifest +%{_sysconfdir}/hal/rootstrap/hal-rootstrap-checker.sh +%{_sysconfdir}/hal/rootstrap/hal-rootstrap-checker.yaml +%{_sysconfdir}/rpm/macros.hal-rootstrap-checker diff --git a/packaging/hal-rootstrap-checker.yaml b/packaging/hal-rootstrap-checker.yaml new file mode 100644 index 0000000..1aacc29 --- /dev/null +++ b/packaging/hal-rootstrap-checker.yaml @@ -0,0 +1,41 @@ +# List of packages that are subject to the hal-rootstrap-checker. +# Follow pattern matching of bash(1). +target_package_name: + - hal-backend-* + - alsa-ucm-data-* + - audio-hal-* + - bluetooth-firmware-* + - camera-hal-* + - fm-data-* + - lbs-server-plugin-* + - media-config-target-* + - model-config-* + - pass-hal-* + +# List of packages that are exempt from the hal-rootstrap-checker. +# It is applied on top of the above 'target_package_name'. +# Follow pattern matching of bash(1). +excluded_target_package_name: + +# List of packages that are allowed to be used as BuildRequires +# Follow pattern matching of bash(1). +allowed_buildrequires: + - cmake + - pkgconfig(hal-rootstrap) + - linux-glibc-devel + - kernel-headers-* + +# List of packages that are allowed to be used as BuildConflicts +# Follow pattern matching of bash(1). +allowed_buildconflicts: + - linux-glibc-devel + - kernel-headers-* + +# List of packages that are allowed to be used as Requires +# Follow pattern matching of bash(1). +allowed_requires: + +# yes or no(default) +# if no, you can skip the hal-rootstrap-checker test +# by giving gbs build parameter, --define 'disable_hal_rootstrap_checker 1'. +check_always: no diff --git a/packaging/macros.hal-rootstrap-checker b/packaging/macros.hal-rootstrap-checker new file mode 100644 index 0000000..77a7054 --- /dev/null +++ b/packaging/macros.hal-rootstrap-checker @@ -0,0 +1,3 @@ +%__hal_rootstrap_checker_install_post \ + /etc/hal/rootstrap/hal-rootstrap-checker.sh %{!?disable_hal_rootstrap_checker:0}%{?disable_hal_rootstrap_checker} %{_sourcedir} \ +%{nil} |