Skip to content

Commit

Permalink
Add PACK_CHECKSUM_EXCLUDE to exclude files from checksum file.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonatanAntoni committed Apr 17, 2024
1 parent fa9cf8a commit b6e1071
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<list file patterns here>` 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
Expand Down
26 changes: 23 additions & 3 deletions gen-pack
Original file line number Diff line number Diff line change
Expand Up @@ -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")")"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -296,15 +297,34 @@ function check_pack {
# Create checksum file for the pack content
# The checksum file is placed to <build>/<vendor>.<pack>.sha1
#
# By default all packaged files are considered.
# Files matching a pattern specified in PACK_CHECKSUM_EXCLUDE are excluded.
#
# Usage: create_sha1 <build> <vendor> <pack>
# <build> Pack build folder
# <vendor> Pack vendor name
# <pack> Pack name
#
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
}

Expand Down
16 changes: 14 additions & 2 deletions template/gen_pack.sh
Original file line number Diff line number Diff line change
@@ -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:
#

Expand Down Expand Up @@ -75,6 +75,18 @@ DEFAULT_ARGS=()
#
# PACK_CHANGELOG_MODE="<full|release|tag>"

# Specify file patterns to be excluded from the checksum file
# Default: <empty>
# 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="
# <list file patterns here>
# "

#
# custom pre-processing steps
#
Expand Down
46 changes: 42 additions & 4 deletions test/tests_gen_pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit b6e1071

Please sign in to comment.