win_tools.bat 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. @echo off
  2. :: Copyright (c) 2017 The Chromium Authors. All rights reserved.
  3. :: Use of this source code is governed by a BSD-style license that can be
  4. :: found in the LICENSE file.
  5. :: This script will determine if python or git binaries need updates. It
  6. :: returns !0 as failure
  7. :: Note: we set EnableDelayedExpansion so we can perform string manipulations
  8. :: in our manifest parsing loop. This only works on Windows XP+.
  9. setlocal EnableDelayedExpansion
  10. :: Get absolute root directory (.js scripts don't handle relative paths well).
  11. pushd %~dp0..
  12. set BOOTSTRAP_ROOT_DIR=%CD%
  13. popd
  14. :: Extra arguments to pass to our "win_tools.py" script.
  15. set BOOTSTRAP_EXTRA_ARGS=
  16. :: Determine if we're running a bleeding-edge installation.
  17. if not exist "%BOOTSTRAP_ROOT_DIR%\.bleeding_edge" (
  18. set CIPD_MANIFEST=manifest.txt
  19. ) else (
  20. set CIPD_MANIFEST=manifest_bleeding_edge.txt
  21. )
  22. :: Parse our CIPD manifest and identify the "cpython3" version. We do this by
  23. :: reading it line-by-line, identifying the line containing "cpython3", and
  24. :: stripping all text preceding "version:". This leaves us with the version
  25. :: string.
  26. ::
  27. :: This method requires EnableDelayedExpansion, and extracts the Python version
  28. :: from our CIPD manifest. Variables referenced using "!" instead of "%" are
  29. :: delayed expansion variables.
  30. for /F "usebackq tokens=*" %%A in ("%~dp0%CIPD_MANIFEST%") do (
  31. set LINE=%%A
  32. if not "x!LINE:cpython3/=!" == "x!LINE!" set PYTHON3_VERSION=!LINE:*version:=!
  33. )
  34. if "%PYTHON3_VERSION%" == "" (
  35. @echo Could not extract Python version from manifest.
  36. set ERRORLEVEL=1
  37. goto :END
  38. )
  39. :: We will take the version string, replace "." with "_", and surround it with
  40. :: "bootstrap-<PYTHON3_VERSION>_bin" so that it matches "win_tools.py"'s cleanup
  41. :: expression and ".gitignore".
  42. ::
  43. :: We incorporate PYTHON3_VERSION into the "win_tools" directory name so that
  44. :: new installations don't interfere with long-running Python processes if
  45. :: Python is upgraded.
  46. set BOOTSTRAP_NAME=bootstrap-%PYTHON3_VERSION:.=_%_bin
  47. set BOOTSTRAP_PATH=%BOOTSTRAP_ROOT_DIR%\%BOOTSTRAP_NAME%
  48. set BOOTSTRAP_EXTRA_ARGS=--bootstrap-name "%BOOTSTRAP_NAME%"
  49. :: Install our CIPD packages. The CIPD client self-bootstraps.
  50. :: See "//cipd.bat" and "//.cipd_impl.ps1" for more information.
  51. set CIPD_EXE=%BOOTSTRAP_ROOT_DIR%\cipd.bat
  52. call "%CIPD_EXE%" ensure -log-level warning -ensure-file "%~dp0%CIPD_MANIFEST%" -root "%BOOTSTRAP_PATH%"
  53. if errorlevel 1 (
  54. echo Error installing CIPD packages.
  55. goto :END
  56. )
  57. :: This executes "bootstrap.py" using the bundle's Python interpreter.
  58. set BOOTSTRAP_PYTHON_BIN=%BOOTSTRAP_PATH%\python3\bin\python3.exe
  59. call "%BOOTSTRAP_PYTHON_BIN%" "%~dp0bootstrap.py" %BOOTSTRAP_EXTRA_ARGS%
  60. :END
  61. set EXPORT_ERRORLEVEL=%ERRORLEVEL%
  62. endlocal & (
  63. set ERRORLEVEL=%EXPORT_ERRORLEVEL%
  64. )
  65. exit /b %ERRORLEVEL%