You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
depot_tools/bootstrap/bootstrap.py

348 lines
12 KiB
Python

[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
# Copyright 2016 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.
import argparse
import collections
import contextlib
import fnmatch
import hashlib
import logging
import os
import platform
import posixpath
import shutil
import string
import subprocess
import sys
import tempfile
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
ROOT_DIR = os.path.abspath(os.path.join(THIS_DIR, '..'))
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
DEVNULL = open(os.devnull, 'w')
IS_WIN = sys.platform.startswith('win')
BAT_EXT = '.bat' if IS_WIN else ''
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
# Top-level stubs to generate that fall through to executables within the Git
# directory.
WIN_GIT_STUBS = {
'git.bat': 'cmd\\git.exe',
'gitk.bat': 'cmd\\gitk.exe',
'ssh.bat': 'usr\\bin\\ssh.exe',
'ssh-keygen.bat': 'usr\\bin\\ssh-keygen.exe',
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
}
# Accumulated template parameters for generated stubs.
class Template(
collections.namedtuple('Template', (
'PYTHON3_BIN_RELDIR',
'PYTHON3_BIN_RELDIR_UNIX',
'GIT_BIN_RELDIR',
'GIT_BIN_RELDIR_UNIX',
'GIT_PROGRAM',
))):
@classmethod
def empty(cls):
return cls(**{k: None for k in cls._fields})
def maybe_install(self, name, dst_path):
"""Installs template |name| to |dst_path| if it has changed.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
This loads the template |name| from THIS_DIR, resolves template parameters,
and installs it to |dst_path|. See `maybe_update` for more information.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Args:
name (str): The name of the template to install.
dst_path (str): The destination filesystem path.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Returns (bool): True if |dst_path| was updated, False otherwise.
"""
template_path = os.path.join(THIS_DIR, name)
with open(template_path, 'r', encoding='utf8') as fd:
t = string.Template(fd.read())
return maybe_update(t.safe_substitute(self._asdict()), dst_path)
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def maybe_update(content, dst_path):
"""Writes |content| to |dst_path| if |dst_path| does not already match.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
This function will ensure that there is a file at |dst_path| containing
|content|. If |dst_path| already exists and contains |content|, no operation
will be performed, preserving filesystem modification times and avoiding
potential write contention.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Args:
content (str): The file content.
dst_path (str): The destination filesystem path.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Returns (bool): True if |dst_path| was updated, False otherwise.
"""
# If the path already exists and matches the new content, refrain from
# writing a new one.
if os.path.exists(dst_path):
with open(dst_path, 'r', encoding='utf-8') as fd:
if fd.read() == content:
return False
logging.debug('Updating %r', dst_path)
with open(dst_path, 'w', encoding='utf-8') as fd:
fd.write(content)
os.chmod(dst_path, 0o755)
return True
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def maybe_copy(src_path, dst_path):
"""Writes the content of |src_path| to |dst_path| if needed.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
See `maybe_update` for more information.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Args:
src_path (str): The content source filesystem path.
dst_path (str): The destination filesystem path.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Returns (bool): True if |dst_path| was updated, False otherwise.
"""
with open(src_path, 'r', encoding='utf-8') as fd:
content = fd.read()
return maybe_update(content, dst_path)
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def call_if_outdated(stamp_path, stamp_version, fn):
"""Invokes |fn| if the stamp at |stamp_path| doesn't match |stamp_version|.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
This can be used to keep a filesystem record of whether an operation has been
performed. The record is stored at |stamp_path|. To invalidate a record,
change the value of |stamp_version|.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
After |fn| completes successfully, |stamp_path| will be updated to match
|stamp_version|, preventing the same update from happening in the future.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Args:
stamp_path (str): The filesystem path of the stamp file.
stamp_version (str): The desired stamp version.
fn (callable): A callable to invoke if the current stamp version doesn't
match |stamp_version|.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Returns (bool): True if an update occurred.
"""
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
stamp_version = stamp_version.strip()
if os.path.isfile(stamp_path):
with open(stamp_path, 'r', encoding='utf-8') as fd:
current_version = fd.read().strip()
if current_version == stamp_version:
return False
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
fn()
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
with open(stamp_path, 'w', encoding='utf-8') as fd:
fd.write(stamp_version)
return True
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def _in_use(path):
"""Checks if a Windows file is in use.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
When Windows is using an executable, it prevents other writers from
modifying or deleting that executable. We can safely test for an in-use
file by opening it in write mode and checking whether or not there was
an error.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
Returns (bool): True if the file was in use, False if not.
"""
try:
with open(path, 'r+'):
return False
except IOError:
return True
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def _toolchain_in_use(toolchain_path):
"""Returns (bool): True if a toolchain rooted at |path| is in use.
"""
# Look for Python files that may be in use.
for python_dir in (
os.path.join(toolchain_path, 'python', 'bin'), # CIPD
toolchain_path, # Legacy ZIP distributions.
):
for component in (
os.path.join(python_dir, 'python.exe'),
os.path.join(python_dir, 'DLLs', 'unicodedata.pyd'),
):
if os.path.isfile(component) and _in_use(component):
return True
# Look for Pytho:n 3 files that may be in use.
python_dir = os.path.join(toolchain_path, 'python3', 'bin')
for component in (
os.path.join(python_dir, 'python3.exe'),
os.path.join(python_dir, 'DLLs', 'unicodedata.pyd'),
):
if os.path.isfile(component) and _in_use(component):
return True
return False
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def _check_call(argv, stdin_input=None, **kwargs):
"""Wrapper for subprocess.check_call that adds logging."""
logging.info('running %r', argv)
if stdin_input is not None:
kwargs['stdin'] = subprocess.PIPE
proc = subprocess.Popen(argv, **kwargs)
proc.communicate(input=stdin_input)
if proc.returncode:
raise subprocess.CalledProcessError(proc.returncode, argv, None)
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def _safe_rmtree(path):
if not os.path.exists(path):
return
def _make_writable_and_remove(path):
st = os.stat(path)
new_mode = st.st_mode | 0o200
if st.st_mode == new_mode:
return False
try:
os.chmod(path, new_mode)
os.remove(path)
return True
except Exception:
return False
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def _on_error(function, path, excinfo):
if not _make_writable_and_remove(path):
logging.warning('Failed to %s: %s (%s)', function, path, excinfo)
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
shutil.rmtree(path, onerror=_on_error)
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def clean_up_old_installations(skip_dir):
"""Removes Python installations other than |skip_dir|.
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
This includes an "in-use" check against the "python.exe" in a given directory
to avoid removing Python executables that are currently ruinning. We need
this because our Python bootstrap may be run after (and by) other software
that is using the bootstrapped Python!
"""
root_contents = os.listdir(ROOT_DIR)
for f in ('win_tools-*_bin', 'python27*_bin', 'git-*_bin',
'bootstrap-*_bin'):
for entry in fnmatch.filter(root_contents, f):
full_entry = os.path.join(ROOT_DIR, entry)
if full_entry == skip_dir or not os.path.isdir(full_entry):
continue
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
logging.info('Cleaning up old installation %r', entry)
if not _toolchain_in_use(full_entry):
_safe_rmtree(full_entry)
else:
logging.info('Toolchain at %r is in-use; skipping', full_entry)
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
# Version of "git_postprocess" system configuration (see |git_postprocess|).
GIT_POSTPROCESS_VERSION = '2'
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def git_get_mingw_dir(git_directory):
"""Returns (str) The "mingw" directory in a Git installation, or None."""
for candidate in ('mingw64', 'mingw32'):
mingw_dir = os.path.join(git_directory, candidate)
if os.path.isdir(mingw_dir):
return mingw_dir
return None
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def git_postprocess(template, git_directory):
# Update depot_tools files for "git help <command>"
mingw_dir = git_get_mingw_dir(git_directory)
if mingw_dir:
docsrc = os.path.join(ROOT_DIR, 'man', 'html')
git_docs_dir = os.path.join(mingw_dir, 'share', 'doc', 'git-doc')
for name in os.listdir(docsrc):
maybe_copy(os.path.join(docsrc, name),
os.path.join(git_docs_dir, name))
else:
logging.info('Could not find mingw directory for %r.', git_directory)
# Create Git templates and configure its base layout.
for stub_name, relpath in WIN_GIT_STUBS.items():
stub_template = template._replace(GIT_PROGRAM=relpath)
stub_template.maybe_install('git.template.bat',
os.path.join(ROOT_DIR, stub_name))
# Set-up our system configuration environment. The following set of
# parameters is versioned by "GIT_POSTPROCESS_VERSION". If they change,
# update "GIT_POSTPROCESS_VERSION" accordingly.
def configure_git_system():
git_bat_path = os.path.join(ROOT_DIR, 'git.bat')
_check_call(
[git_bat_path, 'config', '--system', 'core.autocrlf', 'false'])
_check_call(
[git_bat_path, 'config', '--system', 'core.filemode', 'false'])
_check_call(
[git_bat_path, 'config', '--system', 'core.preloadindex', 'true'])
_check_call(
[git_bat_path, 'config', '--system', 'core.fscache', 'true'])
_check_call(
[git_bat_path, 'config', '--system', 'protocol.version', '2'])
call_if_outdated(os.path.join(git_directory, '.git_postprocess'),
GIT_POSTPROCESS_VERSION, configure_git_system)
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--bootstrap-name',
required=True,
help='The directory of the Python installation.')
args = parser.parse_args(argv)
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.WARN)
template = Template.empty()._replace(
PYTHON3_BIN_RELDIR=os.path.join(args.bootstrap_name, 'python3', 'bin'),
PYTHON3_BIN_RELDIR_UNIX=posixpath.join(args.bootstrap_name, 'python3',
'bin'),
GIT_BIN_RELDIR=os.path.join(args.bootstrap_name, 'git'),
GIT_BIN_RELDIR_UNIX=posixpath.join(args.bootstrap_name, 'git'))
bootstrap_dir = os.path.join(ROOT_DIR, args.bootstrap_name)
# Clean up any old Python and Git installations.
clean_up_old_installations(bootstrap_dir)
if IS_WIN:
git_postprocess(template, os.path.join(bootstrap_dir, 'git'))
templates = [
('git-bash.template.sh', 'git-bash', ROOT_DIR),
('python3.bat', 'python3.bat', ROOT_DIR),
]
for src_name, dst_name, dst_dir in templates:
# Re-evaluate and regenerate our root templated files.
template.maybe_install(src_name, os.path.join(dst_dir, dst_name))
# Emit our Python bin depot-tools-relative directory. This is read by
# python3.bat to identify the path of the current Python installation.
#
# We use this indirection so that upgrades can change this pointer to
# redirect "python.bat" to a new Python installation. We can't just update
# "python.bat" because batch file executions reload the batch file and seek
# to the previous cursor in between every command, so changing the batch
# file contents could invalidate any existing executions.
#
# The intention is that the batch file itself never needs to change when
# switching Python versions.
maybe_update(template.PYTHON3_BIN_RELDIR,
os.path.join(ROOT_DIR, 'python3_bin_reldir.txt'))
return 0
[win_tools] Use bundled Python CIPD packages (#2). Re-land of bf1446791e4b1c5b102559de9fb090ed5ba50cf5. Enable bundled Python CIPD packages in bleeding-edge mode. This replaces the ZIP unpacking approach used before, and introduces validation and management through the CIPD tool. The bleeding edge version will only install if a sentinel file is present in the "depot_tools" root; otherwise, default behavior will continue. This method adds a upgrade and downgrade path to/from ZIP and CIPD installations. This is done by rewriting the "win_tools.bat" process: 1) Ensure that a bootstrap Python is present. 2) Use it to run "win_tools.py", which has the functionality of "git_bootstrap.py" plus Python installation. 3) Run "win_tools.py" with appropriate flags. Some tricks were employed to handle cases where there is an already-running Python instance that uses the current Python installation and executable. This happens on bots because the system uses the same "depot_tools" checkout at multiple launch layers. To this end, we use the "python.bat" as the "current Python" authority and refrain from cleaning up old Python directories if their "python.exe" binaries are currently in use. We change the Git bleeding edge file to share the same sentinel file as Python, ".bleeding_edge". The new Python should have the same facilities as the original Python bundle. BUG=chromium:740171 TEST=local Change-Id: I51ba6415c60b95c2aaba94b6e21bd9b3fc82f35d Reviewed-on: https://chromium-review.googlesource.com/568524 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
8 years ago
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))