Class: XcodeArchiveCache::Injection::FrameworkEmbedder

Inherits:
Object
  • Object
show all
Includes:
Logs
Defined in:
lib/injection/framework_embedder.rb

Instance Method Summary collapse

Methods included from Logs

#debug, #error, #info, #set_log_level

Constructor Details

#initializeFrameworkEmbedder

Returns a new instance of FrameworkEmbedder.



7
8
9
# File 'lib/injection/framework_embedder.rb', line 7

def initialize
  @shell_executor = XcodeArchiveCache::Shell::Executor.new
end

Instance Method Details

#embed(framework_file_paths, target) ⇒ Object

Parameters:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/injection/framework_embedder.rb', line 14

def embed(framework_file_paths, target)
  return unless target.product_type == Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application]

  dynamic_framework_file_paths = framework_file_paths.select do |path|
    binary_name = File.basename(path, ".framework")
    binary_path = File.join(path, binary_name)
    shell_executor.execute("file #{binary_path} | grep dynamic")
  end

  return if dynamic_framework_file_paths.length == 0

  debug("Embedding frameworks:\n\t#{dynamic_framework_file_paths.join("\n\t")}")

  frameworks_group = target.project.main_group.new_group("XcodeArchiveCache Frameworks")
  file_references = dynamic_framework_file_paths.map {|file_path| frameworks_group.new_reference(file_path)}
  embed_frameworks_phase = target.new_copy_files_build_phase("Embed XcodeArchiveCache Frameworks")
  embed_frameworks_phase.symbol_dst_subfolder_spec = :frameworks
  embed_frameworks_phase.run_only_for_deployment_postprocessing = false

  file_references.each do |file_reference|
    build_file = target.project.new(Xcodeproj::Project::Object::PBXBuildFile)
    build_file.file_ref = file_reference
    build_file.settings = {"ATTRIBUTES" => %w(CodeSignOnCopy RemoveHeadersOnCopy)}
    build_file.add_referrer(frameworks_group)
    embed_frameworks_phase.files.push(build_file)
  end
end