Skip to content

Commit

Permalink
Add pre- and post-processing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JonatanAntoni authored Sep 26, 2022
1 parent 2f54c8b commit 50ee2cc
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 33 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ can use the same relative file names as within the `.pdsc` file.
7. Add any required default command line arguments to the line `DEFAULT_ARGS=()`.
For example, add `-c [<prefix>]` here to force creating release history from Git.
The `<prefix>` is the version prefixed used for release tags if any.
8. Put custom commands to be executed before/after populating the pack build folder
into the `preprocess` and `postprocess` functions.

## Usage

A `gen_pack.sh` script accepts the following command line flags and arguments:

- `-h, --help`: Prints below usage message end exits with error level 1.
- `-k, --keep`: Prevents the temporary build directory from being automatically deleted.
- `-c, --changelog <prefix>`: Update the `<releases>` section in the `.pdsc` file with a generated history. The
versions, dates and descriptions are inferred from Git tags. The `<prefix>` can be
used to filter tags for release tags by the given string.
- `-c, --[no-]changelog <prefix>`: Update the `<releases>` section in the `.pdsc` file with a generated history. The
versions, dates and descriptions are inferred from Git tags. The `<prefix>` can be
used to filter tags for release tags by the given string.
- `--[no-]preprocess`: Run custom preprocess function if implemented.
- `--[no-]postproces`: Run custom postprocess function if implemented.
- `-v, --verbose`: Enable verbose log output such as full sub-commands being issues.

```sh
Expand All @@ -120,11 +124,13 @@ $ ./gen_pack.sh -h
Usage: gen_pack.sh [-h] [-k] [-c <prefix>] [<pdsc>]

Arguments:
-h, --help Print this usage message and exit.
-k, --keep Keep build directory.
-c, --changelog <prefix> Generate changelog. Tags are filtered for <prefix>.
-v, --verbose Print verbose log output.
<pdsc> The pack description to generate the pack for.
-h, --help Print this usage message and exit.
-k, --keep Keep build directory.
-c, --[no-]changelog <prefix> Generate changelog. Tags are filtered for <prefix>.
--[no-]preprocess Run the preprocess function if implemented in the enclosing script.
--[no-]postproces Run the postprocess function if implemented in the enclosing script.
-v, --verbose Print verbose log output.
<pdsc> The pack description to generate the pack for.
```

## License
Expand Down
35 changes: 20 additions & 15 deletions gen-pack
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

GEN_PACK_LIB_VERSION="0.3.0"
GEN_PACK_LIB_VERSION="0.4.0"
GEN_PACK_LIB_SOURCE="$(realpath $(dirname ${BASH_SOURCE}))"

