Module: Pod::Installer::Xcode::PodsProjectGenerator::TargetInstallerHelper

Defined in:
lib/cocoapods-kz/native/target_installer_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_repair_modulemap(xcconfig, repair_modulemap_paths, uses_swift = false) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/cocoapods-kz/native/target_installer_helper.rb', line 146

def add_repair_modulemap(xcconfig, repair_modulemap_paths, uses_swift = false)
  if repair_modulemap_paths.count > 0
    repair_modulemap_paths.each do |repair_modulemap_path|
      fmodule_map = ' -fmodule-map-file=' + KZ.deal_path_for_xcconfig(repair_modulemap_path, true)
      unless xcconfig.attributes['OTHER_CFLAGS'].include?(fmodule_map)
        xcconfig.attributes['OTHER_CFLAGS'] += fmodule_map
      end
      if uses_swift
        xfmodule_map = ' -Xcc -fmodule-map-file=' + KZ.deal_path_for_xcconfig(repair_modulemap_path, true)
        unless xcconfig.attributes['OTHER_SWIFT_FLAGS'].include?(xfmodule_map)
          xcconfig.attributes['OTHER_SWIFT_FLAGS'] += xfmodule_map
        end
      end
    end
  end
end

#add_repair_swift_include_path(xcconfig, repair_swift_include_paths, uses_swift) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/cocoapods-kz/native/target_installer_helper.rb', line 163

def add_repair_swift_include_path(xcconfig, repair_swift_include_paths, uses_swift)
  # 只有当前pod支持swift,才需要所依赖的pod提供的swiftmodule
  if repair_swift_include_paths.count > 0 && uses_swift
    repair_swift_include_paths.each do |repair_swift_include_path|
      swift_include_path = ' ' + KZ.deal_path_for_xcconfig(repair_swift_include_path, true)
      unless xcconfig.attributes['SWIFT_INCLUDE_PATHS'].include?(swift_include_path)
        xcconfig.attributes['SWIFT_INCLUDE_PATHS'] += swift_include_path
      end
    end
  end
end

#kz_add_force_load_tag(xcconfig, kz_pod_target) ⇒ Object



207
208
209
210
211
212
213
214
# File 'lib/cocoapods-kz/native/target_installer_helper.rb', line 207

def kz_add_force_load_tag(xcconfig, kz_pod_target)
  other_linker_flags = xcconfig.other_linker_flags
  frameworks_flags = other_linker_flags[:frameworks]
  force_flags = other_linker_flags[:force_load]

  frameworks_flags.delete(kz_pod_target.product_basename)
  force_flags.add(KZ.deal_path_for_xcconfig(kz_pod_target.force_load_info, true))
end

#kz_add_swift_lldb_ast_paths(xcconfig, swift_lldb_ast_paths) ⇒ Object



216
217
218
219
220
221
222
223
224
# File 'lib/cocoapods-kz/native/target_installer_helper.rb', line 216

def kz_add_swift_lldb_ast_paths(xcconfig, swift_lldb_ast_paths)
  if swift_lldb_ast_paths.count > 0
    other_linker_flags = xcconfig.other_linker_flags
    simple = other_linker_flags[:simple]
    swift_lldb_ast_paths.each do |swift_lldb_ast_path|
      simple.add("-Wl,-add_ast_path,#{KZ.deal_path_for_xcconfig(swift_lldb_ast_path, true)}")
    end
  end
end

#kz_clean_xcconfig(xcconfig) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/cocoapods-kz/native/target_installer_helper.rb', line 189

def kz_clean_xcconfig(xcconfig)
  other_cflags = xcconfig.attributes['OTHER_CFLAGS']
  flags = other_cflags.split(' ')
  new_flags = []
  appear_delete_tag = false
  flags.each do |flag|
    if flag.include?('isystem') || flag.include?('iframework')
      appear_delete_tag = true
    else
      unless appear_delete_tag || new_flags.include?(flag)
        new_flags << flag
      end
      appear_delete_tag = false
    end
  end
  xcconfig.attributes['OTHER_CFLAGS'] = new_flags.join(' ')
end

#kz_update_xcconfig_file(xcconfig, path) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/cocoapods-kz/native/target_installer_helper.rb', line 175

def kz_update_xcconfig_file(xcconfig, path)
  if path.exist?
    contents = xcconfig.to_s
    content_stream = StringIO.new(contents)
    identical = File.open(path, 'rb') { |f| FileUtils.compare_stream(f, content_stream) }
    return if identical

    File.open(path, 'w') { |f| f.write(contents) }
  else
    path.dirname.mkpath
    xcconfig.save_as(path)
  end
end

#origin_update_changed_fileObject



11
# File 'lib/cocoapods-kz/native/target_installer_helper.rb', line 11

alias_method :origin_update_changed_file, :update_changed_file

#update_changed_file(generator, path) ⇒ Object



12
13
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cocoapods-kz/native/target_installer_helper.rb', line 12

def update_changed_file(generator, path)
  unless KZ::KZGlobalHelper.instance.kz_pod_enable
    origin_update_changed_file(generator, path)
    return
  end

  if generator.is_a?(Pod::Target::BuildSettings::AggregateTargetSettings)
    unless self.target.application_extension_api_only
      xcconfig = generator.xcconfig
      kz_clean_xcconfig(xcconfig)
      main_hamp_search_path = '"' + KZ::KZ_POD_CONFIG_ROOT_STR + "/#{self.target.user_project.root_object.display_name}.hmap" + '"'
      pod_targets = self.target.pod_targets_for_build_configuration(generator.configuration_name)

      swift_lldb_ast_paths = []
      on_demand_resources_config_paths = []
      pod_targets.each do |native_pod_target|
        kz_pod_target = native_pod_target.weakRef_kz_pod_target
        if kz_pod_target
          if kz_pod_target.repair_header_search_path
            main_hamp_search_path += (' ' + KZ.deal_path_for_xcconfig(kz_pod_target.repair_header_search_path, true))
          end
          add_repair_modulemap(xcconfig, kz_pod_target.all_repair_modulemap_paths, self.target.uses_swift?)
          add_repair_swift_include_path(xcconfig, kz_pod_target.all_repair_swift_include_paths, self.target.uses_swift?)

          if kz_pod_target.force_load
            kz_add_force_load_tag(xcconfig, kz_pod_target)
          end

          # 添加swift ast path
          ast_path = kz_pod_target.get_swift_lldb_ast_path
          if !ast_path.nil? and generator.configuration_name == "Debug"
            swift_lldb_ast_paths << ast_path
          end

          unless kz_pod_target.on_demand_resources_config_path.nil?
            on_demand_resources_config_paths << (kz_pod_target.name + ":" + kz_pod_target.on_demand_resources_config_path)
          end
        end
      end

      kz_add_swift_lldb_ast_paths(xcconfig, swift_lldb_ast_paths)
      xcconfig.attributes['HEADER_SEARCH_PATHS'] = main_hamp_search_path
      xcconfig.attributes['USE_HEADERMAP'] = 'NO'
      xcconfig.attributes["KZ_POD_CONFIG_ROOT"] = KZ::KZ_POD_CONFIG_ROOT_STR
      if KZ::KZGlobalHelper.instance.arm64_simulator
        xcconfig.attributes.delete("EXCLUDED_ARCHS[sdk=iphonesimulator*]")
        xcconfig.attributes['VALID_ARCHS'] = 'arm64 arm64_32 x86_64'
      end
      if KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_names.include?(self.target.name.sub('Pods-', ''))
        xcconfig.attributes["ENABLE_ON_DEMAND_RESOURCES"] = "NO"

        on_demadn_resources_paths = ""
        on_demand_resources_config_paths.each do |path|
          on_demadn_resources_paths += ((on_demadn_resources_paths.empty? ? ''  : ' ') + '"' + path + '"')
        end
        xcconfig.attributes["KZ_ON_DEMAND_RESOURCES_PATHS"] = on_demadn_resources_paths unless on_demadn_resources_paths.empty?
      end

      kz_update_xcconfig_file(xcconfig, path)
      return
    end
  elsif generator.is_a?(Pod::Target::BuildSettings::PodTargetSettings)
    kz_pod_target = self.target.weakRef_kz_pod_target
    if kz_pod_target
      xcconfig = generator.xcconfig

      custom_paths = []
      origin_header_search_paths = xcconfig.attributes['HEADER_SEARCH_PATHS'].split(" ")
      unless origin_header_search_paths.nil? || origin_header_search_paths.empty?
        origin_header_search_paths.each do |origin_search_paht|
          if origin_search_paht.include?("PODS_XCFRAMEWORKS_BUILD_DIR")
            custom_paths.append(origin_search_paht)
          end
        end
      end

      pod_custom_header_search_paths = generator.pod_target_xcconfig_values_by_consumer_by_key["HEADER_SEARCH_PATHS"]
      unless pod_custom_header_search_paths.nil? || pod_custom_header_search_paths.values.empty?
        custom_paths.concat(pod_custom_header_search_paths.values)
      end

      xcconfig.attributes['HEADER_SEARCH_PATHS'] = kz_pod_target.header_search_paths(custom_paths)
      xcconfig.attributes['USE_HEADERMAP'] = 'NO'
      framework_cache_path = KZ.deal_path_for_xcconfig(kz_pod_target.pod_config_cache_path(true))
      xcconfig.attributes['KZ_FRAMEWORK_CACHE_PATH'] = framework_cache_path
      if kz_pod_target.force_load
        xcconfig.attributes['KZ_FIX_FORCE_LOAD_EXE_FOLDER'] = kz_pod_target.configuration_build_dir(true)
      end
      if KZ::KZGlobalHelper.instance.arm64_simulator
        xcconfig.attributes.delete("EXCLUDED_ARCHS[sdk=iphonesimulator*]")
        xcconfig.attributes['VALID_ARCHS'] = 'arm64 arm64_32 x86_64'
      end

      unless kz_pod_target.custom_origin_yaml_path.nil?
        xcconfig.attributes['KZ_CUSTOM_ORIGIN_YAML_PATH'] = KZ.deal_path_for_xcconfig(kz_pod_target.custom_origin_yaml_path)
        xcconfig.attributes['KZ_CUSTOM_YAML_PATH'] = KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path)

        other_cflags = xcconfig.attributes['OTHER_CFLAGS']
        if other_cflags == nil
          other_cflags = ""
        elsif !other_cflags.end_with?(" ")
          other_cflags += " "
        end
        other_cflags += ("-ivfsoverlay #{KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path, true)}")
        xcconfig.attributes['OTHER_CFLAGS'] = other_cflags

        other_cplusplusflags = xcconfig.attributes['OTHER_CPLUSPLUSFLAGS']
        if other_cplusplusflags == nil
          other_cplusplusflags = ""
        elsif !other_cplusplusflags.end_with?(" ")
          other_cplusplusflags += " "
        end
        other_cplusplusflags += ("-ivfsoverlay #{KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path, true)}")
        xcconfig.attributes['OTHER_CPLUSPLUSFLAGS'] = other_cplusplusflags

        other_swift_flags = xcconfig.attributes['OTHER_SWIFT_FLAGS']
        if other_swift_flags == nil
          other_swift_flags = ""
        elsif !other_swift_flags.end_with?(" ")
          other_swift_flags += " "
        end
        other_swift_flags += ("-Xcc -ivfsoverlay -Xcc #{KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path, true)}")
        xcconfig.attributes['OTHER_SWIFT_FLAGS'] = other_swift_flags
      end

      add_repair_modulemap(xcconfig, kz_pod_target.all_repair_modulemap_paths, kz_pod_target.current_uses_swift?)
      add_repair_swift_include_path(xcconfig, kz_pod_target.all_repair_swift_include_paths, kz_pod_target.current_uses_swift?)
      kz_update_xcconfig_file(xcconfig, path)
      return
    end
  end
  origin_update_changed_file(generator, path)
end