зеркало из https://github.com/electron/electron.git
build: Python3 compat and Win line-endings fixes (#26091)
This commit is contained in:
Родитель
f065b2ddef
Коммит
e9cd227b5b
|
@ -7,7 +7,7 @@ from lib import git
|
||||||
|
|
||||||
|
|
||||||
def export_patches(dirs, dry_run):
|
def export_patches(dirs, dry_run):
|
||||||
for patch_dir, repo in dirs.iteritems():
|
for patch_dir, repo in dirs.items():
|
||||||
git.export_patches(repo=repo, out_dir=patch_dir, dry_run=dry_run)
|
git.export_patches(repo=repo, out_dir=patch_dir, dry_run=dry_run)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ verbose_mode = False
|
||||||
|
|
||||||
|
|
||||||
def get_platform_key():
|
def get_platform_key():
|
||||||
if os.environ.has_key('MAS_BUILD'):
|
if 'MAS_BUILD' in os.environ:
|
||||||
return 'mas'
|
return 'mas'
|
||||||
else:
|
else:
|
||||||
return PLATFORM
|
return PLATFORM
|
||||||
|
|
|
@ -6,7 +6,11 @@ Everything here should be project agnostic: it shouldn't rely on project's
|
||||||
structure, or make assumptions about the passed arguments or calls' outcomes.
|
structure, or make assumptions about the passed arguments or calls' outcomes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
|
import posixpath
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -106,13 +110,13 @@ def get_patch(repo, commit_hash):
|
||||||
'--' # Explicitly tell Git `commit_hash` is a revision, not a path.
|
'--' # Explicitly tell Git `commit_hash` is a revision, not a path.
|
||||||
]
|
]
|
||||||
|
|
||||||
return subprocess.check_output(args)
|
return subprocess.check_output(args).decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def get_head_commit(repo):
|
def get_head_commit(repo):
|
||||||
args = ['git', '-C', repo, 'rev-parse', 'HEAD']
|
args = ['git', '-C', repo, 'rev-parse', 'HEAD']
|
||||||
|
|
||||||
return subprocess.check_output(args).strip()
|
return subprocess.check_output(args).decode('utf-8').strip()
|
||||||
|
|
||||||
|
|
||||||
def update_ref(repo, ref, newvalue):
|
def update_ref(repo, ref, newvalue):
|
||||||
|
@ -154,7 +158,7 @@ def get_upstream_head(repo):
|
||||||
'--verify',
|
'--verify',
|
||||||
'refs/patches/upstream-head',
|
'refs/patches/upstream-head',
|
||||||
]
|
]
|
||||||
return subprocess.check_output(args).strip()
|
return subprocess.check_output(args).decode('utf-8').strip()
|
||||||
|
|
||||||
def get_commit_count(repo, commit_range):
|
def get_commit_count(repo, commit_range):
|
||||||
args = [
|
args = [
|
||||||
|
@ -165,7 +169,7 @@ def get_commit_count(repo, commit_range):
|
||||||
'--count',
|
'--count',
|
||||||
commit_range
|
commit_range
|
||||||
]
|
]
|
||||||
return int(subprocess.check_output(args).strip())
|
return int(subprocess.check_output(args).decode('utf-8').strip())
|
||||||
|
|
||||||
def guess_base_commit(repo):
|
def guess_base_commit(repo):
|
||||||
"""Guess which commit the patches might be based on"""
|
"""Guess which commit the patches might be based on"""
|
||||||
|
@ -181,7 +185,7 @@ def guess_base_commit(repo):
|
||||||
'describe',
|
'describe',
|
||||||
'--tags',
|
'--tags',
|
||||||
]
|
]
|
||||||
return subprocess.check_output(args).rsplit('-', 2)[0:2]
|
return subprocess.check_output(args).decode('utf-8').rsplit('-', 2)[0:2]
|
||||||
|
|
||||||
|
|
||||||
def format_patch(repo, since):
|
def format_patch(repo, since):
|
||||||
|
@ -190,7 +194,11 @@ def format_patch(repo, since):
|
||||||
'-C',
|
'-C',
|
||||||
repo,
|
repo,
|
||||||
'-c',
|
'-c',
|
||||||
'core.attributesfile=' + os.path.join(os.path.dirname(os.path.realpath(__file__)), 'electron.gitattributes'),
|
'core.attributesfile='
|
||||||
|
+ os.path.join(
|
||||||
|
os.path.dirname(os.path.realpath(__file__)),
|
||||||
|
'electron.gitattributes',
|
||||||
|
),
|
||||||
# Ensure it is not possible to match anything
|
# Ensure it is not possible to match anything
|
||||||
# Disabled for now as we have consistent chunk headers
|
# Disabled for now as we have consistent chunk headers
|
||||||
# '-c',
|
# '-c',
|
||||||
|
@ -215,7 +223,7 @@ def format_patch(repo, since):
|
||||||
'--full-index',
|
'--full-index',
|
||||||
since
|
since
|
||||||
]
|
]
|
||||||
return subprocess.check_output(args)
|
return subprocess.check_output(args).decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def split_patches(patch_data):
|
def split_patches(patch_data):
|
||||||
|
@ -252,9 +260,13 @@ def remove_patch_filename(patch):
|
||||||
force_keep_next_line = False
|
force_keep_next_line = False
|
||||||
for i, l in enumerate(patch):
|
for i, l in enumerate(patch):
|
||||||
is_patchfilename = l.startswith('Patch-Filename: ')
|
is_patchfilename = l.startswith('Patch-Filename: ')
|
||||||
next_is_patchfilename = i < len(patch) - 1 and patch[i+1].startswith('Patch-Filename: ')
|
next_is_patchfilename = i < len(patch) - 1 and patch[i + 1].startswith(
|
||||||
if not force_keep_next_line and (is_patchfilename or (next_is_patchfilename and len(l.rstrip()) == 0)):
|
'Patch-Filename: '
|
||||||
pass # drop this line
|
)
|
||||||
|
if not force_keep_next_line and (
|
||||||
|
is_patchfilename or (next_is_patchfilename and len(l.rstrip()) == 0)
|
||||||
|
):
|
||||||
|
pass # drop this line
|
||||||
else:
|
else:
|
||||||
yield l
|
yield l
|
||||||
force_keep_next_line = l.startswith('Subject: ')
|
force_keep_next_line = l.startswith('Subject: ')
|
||||||
|
@ -263,7 +275,9 @@ def remove_patch_filename(patch):
|
||||||
def export_patches(repo, out_dir, patch_range=None, dry_run=False):
|
def export_patches(repo, out_dir, patch_range=None, dry_run=False):
|
||||||
if patch_range is None:
|
if patch_range is None:
|
||||||
patch_range, num_patches = guess_base_commit(repo)
|
patch_range, num_patches = guess_base_commit(repo)
|
||||||
sys.stderr.write("Exporting {} patches since {}\n".format(num_patches, patch_range))
|
sys.stderr.write(
|
||||||
|
"Exporting {} patches since {}\n".format(num_patches, patch_range)
|
||||||
|
)
|
||||||
patch_data = format_patch(repo, patch_range)
|
patch_data = format_patch(repo, patch_range)
|
||||||
patches = split_patches(patch_data)
|
patches = split_patches(patch_data)
|
||||||
|
|
||||||
|
@ -274,31 +288,46 @@ def export_patches(repo, out_dir, patch_range=None, dry_run=False):
|
||||||
|
|
||||||
if dry_run:
|
if dry_run:
|
||||||
# If we're doing a dry run, iterate through each patch and see if the newly
|
# If we're doing a dry run, iterate through each patch and see if the newly
|
||||||
# exported patch differs from what exists. Report number of mismatched patches
|
# exported patch differs from what exists. Report number of mismatched
|
||||||
# and fail if there's more than one.
|
# patches and fail if there's more than one.
|
||||||
patch_count = 0
|
patch_count = 0
|
||||||
for patch in patches:
|
for patch in patches:
|
||||||
filename = get_file_name(patch)
|
filename = get_file_name(patch)
|
||||||
filepath = os.path.join(out_dir, filename)
|
filepath = posixpath.join(out_dir, filename)
|
||||||
existing_patch = open(filepath, 'r').read()
|
existing_patch = io.open(filepath, 'r', encoding='utf-8').read()
|
||||||
formatted_patch = '\n'.join(remove_patch_filename(patch)).rstrip('\n') + '\n'
|
formatted_patch = (
|
||||||
|
'\n'.join(remove_patch_filename(patch)).rstrip('\n') + '\n'
|
||||||
|
)
|
||||||
if formatted_patch != existing_patch:
|
if formatted_patch != existing_patch:
|
||||||
patch_count += 1
|
patch_count += 1
|
||||||
if patch_count > 0:
|
if patch_count > 0:
|
||||||
sys.stderr.write("Patches in {} not up to date: {} patches need update\n".format(out_dir, patch_count))
|
sys.stderr.write(
|
||||||
|
"Patches in {} not up to date: {} patches need update\n".format(
|
||||||
|
out_dir, patch_count
|
||||||
|
)
|
||||||
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
# Remove old patches so that deleted commits are correctly reflected in the
|
# Remove old patches so that deleted commits are correctly reflected in the
|
||||||
# patch files (as a removed file)
|
# patch files (as a removed file)
|
||||||
for p in os.listdir(out_dir):
|
for p in os.listdir(out_dir):
|
||||||
if p.endswith('.patch'):
|
if p.endswith('.patch'):
|
||||||
os.remove(os.path.join(out_dir, p))
|
os.remove(posixpath.join(out_dir, p))
|
||||||
with open(os.path.join(out_dir, '.patches'), 'w') as pl:
|
with io.open(
|
||||||
|
posixpath.join(out_dir, '.patches'),
|
||||||
|
'w',
|
||||||
|
newline='\n',
|
||||||
|
encoding='utf-8',
|
||||||
|
) as pl:
|
||||||
for patch in patches:
|
for patch in patches:
|
||||||
filename = get_file_name(patch)
|
filename = get_file_name(patch)
|
||||||
file_path = os.path.join(out_dir, filename)
|
file_path = posixpath.join(out_dir, filename)
|
||||||
formatted_patch = '\n'.join(remove_patch_filename(patch)).rstrip('\n') + '\n'
|
formatted_patch = (
|
||||||
with open(file_path, 'w') as f:
|
'\n'.join(remove_patch_filename(patch)).rstrip('\n') + '\n'
|
||||||
|
)
|
||||||
|
with io.open(
|
||||||
|
file_path, 'w', newline='\n', encoding='utf-8'
|
||||||
|
) as f:
|
||||||
f.write(formatted_patch)
|
f.write(formatted_patch)
|
||||||
pl.write(filename + '\n')
|
pl.write(filename + '\n')
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,7 @@ def run_python_upload_script(script, *args):
|
||||||
|
|
||||||
|
|
||||||
def get_electron_build_version():
|
def get_electron_build_version():
|
||||||
if get_target_arch().startswith('arm') or os.environ.has_key('CI'):
|
if get_target_arch().startswith('arm') or 'CI' in os.environ:
|
||||||
# In CI we just build as told.
|
# In CI we just build as told.
|
||||||
return ELECTRON_VERSION
|
return ELECTRON_VERSION
|
||||||
electron = get_electron_exec()
|
electron = get_electron_exec()
|
||||||
|
|
Загрузка…
Ссылка в новой задаче