Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Launcher/Test-NativePrebuiltParser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,63 @@ else
failed=$((failed + 1))
fi

# ---------------------------------------------------------------------------
# The same guard on the other Launcher shell entry points. Only rejection paths are
# exercised: unlike Prepare-NativePrebuilt.sh these scripts have no parse-only mode, so an
# accepted command line would start real work. build-appimage.sh is edited but not driven
# here: its pre-parser ELF architecture probe exits on a non-Linux userspace before the
# argument parser is reached.
# ---------------------------------------------------------------------------

# expect_value_reject <script> <option> <description> [value...]
# Runs "$script" "$option" <value...>. With no value arguments this is the trailing-option
# case, with --help it is an option-like value, with "" an empty value.
expect_value_reject() {
local script=$1 option=$2 description=$3
shift 3
local output status
output=$("$script" "$option" "$@" 2>&1)
status=$?
if [[ $status -eq 0 ]]; then
echo "FAIL: $description: expected rejection, exited 0"
failed=$((failed + 1))
return
fi
if [[ "$output" != *"$option"* || "$output" != *"requires a value"* ]]; then
echo "FAIL: $description: error does not name $option with a value complaint:"
echo "$output"
failed=$((failed + 1))
return
fi
echo "PASS: $description"
passed=$((passed + 1))
}

launcher_dir=$(cd "$(dirname "$script_under_test")" && pwd)

value_options_of() {
case $1 in
prepare-portable-tools.sh)
echo "--arch --destination" ;;
local-build.sh)
echo "--workspace --profile --output-dir --base-output-dir --retro-rewind-package-dir --retro-wfc-offline-dir --parallel --cc --cxx --fuse-ld --cmake --ninja --dotnet --translator-dll --translator-bin --native-prebuilt-dir --sysroot --setup-version --x86-cpu-profile" ;;
local-build-macos.command)
echo "--workspace --profile --output-dir --base-output-dir --game --nodtool --retro-rewind-package-dir --retro-wfc-offline-dir --parallel --cmake --ninja --dotnet --translator-bin --setup-version" ;;
esac
}

for script_name in prepare-portable-tools.sh local-build.sh local-build-macos.command; do
script=$launcher_dir/$script_name
first_option=""
for option in $(value_options_of "$script_name"); do
[[ -z "$first_option" ]] && first_option=$option
expect_value_reject "$script" "$option" "$script_name: $option with an option-like value" --help
done
expect_value_reject "$script" "$first_option" "$script_name: $first_option swallowing -h" -h
expect_value_reject "$script" "$first_option" "$script_name: $first_option with an empty value" ""
expect_value_reject "$script" "$first_option" "$script_name: trailing $first_option without a value"
done

echo
echo "$passed passed, $failed failed"
[[ $failed -eq 0 ]]
17 changes: 15 additions & 2 deletions Launcher/build-appimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,23 @@ esac
output_dir="$workspace/Launcher/dist"
appimagetool_override=""

