Commit 642dd84c authored by Dan Jacques's avatar Dan Jacques Committed by Commit Bot

[win/bootstrap] Use "for" instead of "set".

Using "set /p" to read a file fails when STDOUT is not connected.
Replace it with a method of reading using "for".

In the Python batch file, we eat up some of our sled buffer in order to
accommodate currently-running Python scripts. They should now resume
past the end of the file without issue. The sled was oversized, so this
shouldn't affect upgrade paths.

BUG=chromium:746602
TEST=local
  - On Windows machine, tested upgrade from pre-rework and current
    bootstraps. This code works on both, and no running Python
    processes were disrupted on exit, suggesting the sled change is
    sound.
R=iannucci@chromium.org, smut@chromium.org

Change-Id: Ica51999d672dd4e448fdad797bffc06ec9e9febf
Reviewed-on: https://chromium-review.googlesource.com/578725
Commit-Queue: Daniel Jacques <dnj@chromium.org>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Reviewed-by: 's avatarsmut <smut@google.com>
parent ca01e2c8
@echo off
:: Copyright 2017 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.
setlocal
set PYTHON_BAT_RUNNER=1
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This file is automatically generated by "bootstrap\win\win_tools.py", and
:: should not be modified.
::
:: The previous "::" block acts as a nop-sled. Each time a batch file executes
:: a command, it reloads itself and seeks to its previous execution offset to
:: begin execution. Updating this batch file is, therefore, risky, since any
:: running Python instance that is using the old batch file will reload the new
:: batch file once the Python command terminates and resume at some unknown
:: offset.
::
:: With the sled in place, a previous instance will resume mid-label. We are
:: assuming that the offset of the Python invocation is greater than the
:: PYTHON_BAT_RUNNER set command, which is the case since the old instance has
:: a large PATH set block before the Python execution. Old instances will hit
:: the next block of code without PYTHON_BAT_RUNNER set. New instances will have
:: it set.
::
:: We remedy this in the future by having the batch file load its core paths
:: from an external file with for/set, removing the need to modify "python.bat"
:: during upgrade.
::
:: After all of the old batch files are believed to be replaced, we can remove
:: the PYTHON_BAT_RUNNER block and the sled. For this update, old instances
:: will resume past the end of the file and terminate.
if not "%PYTHON_BAT_RUNNER%" == "1" goto :END
for /f %%i in (%~dp0python_bin_reldir.txt) do set PYTHON_BIN_RELDIR=%%i
set PATH=%~dp0%PYTHON_BIN_RELDIR%;%~dp0%PYTHON_BIN_RELDIR%\Scripts;%PATH%
"%~dp0%PYTHON_BIN_RELDIR%\python.exe" %*
:END
...@@ -320,11 +320,14 @@ def main(argv): ...@@ -320,11 +320,14 @@ def main(argv):
template.PYTHON_BIN_RELDIR, template.PYTHON_BIN_RELDIR,
os.path.join(ROOT_DIR, 'python_bin_reldir.txt')) os.path.join(ROOT_DIR, 'python_bin_reldir.txt'))
python_bat_template = ('python27.new.bat' if not args.bleeding_edge
else 'python27.bleeding_edge.bat')
# Re-evaluate and regenerate our root templated files. # Re-evaluate and regenerate our root templated files.
for src_name, dst_name in ( for src_name, dst_name in (
('git-bash.template.sh', 'git-bash'), ('git-bash.template.sh', 'git-bash'),
('pylint.new.bat', 'pylint.bat'), ('pylint.new.bat', 'pylint.bat'),
('python27.new.bat', 'python.bat'), (python_bat_template, 'python.bat'),
): ):
template.maybe_install(src_name, os.path.join(ROOT_DIR, dst_name)) template.maybe_install(src_name, os.path.join(ROOT_DIR, dst_name))
......
...@@ -17,7 +17,7 @@ if not exist "%~dp0.cipd_client.exe" ( ...@@ -17,7 +17,7 @@ if not exist "%~dp0.cipd_client.exe" (
if not errorlevel 0 goto :END if not errorlevel 0 goto :END
) )
set /p CIPD_CLIENT_VER=<%~dp0cipd_client_version for /f %%i in (%~dp0cipd_client_version) do set CIPD_CLIENT_VER=%%i
"%~dp0.cipd_client.exe" selfupdate -version "%CIPD_CLIENT_VER%" "%~dp0.cipd_client.exe" selfupdate -version "%CIPD_CLIENT_VER%"
if not errorlevel 0 goto :END if not errorlevel 0 goto :END
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment