From 381123594221b58bcb024c66f20cccffe6227816 Mon Sep 17 00:00:00 2001 From: "mmoss@chromium.org" Date: Wed, 28 Oct 2015 15:06:10 +0000 Subject: [PATCH] Generalize python_git_runner for use in non-git scripts. Also fixes an msys (git-bash) incompatibility, similar to the one fixed in crrev.com/4845f0ed694ff071da5f6ee937a0bce2ea4e6fd2. 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 Review URL: https://codereview.chromium.org/1415993003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@297357 0039d316-1c4b-4281-b951-d872f2087c98 --- git-auto-svn | 2 +- git-cache | 2 +- git-cherry-pick-upload | 2 +- git-cl | 2 +- git-drover | 2 +- git-find-releases | 2 +- git-footers | 2 +- git-freeze | 2 +- git-map | 2 +- git-map-branches | 2 +- git-mark-merge-base | 2 +- git-nav-downstream | 2 +- git-new-branch | 2 +- git-number | 2 +- git-rebase-update | 2 +- git-rename-branch | 2 +- git-reparent-branch | 2 +- git-retry | 2 +- git-squash-branch | 2 +- git-thaw | 2 +- git-try | 2 +- git-upstream-diff | 2 +- python_git_runner.sh => python_runner.sh | 22 +++++++++++----------- 23 files changed, 33 insertions(+), 33 deletions(-) rename python_git_runner.sh => python_runner.sh (60%) diff --git a/git-auto-svn b/git-auto-svn index 6a079620f9..6b1a88a79f 100755 --- a/git-auto-svn +++ b/git-auto-svn @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-cache b/git-cache index 6a079620f9..6b1a88a79f 100755 --- a/git-cache +++ b/git-cache @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-cherry-pick-upload b/git-cherry-pick-upload index 6a079620f9..6b1a88a79f 100755 --- a/git-cherry-pick-upload +++ b/git-cherry-pick-upload @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-cl b/git-cl index 12b19e30f0..935365f976 100755 --- a/git-cl +++ b/git-cl @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-drover b/git-drover index ff4eba7a37..817b6b8dcf 100755 --- a/git-drover +++ b/git-drover @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-find-releases b/git-find-releases index 6a079620f9..6b1a88a79f 100755 --- a/git-find-releases +++ b/git-find-releases @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-footers b/git-footers index 6a079620f9..6b1a88a79f 100755 --- a/git-footers +++ b/git-footers @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-freeze b/git-freeze index 5e485bb28a..ffba0cbe77 100755 --- a/git-freeze +++ b/git-freeze @@ -5,4 +5,4 @@ SCRIPT=git_freezer.py set -- freeze "$@" -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-map b/git-map index 03e8418ed8..21cffeabb5 100755 --- a/git-map +++ b/git-map @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) | less -R +. $(type -P python_runner.sh) | less -R diff --git a/git-map-branches b/git-map-branches index 6a079620f9..6b1a88a79f 100755 --- a/git-map-branches +++ b/git-map-branches @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-mark-merge-base b/git-mark-merge-base index 6a079620f9..6b1a88a79f 100755 --- a/git-mark-merge-base +++ b/git-mark-merge-base @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-nav-downstream b/git-nav-downstream index 6a079620f9..6b1a88a79f 100755 --- a/git-nav-downstream +++ b/git-nav-downstream @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-new-branch b/git-new-branch index 6a079620f9..6b1a88a79f 100755 --- a/git-new-branch +++ b/git-new-branch @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-number b/git-number index a5037a4385..2b9c996d71 100755 --- a/git-number +++ b/git-number @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-rebase-update b/git-rebase-update index 6a079620f9..6b1a88a79f 100755 --- a/git-rebase-update +++ b/git-rebase-update @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-rename-branch b/git-rename-branch index 6a079620f9..6b1a88a79f 100755 --- a/git-rename-branch +++ b/git-rename-branch @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-reparent-branch b/git-reparent-branch index 6a079620f9..6b1a88a79f 100755 --- a/git-reparent-branch +++ b/git-reparent-branch @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-retry b/git-retry index beb0976d33..014743a6a2 100755 --- a/git-retry +++ b/git-retry @@ -5,4 +5,4 @@ SCRIPT=git_retry.py set -- retry "$@" -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-squash-branch b/git-squash-branch index 6a079620f9..6b1a88a79f 100755 --- a/git-squash-branch +++ b/git-squash-branch @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-thaw b/git-thaw index 74716f1cef..8f6a4e3646 100755 --- a/git-thaw +++ b/git-thaw @@ -10,4 +10,4 @@ SCRIPT=git_freezer.py set -- thaw "$@" -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-try b/git-try index 63c7d56fda..f847754af1 100755 --- a/git-try +++ b/git-try @@ -6,4 +6,4 @@ # git_try.py - Commits a patch to the SVN try patch repo. # It is highly recommended to use `git cl try` instead. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/git-upstream-diff b/git-upstream-diff index 7d44073e96..ba16876d04 100755 --- a/git-upstream-diff +++ b/git-upstream-diff @@ -6,4 +6,4 @@ # git_upstream_diff.py -- Provide the diff between the current branch and its # upstream. -. $(type -P python_git_runner.sh) +. $(type -P python_runner.sh) diff --git a/python_git_runner.sh b/python_runner.sh similarity index 60% rename from python_git_runner.sh rename to python_runner.sh index 2dbda0aad5..fc21bd75f4 100755 --- a/python_git_runner.sh +++ b/python_runner.sh @@ -1,14 +1,14 @@ -# Copyright 2014 The Chromium Authors. All rights reserved. +# 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 'git-sub-command'. This script will then instead invoke -## '[depot_tools]/git_sub_command.py' correctly under mingw as well +## 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_git_runner.sh" > git-foo-command +## echo ". python_runner.sh" > git-foo-command ## ./git-foo-command #=> runs `python git_foo_command.py` ## Constants @@ -19,14 +19,14 @@ PYTHONDONTWRITEBYTECODE=1 # # 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##*/}" +DEPOT_TOOLS="${0%/*}" +# 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 like it was run like: +# "./command" +if [[ "$DEPOT_TOOLS" = "$0" ]]; then + DEPOT_TOOLS="." fi +BASENAME="${0##*/}" SCRIPT="${SCRIPT-${BASENAME//-/_}.py}" if [[ -e "$DEPOT_TOOLS/python.bat" && $OSTYPE = msys ]]; then