# Same guard as Prepare-NativePrebuilt.sh: a value-taking option must not swallow a missing,
# empty, or option-like value (issue #274).
require_value() {
if [[ $# -lt 2 || -z "$2" ]]; then
echo "build-appimage.sh: $1 requires a value" >&2
exit 1
fi
if [[ "$2" == --* || "$2" == -h ]]; then
echo "build-appimage.sh: $1 requires a value; \"$2\" looks like another option" >&2
exit 1
fi
}

while [[ $# -gt 0 ]]; do
case "$1" in
--output-dir) output_dir=$2; shift 2 ;;
--appimagetool) appimagetool_override=$2; shift 2 ;;
--output-dir) require_value "$@"; output_dir=$2; shift 2 ;;
--appimagetool) require_value "$@"; appimagetool_override=$2; shift 2 ;;
-h|--help)
echo "Usage: build-appimage.sh [--output-dir DIR] [--appimagetool PATH]"
exit 0
Expand Down
39 changes: 25 additions & 14 deletions Launcher/local-build-macos.command
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,35 @@ workspace="$default_workspace"; profile=base; output_dir=""; base_output_dir=""
game=""; nodtool=""; retro_root=""; retro_wfc=""; skip_retro_wfc=0; force_clean=0
parallel=0; cmake_bin=cmake; ninja_bin=ninja; dotnet_bin=dotnet; translator_bin=""
setup_version=""
# Same guard as Prepare-NativePrebuilt.sh: a value-taking option must not swallow a missing,
# empty, or option-like value (issue #274).
require_value() {
if [[ $# -lt 2 || -z "$2" ]]; then
fail "$1 requires a value"
fi
if [[ "$2" == --* || "$2" == -h ]]; then
fail "$1 requires a value; \"$2\" looks like another option"
fi
}

while (($#)); do
case "$1" in
--workspace) workspace=${2:-}; shift 2 ;;
--profile) profile=${2:-}; shift 2 ;;
--output-dir) output_dir=${2:-}; shift 2 ;;
--base-output-dir) base_output_dir=${2:-}; shift 2 ;;
--game) game=${2:-}; shift 2 ;;
--nodtool) nodtool=${2:-}; shift 2 ;;
--retro-rewind-package-dir) retro_root=${2:-}; shift 2 ;;
--retro-wfc-offline-dir) retro_wfc=${2:-}; shift 2 ;;
--workspace) require_value "$@"; workspace=$2; shift 2 ;;
--profile) require_value "$@"; profile=$2; shift 2 ;;
--output-dir) require_value "$@"; output_dir=$2; shift 2 ;;
--base-output-dir) require_value "$@"; base_output_dir=$2; shift 2 ;;
--game) require_value "$@"; game=$2; shift 2 ;;
--nodtool) require_value "$@"; nodtool=$2; shift 2 ;;
--retro-rewind-package-dir) require_value "$@"; retro_root=$2; shift 2 ;;
--retro-wfc-offline-dir) require_value "$@"; retro_wfc=$2; shift 2 ;;
--skip-retro-wfc-payload) skip_retro_wfc=1; shift ;;
--force-clean-build) force_clean=1; shift ;;
--parallel) parallel=${2:-}; shift 2 ;;
--cmake) cmake_bin=${2:-}; shift 2 ;;
--ninja) ninja_bin=${2:-}; shift 2 ;;
--dotnet) dotnet_bin=${2:-}; shift 2 ;;
--translator-bin) translator_bin=${2:-}; shift 2 ;;
--setup-version) setup_version=${2:-}; shift 2 ;;
--parallel) require_value "$@"; parallel=$2; shift 2 ;;
--cmake) require_value "$@"; cmake_bin=$2; shift 2 ;;
--ninja) require_value "$@"; ninja_bin=$2; shift 2 ;;
--dotnet) require_value "$@"; dotnet_bin=$2; shift 2 ;;
--translator-bin) require_value "$@"; translator_bin=$2; shift 2 ;;
--setup-version) require_value "$@"; setup_version=$2; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) fail "unknown option: $1" ;;
esac
Expand Down
49 changes: 30 additions & 19 deletions Launcher/local-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,40 @@ Usage: local-build.sh --output-dir DIR [options]
EOF
}

