Introducing `mariner_rpmspec` function. (#3258)

This commit is contained in:
Pawel Winogrodzki 2022-06-29 14:40:23 -07:00 committed by GitHub
parent 454f40d121
commit 49e2b9d984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 15 deletions

View File

@ -11,6 +11,9 @@
# $@ - Paths to spec files to check
# shellcheck source=../../toolkit/scripts/rpmops.sh
source "$(git rev-parse --show-toplevel)"/toolkit/scripts/rpmops.sh
# Specs, which contain multiple source files and are split into many entries inside 'cgmanifest.json'.
ignore_multiple_sources=" \
xorg-x11-apps \
@ -57,7 +60,6 @@ ignore_signed_package=" \
shim"
alt_source_tag="Source9999"
mariner_sources_url="https://cblmarinerstorage.blob.core.windows.net/sources/core"
rm -f bad_registrations.txt
rm -rf ./cgmanifest_test_dir/
@ -92,15 +94,11 @@ do
# Removing trailing comments from "Source" tags.
sed -Ei "s/^(\s*Source[0-9]*:.*)#.*/\1/" "$spec"
# Additional macros required to parse some spec files.
spec_dir="$(dirname "$original_spec")"
defines=(-D "_mariner_sources_url $mariner_sources_url" -D "forgemeta %{nil}" -D "py3_dist X" -D "with_check 0" -D "dist .cm2" -D "__python3 python3" -D "_sourcedir $spec_dir" -D "fillup_prereq fillup")
name=$(rpmspec --srpm "${defines[@]}" --qf "%{NAME}" -q "$spec" 2>/dev/null)
name=$(mariner_rpmspec --srpm --qf "%{NAME}" -q "$spec" 2>/dev/null)
if [[ -z $name ]]
then
echo "Failed to get name from '$original_spec'. Please update the spec or the macros from the 'defines' variable in this script. Error:" >> bad_registrations.txt
rpmspec --srpm "${defines[@]}" --qf "%{NAME}" -q "$spec" &>> bad_registrations.txt
mariner_rpmspec --srpm --qf "%{NAME}" -q "$spec" &>> bad_registrations.txt
continue
fi
@ -111,15 +109,15 @@ do
continue
fi
version=$(rpmspec --srpm "${defines[@]}" --qf "%{VERSION}" -q "$spec" 2>/dev/null )
version=$(mariner_rpmspec --srpm --qf "%{VERSION}" -q "$spec" 2>/dev/null )
if [[ -z $version ]]
then
echo "Failed to get version from '$original_spec'. Please update the spec or the macros from the 'defines' variable in this script. Error:" >> bad_registrations.txt
rpmspec --srpm "${defines[@]}" --qf "%{VERSION}" -q "$spec" &>> bad_registrations.txt
mariner_rpmspec --srpm --qf "%{VERSION}" -q "$spec" &>> bad_registrations.txt
continue
fi
parsed_spec="$(rpmspec "${defines[@]}" --parse "$spec")"
parsed_spec="$(mariner_rpmspec --parse "$spec" 2>/dev/null)"
# Reading the source0 file/URL.
source0=$(echo "$parsed_spec" | grep -P "^\s*Source0?:" | cut -d: -f2- | xargs)

38
toolkit/scripts/rpmops.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Helper functions for working with RPM tools in Mariner's context.
REPO_ROOT="$(git rev-parse --show-toplevel)"
# Additional macros required to parse spec files.
DEFINES=(-D "with_check 1" -D "dist $(grep -P "DIST_TAG" "$REPO_ROOT"/toolkit/Makefile | grep -oP "\.cm\d+")")
# Mariner macro files used during spec parsing.
MACROS=()
for macro_file in "$REPO_ROOT"/SPECS/mariner-rpm-macros/macros*
do
MACROS+=("--load=$macro_file")
done
function mariner_rpmspec {
# Looking for spec path in the argument list to extract its directory.
local sourcedir
for arg in "$@"
do
if [[ "$arg" == *.spec && -f "$arg" ]]
then
sourcedir="$(dirname "$arg")"
break
fi
done
if [[ -z $sourcedir ]]
then
echo "Must pass valid spec path to 'mariner_rpmspec'!"
return 1
fi
rpmspec "${DEFINES[@]}" -D "_sourcedir $sourcedir" "${MACROS[@]}" "$@"
}

View File

@ -8,6 +8,9 @@
# $1 - Changelog message.
# ${@:2} - Paths to spec files to update.
# shellcheck source=../../toolkit/scripts/rpmops.sh
source "$(git rev-parse --show-toplevel)"/toolkit/scripts/rpmops.sh
changelog_message="$1"
if [[ $# -lt 2 ]]
@ -41,14 +44,11 @@ do
echo "Updating '$spec_path'."
spec_dir="$(dirname "$spec_path")"
defines=(-D "py3_dist X" -D "with_check 1" -D "dist .cm1" -D "__python3 python3" -D "_sourcedir '$spec_dir'")
release=$(grep -oP "^Release:\s*\d+" "$spec_path" | grep -oP "\d+$")
release=$((release+1))
version=$(rpmspec --srpm -q "$spec_path" --qf "%{VERSION}\n" "${defines[@]}" 2>/dev/null)
version=$(mariner_rpmspec --srpm -q "$spec_path" --qf "%{VERSION}\n" 2>/dev/null)
epoch="$(rpmspec --srpm -q "$spec_path" --qf "%{EPOCH}\n" "${defines[@]}" 2>/dev/null):"
epoch="$(mariner_rpmspec --srpm -q "$spec_path" --qf "%{EPOCH}\n" 2>/dev/null):"
if [[ "$epoch" == "(none):" ]]
then
epoch=""