Skip to content

Commit

Permalink
Add support for @version-{retail,classic,bc}@ replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
nebularg committed Mar 31, 2021
1 parent 0f9c9dd commit 3b41ec3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ for more info.
- *namespace*
- *same-key-is-true*
- *table-name*
- *@alpha@*...*@end-alpha@* / *@non-alpha@*...*@end-non-alpha@*
- *@debug@*...*@end-debug@* / *@non-debug@*...*@end-non-debug@*
- *@retail@*...*@end-retail@* / *@non-retail@*...*@end-non-retail@*
- *@no-lib-strip@*...*@end-no-lib-strip@*
- *@do-not-package@*...*@end-do-not-package@*
- *@file-revision@*
- *@project-revision@*
- *@file-hash@*
Expand All @@ -106,21 +101,35 @@ for more info.

### Build type keywords

`alpha`, `debug`, `retail`, `no-lib-strip`, and `do-not-package` are build type
keywords and are used to conditionally run a block of code based on the build
type with the use of comments.

`@do-not-package@` and `@end-do-not-package@` are a bit special. Everything
between the tags, including the tags themselves, will be removed from the file.
This will cause the line numbers of subsequent lines to change, which can result
in bug report line numbers not matching the source code. The typical usage is
at the end of Lua files surrounding debugging functions and other code that end
users should never see or execute.
Specific keywords used in a comment at the start (`@keyword@`) and end
(`@end-keyword@`) of a block of code can be used to conditionally run that code
based on the build type. If the build type does not match, the block of code
is comment out so line numbers do not change.

Supported keywords and when the code block will run:

- `alpha`: in untagged builds.
- `debug`: never. Code will only run when using an unpackaged source.
- `do-not-package`: never. Same as `debug` except removed from the packaged
file.
- `no-lib-strip`: _(not supported in Lua files)_ in any build other than a
*nolib* build.
- `retail`,`version-retail`,`version-classic`,`version-bc`: based on game
version.

`do-not-package` is a bit special. Everything between the tags, including the
tags themselves, will always be removed from the packaged file. This will cause
the line numbers of subsequent lines to change, which can result in bug report
line numbers not matching the source code. The typical usage is at the end of
Lua files surrounding debugging functions and other code that end users should
never see or execute.

All keywords except `do-not-package` can be prefixed with `non-` to inverse the
logic. When doing this, the keywords should start and end a **block comment**
as shown below.

More examples are available on the [wiki page](https://github.com/BigWigsMods/packager/wiki/Repository-Keyword-Substitutions#debug-replacements).

#### In Lua files

`--@keyword@` and `--@end-keyword@`
Expand Down
24 changes: 16 additions & 8 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -954,10 +954,10 @@ else
if [[ -z "$toc_version" ]] || [[ "$game_type" == "classic" && "$toc_version" != "113"* ]] || [[ "$game_type" == "bc" && "$toc_version" != "205"* ]] || [[ "$game_type" == "retail" && ("$toc_version" == "113"* || "$toc_version" == "205"*) ]]; then
toc_version=$( echo "$toc_file" | awk 'tolower($0) ~ /^## interface-'${game_type}':/ { print $NF; exit }' )
if [[ -z "$toc_version" ]]; then
# Check @non-retail@ blocks
# Check @non-@ blocks
case $game_type in
classic) toc_version=$( echo "$toc_file" | sed -n '/@non-retail@/,/@end-non-retail@/{//b;p}'| awk '/#[[:blank:]]*## Interface:[[:blank:]]*(113)/ { print $NF; exit }' ) ;;
bc) toc_version=$( echo "$toc_file" | sed -n '/@non-retail@/,/@end-non-retail@/{//b;p}' | awk '/#[[:blank:]]*## Interface:[[:blank:]]*(205)/ { print $NF; exit }' ) ;;
classic) toc_version=$( echo "$toc_file" | sed -n '/@non-[-a-z]*@/,/@end-non-[-a-z]*@/{//b;p}'| awk '/#[[:blank:]]*## Interface:[[:blank:]]*(113)/ { print $NF; exit }' ) ;;
bc) toc_version=$( echo "$toc_file" | sed -n '/@non-[-a-z]*@/,/@end-non-[-a-z]*@/{//b;p}' | awk '/#[[:blank:]]*## Interface:[[:blank:]]*(205)/ { print $NF; exit }' ) ;;
esac
# This becomes the actual interface version after string replacements
root_toc_version="$toc_version"
Expand Down Expand Up @@ -1023,7 +1023,7 @@ if [ -n "$previous_version" ]; then
echo "Previous version: $previous_version"
fi
(
[ "$game_type" = "retail" ] && retail="retail" || retail="non-retail"
[ "$game_type" = "retail" ] && retail="retail" || retail="non-retail version-${game_type}"
[ "$file_type" = "alpha" ] && alpha="alpha" || alpha="non-alpha"
echo "Build type: ${retail} ${alpha} non-debug${nolib:+ nolib}"
echo "Game version: ${game_version}"
Expand Down Expand Up @@ -1348,7 +1348,7 @@ copy_directory_tree() {
_cdt_unchanged_patterns=
_cdt_classic=
OPTIND=1
while getopts :adi:lnpu:c _cdt_opt "$@"; do
while getopts :adi:lnpu:c: _cdt_opt "$@"; do
# shellcheck disable=2220
case $_cdt_opt in
a) _cdt_alpha="true" ;;
Expand All @@ -1360,7 +1360,7 @@ copy_directory_tree() {
n) _cdt_nolib="true" ;;
p) _cdt_do_not_package="true" ;;
u) _cdt_unchanged_patterns=$OPTARG ;;
c) _cdt_classic="true" ;;
c) _cdt_classic=$OPTARG ;;
esac
done
shift $((OPTIND - 1))
Expand Down Expand Up @@ -1427,7 +1427,15 @@ copy_directory_tree() {
[ -n "$_cdt_do_not_package" ] && _cdt_filters+="|do_not_package_filter lua"
[ -n "$_cdt_alpha" ] && _cdt_filters+="|lua_filter alpha"
[ -n "$_cdt_debug" ] && _cdt_filters+="|lua_filter debug"
[ -n "$_cdt_classic" ] && _cdt_filters+="|lua_filter retail"
if [ -n "$_cdt_classic" ]; then
_cdt_filters+="|lua_filter retail"
_cdt_filters+="|lua_filter version-retail"
[ "$_cdt_classic" = "classic" ] && _cdt_filters+="|lua_filter version-bc"
[ "$_cdt_classic" = "bc" ] && _cdt_filters+="|lua_filter version-classic"
else
_cdt_filters+="|lua_filter version-classic"
_cdt_filters+="|lua_filter version-bc"
fi
[ -n "$_cdt_localization" ] && _cdt_filters+="|localization_filter"
;;
*.xml)
Expand Down Expand Up @@ -1481,7 +1489,7 @@ if [ -z "$skip_copying" ]; then
[ "$file_type" != "alpha" ] && cdt_args+="a"
[ -z "$skip_localization" ] && cdt_args+="l"
[ -n "$nolib" ] && cdt_args+="n"
[ "$game_type" != "retail" ] && cdt_args+="c"
[ "$game_type" != "retail" ] && cdt_args+=" -c $game_type"
[ -n "$ignore" ] && cdt_args+=" -i \"$ignore\""
[ -n "$changelog" ] && cdt_args+=" -u \"$changelog\""
eval copy_directory_tree "$cdt_args" "\"$topdir\"" "\"$pkgdir\""
Expand Down

0 comments on commit 3b41ec3

Please sign in to comment.