Module: HMap::Pods

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

Overview

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

Constant Summary collapse

HMAP_DIR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

mapfile dir name

'HMap'
HEADER_EXTENSIONS =
%w[h hh hpp ipp tpp hxx def inl inc].join(',')

Class Method Summary collapse

Class Method Details

.clean_hmap_build_setting(targets, log: false) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/hmap/helper/pods_helper.rb', line 88

def self.clean_hmap_build_setting(targets, log: false)
  puts 'Clean build setting: '.blue if log
  targets.each do |target|
    xcconfig_path_from(target) do |xcconfig|
      HMap::XcodeprojHelper.new(xcconfig).clean_hmap_build_setting_and_save
      puts "\t -xcconfig path: #{xcconfig} clean finish." if log
    end
  end
end

.clean_hmap_setting(clean_hmap, *targets) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/hmap/helper/pods_helper.rb', line 80

def self.clean_hmap_setting(clean_hmap, *targets)
  return clean_hmap unless clean_hmap

  FileUtils.rm_rf(Pods.hmap_files_dir)
  targets.each { |target| clean_hmap_build_setting(target, log: true) }
  clean_hmap
end

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



59
60
61
62
63
64
65
66
67
68
# File 'lib/hmap/helper/pods_helper.rb', line 59

def self.headers_mappings_by_file(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.compact
end

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hmap/helper/pods_helper.rb', line 32

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[:private_header_files] ||= []
    sum[:public_header_files] ||= []
    sum[:source_files] ||= []
    case type
    when :private_header_files
      sum[:private_header_files] += file_accessor.private_headers
    when :source_files
      header_mappings_dir = file_accessor.spec_consumer.header_mappings_dir
      headers = paths_for_attribute(file_accessor.path_list.root)
      unless header_mappings_dir.nil?
        headers = paths_for_attribute(file_accessor.path_list.root + header_mappings_dir)
      end
      sum[:private_header_files] += file_accessor.private_headers
      sum[:public_header_files] +=  file_accessor.public_headers
      sum[:public_header_files] << target.umbrella_header_path if target.build_as_framework?
      sum[:source_files] << target.prefix_header_path if target.build_as_framework?
      sum[:source_files] += (headers - file_accessor.public_headers - file_accessor.private_headers)
    when :public_header_files
      sum[:public_header_files] += file_accessor.public_headers
      sum[:public_header_files] << target.umbrella_header_path if target.build_as_framework?
    end
  end
end

.hmap_files_dirObject



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

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

.paths_for_attribute(path) ⇒ Object



25
26
27
28
29
30
# File 'lib/hmap/helper/pods_helper.rb', line 25

def self.paths_for_attribute(path)
  return [] unless path.exist?

  path_list = Pod::Sandbox::PathList.new(path)
  path_list.glob("**/*.{#{HEADER_EXTENSIONS}}")
end

.pods_hmap_files_dirObject



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

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

.target_support_platforms(spec_path) ⇒ Object



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

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

.xcconfig_path_from(target) ⇒ Object

Raises:



70
71
72
73
74
75
76
77
78
# File 'lib/hmap/helper/pods_helper.rb', line 70

def self.xcconfig_path_from(target)
  raise ClassIncludedError.new(target.class, Pod::Target) unless target.is_a?(Pod::Target)

  config_h = Pod::Target.instance_method(:build_settings).bind(target).call
  config_h.each_key do |configuration_name|
    xcconfig = target.xcconfig_path(configuration_name)
    yield(xcconfig, target) if block_given?
  end
end