build: remove dead python methods and helper (#28884)
This commit is contained in:
parent
e373df3bc3
commit
56c3103e73
5 changed files with 0 additions and 275 deletions
|
@ -1,102 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import itertools
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def validate_pair(ob):
|
||||
if not (len(ob) == 2):
|
||||
print("Unexpected result:", ob, file=sys.stderr)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def consume(iterator):
|
||||
try:
|
||||
while True:
|
||||
next(iterator)
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
|
||||
def get_environment_from_batch_command(env_cmd, initial=None):
|
||||
"""
|
||||
Take a command (either a single command or list of arguments)
|
||||
and return the environment created after running that command.
|
||||
Note that if the command must be a batch file or .cmd file, or the
|
||||
changes to the environment will not be captured.
|
||||
|
||||
If initial is supplied, it is used as the initial environment passed
|
||||
to the child process.
|
||||
"""
|
||||
if not isinstance(env_cmd, (list, tuple)):
|
||||
env_cmd = [env_cmd]
|
||||
# Construct the command that will alter the environment.
|
||||
cmd = subprocess.list2cmdline(env_cmd)
|
||||
# Create a tag so we can tell in the output when the proc is done.
|
||||
tag = 'END OF BATCH COMMAND'
|
||||
# Construct a cmd.exe command to do accomplish this.
|
||||
cmd = 'cmd.exe /s /c "{cmd} && echo "{tag}" && set"'.format(**locals())
|
||||
# Launch the process.
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=initial)
|
||||
# Parse the output sent to stdout.
|
||||
lines = proc.stdout
|
||||
# Consume whatever output occurs until the tag is reached.
|
||||
consume(itertools.takewhile(lambda l: tag not in l, lines))
|
||||
# Define a way to handle each KEY=VALUE line.
|
||||
handle_line = lambda l: l.rstrip().split('=',1)
|
||||
# Parse key/values into pairs.
|
||||
pairs = map(handle_line, lines)
|
||||
# Make sure the pairs are valid.
|
||||
valid_pairs = filter(validate_pair, pairs)
|
||||
# Construct a dictionary of the pairs.
|
||||
result = dict(valid_pairs)
|
||||
# Let the process finish.
|
||||
proc.communicate()
|
||||
return result
|
||||
|
||||
def get_vs_location(vs_version):
|
||||
"""
|
||||
Returns the location of the VS building environment.
|
||||
|
||||
The vs_version can be strings like "[15.0,16.0)", meaning 2017,
|
||||
but not the next version.
|
||||
"""
|
||||
|
||||
# vswhere can't handle spaces. "[15.0, 16.0)" should become "[15.0,16.0)"
|
||||
vs_version = vs_version.replace(" ", "")
|
||||
|
||||
program_files = os.environ.get('ProgramFiles(x86)')
|
||||
# Find visual studio
|
||||
proc = subprocess.Popen(
|
||||
program_files + "\\Microsoft Visual Studio\\Installer\\vswhere.exe "
|
||||
"-property installationPath "
|
||||
"-requires Microsoft.VisualStudio.Component.VC.CoreIde "
|
||||
"-format value "
|
||||
"-version {0}".format(vs_version),
|
||||
stdout=subprocess.PIPE)
|
||||
|
||||
location = proc.stdout.readline().rstrip()
|
||||
return location
|
||||
|
||||
def get_vs_env(vs_version, arch):
|
||||
"""
|
||||
Returns the env object for VS building environment.
|
||||
|
||||
vs_version is the version of Visual Studio to use.
|
||||
See get_vs_location for more details.
|
||||
The arch must be one of "x86", "amd64", "arm", "x86_amd64", "x86_arm",
|
||||
"amd64_x86", "amd64_arm", i.e. the args passed to vcvarsall.bat.
|
||||
"""
|
||||
|
||||
location = get_vs_location(vs_version)
|
||||
|
||||
# Launch the process.
|
||||
vsvarsall = "{0}\\VC\\Auxiliary\\Build\\vcvarsall.bat".format(location)
|
||||
|
||||
return get_environment_from_batch_command([vsvarsall, arch])
|
|
@ -77,25 +77,6 @@ def am(repo, patch_data, threeway=False, directory=None, exclude=None,
|
|||
proc.returncode))
|
||||
|
||||
|
||||
def apply_patch(repo, patch_path, directory=None, index=False, reverse=False):
|
||||
args = ['git', '-C', repo, 'apply',
|
||||
'--ignore-space-change',
|
||||
'--ignore-whitespace',
|
||||
'--whitespace', 'fix'
|
||||
]
|
||||
if directory:
|
||||
args += ['--directory', directory]
|
||||
if index:
|
||||
args += ['--index']
|
||||
if reverse:
|
||||
args += ['--reverse']
|
||||
args += ['--', patch_path]
|
||||
|
||||
return_code = subprocess.call(args)
|
||||
applied_successfully = (return_code == 0)
|
||||
return applied_successfully
|
||||
|
||||
|
||||
def import_patches(repo, **kwargs):
|
||||
"""same as am(), but we save the upstream HEAD so we can refer to it when we
|
||||
later export patches"""
|
||||
|
@ -107,52 +88,12 @@ def import_patches(repo, **kwargs):
|
|||
am(repo=repo, **kwargs)
|
||||
|
||||
|
||||
def get_patch(repo, commit_hash):
|
||||
args = ['git', '-C', repo, 'diff-tree',
|
||||
'-p',
|
||||
commit_hash,
|
||||
'--' # Explicitly tell Git `commit_hash` is a revision, not a path.
|
||||
]
|
||||
|
||||
return subprocess.check_output(args).decode('utf-8')
|
||||
|
||||
|
||||
def get_head_commit(repo):
|
||||
args = ['git', '-C', repo, 'rev-parse', 'HEAD']
|
||||
|
||||
return subprocess.check_output(args).decode('utf-8').strip()
|
||||
|
||||
|
||||
def update_ref(repo, ref, newvalue):
|
||||
args = ['git', '-C', repo, 'update-ref', ref, newvalue]
|
||||
|
||||
return subprocess.check_call(args)
|
||||
|
||||
|
||||
def reset(repo):
|
||||
args = ['git', '-C', repo, 'reset']
|
||||
|
||||
subprocess.check_call(args)
|
||||
|
||||
|
||||
def commit(repo, author, message):
|
||||
"""Commit whatever in the index is now."""
|
||||
|
||||
# Let's setup committer info so git won't complain about it being missing.
|
||||
# TODO: Is there a better way to set committer's name and email?
|
||||
env = os.environ.copy()
|
||||
env['GIT_COMMITTER_NAME'] = 'Anonymous Committer'
|
||||
env['GIT_COMMITTER_EMAIL'] = 'anonymous@electronjs.org'
|
||||
|
||||
args = ['git', '-C', repo, 'commit',
|
||||
'--author', author,
|
||||
'--message', message
|
||||
]
|
||||
|
||||
return_code = subprocess.call(args, env=env)
|
||||
committed_successfully = (return_code == 0)
|
||||
return committed_successfully
|
||||
|
||||
def get_upstream_head(repo):
|
||||
args = [
|
||||
'git',
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from lib.util import scoped_cwd
|
||||
|
||||
|
||||
class GNProject:
|
||||
def __init__(self, out_dir):
|
||||
self.out_dir = out_dir
|
||||
|
||||
def _get_executable_name(self):
|
||||
if sys.platform == 'win32':
|
||||
return 'gn.bat'
|
||||
|
||||
return 'gn'
|
||||
|
||||
def run(self, command_name, command_args):
|
||||
with scoped_cwd(self.out_dir):
|
||||
complete_args = [self._get_executable_name(), command_name, '.'] + \
|
||||
command_args
|
||||
return subprocess.check_output(complete_args)
|
||||
|
||||
def args(self):
|
||||
return GNArgs(self)
|
||||
|
||||
|
||||
class GNArgs:
|
||||
def __init__(self, project):
|
||||
self.project = project
|
||||
|
||||
def _get_raw_value(self, name):
|
||||
# E.g. 'version = "1.0.0"\n'
|
||||
raw_output = self.project.run('args',
|
||||
['--list={}'.format(name), '--short'])
|
||||
|
||||
# E.g. 'version = "1.0.0"'
|
||||
name_with_raw_value = raw_output[:-1]
|
||||
|
||||
# E.g. ['version', '"1.0.0"']
|
||||
name_and_raw_value = name_with_raw_value.split(' = ')
|
||||
|
||||
raw_value = name_and_raw_value[1]
|
||||
return raw_value
|
||||
|
||||
def get_string(self, name):
|
||||
# Expects to get a string in double quotes, e.g. '"some_value"'.
|
||||
raw_value = self._get_raw_value(name)
|
||||
|
||||
# E.g. 'some_value' (without enclosing quotes).
|
||||
value = raw_value[1:-1]
|
||||
return value
|
||||
|
||||
def get_boolean(self, name):
|
||||
# Expects to get a 'true' or a 'false' string.
|
||||
raw_value = self._get_raw_value(name)
|
||||
|
||||
if raw_value == 'true':
|
||||
return True
|
||||
|
||||
if raw_value == 'false':
|
||||
return False
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def gn(out_dir):
|
||||
return GNProject(out_dir)
|
|
@ -34,12 +34,6 @@ if sys.platform in ['win32', 'cygwin']:
|
|||
TS_NODE += '.cmd'
|
||||
|
||||
|
||||
def tempdir(prefix=''):
|
||||
directory = tempfile.mkdtemp(prefix=prefix)
|
||||
atexit.register(shutil.rmtree, directory)
|
||||
return directory
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def scoped_cwd(path):
|
||||
cwd = os.getcwd()
|
||||
|
@ -97,19 +91,6 @@ def download(text, url, path):
|
|||
return path
|
||||
|
||||
|
||||
def extract_tarball(tarball_path, member, destination):
|
||||
with tarfile.open(tarball_path) as tarball:
|
||||
tarball.extract(member, destination)
|
||||
|
||||
|
||||
def extract_zip(zip_path, destination):
|
||||
if sys.platform == 'darwin':
|
||||
# Use unzip command on Mac to keep symbol links in zip file work.
|
||||
execute(['unzip', zip_path, '-d', destination])
|
||||
else:
|
||||
with zipfile.ZipFile(zip_path) as z:
|
||||
z.extractall(destination)
|
||||
|
||||
def make_zip(zip_file_path, files, dirs):
|
||||
safe_unlink(zip_file_path)
|
||||
if sys.platform == 'darwin':
|
||||
|
@ -166,19 +147,6 @@ def execute(argv, env=None, cwd=None):
|
|||
raise e
|
||||
|
||||
|
||||
def execute_stdout(argv, env=None, cwd=None):
|
||||
if env is None:
|
||||
env = os.environ
|
||||
if is_verbose_mode():
|
||||
print(' '.join(argv))
|
||||
try:
|
||||
subprocess.check_call(argv, env=env, cwd=cwd)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.output)
|
||||
raise e
|
||||
else:
|
||||
execute(argv, env, cwd)
|
||||
|
||||
def get_electron_branding():
|
||||
SOURCE_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
|
||||
branding_file_path = os.path.join(
|
||||
|
@ -206,10 +174,6 @@ def s3put(bucket, access_key, secret_key, prefix, key_prefix, files):
|
|||
] + files, env)
|
||||
print(output)
|
||||
|
||||
|
||||
def add_exec_bit(filename):
|
||||
os.chmod(filename, os.stat(filename).st_mode | stat.S_IEXEC)
|
||||
|
||||
def get_out_dir():
|
||||
out_dir = 'Debug'
|
||||
override = os.environ.get('ELECTRON_OUT_DIR')
|
||||
|
|
|
@ -23,7 +23,6 @@ from lib.util import get_electron_branding, execute, get_electron_version, \
|
|||
SRC_DIR, ELECTRON_DIR, TS_NODE
|
||||
|
||||
|
||||
ELECTRON_REPO = 'electron/electron'
|
||||
ELECTRON_VERSION = get_electron_version()
|
||||
|
||||
PROJECT_NAME = get_electron_branding()['project_name']
|
||||
|
@ -360,14 +359,6 @@ def upload_sha256_checksum(version, file_path, key_prefix=None):
|
|||
key_prefix, [checksum_path])
|
||||
|
||||
|
||||
def auth_token():
|
||||
token = get_env_var('GITHUB_TOKEN')
|
||||
message = ('Error: Please set the $ELECTRON_GITHUB_TOKEN '
|
||||
'environment variable, which is your personal token')
|
||||
assert token, message
|
||||
return token
|
||||
|
||||
|
||||
def get_release(version):
|
||||
script_path = os.path.join(
|
||||
ELECTRON_DIR, 'script', 'release', 'find-github-release.js')
|
||||
|
|
Loading…
Reference in a new issue