自动将生成的源文件添加到xcode项目

时间:2023-01-13 20:32:44

I am using an IDL which automatically generates source files for my xcode project. Does anyone know how I can automatically have the generated files added to the project? Currently I have to delete the current files from the project and add the new ones. This gets really annoying.

我正在使用IDL自动为我的xcode项目生成源文件。有谁知道如何自动将生成的文件添加到项目中?目前,我必须从项目中删除当前文件并添加新文件。这真令人讨厌。

Using a folder reference works for the header files but xcode doesn't want to recognize any files in a folder reference as source files. Has anyone ever found a solution to this problem?

使用文件夹引用适用于头文件,但xcode不希望将文件夹引用中的任何文件识别为源文件。有没有人找到解决这个问题的方法?

4 个解决方案

#1


3  

I also spent a couple of days writing a solution for this problem. Here is a ruby script that you can add to your project's target as a run script build phase. This was tested with XCode 3.2.4 and ruby 1.8.7.

我也花了几天时间为这个问题编写解决方案。这是一个ruby脚本,您可以将其作为运行脚本构建阶段添加到项目的目标中。用XCode 3.2.4和ruby 1.8.7测试了这一点。

For this to work you will need to install rb-appscript ruby gem. ( eg: sudo gem install rb-appscript )

为此,您需要安装rb-appscript ruby​​ gem。 (例如:sudo gem install rb-appscript)

There is little setup to do:

几乎没有设置:

  1. First it needs a list of compile targets for added files.
  2. 首先,它需要一个添加文件的编译目标列表。
  3. Second it expects a project group name which it will synchronize with it's associated disk folder ('objc' in my case) . Obviously this group needs to exist and to point to a real folder.
  4. 其次它需要一个项目组名称,它将与它的相关磁盘文件夹同步(在我的例子中是'objc')。显然,这个组需要存在并指向一个真正的文件夹。

Here is the script:

这是脚本:

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
}

#2


1  

A good idea can be found here: https://*.com/a/17894337/354018

可以在这里找到一个好主意:https://*.com/a/17894337/354018

Basically, you import the generated .m files into a known source file that is added to the compile phase.

基本上,您将生成的.m文件导入已添加到编译阶段的已知源文件。

#3


1  

Look at xcode-editor project, an API for manipulating Xcode project files.

查看xcode-editor项目,这是一个用于操作Xcode项目文件的API。

You can add files to a project, specify which target it belongs, add xib files and frameworks.

您可以将文件添加到项目,指定它所属的目标,添加xib文件和框架。

#4


0  

I've added a radar (details at http://www.openradar.me/radar?id=4885314376040448) asking for support for this.

我添加了一个雷达(详见http://www.openradar.me/radar?id=4885314376040448),要求对此提供支持。

#1


3  

I also spent a couple of days writing a solution for this problem. Here is a ruby script that you can add to your project's target as a run script build phase. This was tested with XCode 3.2.4 and ruby 1.8.7.

我也花了几天时间为这个问题编写解决方案。这是一个ruby脚本,您可以将其作为运行脚本构建阶段添加到项目的目标中。用XCode 3.2.4和ruby 1.8.7测试了这一点。

For this to work you will need to install rb-appscript ruby gem. ( eg: sudo gem install rb-appscript )

为此,您需要安装rb-appscript ruby​​ gem。 (例如:sudo gem install rb-appscript)

There is little setup to do:

几乎没有设置:

  1. First it needs a list of compile targets for added files.
  2. 首先,它需要一个添加文件的编译目标列表。
  3. Second it expects a project group name which it will synchronize with it's associated disk folder ('objc' in my case) . Obviously this group needs to exist and to point to a real folder.
  4. 其次它需要一个项目组名称,它将与它的相关磁盘文件夹同步(在我的例子中是'objc')。显然,这个组需要存在并指向一个真正的文件夹。

Here is the script:

这是脚本:

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
}

#2


1  

A good idea can be found here: https://*.com/a/17894337/354018

可以在这里找到一个好主意:https://*.com/a/17894337/354018

Basically, you import the generated .m files into a known source file that is added to the compile phase.

基本上,您将生成的.m文件导入已添加到编译阶段的已知源文件。

#3


1  

Look at xcode-editor project, an API for manipulating Xcode project files.

查看xcode-editor项目,这是一个用于操作Xcode项目文件的API。

You can add files to a project, specify which target it belongs, add xib files and frameworks.

您可以将文件添加到项目,指定它所属的目标,添加xib文件和框架。

#4


0  

I've added a radar (details at http://www.openradar.me/radar?id=4885314376040448) asking for support for this.

我添加了一个雷达(详见http://www.openradar.me/radar?id=4885314376040448),要求对此提供支持。