On Wed, Jun 24, 2026 at 1:58 PM Jonathan Wakely <[email protected]> wrote:
>
> The relpath.sh script always writes its usage message to stdout and
> exits with zero status, even for invalid arguments. This causes a
> problem for libstdc++-v3/src/c++23/Makefile which assumes that it
> doesn't exit successfully on error, via:
>
> relpath=$(relpath.sh ...) && sed 's,@MODPATH@,$$relpath,' ...
>
> Because it exits successfully for invalid args, the sed command still
> runs even if relpath.sh is invoked incorrectly.
>
> contrib/ChangeLog:
>
> PR libstdc++/125956
> * relpath.sh: For invalid arguments write to stderr and exit
> with non-zero status.
> ---
>
> OK for trunk?
Ok.
>
> contrib/relpath.sh | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/relpath.sh b/contrib/relpath.sh
> index 1b329fc04a78..286e7f1a1752 100755
> --- a/contrib/relpath.sh
> +++ b/contrib/relpath.sh
> @@ -1,10 +1,18 @@
> #!/bin/sh
>
> -if [ "$1" = "--help" -o $# -ne 2 -o -f "$1" ]; then
> +usage()
> +{
> echo Usage: relpath.sh FROM TO
> echo Print the relative path from FROM to TO
> echo FROM must be a directory, but need not exist
> +}
> +
> +if [ "$1" = "--help" ]; then
> + usage
> exit 0
> +elif [ $# -ne 2 -o -f "$1" ]; then
> + usage >&2
> + exit 1
> fi
>
> from="${1%%/}"
> --
> 2.54.0
>