-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Add common utility functions, tidy up build process
JIRA: NIL-595, CI-339
- Loading branch information
Showing
2 changed files
with
109 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Shell script for building Phoenix-RTOS ports | ||
# | ||
# Common functions | ||
# | ||
# Copyright 2024 Phoenix Systems | ||
# Author: Daniel Sawka | ||
# | ||
|
||
# b_port_download(baseurl, filename, [url_filename]) | ||
b_port_download() { | ||
local baseurl="$1" | ||
local filename="$2" | ||
local url_filename="${3:-$filename}" | ||
|
||
if [ ! -f "${PREFIX_PORT}/${filename}" ]; then | ||
if ! wget "${baseurl}${url_filename}" -O "${PREFIX_PORT}/${filename}.part" --no-check-certificate; then | ||
wget "${PORTS_MIRROR_BASEURL}${filename}" -O "${PREFIX_PORT}/${filename}.part" --no-check-certificate | ||
fi | ||
|
||
if [ -f "${PREFIX_PORT}/checksums" ]; then | ||
local cksum_pattern='^(\S+)\s*\(([^\)]+)\)\s*\=\s*(\S+)\s*$' | ||
# Verify checksums one after another. `cksum -c` it too limited | ||
while read -r line; do | ||
if [[ "$line" =~ $cksum_pattern ]] && [ "${BASH_REMATCH[2]}" = "${filename}" ]; then | ||
local expected_checksum="${BASH_REMATCH[3]}" | ||
local actual_checksum=$(cksum --untagged -a "${BASH_REMATCH[1],,}" "${PREFIX_PORT}/${BASH_REMATCH[2]}.part" | cut -d' ' -f1) | ||
|
||
if [ "${expected_checksum}" = "${actual_checksum}" ]; then | ||
echo "Checksum OK for \"${filename}\"" | ||
else | ||
b_die "Checksum INVALID for \"${filename}\": expected \"${expected_checksum}\", got \"${actual_checksum}\"" | ||
fi | ||
fi | ||
done < "${PREFIX_PORT}/checksums" | ||
fi | ||
|
||
mv -f "${PREFIX_PORT}/${filename}.part" "${PREFIX_PORT}/${filename}" | ||
fi | ||
} | ||
|
||
# b_port_apply_patches(srcdir, [patch_subdir]) | ||
b_port_apply_patches() { | ||
local srcdir="$1" | ||
local patch_subdir="${2:-.}" | ||
|
||
local patch_dir="${PREFIX_PORT}/patches/${patch_subdir}" | ||
local marker_dir="${PREFIX_PORT_BUILD}/markers/${patch_subdir}" | ||
if [ -d "${patch_dir}" ]; then | ||
mkdir -p "${marker_dir}" | ||
fi | ||
|
||
# Restores the initial value of nullglob option upon function return | ||
trap "$(shopt -p nullglob)" RETURN | ||
shopt -s nullglob | ||
|
||
for patchfile in "${patch_dir}"/*.patch; do | ||
if [ ! -f "${marker_dir}/$(basename "${patchfile}").applied" ]; then | ||
echo "applying patch: ${patchfile}" | ||
patch -d "${srcdir}" -p1 < "${patchfile}" | ||
touch "${marker_dir}/$(basename "${patchfile}").applied" | ||
fi | ||
done | ||
} | ||
|
||
export -f b_port_download b_port_apply_patches |