如何使用 rb-appscript 将文件添加到 Xcode 中的目标? [英] How do I add files to targets in Xcode using rb-appscript?

查看:17
本文介绍了如何使用 rb-appscript 将文件添加到 Xcode 中的目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 rb-appscript 自动将文件添加到我的 Xcode 项目中.我对 Ruby 或 Applescript 没有太多经验,但似乎有两个人为他们做了这项工作:

I am trying to automatically add files to my Xcode project using rb-appscript. I don't have much experience with Ruby or Applescript, but two people seem to have made this work for them:

https://github.com/gonzoua/xcs/blob/master/xcs.thor

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

不幸的是,这些都不适合我.我可以让他们将文件添加到组,但将文件添加到目标会中断.这是对我不起作用的最简单的一段代码:

Unfortunately neither of these work for me. I can get them to add files to groups, but adding files to targets breaks. Here is the simplest piece of code that doesn't work for me:

require 'rubygems'
require 'appscript'

project_path = 'Users:me:Projects:xcode:project:src:AppScaffold.xcodeproj'
project_name = 'AppScaffold'
group_name = 'Classes'
file_name = 'ApplicationDelegate.m'
target_name = 'AppScaffold'

def lookup(sequence, name)
  sequence.get.each { |item|
    if item.name.get == name
      return item
    end
  }
  raise Exception.new("Couldn't find name '" + name + "' in sequence " + sequence.inspect)
end

app = Appscript.app('Xcode')
app.open(project_path)

project = lookup(app.projects, project_name)
target = lookup(project.targets, target_name)
group = lookup(project.root_group.item_references, group_name)
file = lookup(group.item_references, file_name)

file.add({:to => target})
# I also tried this:
# app.add(file, {:to => target})

此消息失败:

/Library/Ruby/Gems/1.8/gems/rb-appscript-0.6.1/lib/appscript.rb:542:in `_send_command': CommandError (Appscript::CommandError)
        OSERROR: -1708
        MESSAGE: Application could not handle this command.
        COMMAND: app("/Developer/Applications/Xcode.app").workspace_documents["project.xcworkspace"].projects["AppScaffold"].root_group.Xcode_3_groups.ID("080E96DDFE201D6D7F000001").Xcode_3_file_references.ID("1D3623250D0F684500981E51").add({:to=>app("/Developer/Applications/Xcode.app").workspace_documents["project.xcworkspace"].projects["AppScaffold"].targets.ID("1D6058900D05DD3D006BFB54")})
    from /Library/Ruby/Gems/1.8/gems/rb-appscript-0.6.1/lib/appscript.rb:642:in `method_missing'
    from add_to_target.rb:28

请注意,我使用的是 Xcode 4,但我的项目似乎有Xcode_3_references".我从头开始创建的项目也是如此;我不知道为什么.

Note that I am using Xcode 4, but my project seems to have "Xcode_3_references". This is also the case for projects I create from scratch; I'm not sure why.

无论如何,我不确定如何处理此错误消息,或者在哪里可以找到有关此的文档.(我查看了 Xcode 字典,但没有太多关于添加"的内容.)任何建议都会很棒.我不喜欢 rb-appscript,我只想以编程方式将文件添加到我的项目中.

Anyway, I'm not sure what to make of this error message, or where to find documentation on this. (I looked at the Xcode dictionary, but it didn't have much to say about "add".) Any advice would be great. I'm not married to rb-appscript, I just want to add files to my project programmatically.

推荐答案

因此,自从 Xcode 移至 AppStore 以来,Xcode 的一个问题是旧版本保持不变,没有被删除 - 更不用说二进制文件都不同(llvm 与 cc).这与您遇到的问题不同,但我确实遇到了使用命令行编译器来处理自制软件之类的问题,并遇到了以下命令:

So, one issue with Xcode since it moved to the AppStore is that older versions were left intact, and not removed - not to mention the binaries are all different (llvm vs cc). It wasn't the same issue you are having, but I did run into complications using the command-line compilers for things like homebrew, and came across this command:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

参见:http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html

我在这里不确定,但是这可能会重新定位"您正在使用的构建系统以引用当前的 xcode,而不是旧版本,这可能会产生预期的结果.

I don't know for sure here, but it's possible this will "re-orient" the build system you are working with to reference the current xcode and not the older version, which may have the intended result.

这篇关于如何使用 rb-appscript 将文件添加到 Xcode 中的目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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