xcode info.plist 构建变量 ${PRODUCT_NAME:rfc1034identifier} 似乎完全没有记录?
我正在尝试查找描述构造 ${PRODUCT_NAME:rfc1034identifier}
建议的语法和可能性的文档。显然,这会变成产品名称的某个版本,但是描述如何实现的文档在哪里?我只是 grep 了整个 /Developer 目录,但没有得到任何有用的东西。
我并不是在寻找这个特定变量发生的情况的狭义定义,我想了解所有此类修饰符,例如rfc1034identifier
。
I'm trying to find documentation that describe the syntax and possibilities suggested by the construction ${PRODUCT_NAME:rfc1034identifier}
. Obviously this turns into some version of the product name, but where is the documentation that describes how? I just grepped the entire /Developer directory, and got nothing useful.
I'm not looking for the narrow definition of what happens to this particular variable, I want to know about all such modifiers like rfc1034identifier
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通过使用
strings
我还挖掘出了以下看起来与:rfc1034identifier
相关的内容::quote
- 在空格之前添加反斜杠 (等),用于 shell 脚本:identifier
- 用下划线替换空格、斜杠(等):rfc1034identifier
- 用破折号替换空格、斜杠(等)./
:abs
- 不知道确切的命令:
还有更多东西看起来像是有趣的修饰符(例如,
:char-range=%@
),但我无法让它们工作。网上只有一个:char-range
示例,它来自 Xcode 的崩溃日志。有人问我们怎么知道这是一个修饰符规范。嗯,我们知道,因为它适用于构建设置中的多个变量。 Plist 预处理器可能使用与构建系统相同的机制来解析构建变量。
Hack Saw,如果您通过该错误报告得到回复,请不要忘记通知我们:-)
By using
strings
I also dug out the following things that look like they're related to:rfc1034identifier
::quote
- adds backslashes before whitespaces (and more), for use in shell scripts:identifier
- replaces whitespace, slashes (and more) with underscores:rfc1034identifier
- replaces whitespace, slashes (and more) with dashes:dir
- don't know, observed replace with./
in some cases:abs
- don't knowExact command:
There are more things that look like interesting modifiers (for example,
:char-range=%@
), but I couldn't get these to work. There's only one example of:char-range
on the net, and it's from a crash log for Xcode.Someone asked how do we know it's a modifier specification. Well, we know because it works on multiple variables in build settings. Plist preprocessor probably uses the same mechanisms to resolve build variables as does the build system.
Hack Saw, if you get a response via that bug report, don't forget to keep us informed :-)
看起来你也可以堆叠这些。有用的案例浮动是
这样的,“Your App”的产品名称变成了
com.yourcompany。你的应用程序
。Looks like you can stack these as well. The useful case floating around out there is
such that a product name of "Your App" becomes
com.yourcompany.your-app
.最后,苹果公司为此制作了一些文档。截至目前,该内容位于 Xcode 手册的“文本宏”部分。
文本宏格式参考
文本宏可以包含任何有效的 unicode 文本。它还可以包含其他文本宏。
包括其他文本宏
要包含另一个文本宏,请在宏名称前后添加三个下划线 (_) 字符:
修改文本宏扩展
您可以通过添加一个或多个修饰符来修改文本宏的最终扩展。通过在宏末尾放置一个冒号 (:),后跟修饰符,向文本宏添加修饰符。通过用逗号 (,) 分隔每个修饰符来添加多个修饰符。
例如,以下宏将从 FILENAME 宏中删除路径扩展:
要将上面修改的宏转换为有效的 C 标识符,请添加标识符宏:
修饰符
bundleIdentifier:替换任何非包标识符字符带连字符 (-)。
deletingLastPathComponent:从扩展字符串中删除最后一个路径组件。
deletingPathExtension:从扩展字符串中删除任何路径扩展。
deletingTrailingDot:删除所有尾随点 (.)。
标识符:用下划线 (_) 替换任何非 C 标识符字符。
lastPathComponent:仅返回扩展字符串的最后一个路径组件。
pathExtension:返回扩展字符串的路径扩展名。
rfc1034Identifier:用连字符 (-) 替换任何非 rfc1034 标识符字符。
xml:用相应的转义字符串替换特殊的 xml 字符。例如,小于 (<) 替换为
<
TEXT MACROS
文本宏参考
COPYRIGHT
使用项目团队的公司名称的版权字符串。如果没有公司名称,则该字符串为空。
该示例显示了公司设置为“Apple”时的版权字符串。
版权所有 © 2018 苹果公司。版权所有。
日期
当前日期。
默认工具链SWIFTV版本
用于默认工具链的 Swift 版本。
文件库名称
当前文件的名称,不带任何扩展名。
文件库名称标识符
当前文件的名称编码为 C 标识符。
文件头
文本放置在每个新文本文件的顶部。
文件名
当前文件的全名。
完整用户名
当前 macOS 用户的全名。
NSHUMANREADABLECOPYRIGHTPLIST
macOS 应用程序目标的 Info.plist 文件中人类可读的版权字符串的条目。宏的值必须包含 plist 的 XML 分隔符。例如,有效值为:
请注意,该值包含换行符。
组织名称
显示在整个项目文件夹的样板文本中的组织名称。您项目中的组织名称与您在 App Store Connect 中输入的组织名称不同。
包名
当前方案构建的包的名称。
包名称标识符
当前方案构建的包名称的 C 标识符编码版本。
产品名称
当前方案构建的产品的应用名称。
项目名称
当前项目的名称。
运行MACOS版本
运行 Xcode 的 macOS 版本。
目标名称
当前目标的名称。
时间
当前时间。
用户名
当前 macOS 用户的登录名。
UUID
返回唯一的 ID。第一次使用该宏时,它会在返回之前生成 ID。您可以使用此宏通过修饰符创建多个唯一 ID。每个修饰符都会返回一个该修饰符唯一的 ID。例如,第一次使用 UUID:firstPurpose 修饰符时,宏会生成并返回该宏和修饰符组合的唯一 ID。后续使用 UUID:firstPurpose 修饰符会返回相同的 ID。添加 UUID:secondPurpose 修饰符会生成并返回一个不同的 ID,该 ID 对于 UUID:secondPurpose 来说是唯一的,并且与 UUID:firstPurpose 的 ID 不同。
工作空间名称
当前工作空间的名称。如果仅打开一个项目,则为当前项目的名称。
年份
当前年份为四位数。
At long last, Apple produced some documentation on this. This is in the "Text Macros" section of the Xcode manual, as of this date.
Text macro format reference
A text macro can contain any valid unicode text. It can also contain other text macros.
Including other text macros
To include another text macro, add three underscore (_) characters before and after the macro name:
Modifying text macro expansion
You can modify the final expansion of the text macro by adding one or more modifiers. Add a modifier to a text macro by placing a colon (:) at the end of the macro followed by the modifier. Add multiple modifiers by separating each one with a comma (,).
For example, the following macro will remove the path extension from the FILENAME macro:
To turn the modified macro above into a valid C identifier, add the identifier macro:
Modifiers
bundleIdentifier: Replaces any non-bundle identifier characters with a hyphen (-).
deletingLastPathComponent: Removes the last path component from the expansion string.
deletingPathExtension: Removes any path extension from the expansion string.
deletingTrailingDot: Removes any trailing dots (.).
identifier: Replaces any non-C identifier characters with an underscore (_).
lastPathComponent: Returns just the last path component of the expansion string.
pathExtension: Returns the path extension of the expansion string.
rfc1034Identifier: Replaces any non-rfc1034 identifier characters with a hyphen (-).
xml: Replaces special xml characters with the corresponding escape string. For example, less-than (<) is replaced with
<
TEXT MACROS
Text macros reference
COPYRIGHT
A copyright string that uses the company name of the team for the project. If there is no company name, the string is blank.
The example shows a copyright string when the company is set to “Apple”.
Copyright © 2018 Apple. All rights reserved.
DATE
The current date.
DEFAULTTOOLCHAINSWIFTVERSION
The version of Swift used for the default toolchain.
FILEBASENAME
The name of the current file without any extension.
FILEBASENAMEASIDENTIFIER
The name of the current file encoded as a C identifier.
FILEHEADER
The text placed at the top of every new text file.
FILENAME
The full name of the current file.
FULLUSERNAME
The full name of the current macOS user.
NSHUMANREADABLECOPYRIGHTPLIST
The entry for the human readable copyright string in the Info.plist file of a macOS app target. The value of the macro must include the XML delimiters for the plist. For example, a valid value is:
Notice that the value includes a newline.
ORGANIZATIONNAME
The name for your organization that appears in boilerplate text throughout your project folder. The organization name in your project isn’t the same as the organization name that you enter in App Store Connect.
PACKAGENAME
The name of the package built by the current scheme.
PACKAGENAMEASIDENTIFIER
A C-identifier encoded version of the package name built by the current scheme.
PRODUCTNAME
The app name of the product built by the current scheme.
PROJECTNAME
The name of the current project.
RUNNINGMACOSVERSION
The version of macOS that is running Xcode.
TARGETNAME
The name of the current target.
TIME
The current time.
USERNAME
The login name for the current macOS user.
UUID
Returns a unique ID. The first time this macro is used, it generates the ID before returning it. You can use this macro to create multiple unique IDs by using a modifier. Each modifier returns an ID that is unique for that modifier. For example, the first time the UUID:firstPurpose modifier is used, the macro generates and returns a unique ID for that macro and modifier combination. Subsequent uses of the UUID:firstPurpose modifier return the same ID. Adding the UUID:secondPurpose modifier generates and returns a different ID that will be unique to UUID:secondPurpose, and different from the ID for UUID:firstPurpose.
WORKSPACENAME
The name of the current workspace. If there is only one project open, then the name of the current project.
YEAR
The current year as a four-digit number.
似乎有 :identifier、:rfc1034identifier 和 :xml 修饰符。但除了这个我没有任何线索。
It seems that there are :identifier, :rfc1034identifier and :xml modifiers. But I have no clue except this.
在偶然发现这个问题及其现有答案之后,我不得不说:近年来,苹果的文档在这个主题上并没有改进。我们目前处于 Xcode 13,仍然没有所有可用修饰符的完整列表。
因此,我做了一些探索,并在
DVTFoundation.framework
中找到了受支持的修饰符,我将在下面列出。我已经在 Xcode 13.3 构建设置中测试了它们,并使用以下两个宏来说明它们的影响:
检索运算符/修饰符
检索修饰符用于提取和/或转换宏/变量/设置的全部或部分。
它们使用以下语法应用:
$(:)
quote
:转义在 shell 脚本/命令中具有特殊含义的所有字符,例如空格、冒号、分号和反斜杠。upper
:将所有字符转换为其等效的大写字母。lower
:将所有字符转换为其小写等效项。identifier
:用下划线 (_) 替换任何非 C 标识符字符。rfc1034identifier
:用连字符 (-) 替换任何非 rfc1034 标识符字符c99extidentifier
:用下划线 (_) 替换任何非 C99 标识符字符。由于 C99 使用 Unicode,因此允许使用变音符号!xml
:根据Apple文档,它应该用相应的转义字符串替换特殊的xml字符。例如,小于号 (<) 被替换为 <。 但在我的示例中这不起作用。dir
:提取路径的目录部分file
:提取路径的文件名部分base
:提取路径的文件名基本部分( =不带后缀/扩展名的文件名)suffix
:提取文件扩展名/后缀为路径或文件名standardizepath
:标准化路径(例如../
和波形符 (~) 已解决)替换运算符/修饰符
除了上述提取/转换运算符之外,构建设置系统中还内置支持替换使用修饰符匹配的目录的特定部分。
它们使用以下语法应用:
$(:=)
dir=
:替换目录部分使用
表示路径并返回新路径file=
:替换路径的文件名部分并返回新路径base =
:替换路径的文件名基本部分(=不带后缀/扩展名的文件名)并返回新路径suffix=
:替换文件扩展名/为路径添加后缀并返回新路径我希望此列表将帮助更多人查看 Xcode 构建设置并想知道如何转换它们。
After stumbling over this question and its existing answers, I have to say: Apples documentation did not improve on this topic over the recent years. We are currently at Xcode 13 and there is still no complete list of all modifiers available.
Therefore I did some spelunking and found the supported modifiers in
DVTFoundation.framework
which I will list below.I've tested them all in Xcode 13.3 build settings and used the following two macros to illustrate their impact:
Retrieval operators/modifiers
Retrieval modifiers are used to extract and/or transform all or parts of a macro/variable/setting.
They are applied using the following syntax:
$(<VARIABLE>:<MODIFIER>)
quote
: Escapes all characters which have a special meaning in shell scripts/commands like space, colon, semicolon and backslash.upper
: Transforms all characters to their uppercase equivalents.lower
: Transforms all characters to their lowercase equivalents.identifier
: Replaces any non-C identifier characters with an underscore (_).rfc1034identifier
: Replaces any non-rfc1034 identifier characters with a hyphen (-)c99extidentifier
: Replaces any non-C99 identifier characters with an underscore (_). Umlauts are allowed as C99 uses Unicode!xml
: According to Apple documentation it should replace special xml characters with the corresponding escape string. For example, less-than (<) is replaced with <. But in my examples this didn't work.dir
: Extracts the directory part of a pathfile
: Extracts the filename part of a pathbase
: Extracts the filename base part of a path (=filename without suffix/extension)suffix
: Extracts the filename extension/suffix a path or filenamestandardizepath
: Standardizes the path (e.g.../
and tilde (~) are resolved)Replacement operators/modifiers
Beside above extracting/transforming operators, there is support built into the build settings system to replace specific parts of a directory which are matched using a modifier.
They are applied using the following syntax:
$(<VARIABLE>:<MODIFIER>=<VALUE>)
dir=<VALUE>
: Replaces the directory part of a path with<VALUE>
and returns the new pathfile=<VALUE>
: Replaces the filename part of a path and returns the new pathbase=<VALUE>
: Replaces the filename base part of a path (=filename without suffix/extension) and returns the new pathsuffix=<VALUE>
: Replaces the filename extension/suffix a path and returns the new pathI hope this list will help more people looking at Xcodes build settings and wondering how they can be transformed.