cocoapods-mapfile 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -22
  3. data/bin/{hmap_writer → hmapfile} +2 -2
  4. data/lib/cocoapods_plugin.rb +18 -4
  5. data/lib/{cocoapods-hmap → hmap}/command/hmap_gen.rb +16 -8
  6. data/lib/{cocoapods-hmap → hmap}/command/hmap_reader.rb +12 -9
  7. data/lib/hmap/command/hmap_writer.rb +53 -0
  8. data/lib/hmap/command.rb +26 -0
  9. data/lib/{cocoapods-hmap → hmap}/exceptions.rb +0 -0
  10. data/lib/{cocoapods-hmap → hmap}/executable.rb +0 -0
  11. data/lib/{cocoapods-hmap → hmap}/framework/framework_vfs.rb +12 -13
  12. data/lib/hmap/helper/build_setting_constants.rb +13 -0
  13. data/lib/hmap/helper/hmap_helper.rb +212 -0
  14. data/lib/hmap/helper/pods_helper.rb +98 -0
  15. data/lib/{cocoapods-hmap → hmap/helper}/utils.rb +0 -4
  16. data/lib/hmap/helper/xcconfig_helper.rb +105 -0
  17. data/lib/{cocoapods-hmap → hmap}/hmap_reader.rb +1 -0
  18. data/lib/{cocoapods-hmap/hmap_save.rb → hmap/hmap_saver.rb} +11 -1
  19. data/lib/{cocoapods-hmap → hmap}/hmap_struct.rb +5 -4
  20. data/lib/hmap/hmap_writer.rb +99 -0
  21. data/lib/{cocoapods-hmap → hmap}/mapfile.rb +0 -0
  22. data/lib/hmap/pods_specification.rb +65 -0
  23. data/lib/hmap/version.rb +5 -0
  24. data/lib/hmap.rb +22 -0
  25. metadata +34 -34
  26. data/bin/hmap_reader +0 -12
  27. data/lib/cocoapods-hmap/helper/build_setting_helper.rb +0 -40
  28. data/lib/cocoapods-hmap/helper/pods_helper.rb +0 -104
  29. data/lib/cocoapods-hmap/helper/xcconfig_helper.rb +0 -82
  30. data/lib/cocoapods-hmap/hmap_writer.rb +0 -107
  31. data/lib/cocoapods-hmap/pods_specification.rb +0 -60
  32. data/lib/cocoapods-hmap/version.rb +0 -5
  33. data/lib/cocoapods-hmap/view.rb +0 -34
  34. data/lib/cocoapods_hmap.rb +0 -21
