Skip to content

Commit

Permalink
Replace cd .. && pwd with readlink -f (#17152)
Browse files Browse the repository at this point in the history
The output of `cd` might be altered by `CDPATH` set on a
system, leading to `dade` being broken because it cannot
read the current path. Instead, using `readlink -f` seem
to get the job done without side effects.
  • Loading branch information
stefanobaghino-da committed Jul 19, 2023
1 parent a9e579e commit d999a21
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ HOOK_TYPES=(pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg p
for HOOK_TYPE in ${HOOK_TYPES[@]}; do pre-commit uninstall -t "$HOOK_TYPE" > /dev/null; done

# install pre-commit hook (opt-out by setting `DADE_NO_PRE_COMMIT`, set the hook type with `DADE_PRE_COMMIT_HOOK_TYPE` -- defaults to 'pre-push')
test "x$DADE_NO_PRE_COMMIT" = x && pre-commit install -t "$DADE_PRE_COMMIT_HOOK_TYPE" > /dev/null
if [[ -z "${DADE_NO_PRE_COMMIT:-}" ]]; then
pre-commit install -t "$DADE_PRE_COMMIT_HOOK_TYPE" > /dev/null
fi
2 changes: 1 addition & 1 deletion dev-env/bin/da-hls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

set -euo pipefail

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
cd $DADE_CURRENT_SCRIPT_DIR
cd ../..

Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/da-test-haskell-update-expected
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
THIS_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
####################################################################

cd $THIS_DIR/../..
Expand Down
4 changes: 2 additions & 2 deletions dev-env/bin/dade
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"
DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"

if [ $# -lt 1 ]; then
"$DADE_CURRENT_SCRIPT_DIR"/dade-help
Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/dade-assist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"

linkTool java out "${DADE_DEVENV_DIR}/jdk"
Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/dade-closure-size
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Compute the size of the development environment closure
#
DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
PATHS=$DADE_CURRENT_SCRIPT_DIR/../var/gc-roots/*/

for bin in $PATHS; do
Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/dade-collect-garbage
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
BASEL_CACHE_DIR="${DADE_CURRENT_SCRIPT_DIR}/../../.bazel-cache"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"

Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/dade-env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EOF
exit 1
fi

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
eval "$("${DADE_CURRENT_SCRIPT_DIR}/../lib/dade-dump-profile")"

exec "$@"
2 changes: 1 addition & 1 deletion dev-env/bin/dade-freeze
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -Eeuo pipefail

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"

if [[ "$DADE_CURRENT_SCRIPT_DIR" =~ ^/nix/store/.* ]]; then
echo "Unable to release dev-env from Nix store. Are you running this from another repository than `da`?"
Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/dade-init
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Installs nix and prepares some common tools
#

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"

if [[ "$DADE_CURRENT_SCRIPT_DIR" =~ ^/nix/store/.* ]]; then
echo "Unable to init dev-env from Nix store. Are you running this from another repository than `da`?"
Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/dade-list
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#set -e

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"

# run 'buildTool' on each of the tools.
Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/dade-preload
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#set -e

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
PATH=$DADE_CURRENT_SCRIPT_DIR:$PATH
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"

Expand Down
2 changes: 1 addition & 1 deletion dev-env/bin/dade-release-tool
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BIN_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
source "$BIN_DIR/../lib/dade-common"
cd $BIN_DIR/../../
execTool da-hs-release-tool out da-hs-release-tool "$@"
4 changes: 2 additions & 2 deletions dev-env/lib/dade-common
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if [[ -n "${DADE_DEBUG+x}" ]]; then
set -x
fi

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_BASE_ROOT="$( cd "${DADE_CURRENT_SCRIPT_DIR}/../../" && pwd)"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
DADE_BASE_ROOT="$( readlink -f "${DADE_CURRENT_SCRIPT_DIR}/../../" )"

errcho() {
>&2 echo "[dev-env] $@"
Expand Down
2 changes: 1 addition & 1 deletion dev-env/lib/dade-dump-profile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ nix_tool() {
# TODO(gleber): Compatibility mode until JBH is ugraded.
DADE_DEVENV_DIR="${DADE_DEVENV_DIR:-${DADE_BASE:-}}"
if [ -z "$DADE_DEVENV_DIR" ]; then
DADE_DEVENV_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
DADE_DEVENV_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
fi
export DADE_DEVENV_DIR="${DADE_DEVENV_DIR}"
export DADE_REPO_ROOT="${DADE_REPO_ROOT:-${DADE_DEVENV_DIR}/..}"
Expand Down
2 changes: 1 addition & 1 deletion dev-env/lib/dade-exec-nix-bin-tool
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# tool. Execute a Nix tool from a derivation that creates a `result-bin`
# directory.

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"
base=$(basename $0)
execTool $base bin $base "$@"
2 changes: 1 addition & 1 deletion dev-env/lib/dade-exec-nix-tool
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Meant to be linked to from `dev-env/bin`, symlink should be named after the
# tool. Execute a Nix tool from a derivation that creates a `result` directory.

DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DADE_CURRENT_SCRIPT_DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"
base=$(basename $0)
execTool $base out $base "$@"

0 comments on commit d999a21

Please sign in to comment.