使用脚本将文件添加到 Xcode 目标

发布于 2025-01-07 17:42:31 字数 452 浏览 1 评论 0原文

有没有办法使用脚本将文件添加到 Xcode 目标?

我在这里谈论的不是构建规则或阶段;而是构建规则。我知道这些。我有一个项目需要将大约 3500 个文件导入到 100 多个目标中。我不想手动执行此操作,因为所述文件分布在几个目录中,并且手动选择它们将需要几天的时间。

源代码最初来自一个基于 makefile 的项目,我将其转换为 Xcode。我可以轻松地破解 makefile,以便使用一些 perl 魔法轻松地在相对于 $(SRCROOT) 的相关目录中创建文件列表。我不知道如何处理这些列表。

如果我能以某种方式运行一个在列表中读取的脚本,在 Xcode 中找到该文件(因为这些文件已经作为文件引用和文件夹组添加到项目中),然后将其添加到单个目标中,那就太理想了我可以定义。仅仅能够做到这一点就意味着为所有目标导入和配置源的整个工作将花费数小时而不是数天。

这有可能以某种方式实现吗?

非常感谢! -KT

Is there any way to use a script to add files to an Xcode target?

I'm not talking about build rules or phases here; I know about those. I have a project that requires about 3500 files to be imported into over 100 targets. I'd rather not do this by hand as said files are spread across a few directories and selecting them all by hand would take days to do.

The source code was originally from a makefile-based project that I'm converting to Xcode. I can hack up the makefiles easily enough to create lists of files in their relevant directories relative to $(SRCROOT) easily enough using some perl magic. What I don't know is what to do with those lists.

It would be ideal if I could somehow run a script that read in the list, found the file inside Xcode (since the files will have already been added to the project as file references and folder groups), then added it to a single target that I could define. Just being able to do this would mean that the entire job of importing and configuring the sources for all the targets would take hours rather than days.

Is this possible to achieve somehow?

Many thanks in advance!
-KT

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[浮城] 2025-01-14 17:42:31

你的工作已经为你完成了。

可能作为最后的解决方法...

当我在添加文件后查看同一项目之间的差异时,它会进行更改
幸运的是,project.pbxproj 是文本。

如果没有其他方法,可能会适当地复制您的文件,您可能会
能够解析/编辑此文件以重建它...很棘手,是的,并且可能不受支持。

我确实在 Dan Wright 的这个文件中找到了一些附加信息 Xcode 简介项目格式
有关 Xcode 项目格式的更多信息

似乎该方法的成功将取决于能否获取文件的 PBXFileReference。

好运

吉姆Z

You have your work cut out for you.

Possibly as a last resort workaround...

When I looked at diff between same project after adding a file, it makes changes to
project.pbxproj fortunately in text.

If there is no other way, possibly post copying your files appropriately, you might be
able to parse/edit this file to reconstruct it...tricky YES, and likely unsupported.

I did find some additional info in this file by Dan Wright A brief look at the Xcode project format
and More on the Xcode project format

Seems the success of the approach will depend on being able to get PBXFileReference(s) for your files.

Good luck

Regards

JimZ

朦胧时间 2025-01-14 17:42:31

将“运行脚本”构建阶段添加到您的目标。

运行脚本构建阶段将有一个文本框,您可以在其中输入脚本。这里的脚本可以访问 Xcode 构建变量。

您可以将整个脚本放在这里,但我通常更喜欢让它调用 ruby​​ 脚本。

以下是一些将资源复制到应用程序包中的示例脚本:

echo SRCROOT is ${SRCROOT}
echo so project root is ${SRCROOT}/..
echo and it contains ...
ls ${SRCROOT}/..
echo Will copy resources to ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
ruby ${SOMEPROJECT}/buildscripts/copy_resources.rb ${SRCROOT}/..   ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app

Add a 'run script' build phase to your target.

The Run Script build phase will have a text box where you can enter script. The script here can access Xcode build variables.

You can put the whole script in here, but I usually prefer to have it call a ruby script.

Here is some example script that copies resources into the app bundle:

echo SRCROOT is ${SRCROOT}
echo so project root is ${SRCROOT}/..
echo and it contains ...
ls ${SRCROOT}/..
echo Will copy resources to ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
ruby ${SOMEPROJECT}/buildscripts/copy_resources.rb ${SRCROOT}/..   ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文