Chris Bracken f5b84d2125 [et] Simplify path canonicalisation logic (flutter/engine#52275)
In order to canonicalise paths, previously we were doing an iterative
computation to resolve symlinks to a canonical path, directory by
directory. This was because on macOS and other BSDs, readlink doesn't
support the `-f` (follow symlinks) option. However, macOS and other
BSD-based systems *do* bundle the `realpath` utility, which resolves
symlinks.

This patch is stacked on top of #52274 and is the second commit
(dec38dda38d1ef0bc3a548ef1f750c5855e9d9f4).

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I signed the [CLA].
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2024-04-19 19:21:58 -07:00

61 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
# Needed because if it is set, cd may print the path it changed to.
unset CDPATH
# Returns the canonical path for its argument, with any symlinks resolved.
function canonical_path() {
if [[ -x "$(which realpath)" ]]; then
realpath -q -- "$1"
elif [[ -x "$(which readlink)" ]]; then
readlink -f -- "$1"
else
echo "The host platform is not supported by this tool"
exit 1
fi
}
SCRIPT_DIR="$(dirname -- "$(canonical_path "${BASH_SOURCE[0]}")")"
ENGINE_DIR="$(cd "$SCRIPT_DIR/.."; pwd -P)"
case "$(uname -s)" in
Linux)
OS="linux"
;;
Darwin)
OS="macos"
;;
*)
echo "The host platform is not supported by this tool"
exit 1
esac
case "$(uname -m)" in
arm64)
CPU="arm64"
;;
x86_64)
CPU="x64"
;;
*)
echo "The host platform is not supported by this tool"
exit 1
esac
PLATFORM="${OS}-${CPU}"
DART_SDK_DIR="${ENGINE_DIR}/prebuilts/${PLATFORM}/dart-sdk"
DART="${DART_SDK_DIR}/bin/dart"
if [ ! -d "${ENGINE_DIR}/tools/engine_tool/.dart_tool" ]; then
echo "You must run 'gclient sync -D' before using this tool."
exit 1
fi
"${DART}" --disable-dart-dev "${ENGINE_DIR}/tools/engine_tool/bin/et.dart" "$@"