Module: HMap::Helper::Pods

Defined in:
lib/cocoapods-hmap/helper/pods_helper.rb

Overview

A collection of Pods Helper functions used throughout cocoapods-hmap.

Class Method Summary collapse

Class Method Details

.header_mappings(target, type = :source_files) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cocoapods-hmap/helper/pods_helper.rb', line 57

def self.header_mappings(target, type = :source_files)
  mappings = {}
  h_headers = lambda { |headers, h_type|
    root = Pod::Config.instance.sandbox.root.join(target.headers_sandbox)
    case h_type
    when :private_header_files
      headers << target.prefix_header_path if target.build_as_framework?
      headers.each do |header|
        mappings[HEAD_SEARCH_IQUOTE] ||= []
        mappings[HEAD_SEARCH_IQUOTE] << [header.basename.to_s, "#{header.dirname}/", header.basename.to_s]
        r_header_path = header.relative_path_from(root)
        mappings[HEAD_SEARCH_IQUOTE] << [r_header_path.to_s, "#{header.dirname}/", header.basename.to_s]
      end
    when :public_header_files
      headers << target.umbrella_header_path if target.build_as_framework?
      headers.each do |header|
        mappings[HEAD_SEARCH_IQUOTE] ||= []
        mappings[HEAD_SEARCH_IQUOTE] << [header.basename.to_s, "#{target.product_module_name}/",
                                         header.basename.to_s]
        r_header_path = header.relative_path_from(root)
        mappings[HEAD_SEARCH_IQUOTE] << [r_header_path.to_s, "#{header.dirname}/", header.basename.to_s]
        mappings[HEAD_SEARCH_I] ||= []
        mappings[HEAD_SEARCH_I] << [r_header_path.to_s, "#{header.dirname}/", header.basename.to_s]
        mappings[HEAD_SEARCH_I] << [header.basename.to_s, "#{target.product_module_name}/",
                                    header.basename.to_s]

        mappings[HEAD_SEARCH_I] << ["#{target.product_module_name}/#{header.basename}", "#{header.dirname}/",
                                    header.basename.to_s]
      end
    end
  }

  valid_accessors = target.file_accessors.reject { |fa| fa.spec.non_library_specification? }
  valid_accessors.each do |file_accessor|
    case type
    when :private_header_files then h_headers.call(file_accessor.headers - file_accessor.public_headers,
                                                   :private_header_files)
    when :source_files
      h_headers.call(file_accessor.headers - file_accessor.public_headers, :private_header_files)
      h_headers.call(file_accessor.public_headers, :public_header_files)
    when :public_header_files then h_headers.call(file_accessor.public_headers, :public_header_files)
    end
  end
  mappings
end

.headers_mappings_by_file_accessor(target, type = :source_files) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/cocoapods-hmap/helper/pods_helper.rb', line 46

def self.headers_mappings_by_file_accessor(target, type = :source_files)
  valid_accessors = target.file_accessors.reject { |fa| fa.spec.non_library_specification? }
  valid_accessors.each_with_object([]) do |file_accessor, sum|
    sum << case type
           when :private_header_files then file_accessor.headers - file_accessor.public_headers
           when :source_files then file_accessor.headers
           when :public_header_files then file_accessor.public_headers
           end
  end.flatten
end

.hmap_files_dirObject



12
13
14
# File 'lib/cocoapods-hmap/helper/pods_helper.rb', line 12

def self.hmap_files_dir
  Pathname(File.join(Pod::Config.instance.sandbox.headers_root, HMAP_DIR))
end

.hmap_files_paths(name) ⇒ Object



20
21
22
# File 'lib/cocoapods-hmap/helper/pods_helper.rb', line 20

def self.hmap_files_paths(name)
  [hmap_files_dir.join("#{name}.hmap"), hmap_files_dir.join("#{name}-iquote.hmap")]
end

.pods_hmap_files_dirObject



24
25
26
# File 'lib/cocoapods-hmap/helper/pods_helper.rb', line 24

def self.pods_hmap_files_dir
  "${PODS_ROOT}/Headers/#{HMAP_DIR}"
end

.target_support_platforms(spec_path) ⇒ Object



41
42
43
44
# File 'lib/cocoapods-hmap/helper/pods_helper.rb', line 41

def self.target_support_platforms(spec_path)
  validator = Pod::Validator.new(spec_path, Pod::Config.instance.sources_manager.master.map(&:url))
  validator.platforms_to_lint(validator.spec).map(&:name)
end

.vfs_files_dirObject



16
17
18
# File 'lib/cocoapods-hmap/helper/pods_helper.rb', line 16

def self.vfs_files_dir
  hmap_files_dir.join('vfs')
end

.write_vfs_yaml(targets) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cocoapods-hmap/helper/pods_helper.rb', line 28

def self.write_vfs_yaml(targets)
  es = targets.flat_map do |target|
    if target.build_as_framework?
      spec_path = target.specs.map(&:defined_in_file).uniq.first
      platforms = target_support_platforms(spec_path)
      headers = headers_mappings_by_file_accessor(target)
      headers << target.umbrella_header_path
      Target::FrameworkEntry.new_entrys_from_configurations_platforms(target.user_build_configurations.keys, platforms, target.name, target.product_module_name, target.support_files_dir, headers)
    end
  end.compact
  Target::FrameworkVFS.new(es).write
end