From eed06d620fa4814a596c359b2d8bba4ad524c934 Mon Sep 17 00:00:00 2001 From: "iannucci@chromium.org" Date: Fri, 1 Apr 2016 00:59:42 +0000 Subject: [PATCH] Better tooling git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299614 0039d316-1c4b-4281-b951-d872f2087c98 --- .gitignore | 1 + bootstrap/win/git-bash.template.sh | 12 ++++++++++++ bootstrap/win/win_tools.bat | 26 +++++++++++++++----------- depot-tools-auth.py | 3 ++- gclient.py | 2 +- git-bash | 11 ----------- git_cl.py | 2 +- git_map_branches.py | 3 ++- python_runner.sh | 11 ++++++++--- 9 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 bootstrap/win/git-bash.template.sh delete mode 100755 git-bash diff --git a/.gitignore b/.gitignore index ca8808ab7..8ceec20b7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.pyc # Ignore the batch files produced by the Windows bootstrapping. +/git-bash /git.bat /gitk.bat /pylint.bat diff --git a/bootstrap/win/git-bash.template.sh b/bootstrap/win/git-bash.template.sh new file mode 100644 index 000000000..b34b5dc56 --- /dev/null +++ b/bootstrap/win/git-bash.template.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +export EDITOR=${EDITOR:=notepad} +WIN_BASE=`dirname $0` +UNIX_BASE=`cygpath "$WIN_BASE"` +export PATH=$PATH:$UNIX_BASE/SVN_BIN_DIR:$UNIX_BASE/PYTHON_BIN_DIR:$UNIX_BASE/PYTHON_BIN_DIR/Scripts +export PYTHON_DIRECT=1 +export PYTHONUNBUFFERED=1 +if [[ $# > 1 ]]; then + $UNIX_BASE/GIT_BIN_DIR/bin/bash.exe "$@" +else + $UNIX_BASE/GIT_BIN_DIR/git-bash.exe & +fi diff --git a/bootstrap/win/win_tools.bat b/bootstrap/win/win_tools.bat index ae9ccef09..f092be431 100644 --- a/bootstrap/win/win_tools.bat +++ b/bootstrap/win/win_tools.bat @@ -89,15 +89,18 @@ for /d %%i in ("%WIN_TOOLS_ROOT_DIR%\git-*_bin") do ( if "%WIN_TOOLS_FORCE%" == "1" goto :GIT_INSTALL -if exist "%GIT_EXE_PATH%" ( - call "%GIT_EXE_PATH%" --version 2>nul 1>nul - if errorlevel 1 goto :GIT_INSTALL - rem Several git versions can live side-by-side; check the top-level - rem batch script to make sure it points to the desired version. - find "%GIT_BIN_DIR%" "%WIN_TOOLS_ROOT_DIR%\git.bat" 2>nul 1>nul +if not exist "%GIT_EXE_PATH%" goto :GIT_INSTALL + +call "%GIT_EXE_PATH%" --version 2>nul 1>nul +if errorlevel 1 goto :GIT_INSTALL + +:: Several git versions can live side-by-side; check the top-level +:: batch script to make sure it points to the desired version. +for %%f in (git.bat gitk.bat ssh.bat ssh-keygen.bat git-bash) do ( + find "%GIT_BIN_DIR%" "%WIN_TOOLS_ROOT_DIR%\%%f" 2>nul 1>nul if errorlevel 1 goto :GIT_MAKE_BATCH_FILES - goto :SYNC_GIT_HELP_FILES ) +goto :SYNC_GIT_HELP_FILES :GIT_INSTALL echo Installing git %GIT_VERSION% (avg 1-2 min download) ... @@ -128,10 +131,11 @@ if not exist "%GIT_INST_DIR%\." goto :GIT_FAIL :: Create the batch files. set GIT_TEMPL=%~dp0git.template.bat set SED=%GIT_INST_DIR%\usr\bin\sed.exe -call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/" -e "s/GIT_PROGRAM/cmd\\\\git.exe/" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\git.bat" -call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/" -e "s/GIT_PROGRAM/cmd\\\\gitk.exe/" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\gitk.bat" -call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh.exe/" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh.bat" -call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh-keygen.exe/" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh-keygen.bat" +call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/cmd\\\\git.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\git.bat" +call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/cmd\\\\gitk.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\gitk.bat" +call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh.bat" +call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh-keygen.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh-keygen.bat" +call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/PYTHON_BIN_DIR/python276_bin/g" -e "s/SVN_BIN_DIR/svn_bin/g" < %~dp0git-bash.template.sh > "%WIN_TOOLS_ROOT_DIR%\git-bash" :: Ensure various git configurations are set correctly at they system level. call "%WIN_TOOLS_ROOT_DIR%\git.bat" config --system core.autocrlf false diff --git a/depot-tools-auth.py b/depot-tools-auth.py index 3ebc239d8..87ec1ccf0 100755 --- a/depot-tools-auth.py +++ b/depot-tools-auth.py @@ -14,6 +14,7 @@ Usage: import logging import optparse import sys +import os from third_party import colorama @@ -94,7 +95,7 @@ def main(argv): if __name__ == '__main__': - colorama.init() + colorama.init(wrap="TERM" not in os.environ) try: sys.exit(main(sys.argv[1:])) except KeyboardInterrupt: diff --git a/gclient.py b/gclient.py index 528aadfcf..aae6783f4 100755 --- a/gclient.py +++ b/gclient.py @@ -2303,7 +2303,7 @@ def main(argv): return 2 fix_encoding.fix_encoding() disable_buffering() - colorama.init() + colorama.init(wrap="TERM" not in os.environ) dispatcher = subcommand.CommandDispatcher(__name__) try: return dispatcher.execute(OptionParser(), argv) diff --git a/git-bash b/git-bash deleted file mode 100755 index 0a5be9321..000000000 --- a/git-bash +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# 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 apparently useless file enables windows users to get access to -# depot_tools' built-in bash.exe. When git executes this file as in `git bash`, -# it has bash and related tools pre-installed in the environment. Therefore even -# though 'bash' from cmd.exe doesn't work, bash here does work as you'd expect. - -bash "$@" diff --git a/git_cl.py b/git_cl.py index 6fe4c6a9b..278cd9ae8 100755 --- a/git_cl.py +++ b/git_cl.py @@ -4478,7 +4478,7 @@ if __name__ == '__main__': # These affect sys.stdout so do it outside of main() to simplify mocks in # unit testing. fix_encoding.fix_encoding() - colorama.init() + colorama.init(wrap="TERM" not in os.environ) try: sys.exit(main(sys.argv[1:])) except KeyboardInterrupt: diff --git a/git_map_branches.py b/git_map_branches.py index 6105f5e87..50b403d4c 100755 --- a/git_map_branches.py +++ b/git_map_branches.py @@ -27,6 +27,7 @@ Branches are colorized as follows: import argparse import collections +import os import sys import subprocess2 @@ -271,7 +272,7 @@ class BranchMapper(object): def main(argv): - colorama.init() + colorama.init(wrap="TERM" not in os.environ) if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION: print >> sys.stderr, ( 'This tool will not show all tracking information for git version ' diff --git a/python_runner.sh b/python_runner.sh index bf9f624dd..2834d1409 100755 --- a/python_runner.sh +++ b/python_runner.sh @@ -41,10 +41,15 @@ if [[ "$DEPOT_TOOLS" = "$0" ]]; then 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" "$@" +if [[ $PYTHON_DIRECT = 1 ]]; then + python.exe "$DEPOT_TOOLS\\$SCRIPT" "$@" else - exec "$DEPOT_TOOLS/$SCRIPT" "$@" + 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 fi