无法理解 xcode 构建参数:“${BUILD_DIR%Build/*}”

发布于 2025-01-11 10:30:10 字数 587 浏览 0 评论 0原文

我正在集成 WireGuardKit,根据其自述文件,我需要创建一个用于构建wireguard-go-bridge 库的外部构建系统目标。

在外部构建系统目标的信息选项卡中。文档说我应该使用这个位置: ${BUILD_DIR%Build/*}SourcePackages/checkouts/wireguard-apple/Sources/WireGuardKitGo 外部构建系统目标的构建失败。由于路径无法解析。 如果我使用正确的绝对路径更改路径,则构建将会成功。

谁能告诉我这个 ${BUILD_DIR%Build/*} 的含义是什么,看起来 firebase 也在使用这个神奇的变量,请参阅 Firebase Crashlytics | Swift 包管理器 (SPM) 运行脚本?

I'm integrating the WireGuardKit, according to its README file, I need to create an external build system target to build wireguard-go-bridge library.

In the external build system target's info tab. The documentation says I should use this location: ${BUILD_DIR%Build/*}SourcePackages/checkouts/wireguard-apple/Sources/WireGuardKitGo
The build for the external build system target failed. As the path can't be resolved.
If I change the path with a correct, absolute path, the build will succeed.

Can anyone tell me what's the meaning of this ${BUILD_DIR%Build/*}, looks firebase is also using this magic variable, see Firebase Crashlytics | Swift Package Manager (SPM) Run Script?

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

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

发布评论

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

评论(2

蔚蓝源自深海 2025-01-18 10:30:10

经过一番谷歌搜索后,我明白了:
引用超级用户贡献者 Marek Rost 的帖子:

当模式 ${variable%substring} 中使用百分号 (%) 时,将返回变量的内容,并将变量后面出现的最短子字符串删除。

此函数支持通配符模式,这就是为什么它接受星号(星号)作为零个或多个字符的替代。应该提到的是,这是 Bash 特有的。其他Linux shell不一定包含此功能。

如果您想了解有关 Bash 中字符串操作的更多信息,那么我强烈建议您阅读以下页面:高级 Bash 脚本指南:第 10 章:操作变量。例如,在许多其他方便的功能中,它解释了双百分号 (%%) 的作用。

我忘了提及,当它在模式 $((variable%number)) 或 $((variable1%$variable2)) 中使用时,百分号 (%) 字符将用作模运算符。

当百分号 (%) 在不同的上下文中使用时,它应该仅被识别为常规字符。

所以假设 ${BUILD_DIR} 是

~/Library/Developer/Xcode/DerivedData/wgShowcase-dejirdnsktlwtagdrhljeefdnxvi/Build/Products

什么 ${BUILD_DIR%Build/*} 的意思是从 ${BUILD_DIR} 后面删除最短出现的子字符串 Build/* (星号是通配符)多变的。在这种情况下,Build/Products 将被删除。那么我们得到的结果是:

~/Library/Developer/Xcode/DerivedData/wgShowcase-dejirdnsktlwtagdrhljeefdnxvi/

由于该项目使用的所有 SPM 包都在 ~/Library/Developer/Xcode/DerivedData/wgShowcase-dejirdnsktlwtagdrhljeefdnxvi/ 的子目录中检出,因此最终解析的路径应该be:

~/Library/Developer/Xcode/DerivedData/wgShowcase-dejirdnsktlwtagdrhljeefdnxvi/SourcePackages/checkouts/wireguard-apple/Sources/WireGuardKitGo

至于为什么构建不成功,我认为是Xcode的bug。我已向苹果报告了一个错误。对于任何正在尝试构建的人。
使用以下作为解决方法:

${BUILD_DIR}/../../SourcePackages/checkouts/wireguard-apple/Sources/WireGuardKitGo

更新:这是 Apple 关于此“问题”的回复

审核您的反馈后,我们为您提供了一些额外信息,或者针对此问题需要采取一些额外信息:

此处的 Directory 字段不会被评估为 bash 变量,而是被评估为 Xcode 构建设置,该设置不支持 % 等 bash 运算符。

您可能需要使用 makefile 将工作目录设置为已知目录,然后让该 makefile 使用最终目标目录中的 makefile。

我们注意到,当我们克隆存储库时,它附带了 macOS 和 iOS 目标,其目录设置为 $(PROJECT_DIR)/Sources/WireGuardKitGo,因此我们想知道项目所有者是否已更新项目来解决此问题,但尚未更新文档。

无论如何,这都是正确的。

After some googling, I figured it out:
Quote SuperUser contributor Marek Rost's Post:

When the percent sign (%) is used in the pattern ${variable%substring}, it will return content of the variable with the shortest occurrence of substring deleted from the back of the variable.

This function supports wildcard patterns, that is why it accepts an asterisk (star) as a substitute for zero or more characters. It should be mentioned that this is Bash specific. Other Linux shells do not necessarily contain this function.

If you want to learn more about string manipulation in Bash, then I highly suggest reading the following page, Advanced Bash-Scripting Guide: Chapter 10. Manipulating Variables. Among many other handy functions, it explains what a double percent sign (%%) does, for example.

I forgot to mention that when it is used in the pattern $((variable%number)) or $((variable1%$variable2)), the percent sign (%) character will function as a modulo operator.

When the percent sign (%) is used in different contexts, it should be recognized as a regular character only.

So suppose ${BUILD_DIR} is

~/Library/Developer/Xcode/DerivedData/wgShowcase-dejirdnsktlwtagdrhljeefdnxvi/Build/Products

What ${BUILD_DIR%Build/*} mean is delete the shortest occurrence of substring Build/*(the star sign is a wildcard) from the back of ${BUILD_DIR} variable. In this case, the Build/Products will be removed. then we have the result:

~/Library/Developer/Xcode/DerivedData/wgShowcase-dejirdnsktlwtagdrhljeefdnxvi/

So since all the SPM packages used by this project checks out at a child directory at ~/Library/Developer/Xcode/DerivedData/wgShowcase-dejirdnsktlwtagdrhljeefdnxvi/, the final resolved path should be:

~/Library/Developer/Xcode/DerivedData/wgShowcase-dejirdnsktlwtagdrhljeefdnxvi/SourcePackages/checkouts/wireguard-apple/Sources/WireGuardKitGo

As for why the build is not succeed, I think it's a Xcode bug. I have reported a bug to apple. For anyone who is trying to build.
Use below as a workaround:

${BUILD_DIR}/../../SourcePackages/checkouts/wireguard-apple/Sources/WireGuardKitGo

Update: Here is the response from Apple regarding to this 'issue'

After reviewing your feedback, we have some additional information for you, or some additional information, or action is necessary for this issue:

The Directory field here is not evaluated as a bash variable, it’s evaluated as an Xcode build setting, which does not support bash operators such as %.

You would likely need to set the working directory to a known directory with a makefile, and then have that makefile use makefiles from the ultimate target directory.

We noticed that when we clone the repo it comes with macOS and iOS targets whose directories are set to $(PROJECT_DIR)/Sources/WireGuardKitGo, so we're wondering if the project owner has updated the project to fix this issue, but hasn’t updated the documentation.

In any event, this is behaving correctly.

孤独患者 2025-01-18 10:30:10

有同样的问题,这篇文章解决了它

经过一天的谷歌搜索,我发现 Xcode 的一些变量是在 com.apple.dt.XCode.plist 文件中设置的,该文件位于 /Users/[用户名]/Library/Preferences/,但是该文件很大,并且由于某种原因,Xcode 不想正确打开它。

解决方案:

如果该文件丢失,Xcode 将在启动时创建默认文件。

Had the same issue, this article solved it

And after a day of googling, I’ve found some of the Xcode’s variables are set in com.apple.dt.XCode.plist file, which is located at /Users/[username]/Library/Preferences/, but that file is huge and for some reason, Xcode doesn’t want to open it properly.

Solution:

It appears if that file is missing, then Xcode would create the default one on launch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文