From 39058571f71ef66bb032ecc1fa143ea15e38cf05 Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Fri, 27 Sep 2019 21:47:49 +0000 Subject: [PATCH] Reland "gclient: Add a GCLIENT_PY3 env var to allow users to execute gclient using Python 3." This is a reland of e656e9883179f680292735a6f1fcea9177b2e81f Original change's description: > gclient: Add a GCLIENT_PY3 env var to allow users to execute gclient using Python 3. > > Bug: 1008202 > Change-Id: I23dd70b72089a09c2a7cdc74e2a63c135a924ebe > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1825996 > Reviewed-by: Anthony Polito > Commit-Queue: Edward Lesmes > Auto-Submit: Edward Lesmes Bug: 1008202 Change-Id: I5181a7f8efb39bdd6adc99db90663cf3cf3cd0bf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1828334 Reviewed-by: Anthony Polito Commit-Queue: Edward Lesmes --- gclient | 10 +++++++++- gclient.bat | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gclient b/gclient index 4ff6b3cbd..7969d6ee0 100755 --- a/gclient +++ b/gclient @@ -19,4 +19,12 @@ if [[ "#grep#fetch#cleanup#diff#setdep#" != *"#$1#"* ]]; then esac fi -PYTHONDONTWRITEBYTECODE=1 exec python "$base_dir/gclient.py" "$@" +# Ensure that "depot_tools" is somewhere in PATH so this tool can be used +# standalone, but allow other PATH manipulations to take priority. +PATH=$PATH:$base_dir + +if [[ $GCLIENT_PY3 == 1 ]]; then + PYTHONDONTWRITEBYTECODE=1 exec vpython3 "$base_dir/gclient.py" "$@" +else + PYTHONDONTWRITEBYTECODE=1 exec python "$base_dir/gclient.py" "$@" +fi diff --git a/gclient.bat b/gclient.bat index 5aaff866c..d7d245d06 100755 --- a/gclient.bat +++ b/gclient.bat @@ -12,4 +12,9 @@ call "%~dp0update_depot_tools.bat" %* set PATH=%PATH%;%~dp0 :: Defer control. -python "%~dp0gclient.py" %* +IF "%GCLIENT_PY3%" == "1" ( + :: TODO(1003139): Use vpython3 once vpython3 works on Windows. + python3 "%~dp0gclient.py" %* +) ELSE ( + python "%~dp0gclient.py" %* +)