فهرست منبع

Generalize python_git_runner for use in non-git scripts.

Retrying the change in https://codereview.chromium.org/1415993003/, with
fixes to properly handle being called with either Windows- or
POSIX-style paths (the previous attempt assumed it was always called
with POSIX-style paths under MSYS, which itself was attempting to fix
the assumption that it was always called with Windows-style paths, but
neither assumption was right).

This change doesn't actually use the wrapper in any new places, but
subsequent changes will be made to use it in places where
'exec python' is called directly, like gclient and fetch.

BUG=411518
R=iannucci@google.com, sky@google.com

Review URL: https://codereview.chromium.org/1411793006

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@297401 0039d316-1c4b-4281-b951-d872f2087c98
mmoss@chromium.org 9 سال پیش
والد
کامیت
375765c6bf
24فایلهای تغییر یافته به همراه72 افزوده شده و 58 حذف شده
  1. 1 1
      git-auto-svn
  2. 1 1
      git-cache
  3. 1 1
      git-cherry-pick-upload
  4. 1 1
      git-cl
  5. 1 1
      git-drover
  6. 1 1
      git-find-releases
  7. 1 1
      git-footers
  8. 1 1
      git-freeze
  9. 1 1
      git-map
  10. 1 1
      git-map-branches
  11. 1 1
      git-mark-merge-base
  12. 1 1
      git-nav-downstream
  13. 1 1
      git-new-branch
  14. 1 1
      git-number
  15. 1 1
      git-rebase-update
  16. 1 1
      git-rename-branch
  17. 1 1
      git-reparent-branch
  18. 1 1
      git-retry
  19. 1 1
      git-squash-branch
  20. 1 1
      git-thaw
  21. 1 1
      git-try
  22. 1 1
      git-upstream-diff
  23. 0 36
      python_git_runner.sh
  24. 50 0
      python_runner.sh

+ 1 - 1
git-auto-svn

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-cache

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-cherry-pick-upload

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-cl

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-drover

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-find-releases

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-footers

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-freeze

@@ -5,4 +5,4 @@
 
 
 SCRIPT=git_freezer.py
 SCRIPT=git_freezer.py
 set -- freeze "$@"
 set -- freeze "$@"
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-map

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh) | less -R
+. $(type -P python_runner.sh) | less -R

+ 1 - 1
git-map-branches

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-mark-merge-base

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-nav-downstream

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-new-branch

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-number

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-rebase-update

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-rename-branch

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-reparent-branch

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-retry

@@ -5,4 +5,4 @@
 
 
 SCRIPT=git_retry.py
 SCRIPT=git_retry.py
 set -- retry "$@"
 set -- retry "$@"
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-squash-branch

@@ -3,4 +3,4 @@
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-thaw

@@ -10,4 +10,4 @@
 
 
 SCRIPT=git_freezer.py
 SCRIPT=git_freezer.py
 set -- thaw "$@"
 set -- thaw "$@"
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-try

@@ -6,4 +6,4 @@
 # git_try.py - Commits a patch to the SVN try patch repo.
 # git_try.py - Commits a patch to the SVN try patch repo.
 #              It is highly recommended to use `git cl try` instead.
 #              It is highly recommended to use `git cl try` instead.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 1 - 1
git-upstream-diff

@@ -6,4 +6,4 @@
 # git_upstream_diff.py -- Provide the diff between the current branch and its
 # git_upstream_diff.py -- Provide the diff between the current branch and its
 # upstream.
 # upstream.
 
 
-. $(type -P python_git_runner.sh)
+. $(type -P python_runner.sh)

+ 0 - 36
python_git_runner.sh

@@ -1,36 +0,0 @@
-# Copyright 2014 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-## This file is designed to be sourced from a bash script whose name takes the
-## form 'git-sub-command'. This script will then instead invoke
-## '[depot_tools]/git_sub_command.py' correctly under mingw as well
-## as posix-ey systems, passing along all other command line flags.
-
-## Example:
-## echo ". python_git_runner.sh" > git-foo-command
-## ./git-foo-command  #=> runs `python git_foo_command.py`
-
-## Constants
-PYTHONDONTWRITEBYTECODE=1
-
-## "Input parameters".
-# If set before the script is sourced, then we'll use the pre-set values.
-#
-# SCRIPT defaults to the basename of $0, with dashes replaced with underscores
-
-if [[ $OSTYPE = msys ]]
-then
-  DEPOT_TOOLS="${0%\\*}"
-  BASENAME="${0##*\\}"
-else
-  DEPOT_TOOLS="${0%/*}"
-  BASENAME="${0##*/}"
-fi
-SCRIPT="${SCRIPT-${BASENAME//-/_}.py}"
-
-if [[ -e "$DEPOT_TOOLS/python.bat" && $OSTYPE = msys ]]; then
-  cmd.exe //c "$DEPOT_TOOLS\\python.bat" "$DEPOT_TOOLS\\$SCRIPT" "$@"
-else
-  exec "$DEPOT_TOOLS/$SCRIPT" "$@"
-fi

+ 50 - 0
python_runner.sh

@@ -0,0 +1,50 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+## This file is designed to be sourced from a bash script whose name takes the
+## form 'command-name'. This script will then instead invoke
+## '[depot_tools]/command_name.py' correctly under mingw as well
+## as posix-ey systems, passing along all other command line flags.
+
+## Example:
+## echo ". python_runner.sh" > git-foo-command
+## ./git-foo-command  #=> runs `python git_foo_command.py`
+
+## Constants
+PYTHONDONTWRITEBYTECODE=1
+
+## "Input parameters".
+# If set before the script is sourced, then we'll use the pre-set values.
+#
+# SCRIPT defaults to the basename of $0, with dashes replaced with underscores
+
+# "$0" can have several different formats depending on how the script was called
+# and the environment being used, including having different formats even in the
+# same environment (e.g. in msys, 'git cl' causes $0 to have a Windows-style
+# path, but calling 'git-cl' results in a POSIX-style path), so don't assume a
+# particular format.
+# First try to split it using Windows format ...
+DEPOT_TOOLS="${0%\\*}"
+if [[ "$DEPOT_TOOLS" = "$0" ]]; then
+  # If that didn't work, try POSIX format ...
+  DEPOT_TOOLS="${0%/*}"
+  if [[ "$DEPOT_TOOLS" = "$0" ]]; then
+    # Sometimes commands will run with no path (e.g. a git command run from
+    # within the depot_tools dir itself). In that case, treat it as if run like:
+    # "./command"
+    DEPOT_TOOLS="."
+    BASENAME="$0"
+  else
+    BASENAME="${0##*/}"
+  fi
+else
+  BASENAME="${0##*\\}"
+fi
+SCRIPT="${SCRIPT-${BASENAME//-/_}.py}"
+
+if [[ -e "$DEPOT_TOOLS/python.bat" && $OSTYPE = msys ]]; then
+  cmd.exe //c "$DEPOT_TOOLS\\python.bat" "$DEPOT_TOOLS\\$SCRIPT" "$@"
+else
+  exec "$DEPOT_TOOLS/$SCRIPT" "$@"
+fi