@@ -1,40 +0,0 @@
1
- module HMap
2
- # A collection of build setting functions used throughout cocoapods-hmap.
3
- module BuildSettingHelper
4
- def self.clean_hmap(clean_hmap, *targets)
5
- return clean_hmap unless clean_hmap
6
-
7
- FileUtils.rm_rf(Helper::Pods.hmap_files_dir)
8
- targets.each { |target| clean_other_c_flags_build_setting(target) }
9
- clean_hmap
10
- end
11
-
12
- def self.target_xcconfig_path(targets)
13
- targets.each do |target|
14
- raise ClassIncludedError.new(target.class, Pod::Target) unless target.is_a?(Pod::Target)
15
-
16
- config_h = Pod::Target.instance_method(:build_settings).bind(target).call
17
- config_h.each_key do |configuration_name|
18
- xcconfig = target.xcconfig_path(configuration_name)
19
- yield(xcconfig, target) if block_given?
20
- end
21
- end
22
- end
23
-
24
- def self.clean_other_c_flags_build_setting(targets)
25
- target_xcconfig_path(targets) do |xc, _|
26
- c = HMap::XcodeprojHelper.new(xc)
27
- c.clean_hmap_xcconfig_other_c_flags_and_save
28
- puts "\t -xcconfig path: #{xc} clean finish."
29
- end
30
- end
31
-
32
- def self.change_other_c_flags_xcconfig_build_settings(hmap_h, targets, use_headermap: false, save_origin: true)
33
- target_xcconfig_path(targets) do |xc, target|
34
- c = HMap::XcodeprojHelper.new(xc)
35
- c.change_xcconfig_other_c_flags_and_save(hmap_h, target.build_as_framework?, use_headermap: use_headermap,
36
- save_origin: save_origin)
37
- end
38
- end
39
- end
40
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml_vfs'
4
- require 'cocoapods'
5
-
6
- module HMap
7
- # A collection of Helper functions used throughout cocoapods-hmap.
8
- module Helper
9
- # A collection of Pods Helper functions used throughout cocoapods-hmap.
10
- module Pods
11
-
12
- def self.hmap_files_dir
13
- Pathname(File.join(Pod::Config.instance.sandbox.headers_root, HMAP_DIR))
14
- end
15
-
16
- def self.vfs_files_dir
17
- hmap_files_dir.join('vfs')
18
- end
19
-
20
- def self.hmap_files_paths(name)
21
- [hmap_files_dir.join("#{name}.hmap"), hmap_files_dir.join("#{name}-iquote.hmap")]
22
- end
23
-
24
- def self.pods_hmap_files_dir
25
- "${PODS_ROOT}/Headers/#{HMAP_DIR}"
26
- end
27
-
28
- def self.write_vfs_yaml(targets)
29
- es = targets.flat_map do |target|
30
- if target.build_as_framework?
31
- spec_path = target.specs.map(&:defined_in_file).uniq.first
32
- platforms = target_support_platforms(spec_path)
33
- headers = headers_mappings_by_file_accessor(target)
34
- headers << target.umbrella_header_path
35
- Target::FrameworkEntry.new_entrys_from_configurations_platforms(target.user_build_configurations.keys, platforms, target.name, target.product_module_name, target.support_files_dir, headers)
36
- end
37
- end.compact
38
- Target::FrameworkVFS.new(es).write
39
- end
40
-
41
- def self.target_support_platforms(spec_path)
42
- validator = Pod::Validator.new(spec_path, Pod::Config.instance.sources_manager.master.map(&:url))
43
- validator.platforms_to_lint(validator.spec).map(&:name)
44
- end
45
-
46
- def self.headers_mappings_by_file_accessor(target, type = :source_files)
47
- valid_accessors = target.file_accessors.reject { |fa| fa.spec.non_library_specification? }
48
- valid_accessors.each_with_object([]) do |file_accessor, sum|
49
- sum << case type
50
- when :private_header_files then file_accessor.headers - file_accessor.public_headers
51
- when :source_files then file_accessor.headers
52
- when :public_header_files then file_accessor.public_headers
53
- end
54
- end.flatten
55
- end
56
-
57
- def self.header_mappings(target, type = :source_files)
58
- mappings = {}
59
- h_headers = lambda { |headers, h_type|
60
- root = Pod::Config.instance.sandbox.root.join(target.headers_sandbox)
61
- case h_type
62
- when :private_header_files
63
- headers << target.prefix_header_path if target.build_as_framework?
64
- headers.each do |header|
65
- mappings[HEAD_SEARCH_IQUOTE] ||= []
66
- mappings[HEAD_SEARCH_IQUOTE] << [header.basename.to_s, "#{header.dirname}/", header.basename.to_s]
67
- r_header_path = header.relative_path_from(root)
68
- mappings[HEAD_SEARCH_IQUOTE] << [r_header_path.to_s, "#{header.dirname}/", header.basename.to_s]
69
- end
70
- when :public_header_files
71
- headers << target.umbrella_header_path if target.build_as_framework?
72
- headers.each do |header|
73
- mappings[HEAD_SEARCH_IQUOTE] ||= []
74
- mappings[HEAD_SEARCH_IQUOTE] << [header.basename.to_s, "#{target.product_module_name}/",
75
- header.basename.to_s]
76
- r_header_path = header.relative_path_from(root)
77
- mappings[HEAD_SEARCH_IQUOTE] << [r_header_path.to_s, "#{header.dirname}/", header.basename.to_s]
78
- mappings[HEAD_SEARCH_I] ||= []
79
- mappings[HEAD_SEARCH_I] << [r_header_path.to_s, "#{header.dirname}/", header.basename.to_s]
80
- mappings[HEAD_SEARCH_I] << [header.basename.to_s, "#{target.product_module_name}/",
81
- header.basename.to_s]
82
-
83
- mappings[HEAD_SEARCH_I] << ["#{target.product_module_name}/#{header.basename}", "#{header.dirname}/",
84
- header.basename.to_s]
85
- end
86
- end
87
- }
88
-
89
- valid_accessors = target.file_accessors.reject { |fa| fa.spec.non_library_specification? }
90
- valid_accessors.each do |file_accessor|
91
- case type
92
- when :private_header_files then h_headers.call(file_accessor.headers - file_accessor.public_headers,
93
- :private_header_files)
94
- when :source_files
95
- h_headers.call(file_accessor.headers - file_accessor.public_headers, :private_header_files)
96
- h_headers.call(file_accessor.public_headers, :public_header_files)
97
- when :public_header_files then h_headers.call(file_accessor.public_headers, :public_header_files)
98
- end
99
- end
100
- mappings
101
- end
102
- end
103
- end
104
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HMap
4
- # A collection of Helper functions used throughout cocoapods-hmap.
5
- class XcodeprojHelper
6
- require 'xcodeproj'
7
- OTHER_CFLAGS = 'OTHER_CFLAGS'
8
- HEAD_SEARCH_PATHS = 'HEADER_SEARCH_PATHS'
9
- # A collection of Pods Helper functions used throughout cocoapods-hmap.
10
- attr_reader :xcconfig_path, :build_setting_key
11
-
12
- def initialize(xcconfig)
13
- @xcconfig_path = xcconfig
14
- @xcconfig = Xcodeproj::Config.new(xcconfig_path)
15
- end
16
-
17
- def change_xcconfig_other_c_flags_and_save(values, build_as_framework, use_headermap: false, save_origin: true)
18
- setting = values.flat_map do |config|
19
- ['$(inherited)', "-I\"#{Helper::Pods.pods_hmap_files_dir}/#{config}.hmap\"",
20
- "-iquote \"#{Helper::Pods.pods_hmap_files_dir}/#{config}-iquote.hmap\""]
21
- end
22
- if build_as_framework
23
- setting << "-ivfsoverlay \"#{Helper::Pods.pods_hmap_files_dir}/vfs/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/all-product-headers.yaml\""
24
- end
25
- change_xcconfig_build_setting(OTHER_CFLAGS, setting.join(' '), save_origin) do |xcconfig|
26
- xcconfig.attributes['USE_HEADERMAP'] = 'NO' unless use_headermap
27
- save_build_setting_to_xcconfig(HMap::XcodeprojHelper::HEAD_SEARCH_PATHS)
28
- end
29
- save_to_path
30
- end
31
-
32
- def change_xcconfig_build_setting(build_setting_key, setting, save_origin)
33
- origin_build_setting = @xcconfig.attributes[build_setting_key]
34
- save_origin_build_setting = save_build_setting_to_xcconfig(build_setting_key)
35
- hmap_build_setting = @xcconfig.attributes[hmap_key(build_setting_key)]
36
- value = setting
37
- value = "#{value} ${#{save_key(build_setting_key)}}" if save_origin && !save_origin_build_setting.nil?
38
- @xcconfig.attributes[hmap_key(build_setting_key)] = value
39
- @xcconfig.attributes[build_setting_key] = "${#{hmap_key(build_setting_key)}}"
40
- yield(@xcconfig) if block_given?
41
- end
42
-
43
- def save_build_setting_to_xcconfig(key)
44
- origin_build_setting = @xcconfig.attributes[key]
45
- if origin_build_setting.nil? || !origin_build_setting.include?(hmap_key(key))
46
- @xcconfig.attributes[save_key(key)] = origin_build_setting unless origin_build_setting.nil?
47
- @xcconfig.attributes.delete(key)
48
- end
49
- @xcconfig.attributes[save_key(key)]
50
- end
51
-
52
- def clean_hmap_xcconfig_other_c_flags_and_save
53
- clean_hmap_build_setting_to_xcconfig(OTHER_CFLAGS)
54
- clean_hmap_build_setting_to_xcconfig(HEAD_SEARCH_PATHS)
55
- @xcconfig.attributes['USE_HEADERMAP'] = 'YES'
56
- save_to_path
57
- end
58
-
59
- def clean_hmap_build_setting_to_xcconfig(build_setting)
60
- save_origin_build_setting = @xcconfig.attributes[save_key(build_setting)]
61
- origin_build_setting = @xcconfig.attributes[build_setting]
62
- @xcconfig.attributes[build_setting] = save_origin_build_setting unless save_origin_build_setting.nil?
63
- @xcconfig.attributes.delete(hmap_key(build_setting))
64
- @xcconfig.attributes.delete(save_key(build_setting))
65
- end
66
-
67
- def save_to_path(path = nil)
68
- path = xcconfig_path if path.nil?
69
- @xcconfig.save_as(path)
70
- end
71
-
72
- private
73
-
74
- def hmap_key(key)
75
- "HMAP_PODS_#{key}"
76
- end
77
-
78
- def save_key(key)
79
- "SAVE_#{key}"
80
- end
81
- end
82
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cocoapods'
4
-
5
- module Pod
6
- Validator.class_eval do
7
- def results=(v)
8
- @results = v
9
- end
10
- end
11
- end
12
-
13
- module HMap
14
- # mapfile dir name
15
- # @api private
16
- HMAP_DIR = 'HMap'
17
- # mapfile type
18
- # @note public => pods public,
19
- # private => pods private,
20
- # all => public + private + extra.
21
- # @api private
22
- HMMAP_TYPE = {
23
- public_header_files: 'public',
24
- private_header_files: 'private',
25
- source_files: 'all'
26
- }.freeze
27
- HEAD_SEARCH_I = '-I'
28
- HEAD_SEARCH_IQUOTE = '-iquote'
29
- # build setting HEAD_SEARCH_PATHs
30
- HEAD_SEARCH_PATHS = 'HEADER_SEARCH_PATHS'
31
-
32
- # Helper module which returns handle method from MapFileWriter.
33
- class MapFileWriter
34
- # @param save_origin_header_search_paths save_origin_header_search_paths
35
- # @param clean_hmap clean up all hmap setup
36
- def initialize(save_origin_header_search_paths, clean_hmap)
37
- @save_origin_header_search_paths = save_origin_header_search_paths
38
- @hmap_saver = HMapSaver.new
39
- @hmap_saver_iquote = HMapSaver.new
40
- create_mapfile(clean_hmap)
41
- end
42
-
43
- private
44
-
45
- # Integrates the projects mapfile associated
46
- # with the App project and Pods project.
47
- #
48
- # @param [clean] clean hmap dir @see #podfile
49
- # @return [void]
50
- #
51
- def create_mapfile(clean)
52
- puts "Current hmap files dir: #{Helper::Pods.hmap_files_dir}"
53
- puts "Current vfs files dir: #{Helper::Pods.vfs_files_dir}"
54
- analyze = PodsSpecification.instance.analyze
55
- targets = analyze.targets
56
- pod_targets = analyze.pod_targets
57
- return if BuildSettingHelper.clean_hmap(clean, targets, pod_targets)
58
-
59
- merge_all_pods_target_headers_mapfile(pod_targets)
60
- merge_all_target_public_headers_mapfile(targets)
61
- end
62
-
63
- def from_header_mappings(target, type = :source_files)
64
- headers = Helper::Pods.header_mappings(target, type)
65
- headers[HEAD_SEARCH_IQUOTE].each { |value| @hmap_saver_iquote.add_to_buckets(*value) }
66
- headers[HEAD_SEARCH_I].each { |value| @hmap_saver.add_to_buckets(*value) }
67
- end
68
-
69
- def merge_all_target_public_headers_mapfile(targets)
70
- names = targets.map do |target|
71
- hmap_name = "all-public-#{target.name}"
72
- create_hmap_vfs_files(target.pod_targets, hmap_name, :public_header_files)
73
- hmap_name
74
- end
75
- BuildSettingHelper.change_other_c_flags_xcconfig_build_settings(names, targets,
76
- save_origin: @save_origin_header_search_paths)
77
- end
78
-
79
- def merge_all_pods_target_headers_mapfile(pod_targets)
80
- hmap_name = 'all-pods-all-header'
81
- create_hmap_vfs_files(pod_targets, hmap_name, :source_files)
82
- BuildSettingHelper.change_other_c_flags_xcconfig_build_settings([hmap_name], pod_targets,
83
- save_origin: @save_origin_header_search_paths)
84
- end
85
-
86
- # Cteate hmap files and vfs files
87
- #
88
- # @param [pod_targets] Pods project all target @see Pod#PodTarget
89
- # @param [hmap_name] -I hmap file name and -iquote hmap file name
90
- # @param [hmap_type] hmap file contains pod targets header type
91
- #
92
- def create_hmap_vfs_files(pod_targets, hmap_name, hmap_type = :public_header_files)
93
- pod_targets.each { |target| from_header_mappings(target, hmap_type) }
94
- Helper::Pods.write_vfs_yaml(pod_targets)
95
- write_hmap_files(*Helper::Pods.hmap_files_paths(hmap_name))
96
- end
97
-
98
- def write_hmap_files(hmap_path_i, hmap_path_iquote)
99
- print "\t - Save hmap file to path: "
100
- puts hmap_path_i.to_s.yellow
101
- print "\t - Save hmap file to path: "
102
- puts hmap_path_iquote.to_s.yellow
103
- @hmap_saver.write_to(hmap_path_i)
104
- @hmap_saver_iquote.write_to(hmap_path_iquote)
105
- end
106
- end
107
- end
@@ -1,60 +0,0 @@
1
- module HMap
2
- class PodsSpecification
3
- attr_reader :workspace_path, :analyze, :app_build_dir, :project_temp_dir
4
-
5
- BUILD_DIR = 'BUILD_DIR'
6
- PROJECT_TEMP_DIR = 'PROJECT_TEMP_DIR'
7
-
8
- def self.instance
9
- @instance ||= new
10
- end
11
-
12
- def initialize
13
- @workspace_path = workspace
14
- @analyze = pod_analyze
15
- workspace_build_dir
16
- end
17
-
18
- private
19
-
20
- def workspace_build_dir
21
- workspace_dic = xcodebuild('-list', workspace_path)['workspace']
22
- scheme = workspace_dic['schemes'].first
23
- build_settings = xcodebuild('analyze', workspace_path, scheme).first['buildSettings']
24
- @app_build_dir = build_settings[BUILD_DIR]
25
- @project_temp_dir = build_settings[PROJECT_TEMP_DIR]
26
- end
27
-
28
- def xcodebuild(action, workspace, scheme = nil)
29
- command = %W[#{action} -workspace #{workspace} -json]
30
- command += %W[-scheme #{scheme} -showBuildSettings] unless scheme.nil?
31
- results = Executable.execute_command('xcodebuild', command, false)
32
- JSON.parse(results) unless results.nil?
33
- end
34
-
35
- def pod_analyze
36
- podfile = Pod::Podfile.from_file(Pod::Config.instance.podfile_path)
37
- lockfile = Pod::Lockfile.from_file(Pod::Config.instance.lockfile_path)
38
- Pod::Installer::Analyzer.new(Pod::Config.instance.sandbox, podfile, lockfile).analyze
39
- end
40
-
41
- def workspace
42
- podfile = Pod::Podfile.from_file(Pod::Config.instance.podfile_path)
43
- user_project_paths = pod_analyze.targets.map(&:user_project_path).compact.uniq
44
- if podfile.workspace_path
45
- declared_path = podfile.workspace_path
46
- path_with_ext = File.extname(declared_path) == '.xcworkspace' ? declared_path : "#{declared_path}.xcworkspace"
47
- podfile_dir = File.dirname(podfile.defined_in_file || '')
48
- absolute_path = File.expand_path(path_with_ext, podfile_dir)
49
- Pathname.new(absolute_path)
50
- elsif user_project_paths.count == 1
51
- project = user_project_paths.first.basename('.xcodeproj')
52
- Pod::Config.instance.installation_root + "#{project}.xcworkspace"
53
- else
54
- raise Informative, 'Could not automatically select an Xcode ' \
55
- "workspace. Specify one in your Podfile like so:\n\n" \
56
- " workspace 'path/to/Workspace.xcworkspace'\n"
57
- end
58
- end
59
- end
60
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CocoapodsHMap
4
- VERSION = '0.2.0'
5
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HMap
4
- # A representation of some unspecified hmap data.
5
- class HMapView
6
- # @return [String] the raw hmap data
7
- attr_reader :raw_data
8
-
9
- # @return [Symbol] the endianness of the data (`:big` or `:little`)
10
- attr_reader :endianness
11
-
12
- # @return [Integer] the offset of the relevant data (in {#raw_data})
13
- attr_reader :offset
14
-
15
- # Creates a new HMapView.
16
- # @param raw_data [String] the raw hmap data
17
- # @param endianness [Symbol] the endianness of the data
18
- # @param offset [Integer] the offset of the relevant data
19
- def initialize(raw_data, endianness, offset)
20
- @raw_data = raw_data
21
- @endianness = endianness
22
- @offset = offset
23
- end
24
-
25
- # @return [Hash] a hash representation of this {HMapView}.
26
- def to_h
27
- {
28
- 'endianness' => endianness,
29
- 'offset' => offset
30
- }
31
- end
32
- end
33
- end
34
-
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The primary namespace for cocoapods-hmap.
4
- module HMap
5
- require_relative 'cocoapods-hmap/version'
6
- require_relative 'cocoapods-hmap/view'
7
- require_relative 'cocoapods-hmap/hmap_struct'
8
- require_relative 'cocoapods-hmap/utils'
9
- require_relative 'cocoapods-hmap/helper/pods_helper'
10
- require_relative 'cocoapods-hmap/exceptions'
11
- require_relative 'cocoapods-hmap/framework/framework_vfs'
12
- require_relative 'cocoapods-hmap/hmap_save'
13
- require_relative 'cocoapods-hmap/helper/xcconfig_helper'
14
- require_relative 'cocoapods-hmap/pods_specification'
15
- require_relative 'cocoapods-hmap/helper/build_setting_helper'
16
-
17
- autoload :MapFileReader, 'cocoapods-hmap/hmap_reader'
18
- autoload :MapFileWriter, 'cocoapods-hmap/hmap_writer'
19
- autoload :MapFile, 'cocoapods-hmap/mapfile'
20
- autoload :Executable, 'cocoapods-hmap/executable'
21
- end