diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7f6b3f7 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Verwendet IntelliSense zum Ermitteln möglicher Attribute. + // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen. + // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "bashdb", + "request": "launch", + "name": "Bash-Debug (simplest configuration)", + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index eeb99ff..46d24a0 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,9 @@ can use the same relative file names as within the `.pdsc` file. If no changelog text can be retrieved pack generation is aborted. +1. Replace `` for `PACK_CHECKSUM_EXCLUDE` wit glob patterns to exclude files from the + checksum file, or provide `*` (match all pattern) to skip checksum file creation completely. + 1. Put custom commands to be executed before/after populating the pack build folder into the `preprocess` and `postprocess` functions. The working directory (`pwd`) for both functions is the base folder containing the pack description file. The first diff --git a/gen-pack b/gen-pack index b823599..2bb2c19 100644 --- a/gen-pack +++ b/gen-pack @@ -7,7 +7,7 @@ # SPDX-License-Identifier: Apache-2.0 # -GEN_PACK_LIB_VERSION="0.10.0" +GEN_PACK_LIB_VERSION="0.11.0" GEN_PACK_LIB_SOURCE="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" GEN_PACK_SCRIPT_SOURCE="$(dirname "$(readlink -f "$0")")" @@ -60,6 +60,7 @@ check_placeholder "PACK_PATCH_FILES" check_placeholder "PACKCHK_DEPS" PACK_CHANGELOG_MODE="${PACK_CHANGELOG_MODE:-full}" check_placeholder "PACK_CHANGELOG_MODE" +check_placeholder "PACK_CHECKSUM_EXCLUDE" # # Add directories listed in PACK_DIRS to build folder. @@ -296,6 +297,9 @@ function check_pack { # Create checksum file for the pack content # The checksum file is placed to /..sha1 # +# By default all packaged files are considered. +# Files matching a pattern specified in PACK_CHECKSUM_EXCLUDE are excluded. +# # Usage: create_sha1 # Pack build folder # Pack vendor name @@ -303,8 +307,24 @@ function check_pack { # function create_sha1 { pushd "$1" > /dev/null || exit - find . -type f -exec "${UTILITY_SHA1SUM}" -b {} + > "${TEMP:-/tmp}/$2.$3.sha1" - mv "${TEMP:-/tmp}/$2.$3.sha1" "$2.$3.sha1" + + local ignore + local find_args=() + mapfile -t ignore <<< "${PACK_CHECKSUM_EXCLUDE:-}" + for p in "${ignore[@]}"; do + p="${p#"${p%%[![:space:]]*}"}" + p="${p%"${p##*[![:space:]]}"}" + if [ -n "$p" ]; then + find_args+=("-not" "-path" "*$p") + fi + done + + find . -type f "${find_args[@]}" -exec "${UTILITY_SHA1SUM}" -b {} + > "${TEMP:-/tmp}/$2.$3.sha1" + + if [ -s "${TEMP:-/tmp}/$2.$3.sha1" ]; then + mv "${TEMP:-/tmp}/$2.$3.sha1" "$2.$3.sha1" + fi + popd > /dev/null || exit } diff --git a/template/gen_pack.sh b/template/gen_pack.sh index a4f14d4..8c7ddeb 100755 --- a/template/gen_pack.sh +++ b/template/gen_pack.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Version: 3.0 -# Date: 2023-11-06 +# Version: 3.1 +# Date: 2024-04-17 # This bash script generates a CMSIS Software Pack: # @@ -75,6 +75,18 @@ DEFAULT_ARGS=() # # PACK_CHANGELOG_MODE="" +# Specify file patterns to be excluded from the checksum file +# Default: +# Values: +# - empty All files packaged are included in the checksum file +# - glob pattern One glob pattern per line. Files matching a given pattern are excluded +# from the checksum file +# - "*" The * (match all pattern) can be used to skip checksum file creating completely. +# +# PACK_CHECKSUM_EXCLUDE=" +# +# " + # # custom pre-processing steps # diff --git a/test/tests_gen_pack.sh b/test/tests_gen_pack.sh index f5d8b80..dec07c5 100755 --- a/test/tests_gen_pack.sh +++ b/test/tests_gen_pack.sh @@ -586,12 +586,50 @@ test_create_sha1() { create_sha1 "${PACK_BUILD}" "ARM" "GenPack" - assertTrue "[ -f \"${PACK_BUILD}/ARM.GenPack.sha1\" ]" - assertContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file11.txt" - assertContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file12.txt" - assertContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file13.txt" + assertTrue "[ -f \"${PACK_BUILD}/ARM.GenPack.sha1\" ]" + assertContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file11.txt" + assertContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file12.txt" + assertContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file13.txt" assertNotContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input2" assertNotContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input3" } +test_create_sha1_with_ignore() { + createTestData + + cp -r --parents "input1" "${PACK_BUILD}" + cp -r --parents "input2" "${PACK_BUILD}" + + UTILITY_SHA1SUM="sha1sum" + PACK_CHECKSUM_EXCLUDE=" + input1/file11.txt + input2/* + " + + create_sha1 "${PACK_BUILD}" "ARM" "GenPack" + + assertTrue "[ -f \"${PACK_BUILD}/ARM.GenPack.sha1\" ]" + assertNotContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file11.txt" + assertContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file12.txt" + assertContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input1/file13.txt" + assertNotContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input2" + assertNotContains "$(cat "${PACK_BUILD}/ARM.GenPack.sha1")" "./input3" +} + +test_create_sha1_with_ignore_all() { + createTestData + + cp -r --parents "input1" "${PACK_BUILD}" + + UTILITY_SHA1SUM="sha1sum" + PACK_CHECKSUM_EXCLUDE="*" + + create_sha1 "${PACK_BUILD}" "ARM" "GenPack" + + ls -lah "${PACK_BUILD}/ARM.GenPack.sha1" + + assertFalse "[ -f \"${PACK_BUILD}/ARM.GenPack.sha1\" ]" +} + + . "$(dirname "$0")/shunit2/shunit2"