From 07d4dbd6dc446ec0edc552878451cac2aa9c0da2 Mon Sep 17 00:00:00 2001 From: Mitch Harding Date: Tue, 5 Nov 2024 13:59:21 -0500 Subject: [PATCH] CASMTRIAGE-7457: Fix bug causing some Python script symlinks from not being created (#624) * CASMTRIAGE-7457: Fix bug causing some Python script symlinks from not being created * Add Mitch Harding and Jacob Salmela to codeowners file * Placate shellcheck --- .github/CODEOWNERS | 3 ++- common.sh | 36 ++++++++++++++++++++++++++++++++ create-python-script-symlinks.sh | 19 ++++++++++++----- update-pyproject.sh | 9 +++++++- 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 common.sh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6001d0f3..0a3d8f9c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,4 @@ * @Cray-HPE/metal * @Cray-HPE/platform-engineering - +* @mharding-hpe +* @jacobsalmela diff --git a/common.sh b/common.sh new file mode 100644 index 00000000..6c63db83 --- /dev/null +++ b/common.sh @@ -0,0 +1,36 @@ +# +# MIT License +# +# (C) Copyright 2024 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# No shebang line included in this file because it is only intended to be sourced, never +# directly executed. But to let shellcheck know: +# shellcheck shell=bash + +# Shared definitions for Bash scripts used in the build process + +# We know these variables are not used in this script -- they are defined to be used by scripts which source this one +#shellcheck disable=SC2034 +SYMLINK_PREFIX="#python-script-symlink" + +#shellcheck disable=SC2034 +SYMLINK_FS="|" diff --git a/create-python-script-symlinks.sh b/create-python-script-symlinks.sh index 62de6e1d..db968cbc 100755 --- a/create-python-script-symlinks.sh +++ b/create-python-script-symlinks.sh @@ -25,6 +25,8 @@ set -euo pipefail +source ./common.sh + # Usage: create-python-script-symlinks.sh # # @@ -61,12 +63,14 @@ done [[ -s pyproject.toml ]] || err_exit "pyproject.toml does not exist or is not a non-empty file" -grep "^[a-z][a-z_]*[a-z] = \"csm_testing[.]${script_type}[.][a-z][a-z_]*[a-z][.]__main__:main\"" pyproject.toml || err_exit "No script lines found in pyproject.toml" +# SYMLINK_PREFIX and SYMLINK_FS are defined in common.sh +full_pattern="^${SYMLINK_PREFIX}${SYMLINK_FS}${script_type}_" +num_found=0 -for source_name_target_name in $(grep "^[a-z][a-z_]*[a-z] = \"csm_testing[.]${script_type}[.][a-z][a-z_]*[a-z][.]__main__:main\"" pyproject.toml | - sed 's/^\([a-z][a-z_]*[a-z]\) .*[.]\([a-z][a-z_]*[a-z]\)[.]__main__:main".*$/\1:\2/'); do - source_script_name=${source_name_target_name%%:*} - target_script_name=${source_name_target_name##*:} +for source_script_name in $(grep -E "${full_pattern}" pyproject.toml | + cut -d"${SYMLINK_FS}" -f2); do + let num_found+=1 + target_script_name=${source_script_name/${script_type}_/} source_script_path="${buildroot}${venv_path}/bin/${source_script_name}" [[ -f ${source_script_path} ]] || err_exit "Script does not exist or is not a regular file: ${source_script_path}" @@ -78,3 +82,8 @@ for source_name_target_name in $(grep "^[a-z][a-z_]*[a-z] = \"csm_testing[.]${sc ln -rsv "${source_script_path}" "${target_script_path}" done done + +if [[ ${num_found} -eq 0 ]]; then + err_exit "No symlink script lines found in pyproject.toml" +fi +echo "Created symlinks for ${num_found} scripts" diff --git a/update-pyproject.sh b/update-pyproject.sh index 58612215..465f975c 100755 --- a/update-pyproject.sh +++ b/update-pyproject.sh @@ -27,6 +27,8 @@ set -eu tmpfile=$(mktemp) +source ./common.sh + function addline { # Usage: local prefix mainfile dirpath subdir script_name script_target @@ -46,7 +48,12 @@ function addline { # Script target is dirpath with / replaced by ., appended with .__main__:main script_target=${dirpath//\//.}.__main__:main - echo "${script_name} = \"${script_target}\"" >> "${tmpfile}" + { + echo "${script_name} = \"${script_target}\"" + # Also add a comment line, which will be used as input by the create-python-script-symlinks.sh script + # SYMLINK_PREFIX and SYMLINK_FS are defined in common.sh + echo "${SYMLINK_PREFIX}${SYMLINK_FS}${script_name}" + } >> "${tmpfile}" } pushd src