使用 bash 脚本在 XCode 中收集 FIXME 和 TODO:'s

问题描述 投票:0回答:1
我之前确实尝试过寻找答案,但是当将以下内容放入 XCode 的脚本部分时,始终没有得到任何结果。

旁注:以防万一,目的是它仅在 Objective-C 和 swift 文件中搜索。

我想扩展它,但让我首先了解基础知识以了解它是如何工作的。我确实通过添加“运行脚本”脚本在“Xcode 15.4”、“Xcode 16”和“Xcode 16.1 beta 2”下尝试了此脚本。

#!/bin/bash # Enable debug mode to log the script steps set -xe # Use Xcode's environment variable to get the project directory (inside sandbox) PROJECT_DIR="${SRCROOT}" # Set the output file (correct concatenation) OUTPUT_FILE="${PROJECT_DIR}/todo_fixme_report.txt" # Ensure the script only searches within the project directory (avoiding external volumes) grep -r --include=\*.{swift,m,h} -l "TODO:\|FIXME:" "$PROJECT_DIR" > "$OUTPUT_FILE" # Check if grep encounters an error (e.g., no matching files found) if [ $? -ne 0 ]; then echo "Error: Could not search files. Check if the directory is correct." exit 1 fi # Check if the output file is not empty if [ -s "$OUTPUT_FILE" ]; then echo "The following files contain TODOs or FIXMEs:" >> "$OUTPUT_FILE" grep -r --include=\*.{swift,m,h} "TODO:\|FIXME:" "$PROJECT_DIR" >> "$OUTPUT_FILE" else echo "No TODOs or FIXMEs found." > "$OUTPUT_FILE" fi # Open the output file in Xcode without adding it to the project open -a /Applications/Xcode-15.4.0.app "$OUTPUT_FILE" & # Ensure the script exits successfully exit 0
如果我在终端中运行这个脚本,它就可以正常工作。
但在 Xcode 中我得到了

沙箱:bash(50795)拒绝(1)文件写入创建/Volumes/Puddle/.../_Projects_Current/MyApp/todo_fixme_report.txt

但是所有应用程序(甚至包括 Grep 和 Bash)都具有完整的磁盘访问权限。 Puddle 驱动器是“用户”数据所在的驱动器。

我在这里想念什么?

任何建议表示赞赏。

xcode bash macos
1个回答
0
投票
就像马特在他的评论中显示的链接一样,你必须有

ENABLE_USER_SCRIPT_SANDBOXING

设置为否。您可以在“构建设置”选项卡下找到它。过滤“用户脚本沙箱”或使用此文本的一部分。将其从“是”更改为“否”。

===

如果您想启动 Xcode,您可以仅使用“Xcode”,但随后它会打开默认的 Xcode 版本。如果您想打开特定的 Xcode 版本,请使用整个应用程序名称。另外,如果停止运行脚本,请在“打开”命令行末尾使用“&”。

© www.soinside.com 2019 - 2024. All rights reserved.