# Same guard as Prepare-NativePrebuilt.sh: a value-taking option must not swallow a missing,
# empty, or option-like value (issue #274).
require_value() {
if [[ $# -lt 2 || -z "$2" ]]; then
fail "$1 requires a value"
fi
if [[ "$2" == --* || "$2" == -h ]]; then
fail "$1 requires a value; \"$2\" looks like another option"
fi
}

while [[ $# -gt 0 ]]; do
case "$1" in
--workspace) workspace=$(cd "$2" && pwd); shift 2 ;;
--profile) profile=$2; shift 2 ;;
--output-dir) output_dir=$2; shift 2 ;;
--base-output-dir) base_output_dir=$2; shift 2 ;;
--retro-rewind-package-dir) retro_rewind_package_dir=$2; shift 2 ;;
--retro-wfc-offline-dir) retro_wfc_offline_dir=$2; shift 2 ;;
--workspace) require_value "$@"; workspace=$(cd "$2" && pwd); shift 2 ;;
--profile) require_value "$@"; profile=$2; shift 2 ;;
--output-dir) require_value "$@"; output_dir=$2; shift 2 ;;
--base-output-dir) require_value "$@"; base_output_dir=$2; shift 2 ;;
--retro-rewind-package-dir) require_value "$@"; retro_rewind_package_dir=$2; shift 2 ;;
--retro-wfc-offline-dir) require_value "$@"; retro_wfc_offline_dir=$2; shift 2 ;;
--skip-retro-wfc-payload) skip_retro_wfc_payload=1; shift ;;
--force-clean-build) force_clean_build=1; shift ;;
--parallel) parallel_override=$2; shift 2 ;;
--cc) cc_override=$2; shift 2 ;;
--cxx) cxx_override=$2; shift 2 ;;
--fuse-ld) fuse_ld_override=$2; shift 2 ;;
--cmake) cmake_override=$2; shift 2 ;;
--ninja) ninja_override=$2; shift 2 ;;
--dotnet) dotnet_override=$2; shift 2 ;;
--translator-dll) translator_dll_override=$2; shift 2 ;;
--translator-bin) translator_bin_override=$2; shift 2 ;;
--native-prebuilt-dir) native_prebuilt_dir=$2; shift 2 ;;
--sysroot) sysroot=$2; shift 2 ;;
--setup-version) setup_version=$2; shift 2 ;;
--x86-cpu-profile) x86_cpu_profile=$2; shift 2 ;;
--parallel) require_value "$@"; parallel_override=$2; shift 2 ;;
--cc) require_value "$@"; cc_override=$2; shift 2 ;;
--cxx) require_value "$@"; cxx_override=$2; shift 2 ;;
--fuse-ld) require_value "$@"; fuse_ld_override=$2; shift 2 ;;
--cmake) require_value "$@"; cmake_override=$2; shift 2 ;;
--ninja) require_value "$@"; ninja_override=$2; shift 2 ;;
--dotnet) require_value "$@"; dotnet_override=$2; shift 2 ;;
--translator-dll) require_value "$@"; translator_dll_override=$2; shift 2 ;;
--translator-bin) require_value "$@"; translator_bin_override=$2; shift 2 ;;
--native-prebuilt-dir) require_value "$@"; native_prebuilt_dir=$2; shift 2 ;;
--sysroot) require_value "$@"; sysroot=$2; shift 2 ;;
--setup-version) require_value "$@"; setup_version=$2; shift 2 ;;
--x86-cpu-profile) require_value "$@"; x86_cpu_profile=$2; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) fail "unknown argument: $1" ;;
esac
Expand Down
17 changes: 15 additions & 2 deletions Launcher/prepare-portable-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,23 @@ Usage: prepare-portable-tools.sh --arch {x86_64|aarch64} [--destination DIR]
EOF
}

# Same guard as Prepare-NativePrebuilt.sh: a value-taking option must not swallow a missing,
# empty, or option-like value (issue #274).
require_value() {
if [[ $# -lt 2 || -z "$2" ]]; then
echo "prepare-portable-tools.sh: $1 requires a value" >&2
exit 1
fi
if [[ "$2" == --* || "$2" == -h ]]; then
echo "prepare-portable-tools.sh: $1 requires a value; \"$2\" looks like another option" >&2
exit 1
fi
}

while [[ $# -gt 0 ]]; do
case "$1" in
--arch) arch=$2; shift 2 ;;
--destination) destination=$2; shift 2 ;;
--arch) require_value "$@"; arch=$2; shift 2 ;;
--destination) require_value "$@"; destination=$2; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) echo "prepare-portable-tools.sh: unknown argument: $1" >&2; exit 1 ;;
esac
Expand Down
Loading