Exemple #1
0
def _main() -> Optional[int]:
    options = PackagerOptions()
    options.parse_args()

    augment_module_search_paths(options=options)

    context = PackagerContext(options)
    context.init_logging(options.verbosity)
    logging_ext.setup_stacktrace_signal()

    executor_type = concurrent.futures.ThreadPoolExecutor
    max_workers = None
    if context.lief_info.not_threadsafe:
        # FIXME: ProcessPoolExecutor causes RuntimeError: Queue objects should only be shared...
        #executor_type = concurrent.futures.ProcessPoolExecutor
        max_workers = 1

    with executor_type(max_workers=max_workers) as executor:
        packager = Packager(context, executor)
        packager.prepare_workspace()
        packager.prepare_icommands()
        packager.prepare_irods_runtime()
        packager.gather_ext_lib_paths()
        packager.prepare_ext_libs()
        packager.set_runpaths()
        packager.create_tarball()
Exemple #2
0
def _main() -> int:
    l = logging.getLogger(__name__)  # noqa: VNE001,E741

    options = StripUtilOptions()
    options.parse_args()

    augment_module_search_paths(options=options)

    context = PackagerContext[StripUtilOptions](options)
    context.init_logging(options.verbosity)
    logging_ex.setup_stacktrace_signal()

    output_path_is_dir = options.output_path is not None and path.isdir(
        options.output_path)

    if len(
            options.libraries
    ) > 1 and options.output_path is not None and not output_path_is_dir:
        l.error(
            'Multiple libraries passed in, but output path %s is not a directory',
            options.output_path)
        return errno.ENOTDIR

    context.lief_info.check_and_whine()
    if not context.lief_info.lief_usable:
        l.warning(
            'lief functionality not available, skipping removal of unneeded library imports.'
        )

    libinfo_util = ElfInfoUtil(context)
    strip_util = StripUtil(context,
                           libinfo_util,
                           raise_if_strip_not_found=True)

    for libpath in options.libraries:
        # We don't want to re-evaluate whether output_path is a dir every time, in case it
        # is deleted midway through. We evaluate once, and pre-evaluate full destinations
        # to avoid this potential race condition
        output_path = options.output_path
        if output_path_is_dir:
            output_path = path.join(output_path, path.basename(libpath))
            # if output_path is still a directory, panic
            if path.isdir(output_path):
                l.error('destination path %s is a directory.', output_path)
                return errno.EISDIR

        strip_util.strip_and_clean(libpath, output_path=output_path)

    return 0