自动将生成的源文件添加到xcode项目
我正在使用IDL,它会自动为我的xcode项目生成源文件。有谁知道我如何自动将生成的文件添加到项目中?目前我必须从项目中删除当前文件并添加新文件。这真的很烦人。自动将生成的源文件添加到xcode项目
使用文件夹引用适用于头文件,但xcode不希望将文件夹引用中的任何文件识别为源文件。有没有人找到解决这个问题的方法?
我也花了几天时间为这个问题写了一个解决方案。 这是一个ruby脚本,您可以将其作为运行脚本构建阶段添加到项目目标中。这是用XCode 3.2.4和ruby 1.8.7测试的。
为此,您需要安装rb-appscript ruby gem。 (例如:sudo的创业板安装RB-appscript)
几乎没有设置要做到:
- 首先它需要添加的文件的编译目标清单。
- 其次,它期望一个项目组名称,它将与它关联的磁盘文件夹(在我的情况下是'objc')进行同步。显然这个组需要存在并指向一个真实的文件夹。
下面是脚本:
require 'rubygems'
require 'appscript'
target_names = ['MinitSample'] # Put your target names here
group_name = 'objc' # Name of Xcode project group where to add the generated files
project_name = ENV["PROJECT_NAME"]
project_dir = ENV["PROJECT_DIR"]
xcode = Appscript.app('Xcode')
project = xcode.projects[project_name]
group = project.groups[group_name]
group_path = group.real_path.get
generated_files = Dir.glob(group_path+"/*.m")
missing_files = Array.new(generated_files)
group.item_references.get.each {|item|
item_path = item.real_path.get
missing_files.delete(item_path)
if ! generated_files.include?(item_path) then
group.file_references[item.name.get].delete
puts "Deleting #{File.basename(item_path)} from group #{group_name}, as it is not in generated files list"
end
}
if missing_files.empty? then
puts "There are no new files to add. "
exit
end
# holds the compile targets for generated files
targets = []
project.targets.get.each{ |target|
targets << target if target_names.include?(target.name.get)
}
if targets.empty? then
puts "Unable to find #{target_names.inspect} in project targets ! Aborting"
exit
end
missing_files.each{ |path|
file_name = File.basename(path)
msg = "Adding #{file_name} to group #{group_name} and to targets: "
item = xcode.make(:new => :file_reference,
:at => group.item_references.after,
:with_properties => {:full_path => path,
:name => file_name})
targets.each {|target|
xcode.add(item,{:to=>target})
msg += target.name.get
}
puts msg
}
这种方法现在是过时的吗?它看起来像你已经删除了minit仓库。 – 2014-08-22 08:35:28
我已经删除了minit参考,因为它不再更新。这种方法是为所提到的特定版本的xcode而设计的。较新的版本可能无法正常工作。 – Adrian 2014-08-25 14:30:03
这仍然很热,尤其是当您考虑使用Swagger和API代码时。在这方面有什么进展? – 2016-10-28 10:20:02