build: fix python util verbose mode logic (#44452)
build: fix verbose mode logic Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
parent
1cbd5f451a
commit
b4a5684493
5 changed files with 46 additions and 25 deletions
2
.github/actions/build-electron/action.yml
vendored
2
.github/actions/build-electron/action.yml
vendored
|
@ -63,7 +63,7 @@ runs:
|
||||||
run: |
|
run: |
|
||||||
cd src
|
cd src
|
||||||
electron/script/copy-debug-symbols.py --target-cpu="${{ inputs.target-arch }}" --out-dir=out/Default/debug --compress
|
electron/script/copy-debug-symbols.py --target-cpu="${{ inputs.target-arch }}" --out-dir=out/Default/debug --compress
|
||||||
electron/script/strip-binaries.py --target-cpu="${{ inputs.target-arch }}"
|
electron/script/strip-binaries.py --target-cpu="${{ inputs.target-arch }}" --verbose
|
||||||
electron/script/add-debug-link.py --target-cpu="${{ inputs.target-arch }}" --debug-dir=out/Default/debug
|
electron/script/add-debug-link.py --target-cpu="${{ inputs.target-arch }}" --debug-dir=out/Default/debug
|
||||||
- name: Build Electron dist.zip ${{ inputs.step-suffix }}
|
- name: Build Electron dist.zip ${{ inputs.step-suffix }}
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
|
@ -28,16 +28,17 @@ def get_target_arch():
|
||||||
return 'x64'
|
return 'x64'
|
||||||
return arch
|
return arch
|
||||||
|
|
||||||
|
def set_verbose_mode(mode):
|
||||||
def enable_verbose_mode():
|
|
||||||
print('Running in verbose mode')
|
print('Running in verbose mode')
|
||||||
global verbose_mode
|
global verbose_mode
|
||||||
verbose_mode = True
|
verbose_mode = mode
|
||||||
|
|
||||||
|
|
||||||
def is_verbose_mode():
|
def is_verbose_mode():
|
||||||
return verbose_mode
|
return verbose_mode
|
||||||
|
|
||||||
|
def verbose_mode_print(output):
|
||||||
|
if verbose_mode:
|
||||||
|
print(output)
|
||||||
|
|
||||||
def get_zip_name(name, version, suffix=''):
|
def get_zip_name(name, version, suffix=''):
|
||||||
arch = get_target_arch()
|
arch = get_target_arch()
|
||||||
|
|
|
@ -11,9 +11,7 @@ import sys
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
# from lib.config import is_verbose_mode
|
from lib.config import verbose_mode_print
|
||||||
def is_verbose_mode():
|
|
||||||
return False
|
|
||||||
|
|
||||||
ELECTRON_DIR = os.path.abspath(
|
ELECTRON_DIR = os.path.abspath(
|
||||||
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||||
|
@ -112,13 +110,11 @@ def safe_mkdir(path):
|
||||||
def execute(argv, env=None, cwd=None):
|
def execute(argv, env=None, cwd=None):
|
||||||
if env is None:
|
if env is None:
|
||||||
env = os.environ
|
env = os.environ
|
||||||
if is_verbose_mode():
|
verbose_mode_print(' '.join(argv))
|
||||||
print(' '.join(argv))
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(argv, stderr=subprocess.STDOUT,
|
output = subprocess.check_output(argv, stderr=subprocess.STDOUT,
|
||||||
env=env, cwd=cwd)
|
env=env, cwd=cwd)
|
||||||
if is_verbose_mode():
|
verbose_mode_print(output.decode('utf-8').strip())
|
||||||
print(output)
|
|
||||||
return output
|
return output
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(e.output)
|
print(e.output)
|
||||||
|
|
|
@ -16,8 +16,9 @@ sys.path.append(
|
||||||
|
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
from lib.config import PLATFORM, get_target_arch, \
|
from lib.config import PLATFORM, get_target_arch, \
|
||||||
get_zip_name, enable_verbose_mode, \
|
get_zip_name, set_verbose_mode, \
|
||||||
is_verbose_mode, get_platform_key
|
is_verbose_mode, get_platform_key, \
|
||||||
|
verbose_mode_print
|
||||||
from lib.util import get_electron_branding, execute, get_electron_version, \
|
from lib.util import get_electron_branding, execute, get_electron_version, \
|
||||||
store_artifact, get_electron_exec, get_out_dir, \
|
store_artifact, get_electron_exec, get_out_dir, \
|
||||||
SRC_DIR, ELECTRON_DIR, TS_NODE
|
SRC_DIR, ELECTRON_DIR, TS_NODE
|
||||||
|
@ -45,8 +46,7 @@ CXX_OBJECTS_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION,
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if args.verbose:
|
set_verbose_mode(args.verbose)
|
||||||
enable_verbose_mode()
|
|
||||||
if args.upload_to_storage:
|
if args.upload_to_storage:
|
||||||
utcnow = datetime.datetime.now(datetime.UTC)
|
utcnow = datetime.datetime.now(datetime.UTC)
|
||||||
args.upload_timestamp = utcnow.strftime('%Y%m%d')
|
args.upload_timestamp = utcnow.strftime('%Y%m%d')
|
||||||
|
@ -391,9 +391,8 @@ def get_release(version):
|
||||||
release_env = os.environ.copy()
|
release_env = os.environ.copy()
|
||||||
release_env['NODE_NO_WARNINGS'] = '1'
|
release_env['NODE_NO_WARNINGS'] = '1'
|
||||||
release_info = execute([TS_NODE, script_path, version], release_env)
|
release_info = execute([TS_NODE, script_path, version], release_env)
|
||||||
if is_verbose_mode():
|
verbose_mode_print(f'Release info for version: {version}:\n')
|
||||||
print(f'Release info for version: {version}:\n')
|
verbose_mode_print(release_info)
|
||||||
print(release_info)
|
|
||||||
release = json.loads(release_info)
|
release = json.loads(release_info)
|
||||||
return release
|
return release
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,26 @@ import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from lib.config import enable_verbose_mode
|
from lib.config import set_verbose_mode, is_verbose_mode, verbose_mode_print
|
||||||
from lib.util import execute, get_linux_binaries, get_out_dir
|
from lib.util import execute, get_linux_binaries, get_out_dir
|
||||||
|
|
||||||
|
def get_size(path):
|
||||||
|
size = os.path.getsize(path)
|
||||||
|
units = ["bytes", "KB", "MB", "GB"]
|
||||||
|
for unit in units:
|
||||||
|
if size < 1024:
|
||||||
|
return f"{size:.2f} {unit}"
|
||||||
|
size /= 1024
|
||||||
|
raise ValueError("File size is too large to be processed")
|
||||||
|
|
||||||
def strip_binaries(directory, target_cpu):
|
def strip_binaries(directory, target_cpu):
|
||||||
|
if not os.path.isdir(directory):
|
||||||
|
verbose_mode_print('Directory ' + directory + ' does not exist.')
|
||||||
|
return
|
||||||
|
|
||||||
|
verbose_mode_print('Stripping binaries in ' + directory)
|
||||||
for binary in get_linux_binaries():
|
for binary in get_linux_binaries():
|
||||||
|
verbose_mode_print('\nStripping ' + binary)
|
||||||
binary_path = os.path.join(directory, binary)
|
binary_path = os.path.join(directory, binary)
|
||||||
if os.path.isfile(binary_path):
|
if os.path.isfile(binary_path):
|
||||||
strip_binary(binary_path, target_cpu)
|
strip_binary(binary_path, target_cpu)
|
||||||
|
@ -20,14 +35,23 @@ def strip_binary(binary_path, target_cpu):
|
||||||
strip = 'aarch64-linux-gnu-strip'
|
strip = 'aarch64-linux-gnu-strip'
|
||||||
else:
|
else:
|
||||||
strip = 'strip'
|
strip = 'strip'
|
||||||
execute([
|
|
||||||
strip, '--discard-all', '--strip-debug', '--preserve-dates',
|
strip_args = [strip,
|
||||||
binary_path])
|
'--discard-all',
|
||||||
|
'--strip-debug',
|
||||||
|
'--preserve-dates',
|
||||||
|
binary_path]
|
||||||
|
if (is_verbose_mode()):
|
||||||
|
strip_args.insert(1, '--verbose')
|
||||||
|
verbose_mode_print('Binary size before stripping: ' +
|
||||||
|
str(get_size(binary_path)))
|
||||||
|
execute(strip_args)
|
||||||
|
verbose_mode_print('Binary size after stripping: ' +
|
||||||
|
str(get_size(binary_path)))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if args.verbose:
|
set_verbose_mode(args.verbose)
|
||||||
enable_verbose_mode()
|
|
||||||
if args.file:
|
if args.file:
|
||||||
strip_binary(args.file, args.target_cpu)
|
strip_binary(args.file, args.target_cpu)
|
||||||
else:
|
else:
|
||||||
|
@ -43,6 +67,7 @@ def parse_args():
|
||||||
help='Path to a specific file to strip.',
|
help='Path to a specific file to strip.',
|
||||||
required=False)
|
required=False)
|
||||||
parser.add_argument('-v', '--verbose',
|
parser.add_argument('-v', '--verbose',
|
||||||
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Prints the output of the subprocesses')
|
help='Prints the output of the subprocesses')
|
||||||
parser.add_argument('--target-cpu',
|
parser.add_argument('--target-cpu',
|
||||||
|
|
Loading…
Reference in a new issue