From 5f9fe1bd602f8c40dfccfb4a9eaeac111d806511 Mon Sep 17 00:00:00 2001 From: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:01:43 +0100 Subject: [PATCH] (fix): Scripts executed with make verify to run on mac os --- scripts/generate_crds_manifests.sh | 61 ++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/scripts/generate_crds_manifests.sh b/scripts/generate_crds_manifests.sh index 4020d60dc3..c66fee83fe 100755 --- a/scripts/generate_crds_manifests.sh +++ b/scripts/generate_crds_manifests.sh @@ -27,10 +27,65 @@ crddir="${chartdir}/crds" crdsrcdir="${tmpdir}/operators" SED="sed" -if ! command -v ${SED} &> /dev/null; then - SED="sed" +if command -v gsed &> /dev/null; then + SED="gsed" +elif ! command -v "${SED}" &> /dev/null; then + echo "GNU sed is required for creating manifests, unable to proceed" + exit 1 fi +relpath() { + local base="$1" + local target="$2" + local base_abs target_abs + local rel="" + + base_abs=$(cd "${base}" && pwd -P) + target_abs=$(cd "$(dirname "${target}")" && pwd -P)/$(basename "${target}") + + IFS='/' read -r -a base_parts <<< "${base_abs}" + IFS='/' read -r -a target_parts <<< "${target_abs}" + + local i=0 + local max_common=${#base_parts[@]} + if [ ${#target_parts[@]} -lt ${max_common} ]; then + max_common=${#target_parts[@]} + fi + + while [ $i -lt ${max_common} ] && [ "${base_parts[$i]}" = "${target_parts[$i]}" ]; do + i=$((i + 1)) + done + + local j=$i + while [ $j -lt ${#base_parts[@]} ]; do + if [ -n "${base_parts[$j]}" ]; then + if [ -z "${rel}" ]; then + rel=".." + else + rel="../${rel}" + fi + fi + j=$((j + 1)) + done + + if [ -z "${rel}" ]; then + rel="." + fi + + while [ $i -lt ${#target_parts[@]} ]; do + if [ -n "${target_parts[$i]}" ]; then + if [ "${rel}" = "." ]; then + rel="${target_parts[$i]}" + else + rel="${rel}/${target_parts[$i]}" + fi + fi + i=$((i + 1)) + done + + printf '%s\n' "${rel}" +} + # OSX distrubtions do not include GNU sed by default, the test below # exits if we detect that the the insert command is not supported by # the sed exectuable. @@ -614,7 +669,7 @@ for file in ${microshift_manifests_files}; do continue 2 fi done - echo " - $(realpath --relative-to "${ROOT_DIR}/microshift-manifests" "${file}")" >> "${ROOT_DIR}/microshift-manifests/kustomization.yaml" + echo " - $(relpath "${ROOT_DIR}/microshift-manifests" "${file}")" >> "${ROOT_DIR}/microshift-manifests/kustomization.yaml" done # Now we need to get rid of these args from the olm-operator deployment: