Example #1
0
def _lipo_exec_files(exec_files, target_archs, strip_bitcode, source_path,
                     destination_path):
    """Strips executable files if needed and copies them to the destination."""
    # Find all architectures from the set of files we might have to lipo.
    exec_archs = lipo.find_archs_for_binaries(
        [os.path.join(source_path, f) for f in exec_files])

    # Ensure directory for remote execution
    if not os.path.exists(destination_path):
        os.makedirs(destination_path)

    # Copy or lipo each file as needed, from source to destination.
    for exec_file in exec_files:
        exec_file_source_path = os.path.join(source_path, exec_file)
        exec_file_destination_path = os.path.join(destination_path, exec_file)
        if len(exec_archs) == 1 or target_archs == exec_archs:
            # If there is no need to lipo, copy and mark as executable.
            shutil.copy(exec_file_source_path, exec_file_destination_path)
            os.chmod(exec_file_destination_path, 0o755)
        else:
            lipo.invoke_lipo(exec_file_source_path, target_archs,
                             exec_file_destination_path)
        if strip_bitcode:
            bitcode_strip.invoke(exec_file_destination_path,
                                 exec_file_destination_path)
Example #2
0
def _lipo_exec_files(exec_files, target_archs, strip_bitcode, source_path,
                     destination_path):
    """Strips executable files if needed and copies them to the destination."""
    # Find all architectures from the set of files we might have to lipo.
    _, exec_archs = lipo.find_archs_for_binaries(
        [os.path.join(source_path, f) for f in exec_files])

    # Copy or lipo each file as needed, from source to destination.
    for exec_file in exec_files:
        exec_file_source_path = os.path.join(source_path, exec_file)
        exec_file_destination_path = os.path.join(destination_path, exec_file)
        file_archs = exec_archs[exec_file_source_path]

        archs_to_keep = target_archs & file_archs

        # On M1 hardware, thin x86_64 libraries do not need lipo when archs_to_keep
        # is empty.
        if len(file_archs
               ) == 1 or archs_to_keep == file_archs or not archs_to_keep:
            # If there is no need to lipo, copy and mark as executable.
            shutil.copy(exec_file_source_path, exec_file_destination_path)
            os.chmod(exec_file_destination_path, 0o755)
        else:
            lipo.invoke_lipo(exec_file_source_path, archs_to_keep,
                             exec_file_destination_path)
        if strip_bitcode:
            bitcode_strip.invoke(exec_file_destination_path,
                                 exec_file_destination_path)
Example #3
0
def _strip_framework_binary(framework_binary, output_path, slices_needed):
  """Strips the binary to only the slices needed, saves output to given path."""
  if not slices_needed:
    print("Internal Error: Did not specify any slices needed for binary at "
          "path: " + framework_binary)
    return 1

  path_from_framework = _relpath_from_framework(framework_binary)
  if not path_from_framework:
    return 1

  temp_framework_path = os.path.join(output_path, path_from_framework)

  lipo.invoke_lipo(framework_binary, slices_needed, temp_framework_path)