blob: ca4ba17ec4f1aacbbe30d45329f8b89e6e1e6560 [file] [log] [blame]
mmoss@chromium.org375765c2015-10-30 15:39:24 +00001# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5## This file is designed to be sourced from a bash script whose name takes the
6## form 'command-name'. This script will then instead invoke
7## '[depot_tools]/command_name.py' correctly under mingw as well
8## as posix-ey systems, passing along all other command line flags.
9
10## Example:
11## echo ". python_runner.sh" > git-foo-command
12## ./git-foo-command #=> runs `python git_foo_command.py`
13
14## Constants
15PYTHONDONTWRITEBYTECODE=1
16
17## "Input parameters".
18# If set before the script is sourced, then we'll use the pre-set values.
19#
20# SCRIPT defaults to the basename of $0, with dashes replaced with underscores
21
22# "$0" can have several different formats depending on how the script was called
23# and the environment being used, including having different formats even in the
24# same environment (e.g. in msys, 'git cl' causes $0 to have a Windows-style
25# path, but calling 'git-cl' results in a POSIX-style path), so don't assume a
26# particular format.
27# First try to split it using Windows format ...
28DEPOT_TOOLS="${0%\\*}"
29if [[ "$DEPOT_TOOLS" = "$0" ]]; then
30 # If that didn't work, try POSIX format ...
31 DEPOT_TOOLS="${0%/*}"
32 if [[ "$DEPOT_TOOLS" = "$0" ]]; then
33 # Sometimes commands will run with no path (e.g. a git command run from
34 # within the depot_tools dir itself). In that case, treat it as if run like:
35 # "./command"
36 DEPOT_TOOLS="."
37 BASENAME="$0"
38 else
39 BASENAME="${0##*/}"
40 fi
41else
42 BASENAME="${0##*\\}"
43fi
iannucci@chromium.org0703ea22016-04-01 01:02:42 +000044
mmoss@chromium.org375765c2015-10-30 15:39:24 +000045SCRIPT="${SCRIPT-${BASENAME//-/_}.py}"
46
iannucci@chromium.org0703ea22016-04-01 01:02:42 +000047if [[ $PYTHON_DIRECT = 1 ]]; then
48 python.exe "$DEPOT_TOOLS\\$SCRIPT" "$@"
mmoss@chromium.org375765c2015-10-30 15:39:24 +000049else
Edward Lemurd6186f92019-08-12 17:56:58 +000050 if [ $OSTYPE = msys ]; then
51 PYTHONDONTWRITEBYTECODE=1 $DEPOT_TOOLS\\vpython "$DEPOT_TOOLS\\$SCRIPT" "$@"
iannucci@chromium.org0703ea22016-04-01 01:02:42 +000052 else
Edward Lemurd6186f92019-08-12 17:56:58 +000053 PYTHONDONTWRITEBYTECODE=1 exec $DEPOT_TOOLS/vpython "$DEPOT_TOOLS/$SCRIPT" "$@"
iannucci@chromium.org0703ea22016-04-01 01:02:42 +000054 fi
mmoss@chromium.org375765c2015-10-30 15:39:24 +000055fi