Skip to content

Commit

Permalink
fix: set shell vars in cli wrapper scripts (yugabyte#3930)
Browse files Browse the repository at this point in the history
Summary:

Running `cqlsh` or `redis-cli` from development environments doesn't
work, complaining about unset `YB_THIRDPARTY_DIR`.  Create
`build-support/common-cli-env.sh` to get common shell variables, namely
`YB_BUILD_ROOT`, and have `cqlsh`, `redis-cli`, and `yb-ctl` source it.
Then, have each wrapper script get further variables as needed.  These
changes should not affect the `cqlsh`, `redis-cli`, and `yb-ctl` of
releases because `yb_release_manifest.json` uses separate files, not
those in `bin`.

Close: yugabyte#3930

Test Plan:

```sh
./yb_build.sh asan
./bin/yb-ctl wipe_restart
./bin/cqlsh --execute "SHOW VERSION"
./bin/redis-cli "INFO"
YB_THIRDPARTY_DIR=/does/not/exist ./bin/cqlsh # should fail
```

Reviewers: bogdan, rahuldesirazu, mikhail

Reviewed By: mikhail

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D8129
  • Loading branch information
jaki committed Apr 3, 2020
1 parent d9a860f commit 87d0f5c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 41 deletions.
13 changes: 8 additions & 5 deletions bin/cqlsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations
# under the License.
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

# This is a wrapper around the "cqlsh" executable in the thirdparty directory. We are putting this
# in the "bin" directory of the source distribution for greater similarity in usage with YugaByte
# in the "bin" directory of the source distribution for greater similarity in usage with Yugabyte
# binary distribution.

. "${BASH_SOURCE%/*}"/../build-support/common-build-env.sh
set -euo pipefail

exec "$YB_THIRDPARTY_DIR/installed/common/cqlsh/bin/cqlsh" "$@"
# shellcheck source=../build-support/common-cli-env.sh
. "${BASH_SOURCE%/*}"/../build-support/common-cli-env.sh

"$YB_THIRDPARTY_DIR"/installed/common/cqlsh/bin/cqlsh "$@"
13 changes: 8 additions & 5 deletions bin/redis-cli
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations
# under the License.
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

# This is a wrapper around the redis-cli executable in the thirdparty directory. We are putting this
# in the "bin" directory of the source distribution for greater similarity in usage with YugaByte
# in the "bin" directory of the source distribution for greater similarity in usage with Yugabyte
# binary distribution.

. "${BASH_SOURCE%/*}"/../build-support/common-build-env.sh
set -euo pipefail

exec "$YB_THIRDPARTY_DIR/installed/common/bin/redis-cli" "$@"
# shellcheck source=../build-support/common-cli-env.sh
. "${BASH_SOURCE%/*}"/../build-support/common-cli-env.sh

"$YB_THIRDPARTY_DIR"/installed/common/bin/redis-cli "$@"
45 changes: 18 additions & 27 deletions bin/yb-ctl
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
#!/usr/bin/env bash

# The actual yb-ctl script has moved to https://github.com/yugabyte/yugabyte-installation.
# Copyright (c) YugaByte, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

# The actual yb-ctl script has moved to <https://github.com/yugabyte/yugabyte-installation>.
# We are invoking it here using a submodule.

set -euo pipefail

# Update submodules.
script_dir=$( cd "${BASH_SOURCE%/*}" && pwd )
. "$script_dir/../build-support/common-test-env.sh"
update_submodules
# shellcheck source=../build-support/common-cli-env.sh
. "${BASH_SOURCE%/*}"/../build-support/common-cli-env.sh
# shellcheck source=../build-support/common-test-env.sh
. "${BASH_SOURCE%/*}"/../build-support/common-test-env.sh

# Get environment variables for ASAN/TSAN.
if [[ -z ${BUILD_ROOT:-} ]]; then
pushd "$YB_SRC_ROOT"/build/latest
cd -P .
handle_build_root_from_current_dir
popd
set_build_root
else
predefined_build_root=$BUILD_ROOT
handle_predefined_build_root
unset preset_build_root
fi
build_root_basename=${BUILD_ROOT##*/}
if [[ $build_root_basename =~ ^(asan|tsan) ]]; then
if [[ -z ${ASAN_SYMBOLIZER_PATH:-} || ! -f ${ASAN_SYMBOLIZER_PATH:-} ]]; then
if [[ -n "${ASAN_SYMBOLIZER_PATH:-}" ]]; then
log "ASAN_SYMBOLIZER_PATH is set to '$ASAN_SYMBOLIZER_PATH' but that file does not " \
"exist, reverting to default behavior."
fi
ASAN_SYMBOLIZER_PATH="$(which llvm-symbolizer)"
fi
fi
# (For ASAN/TSAN builds.)
set_sanitizer_runtime_options

# Invoke the actual yb-ctl script.
Expand Down
4 changes: 2 additions & 2 deletions build-support/common-build-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations
# under the License.
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#

# This is common between build and test scripts.
Expand Down
61 changes: 61 additions & 0 deletions build-support/common-cli-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#@IgnoreInspection BashAddShebang

# Copyright (c) YugaByte, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#

# Common bash code for CLIs (e.g. cqlsh, yb-ctl).

set -euo pipefail

if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
echo "${BASH_SOURCE[0]} must be sourced, not executed" >&2
exit 1
fi

# Guard against multiple inclusions.
if [[ -n ${YB_COMMON_CLI_ENV_SOURCED:-} ]]; then
# Return to the executing script.
return
fi

readonly YB_COMMON_CLI_ENV_SOURCED=1

# shellcheck source=../build-support/common-build-env.sh
. "${BASH_SOURCE%/*}/common-build-env.sh"

# Get variable BUILD_ROOT if it is empty.
set_build_root_from_latest_if_unset() {
expect_num_args 0 "$@"
if [[ -z ${BUILD_ROOT:-} ]]; then
pushd "$YB_SRC_ROOT"/build/latest
cd -P .
handle_build_root_from_current_dir
popd
set_build_root
else
predefined_build_root=$BUILD_ROOT
handle_predefined_build_root
fi
}

# Get variable YB_THIRDPARTY_DIR if it is empty.
set_yb_thirdparty_dir_if_unset() {
expect_num_args 0 "$@"
expect_vars_to_be_set BUILD_ROOT
if [[ -z ${YB_THIRDPARTY_DIR:-} ]]; then
find_or_download_thirdparty
fi
}

set_build_root_from_latest_if_unset
set_yb_thirdparty_dir_if_unset
4 changes: 2 additions & 2 deletions build-support/common-test-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations
# under the License.
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#

# Common bash code for test scripts/
Expand Down

0 comments on commit 87d0f5c

Please sign in to comment.