[英]How to access my app’s derived data folder itself?
I'm in the middle of moving my iOS app's Firebase dependency from CocoaPods to Swift Package Manager.我正在将我的 iOS 应用程序的 Firebase 依赖项从 CocoaPods 转移到 Swift Package Manager。
Firebase's Crashlytics requires a script to be executed while the app is building (using the Run Script build phase). Firebase 的 Crashlytics 需要在构建应用程序时执行脚本(使用运行脚本构建阶段)。 Back in the CocoaPods days, I used to call the script the way documented by Google :
"${PODS_ROOT}/FirebaseCrashlytics/run"
.回到 CocoaPods 时代,我曾经按照Google 记录的方式调用脚本:
"${PODS_ROOT}/FirebaseCrashlytics/run"
。
After I've switched to SPM, Firebase files are no longer in ${PODS_ROOT}
, and there's no such variable available at all.在我切换到 SPM 后,Firebase 文件不再位于
${PODS_ROOT}
,并且根本没有这样的变量可用。 I know the file I need is now located in the DerivedData
folder, specifically it's at ~/Library/Developer/Xcode/DerivedData/MyApp-abcde/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run
.我知道我需要的文件现在位于
DerivedData
文件夹中,特别是它位于~/Library/Developer/Xcode/DerivedData/MyApp-abcde/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run
。 The problem is, the MyApp-abcde
folder is not easily referenced.问题是,
MyApp-abcde
文件夹不容易被引用。
A Medium post I found suggested using the ${BUILD_DIR}
build variable (in regard to the example above, it would resolve to <…>/MyApp-abcde/Build/Products
), and calling the dirname
command to move up the directory hierarchy. 我发现的一篇中等文章建议使用
${BUILD_DIR}
构建变量(关于上面的示例,它将解析为<…>/MyApp-abcde/Build/Products
),并调用dirname
命令以向上移动目录层次结构.
This hack worked only for running the app.此 hack 仅适用于运行该应用程序。 When I tried to archive it,
${BUILD_DIR}
resolved to another path, namely <…>/MyApp-abcde/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/BuildProductsPath
.当我尝试归档它时,
${BUILD_DIR}
解析到另一个路径,即<…>/MyApp-abcde/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/BuildProductsPath
。 I tried a few more build variables, such as ${SYMROOT}
, in place of ${BUILD_DIR}
, but they also produce different paths depending on the operation.我尝试了更多构建变量,例如
${SYMROOT}
代替${BUILD_DIR}
,但它们也会根据操作产生不同的路径。
So, here comes the question…那么,问题来了……
Is there a way to reliably reference my app's derived data folder's root (ie ~/Library/Developer/Xcode/DerivedData/MyApp-abcde
) using Xcode's build variables?有没有办法使用 Xcode 的构建变量可靠地引用我的应用程序的派生数据文件夹的根目录(即
~/Library/Developer/Xcode/DerivedData/MyApp-abcde
) ?
You were close.你很接近。 This should work:
这应该有效:
${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run
I'm reworking my answer as I realized I haven't answered your question..我正在修改我的答案,因为我意识到我没有回答你的问题..
I have a run script that copies the build targets into a new folder.我有一个运行脚本,可以将构建目标复制到一个新文件夹中。 This works for both Build and Archive.
这适用于构建和存档。 Note that you need the -L on copy to follow the symlink
请注意,您需要在复制时使用 -L 来跟随符号链接
# Copy the built framework into a sibling to the project folder
if [[ "$CONFIGURATION" == "Debug" ]]; then
mkdir -p "$PROJECT_DIR/../../iwins-ios-sdk/debug"
rm -rf "$PROJECT_DIR/../../iwins-ios-sdk/debug/IWiNS_SDK.framework"
cp -LR "$BUILD_DIR/Debug-iphoneos/IWiNS_SDK.framework" "$PROJECT_DIR/../../iwins-ios-sdk/debug"
else
mkdir -p "$PROJECT_DIR/../../iwins-ios-sdk/release"
rm -rf "$PROJECT_DIR/../../iwins-ios-sdk/release/IWiNS_SDK.framework"
cp -LR "$BUILD_DIR/Release-iphoneos/IWiNS_SDK.framework" "$PROJECT_DIR/../../iwins-ios-sdk/release"
fi
Also, you can find all of the build envvars here: https://gist.github.com/gdavis/6670468此外,您可以在此处找到所有构建环境变量: https ://gist.github.com/gdavis/6670468
So, it appears that $BUILD_DIR is different for build/release, but by copying the files to a known location at build time, you'll know where to find them.因此,看起来 $BUILD_DIR 对于构建/发布是不同的,但是通过在构建时将文件复制到已知位置,您将知道在哪里可以找到它们。
Crashlytics run script Crashlytics 运行脚本
To build&run from Xcode:从 Xcode 构建和运行:
${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run
To archive for distribution from Xcode Server at CI/CD:要从 Xcode Server 的 CI/CD 存档以进行分发:
${XCS_DERIVED_DATA_DIR%/*}/Dependencies/checkouts/firebase-ios-sdk/Crashlytics/run
To work for both at the same time:同时为两者工作:
if [[ "${XCS_DERIVED_DATA_DIR}" == "" ]]; then
${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run
else
${XCS_DERIVED_DATA_DIR%/*}/Dependencies/checkouts/firebase-ios-sdk/Crashlytics/run
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.