class CarthageArchive

Attributes

archive_filename[R]
archive_path[R]

Public Class Methods

new(framework_name, platform) click to toggle source
# File lib/carthage_archive.rb, line 6
def initialize(framework_name, platform)
  raise AppError.new, "Platform #{platform.inspect} needs to be a symbol" unless platform.kind_of?(Symbol)

  @framework_name = framework_name
  @platform = platform
  @archive_filename = "#{framework_name}-#{platform}.zip"
  @archive_path = @archive_filename
end

Public Instance Methods

archive_size() click to toggle source
# File lib/carthage_archive.rb, line 64
def archive_size
  raise AppError.new, "Archive #{@archive_path} is missing" unless File.exist?(@archive_path)
  File.size(@archive_path)
end
create_archive(shell, carthage_build_dir = CARTHAGE_BUILD_DIR) click to toggle source

Aggregate following files:

  • Carthage/Build/iOS/Alamofire.framework

  • Carthage/Build/iOS/Alamofire.framework/Alamofire

  • Carthage/Build/iOS/618BEB79-4C7F-3692-B140-131FB983AC5E.bcsymbolmap

into Alamofire-iOS.zip

# File lib/carthage_archive.rb, line 20
def create_archive(shell, carthage_build_dir = CARTHAGE_BUILD_DIR)
  $LOG.debug("Archiving #{@framework_name} for #{@platform}")

  platform_path = File.join(carthage_build_dir, platform_to_carthage_dir_string(@platform))
  framework_path = File.join(platform_path, "#{@framework_name}.framework")
  raise MissingFrameworkDirectoryError.new, "Archive can't be created, no framework directory at #{framework_path}" unless Dir.exist?(framework_path)

  # It's very likely, that binary releases don't contain DSYMs.
  dsym_path = File.join(platform_path, "#{@framework_name}.framework.dSYM")
  unless File.exist?(dsym_path)
    $LOG.error("DSYM File #{dsym_path} not found, continuing")
    dsym_path = nil
  end

  binary_path = File.join(framework_path, @framework_name)
  raise AppError.new, "Binary #{binary_path} is missing, failed to read .bcsymbolmap files" unless File.exist?(binary_path)

  bcsymbolmap_paths = find_bcsymbolmap_paths(shell, platform_path, binary_path)

  input_paths = []
  input_paths << framework_path
  input_paths << dsym_path unless dsym_path.nil?
  input_paths += bcsymbolmap_paths

  $LOG.debug("Adding > #{input_paths.inspect}")

  delete_archive
  shell.archive(input_paths, @archive_path)
  $LOG.debug("Created #{@archive_path} archive, file size: #{formatted_archive_size}")
end
delete_archive() click to toggle source
# File lib/carthage_archive.rb, line 60
def delete_archive
  File.delete(@archive_path) if File.exist?(@archive_path)
end
unpack_archive(shell, carthage_build_dir = CARTHAGE_BUILD_DIR) click to toggle source
# File lib/carthage_archive.rb, line 51
def unpack_archive(shell, carthage_build_dir = CARTHAGE_BUILD_DIR)
  raise AppError.new, "Archive #{@archive_path} is missing" unless File.exist?(@archive_path)

  delete_existing_build_framework_if_exists(carthage_build_dir)

  $LOG.debug("Unpacking #{@archive_path}, file size: #{formatted_archive_size}")
  shell.unpack(@archive_path)
end

Private Instance Methods

delete_existing_build_framework_if_exists(carthage_build_dir) click to toggle source
# File lib/carthage_archive.rb, line 90
def delete_existing_build_framework_if_exists(carthage_build_dir)
  platform_path = File.join(carthage_build_dir, platform_to_carthage_dir_string(@platform))
  framework_path = File.join(platform_path, "#{@framework_name}.framework")
  if File.exist?(framework_path)
    $LOG.debug("Deleting #{framework_path}")
    FileUtils.rm_rf(framework_path)
  end
end
find_bcsymbolmap_paths(shell, platform_path, binary_path) click to toggle source
# File lib/carthage_archive.rb, line 71
def find_bcsymbolmap_paths(shell, platform_path, binary_path)
  raw_dwarfdump = shell.dwarfdump(binary_path)
  uuids = parse_uuids(raw_dwarfdump)
  bcsymbolmap_paths = uuids.map { |uuid| File.join(platform_path, "#{uuid}.bcsymbolmap") }.select { |path| File.exist?(path) }
  bcsymbolmap_paths
end
formatted_archive_size() click to toggle source
# File lib/carthage_archive.rb, line 86
def formatted_archive_size
  format_file_size(archive_size)
end
parse_uuids(raw_dwarfdump) click to toggle source

Example dwarfdump link: UUID: 618BEB79-4C7F-3692-B140-131FB983AC5E (i386) Carthage/Build/iOS/CocoaLumberjackSwift.framework/CocoaLumberjackSwift

# File lib/carthage_archive.rb, line 80
def parse_uuids(raw_dwarfdump)
  lines = raw_dwarfdump.split("\n")
  uuids = lines.map { |line| line[/^UUID: ([A-Z0-9\-]+)\s+\(.*$/, 1] }
  uuids.compact
end