使用Podfile post_install钩子添加自定义构建规则



我有一个Cocoapod,它需要一些自定义构建规则才能正常工作。

在我看来,没有办法在podspec中添加任何自定义构建规则,但也许有办法在Podfile中使用post_install挂钩?

我最终能够实现这一点。我写了一个ruby函数,它使用Xcodeproj gem(可以在Podfile中使用(

def add_build_rule(target_name, project)
new_rule = project.new(Xcodeproj::Project::Object::PBXBuildRule)
project.targets.each do |target|
if target.name == target_name
if target.build_rules.count != 0
puts "#{target.name} already has a build rule."
return
end
puts "Updating #{target.name} rules"
new_rule.name = 'My Custom Rule'
new_rule.compiler_spec = 'com.apple.compilers.proxy.script'
new_rule.file_patterns = 'myFile.whatever'
new_rule.file_type = 'pattern.proxy'
new_rule.is_editable = '1'
new_rule.output_files = []
new_rule.input_files = []
new_rule.output_files_compiler_flags = []
new_rule.script = "echo Hello World"
target.build_rules.append(new_rule)
end
end
project.objects_by_uuid[new_rule.uuid] = new_rule
project.save()
end

然后在我的podfile中,我添加了这个post_install钩子。

post_install do |installer|
add_build_rule("MyTarget", installer.pods_project)
end

最新更新