【发布时间】:2016-09-01 21:27:26
【问题描述】:
问题是:CocoaPods 为我的项目生成 xcconfig 文件,我想将我的 xcconfig 文件作为依赖项包含在其中。例如,我可以在post_install 钩子中做吗?
我只发现 XCBuildConfiguration 有 build_settings 哈希,但据我了解,我只能添加或更改键,而不是包含带有该哈希的语句。
【问题讨论】:
问题是:CocoaPods 为我的项目生成 xcconfig 文件,我想将我的 xcconfig 文件作为依赖项包含在其中。例如,我可以在post_install 钩子中做吗?
我只发现 XCBuildConfiguration 有 build_settings 哈希,但据我了解,我只能添加或更改键,而不是包含带有该哈希的语句。
【问题讨论】:
按照this answer 的说明,我能够更新xcconfig 并使用此代码将我的xcconfig 文件包含到生成的pod 中:
post_install do |installer|
installer.pods_project.targets.each do |target|
next unless target.name.include?("Pods-CNISDK")
puts "Updating #{target.name}"
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
# read from xcconfig to build_settings dictionary
build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.split(/\s*=\s*/, 2)}.flatten]
# write build_settings dictionary to xcconfig
File.open(xcconfig_path, "w") do |file|
file.puts "#include \"../configurations/Warnings.xcconfig\"\n"
build_settings.each do |key,value|
file.puts "#{key} = #{value}"
end
end
end
end
end
【讨论】: