Skip to content

Commit

Permalink
make install_dependencies more reslient to weirdness in different spe…
Browse files Browse the repository at this point in the history
…c files (microsoft#8012)

install_dependencies in the containerized_rpmbuild environment was initially done as a quick script to install multiple dependencies in spec files. This change makes it more robust to handle some cases it wouldn't handle.
  • Loading branch information
tobiasb-ms authored Feb 28, 2024
1 parent 0e84a68 commit 64f06a6
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions toolkit/scripts/containerized-build/resources/setup_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,36 @@ get_pkg_dependency() {

# Install package dependencies listed as BuildRequires in spec
install_dependencies() {
local PKG=("$@")
if [ -z "$PKG" ]; then echo "Please provide pkg name"; return; fi
# Accept a single argument, which is a pattern to find spec files.
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <pkg_pattern>"
return 1
fi

local PKG="$1"

echo "-------- installing build dependencies ---------"
spec_file=$SPECS_DIR/$PKG/$PKG.spec
dep_list=$(grep "BuildRequires:" $spec_file | cut -d ':' -f 2)
for dependency in $dep_list

# Find all spec files for the package pattern given.
spec_file_pattern=$SPECS_DIR/$PKG/$PKG.spec
echo "using spec file pattern: '$spec_file_pattern'"
spec_files=($spec_file_pattern)

# Install dependencies for each spec file found, preserving tdnf error codes.
echo "found ${#spec_files[@]} spec files; installing dependencies for each spec file sequentially"
exit_code=0
for spec_file in "${spec_files[@]}"
do
tdnf install -y $dependency 2>&1
echo "installing dependencies for spec file: '$spec_file'"

# Get the list of dependencies from the spec file.
mapfile -t dep_list < <(rpmspec -q --buildrequires $spec_file)

# Install all the dependencies.
tdnf install -y "${dep_list[@]}" || exit_code=$?
done

return $exit_code
}

# use Mariner specific DEFINES
Expand Down

0 comments on commit 64f06a6

Please sign in to comment.