shopt -s expand_aliases
Expand Down Expand Up @@ -102,8 +102,8 @@ function check_schema {
echo " Hint: Assure one of the following to get the schema check working." >&2
echo " - Provide PACK.XSD into '${CMSISSCHEMA}'." >&2
echo " - Provide schema URL in PDSC file's xs:noNamespaceSchemaLocation attribute." >&2
echo " - Provide schema release tag version in PDSC file's schemaVersion attribute." >&2
echo " Available schema releases are listed on https://github.com/Open-CMSIS-Pack/Open-CMSIS-Pack-Spec/tags." >&2
echo " - Provide schema release tag version in PDSC file's schemaVersion attribute." >&2
echo " Available schema releases are listed on https://github.com/Open-CMSIS-Pack/Open-CMSIS-Pack-Spec/tags." >&2
echo " " >&2
exit $errorlevel
fi
Expand Down Expand Up @@ -147,58 +147,63 @@ function gen_pack {
find_packchk
find_xmllint
find_sha1sum
if [ -n "${UTILITY_XMLLINT}" ]; then
if [ -n "${UTILITY_XMLLINT}" ]; then
find_curl
fi
if [ -n "${CHANGELOG+x}" ]; then
find_git
find_ghcli
fi

echo " "

PACK_DESCRIPTION_FILE=$(locate_pdsc $@)
echo "PDSC is ${PACK_DESCRIPTION_FILE}"
echo " "

PACK_BASEDIR=$(dirname ${PACK_DESCRIPTION_FILE})
PACK_VENDOR=$(pdsc_vendor "${PACK_DESCRIPTION_FILE}")
PACK_NAME=$(pdsc_name "${PACK_DESCRIPTION_FILE}")
echo "Generating Pack for $PACK_VENDOR.$PACK_NAME"

PACK_BUILD=$(realpath "${PACK_BASEDIR}/${PACK_BUILD}")
PACK_OUTPUT=$(realpath "${PACK_BASEDIR}/${PACK_OUTPUT}")
PACK_BUILD_DESCRIPTION_FILE="${PACK_BUILD}/$(basename ${PACK_DESCRIPTION_FILE})"

echo " via $PACK_BUILD"
echo " to $PACK_OUTPUT"
echo ""

if [ -d "$PACK_BUILD" ]; then
rm -r "$PACK_BUILD"
fi
mkdir -p "$PACK_BUILD"
mkdir -p "$PACK_OUTPUT"

pushd ${PACK_BASEDIR} >/dev/null


[[ ${PREPROCESS} == 1 && "$(type -t preprocess)" == "function" ]] && preprocess

if [ -n "${CHANGELOG+x}" ]; then
pdsc_update_releases "${PACK_DESCRIPTION_FILE}" "${PACK_BUILD_DESCRIPTION_FILE}" "${CHANGELOG}"
else
cp "${PACK_DESCRIPTION_FILE}" "${PACK_BUILD_DESCRIPTION_FILE}"
fi

add_dirs "${PACK_BUILD}"
add_files "${PACK_BUILD}"
delete_files "${PACK_BUILD}"
apply_patches "${PACK_BUILD}"

check_schema "${PACK_BUILD_DESCRIPTION_FILE}"
check_pack "${PACK_BUILD_DESCRIPTION_FILE}"
create_sha1 "$PACK_BUILD" $PACK_VENDOR $PACK_NAME

[[ ${POSTPROCESS} == 1 && "$(type -t postprocess)" == "function" ]] && postprocess

archive "$PACK_BUILD" "$PACK_OUTPUT/$(cat "$PACK_OUTPUT/PackName.txt")"
if [[ $KEEP == 0 ]]; then

if [[ $KEEP == 0 ]]; then
echo "Cleaning up $PACK_BUILD..."
rm -rf "$PACK_BUILD"
rm -f "$PACK_OUTPUT/PackName.txt"
Expand Down
14 changes: 14 additions & 0 deletions lib/getopts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

function getopts {
KEEP=0
PREPROCESS=1
POSTPROCESS=1
POSITIONAL=()
while [[ $# -gt 0 ]]
do
Expand All @@ -25,6 +27,18 @@ function getopts {
'-v','--verbose')
VERBOSE=1
;;
'--preprocess')
PREPROCESS=1
;;
'--no-preprocess')
PREPROCESS=0
;;
'--postprocess')
POSTPROCESS=1
;;
'--no-postprocess')
POSTPROCESS=0
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
;;
Expand Down
12 changes: 7 additions & 5 deletions lib/usage
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ cat << EOF
Usage: $(basename $0) [-h] [-k] [-c <prefix>] [-v] [<pdsc>]

Arguments:
-h, --help Print this usage message and exit.
-k, --keep Keep build directory.
-c, --changelog <prefix> Generate changelog. Tags are filtered for <prefix>.
-v, --verbose Print verbose log output.
<pdsc> The pack description to generate the pack for.
-h, --help Print this usage message and exit.
-k, --keep Keep build directory.
-c, --[no-]changelog <prefix> Generate changelog. Tags are filtered for <prefix>.
--[no-]preprocess Run custom preprocess function if implemented.
--[no-]postproces Run custom postprocess function if implemented.
-v, --verbose Print verbose log output.
<pdsc> The pack description to generate the pack for.
EOF
}
26 changes: 21 additions & 5 deletions template/gen_pack.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# Version: 2.1
# Date: 2022-08-09
# Version: 2.2
# Date: 2022-09-26
# This bash script generates a CMSIS Software Pack:
#

Expand All @@ -9,7 +9,6 @@ set -o pipefail
# Set version of gen pack library
REQUIRED_GEN_PACK_LIB="<pin lib version here>"


# Set default command line arguments
DEFAULT_ARGS=()

Expand Down Expand Up @@ -43,6 +42,19 @@ PACK_PATCH_FILES="
# Specify addition argument to packchk
PACKCHK_ARGS=()

# custom pre-processing steps
function preprocess() {
# add custom steps here to be executed
# before populating the pack build folder
}

# custom post-processing steps
function postprocess() {
# add custom steps here to be executed
# after populating the pack build folder
# but before archiving the pack into output folder
}

############ DO NOT EDIT BELOW ###########

function install_lib() {
Expand All @@ -53,13 +65,17 @@ function install_lib() {
}

function load_lib() {
if [[ -d ${GEN_PACK_LIB} ]]; then
. "${GEN_PACK_LIB}/gen-pack"
return 0
fi
local GLOBAL_LIB="/usr/local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
local USER_LIB="${HOME}/.local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
if [[ ! -d "${GLOBAL_LIB}" && ! -d "${USER_LIB}" ]]; then
echo "Required gen_pack lib not found!" >&2
install_lib "${REQUIRED_GEN_PACK_LIB}" "${USER_LIB}"
fi
fi

if [[ -d "${GLOBAL_LIB}" ]]; then
. "${GLOBAL_LIB}/gen-pack"
elif [[ -d "${USER_LIB}" ]]; then
Expand Down

0 comments on commit 50ee2cc

Please sign in to comment.