Rollup merge of #116732 - onur-ozkan:resolve-linked-x, r=Mark-Simulacrum

Make x capable of resolving symlinks

When bootstrapping from outside of the rust source, instead of calling 'x' from the absolute path
(like /home/user/rust/x), we should be able to link 'x' from the rust source to binary paths so it can be used easily. Before this change, 'x' was not capable of finding 'x.py' when called from the linked file.
This commit is contained in:
Matthias Krüger 2023-10-15 21:29:08 +02:00 committed by GitHub
commit dd5023599d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

9
x
View File

@ -11,10 +11,13 @@ set -eu
sh -n "$0"
realpath() {
if [ -d "$1" ]; then
CDPATH='' command cd "$1" && pwd -P
local path="$1"
if [ -L "$path" ]; then
readlink -f "$path"
elif [ -d "$path" ]; then
(cd -P "$path" && pwd)
else
echo "$(realpath "$(dirname "$1")")/$(basename "$1")"
echo "$(realpath "$(dirname "$path")")/$(basename "$path")"
fi
}