|
@@ -4,7 +4,6 @@
|
|
|
# Copyright (c) 2018 The ungoogled-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.
|
|
|
-
|
|
|
"""
|
|
|
buildkit: A small helper utility for building ungoogled-chromium.
|
|
|
|
|
@@ -24,9 +23,11 @@ from .extraction import prune_dir
|
|
|
|
|
|
# Classes
|
|
|
|
|
|
+
|
|
|
class _CLIError(RuntimeError):
|
|
|
"""Custom exception for printing argument parser errors from callbacks"""
|
|
|
|
|
|
+
|
|
|
class NewBundleAction(argparse.Action): #pylint: disable=too-few-public-methods
|
|
|
"""argparse.ArgumentParser action handler with more verbose logging"""
|
|
|
|
|
@@ -46,35 +47,50 @@ class NewBundleAction(argparse.Action): #pylint: disable=too-few-public-methods
|
|
|
parser.exit(status=1)
|
|
|
setattr(namespace, self.dest, bundle)
|
|
|
|
|
|
+
|
|
|
# Methods
|
|
|
|
|
|
+
|
|
|
def setup_bundle_arg(parser):
|
|
|
"""Helper to add an argparse.ArgumentParser argument for a config bundle"""
|
|
|
parser.add_argument(
|
|
|
- '-b', '--bundle', metavar='PATH', dest='bundle', required=True, action=NewBundleAction,
|
|
|
+ '-b',
|
|
|
+ '--bundle',
|
|
|
+ metavar='PATH',
|
|
|
+ dest='bundle',
|
|
|
+ required=True,
|
|
|
+ action=NewBundleAction,
|
|
|
help='Path to the bundle. Dependencies must reside next to the bundle.')
|
|
|
|
|
|
+
|
|
|
def _add_downloads(subparsers):
|
|
|
"""Retrieve, check, and unpack downloads"""
|
|
|
+
|
|
|
def _add_common_args(parser):
|
|
|
setup_bundle_arg(parser)
|
|
|
parser.add_argument(
|
|
|
- '-c', '--cache', type=Path, required=True,
|
|
|
+ '-c',
|
|
|
+ '--cache',
|
|
|
+ type=Path,
|
|
|
+ required=True,
|
|
|
help='Path to the directory to cache downloads.')
|
|
|
+
|
|
|
def _retrieve_callback(args):
|
|
|
- downloads.retrieve_downloads(
|
|
|
- args.bundle, args.cache, args.show_progress, args.disable_ssl_verification)
|
|
|
+ downloads.retrieve_downloads(args.bundle, args.cache, args.show_progress,
|
|
|
+ args.disable_ssl_verification)
|
|
|
try:
|
|
|
downloads.check_downloads(args.bundle, args.cache)
|
|
|
except downloads.HashMismatchError as exc:
|
|
|
get_logger().error('File checksum does not match: %s', exc)
|
|
|
raise _CLIError()
|
|
|
+
|
|
|
def _unpack_callback(args):
|
|
|
extractors = {
|
|
|
ExtractorEnum.SEVENZIP: args.sevenz_path,
|
|
|
ExtractorEnum.TAR: args.tar_path,
|
|
|
}
|
|
|
downloads.unpack_downloads(args.bundle, args.cache, args.output, extractors)
|
|
|
+
|
|
|
# downloads
|
|
|
parser = subparsers.add_parser(
|
|
|
'downloads', help=_add_downloads.__doc__ + '.', description=_add_downloads.__doc__)
|
|
@@ -83,36 +99,45 @@ def _add_downloads(subparsers):
|
|
|
|
|
|
# downloads retrieve
|
|
|
retrieve_parser = subsubparsers.add_parser(
|
|
|
- 'retrieve', help='Retrieve and check download files',
|
|
|
+ 'retrieve',
|
|
|
+ help='Retrieve and check download files',
|
|
|
description='Retrieves and checks downloads without unpacking.')
|
|
|
_add_common_args(retrieve_parser)
|
|
|
retrieve_parser.add_argument(
|
|
|
- '--hide-progress-bar', action='store_false', dest='show_progress',
|
|
|
+ '--hide-progress-bar',
|
|
|
+ action='store_false',
|
|
|
+ dest='show_progress',
|
|
|
help='Hide the download progress.')
|
|
|
retrieve_parser.add_argument(
|
|
|
- '--disable-ssl-verification', action='store_true',
|
|
|
+ '--disable-ssl-verification',
|
|
|
+ action='store_true',
|
|
|
help='Disables certification verification for downloads using HTTPS.')
|
|
|
retrieve_parser.set_defaults(callback=_retrieve_callback)
|
|
|
|
|
|
# downloads unpack
|
|
|
unpack_parser = subsubparsers.add_parser(
|
|
|
- 'unpack', help='Unpack download files',
|
|
|
+ 'unpack',
|
|
|
+ help='Unpack download files',
|
|
|
description='Verifies hashes of and unpacks download files into the specified directory.')
|
|
|
_add_common_args(unpack_parser)
|
|
|
unpack_parser.add_argument(
|
|
|
- '--tar-path', default='tar',
|
|
|
+ '--tar-path',
|
|
|
+ default='tar',
|
|
|
help=('(Linux and macOS only) Command or path to the BSD or GNU tar '
|
|
|
'binary for extraction. Default: %(default)s'))
|
|
|
unpack_parser.add_argument(
|
|
|
- '--7z-path', dest='sevenz_path', default=SEVENZIP_USE_REGISTRY,
|
|
|
+ '--7z-path',
|
|
|
+ dest='sevenz_path',
|
|
|
+ default=SEVENZIP_USE_REGISTRY,
|
|
|
help=('Command or path to 7-Zip\'s "7z" binary. If "_use_registry" is '
|
|
|
'specified, determine the path from the registry. Default: %(default)s'))
|
|
|
- unpack_parser.add_argument(
|
|
|
- 'output', type=Path, help='The directory to unpack to.')
|
|
|
+ unpack_parser.add_argument('output', type=Path, help='The directory to unpack to.')
|
|
|
unpack_parser.set_defaults(callback=_unpack_callback)
|
|
|
|
|
|
+
|
|
|
def _add_prune(subparsers):
|
|
|
"""Prunes binaries in the given path."""
|
|
|
+
|
|
|
def _callback(args):
|
|
|
if not args.directory.exists():
|
|
|
get_logger().error('Specified directory does not exist: %s', args.directory)
|
|
@@ -121,15 +146,16 @@ def _add_prune(subparsers):
|
|
|
if unremovable_files:
|
|
|
get_logger().error('Files could not be pruned: %s', unremovable_files)
|
|
|
raise _CLIError()
|
|
|
- parser = subparsers.add_parser(
|
|
|
- 'prune', help=_add_prune.__doc__, description=_add_prune.__doc__)
|
|
|
+
|
|
|
+ parser = subparsers.add_parser('prune', help=_add_prune.__doc__, description=_add_prune.__doc__)
|
|
|
setup_bundle_arg(parser)
|
|
|
- parser.add_argument(
|
|
|
- 'directory', type=Path, help='The directory to apply binary pruning.')
|
|
|
+ parser.add_argument('directory', type=Path, help='The directory to apply binary pruning.')
|
|
|
parser.set_defaults(callback=_callback)
|
|
|
|
|
|
+
|
|
|
def _add_domains(subparsers):
|
|
|
"""Operations with domain substitution"""
|
|
|
+
|
|
|
def _callback(args):
|
|
|
try:
|
|
|
if args.reverting:
|
|
@@ -148,6 +174,7 @@ def _add_domains(subparsers):
|
|
|
except KeyError as exc:
|
|
|
get_logger().error('%s', exc)
|
|
|
raise _CLIError()
|
|
|
+
|
|
|
# domains
|
|
|
parser = subparsers.add_parser(
|
|
|
'domains', help=_add_domains.__doc__, description=_add_domains.__doc__)
|
|
@@ -158,39 +185,49 @@ def _add_domains(subparsers):
|
|
|
|
|
|
# domains apply
|
|
|
apply_parser = subsubparsers.add_parser(
|
|
|
- 'apply', help='Apply domain substitution',
|
|
|
+ 'apply',
|
|
|
+ help='Apply domain substitution',
|
|
|
description='Applies domain substitution and creates the domain substitution cache.')
|
|
|
setup_bundle_arg(apply_parser)
|
|
|
apply_parser.add_argument(
|
|
|
- '-c', '--cache', type=Path, required=True,
|
|
|
+ '-c',
|
|
|
+ '--cache',
|
|
|
+ type=Path,
|
|
|
+ required=True,
|
|
|
help='The path to the domain substitution cache. The path must not already exist.')
|
|
|
apply_parser.add_argument(
|
|
|
- 'directory', type=Path,
|
|
|
- help='The directory to apply domain substitution')
|
|
|
+ 'directory', type=Path, help='The directory to apply domain substitution')
|
|
|
apply_parser.set_defaults(reverting=False)
|
|
|
|
|
|
# domains revert
|
|
|
revert_parser = subsubparsers.add_parser(
|
|
|
- 'revert', help='Revert domain substitution',
|
|
|
+ 'revert',
|
|
|
+ help='Revert domain substitution',
|
|
|
description='Reverts domain substitution based only on the domain substitution cache.')
|
|
|
revert_parser.add_argument(
|
|
|
- 'directory', type=Path,
|
|
|
- help='The directory to reverse domain substitution')
|
|
|
+ 'directory', type=Path, help='The directory to reverse domain substitution')
|
|
|
revert_parser.add_argument(
|
|
|
- '-c', '--cache', type=Path, required=True,
|
|
|
+ '-c',
|
|
|
+ '--cache',
|
|
|
+ type=Path,
|
|
|
+ required=True,
|
|
|
help=('The path to the domain substitution cache. '
|
|
|
'The path must exist and will be removed if successful.'))
|
|
|
revert_parser.set_defaults(reverting=True)
|
|
|
|
|
|
+
|
|
|
def _add_patches(subparsers):
|
|
|
"""Operations with patches"""
|
|
|
+
|
|
|
def _export_callback(args):
|
|
|
patches.export_patches(args.bundle, args.output)
|
|
|
+
|
|
|
def _apply_callback(args):
|
|
|
patches.apply_patches(
|
|
|
patches.patch_paths_by_bundle(args.bundle),
|
|
|
args.directory,
|
|
|
patch_bin_path=args.patch_bin)
|
|
|
+
|
|
|
# patches
|
|
|
parser = subparsers.add_parser(
|
|
|
'patches', help=_add_patches.__doc__, description=_add_patches.__doc__)
|
|
@@ -199,11 +236,13 @@ def _add_patches(subparsers):
|
|
|
|
|
|
# patches export
|
|
|
export_parser = subsubparsers.add_parser(
|
|
|
- 'export', help='Export patches in GNU quilt-compatible format',
|
|
|
+ 'export',
|
|
|
+ help='Export patches in GNU quilt-compatible format',
|
|
|
description='Export a config bundle\'s patches to a quilt-compatible format')
|
|
|
setup_bundle_arg(export_parser)
|
|
|
export_parser.add_argument(
|
|
|
- 'output', type=Path,
|
|
|
+ 'output',
|
|
|
+ type=Path,
|
|
|
help='The directory to write to. It must either be empty or not exist.')
|
|
|
export_parser.set_defaults(callback=_export_callback)
|
|
|
|
|
@@ -216,10 +255,13 @@ def _add_patches(subparsers):
|
|
|
apply_parser.add_argument('directory', type=Path, help='The source tree to apply patches.')
|
|
|
apply_parser.set_defaults(callback=_apply_callback)
|
|
|
|
|
|
+
|
|
|
def _add_gnargs(subparsers):
|
|
|
"""Operations with GN arguments"""
|
|
|
+
|
|
|
def _print_callback(args):
|
|
|
print(str(args.bundle.gn_flags), end='')
|
|
|
+
|
|
|
# gnargs
|
|
|
parser = subparsers.add_parser(
|
|
|
'gnargs', help=_add_gnargs.__doc__, description=_add_gnargs.__doc__)
|
|
@@ -227,15 +269,17 @@ def _add_gnargs(subparsers):
|
|
|
|
|
|
# gnargs print
|
|
|
print_parser = subsubparsers.add_parser(
|
|
|
- 'print', help='Prints GN args in args.gn format',
|
|
|
+ 'print',
|
|
|
+ help='Prints GN args in args.gn format',
|
|
|
description='Prints a list of GN args in args.gn format to standard output')
|
|
|
setup_bundle_arg(print_parser)
|
|
|
print_parser.set_defaults(callback=_print_callback)
|
|
|
|
|
|
+
|
|
|
def main(arg_list=None):
|
|
|
"""CLI entry point"""
|
|
|
- parser = argparse.ArgumentParser(description=__doc__,
|
|
|
- formatter_class=argparse.RawTextHelpFormatter)
|
|
|
+ parser = argparse.ArgumentParser(
|
|
|
+ description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
|
|
|
|
|
|
subparsers = parser.add_subparsers(title='Available commands', dest='command')
|
|
|
subparsers.required = True # Workaround for http://bugs.python.org/issue9253#msg186387
|