python_git_runner.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright 2014 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. ## This file is designed to be sourced from a bash script whose name takes the
  5. ## form 'git-sub-command'. This script will then instead invoke
  6. ## '[depot_tools]/git_sub_command.py' correctly under mingw as well
  7. ## as posix-ey systems, passing along all other command line flags.
  8. ## Example:
  9. ## echo ". python_git_runner.sh" > git-foo-command
  10. ## ./git-foo-command #=> runs `python git_foo_command.py`
  11. ## Constants
  12. PYTHONDONTWRITEBYTECODE=1
  13. ## "Input parameters".
  14. # If set before the script is sourced, then we'll use the pre-set values.
  15. #
  16. # SCRIPT defaults to the basename of $0, with dashes replaced with underscores
  17. if [[ $OSTYPE = msys ]]
  18. then
  19. DEPOT_TOOLS="${0%\\*}"
  20. BASENAME="${0##*\\}"
  21. else
  22. DEPOT_TOOLS="${0%/*}"
  23. BASENAME="${0##*/}"
  24. fi
  25. SCRIPT="${SCRIPT-${BASENAME//-/_}.py}"
  26. if [[ -e "$DEPOT_TOOLS/python.bat" && $OSTYPE = msys ]]; then
  27. cmd.exe //c "$DEPOT_TOOLS\\python.bat" "$DEPOT_TOOLS\\$SCRIPT" "$@"
  28. else
  29. exec "$DEPOT_TOOLS/$SCRIPT" "$@"
  30. fi