2019-11-22 21:14:01 +00:00
|
|
|
# Copyright 2019 The Pigweed Authors
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# https://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.
|
|
|
|
|
|
|
|
# This script must be tested on bash, zsh, and dash.
|
|
|
|
|
2019-12-04 18:05:28 +00:00
|
|
|
function _realpath () {
|
|
|
|
python -c "import os.path; print(os.path.realpath('$@'))"
|
|
|
|
}
|
|
|
|
|
2019-11-22 21:14:01 +00:00
|
|
|
# Shell: bash.
|
|
|
|
if test -n "$BASH"; then
|
2019-12-04 18:05:28 +00:00
|
|
|
PW_SETUP_SCRIPT_PATH=$(_realpath $BASH_SOURCE)
|
2019-11-22 21:14:01 +00:00
|
|
|
# Shell: zsh.
|
|
|
|
elif test -n "$ZSH_NAME"; then
|
2019-12-04 18:05:28 +00:00
|
|
|
PW_SETUP_SCRIPT_PATH=$(_realpath ${(%):-%N})
|
2019-11-22 21:14:01 +00:00
|
|
|
# Shell: dash.
|
|
|
|
elif test ${0##*/} = dash; then
|
2019-12-04 18:05:28 +00:00
|
|
|
PW_SETUP_SCRIPT_PATH=$(_realpath \
|
2019-11-22 21:14:01 +00:00
|
|
|
$(lsof -p $$ -Fn0 | tail -1 | sed 's#^[^/]*##;'))
|
|
|
|
# If everything else fails, try $0. It could work.
|
|
|
|
else
|
2019-12-04 18:05:28 +00:00
|
|
|
PW_SETUP_SCRIPT_PATH=$(_realpath $0)
|
2019-11-22 21:14:01 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
PW_ENVSETUP=$(dirname $PW_SETUP_SCRIPT_PATH)
|
|
|
|
export PW_ENVSETUP
|
|
|
|
|
|
|
|
PW_ROOT=$(dirname "$PW_ENVSETUP")
|
|
|
|
export PW_ROOT
|
|
|
|
|
2019-12-04 18:05:28 +00:00
|
|
|
unset ABORT_PW_ENVSETUP
|
|
|
|
|
2019-11-22 21:14:01 +00:00
|
|
|
. "$PW_ENVSETUP/cipd/init.sh"
|
2019-12-04 18:05:28 +00:00
|
|
|
|
|
|
|
if [[ -z "$ABORT_PW_ENVSETUP" ]]; then
|
|
|
|
. "$PW_ENVSETUP/virtualenv/init.sh"
|
|
|
|
fi
|