xcodebuild能够删除项目的Build文件夹内容吗?

7

在 Xcode 9 中,有一个名为“Clean Build Folder...”(K)的构建选项,它会删除构建文件夹中的所有文件,只留下空文件夹。此后,该行为被移除,菜单项标题更改为“Clean Build Folder”,现在的行为类似于旧版“Clean”。

xcodebuild 有一个构建选项叫做 clean,它与 Xcode 的“Clean Build Folder”(K)一样,都会保留一些文件。

是否有一种可通过脚本命令删除构建文件夹中所有文件的方法?


我的尝试:

xcodebuild clean -workspace "My Workspace.xcworkspace" -scheme "My Scheme"

正如我所说,这并不能真正清理所有东西。为此,我在我的构建脚本中添加了以下修补程序:

export IS_XCODE_CACHE_FOLDER_PRESENT="`ls -la ~/Library/Developer/ | grep -x "Xcode"`"

if [ 0 -ne "$IS_XCODE_CACHE_FOLDER_PRESENT" ]; then
    echo "Xcode cache folder should not be present at build time! Attempting to delete..."
    rm -rf "~/Library/Developer/Xcode"
    RM_RESULT=$?
    if [ 0 -ne "$RM_RESULT" ]; then
        echo "FAILED to remove Xcode cache folder!"
        exit $RM_RESULT
    fi
fi

你目前尝试了什么? - Elise van Looij
@ElisevanLooij 感谢您的提问!问题已更新。 - Ky -
2个回答

2

我曾经遇到过类似的需求。所以在试用了几个小时后,我决定使用自定义脚本来代替使用Xcode的运行脚本。

因此,我使用我的脚本来代替在模拟器上使用Xcode运行应用程序,该脚本首先清理构建文件夹,然后构建项目,接着安装并最终在模拟器中启动应用程序。

以下是我正在使用的快捷脚本:

 # Delete Build directory
 rm -rf ./build/Build

 # pod install
 pod install

 # Build project
 xcrun xcodebuild -scheme Example -workspace Example.xcworkspace -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.1' -derivedDataPath build

 # Install App
 xcrun simctl install "iPhone 11 Pro Max" ./build/Build/Products/Debug-iphonesimulator/Example.app/

 # Launch in Simulator
 xcrun simctl launch "iPhone 11 Pro Max" com.ihak.arpatech.Example

注意:查看我发布的这个问题以了解我所面临的问题。


-1

您可以添加 clean 操作。

xcodebuild clean build -workspace "My Workspace.xcworkspace" -scheme "My Scheme"

请查看 man xcodebuild 获取更多信息。

 action ...
           Specify one or more actions to perform. Available actions are:

           build                  Build the target in the build root (SYMROOT).  This is the default action, and is used if no action is given.

           build-for-testing      Build the target and associated tests in the build root (SYMROOT).  This will also produce an xctestrun file in the build root. This requires speci-
                                  fying a scheme.

           analyze                Build and analyze a target or scheme from the build root (SYMROOT).  This requires specifying a scheme.

           archive                Archive a scheme from the build root (SYMROOT).  This requires specifying a scheme.

           test                   Test a scheme from the build root (SYMROOT).  This requires specifying a scheme and optionally a destination.

           test-without-building  Test compiled bundles. If a scheme is provided with -scheme then the command finds bundles in the build root (SRCROOT).  If an xctestrun file is
                                  provided with -xctestrun then the command finds bundles at paths specified in the xctestrun file.

           installsrc             Copy the source of the project to the source root (SRCROOT).

           install                Build the target and install it into the target's installation directory in the distribution root (DSTROOT).

           clean                  Remove build products and intermediate files from the build root (SYMROOT).

我的问题提到我已经尝试过这个。以防自那时以来事情有所改变,我刚刚尝试了使用应用商店版本的Xcode(当前版本为11.5),并且它留下了构建文件夹:https://i.imgur.com/UB8dpEd.mp4 - Ky -

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接