自动添加生成的源文件到X code项目 [英] Automatically adding generated source files to an xcode project

查看:127
本文介绍了自动添加生成的源文件到X code项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是IDL自动生成源文件,我的X code项目。有谁知道我可以有自动添加到项目中生成的文件?目前,我不得不删除该项目当前的文件,并添加新的。这得到真烦。

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.

使用的头文件,但X code进行文件夹中引用的作品并不想承认文件夹中的引用作为源文件的任何文件。有没有人找到了解决这个问题的?

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?

推荐答案

我也花了几天写了这个问题的解决方案。
这里是一个Ruby脚本,您可以添加到项目的目标为运行脚本生成阶段。这是利用X code 3.2.4和1.8.7的红宝石测试。

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.

对于这个工作,你需要安装RB-appscript红宝石的宝石。 (例如:sudo的创业板安装RB-appscript)

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

有一点的设置要做到:


  1. 首先它需要添加的文件的编译目标的列表。

  2. 其次,它预计其将与之同步项目组名的关联的磁盘文件夹(在我的情况下'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
}

这篇关于自动添加生成的源文件到X code项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