-
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: Move common definitions/actions from ports to a single spot
JIRA: NIL-595, CI-339
- Loading branch information
Showing
2 changed files
with
124 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,79 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Shell script for building Phoenix-RTOS ports | ||
# | ||
# Common functions | ||
# | ||
# Copyright 2024 Phoenix Systems | ||
# Author: Daniel Sawka | ||
# | ||
|
||
# Variables needed for the functions below | ||
: "${PREFIX_PORT:?variable unset}" | ||
: "${PREFIX_PORT_BUILD:?variable unset}" | ||
: "${PORTS_MIRROR_BASEURL:?variable unset}" | ||
|
||
|
||
# b_port_download(baseurl, filename, [orig_filename]) | ||
# Fetch a file from ${baseurl}${filename} (or ${baseurl}${orig_filename} if provided) and save as ${filename} | ||
# in current port's directory. If this fails, try ${PORTS_MIRROR_BASEURL}${filename}. Also verifies checksums | ||
# if checksums.sha256 file exists (opt-in). | ||
b_port_download() { | ||
local baseurl="$1" | ||
local filename="$2" | ||
local orig_filename="${3:-$filename}" | ||
|
||
if [ ! -f "${PREFIX_PORT}/${filename}" ]; then | ||
if ! wget "${baseurl}${orig_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.sha256" ]; then | ||
while read -r line; do | ||
local expected_checksum="${line%% *}" | ||
local line_file="${line#*\*}" # shasum binary mode (*) expected | ||
|
||
if [ -n "${expected_checksum}" ] && [ "${line_file}" = "${filename}" ]; then | ||
local actual_checksum="$(shasum -b -a 256 "${PREFIX_PORT}/${filename}.part")" | ||
actual_checksum="${actual_checksum%% *}" | ||
|
||
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.sha256" | ||
fi | ||
|
||
mv -f "${PREFIX_PORT}/${filename}.part" "${PREFIX_PORT}/${filename}" | ||
fi | ||
} | ||
|
||
# b_port_apply_patches(srcdir, [patch_subdir]) | ||
# Apply patches to files in ${srcdir}. Non-recursive - use multiple calls with | ||
# ${patch_subdir} if you group patches into separate directories. | ||
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 |