我认为我找到了更好的解决方案,您可以使用xctool。
您可以将路径传递给您的 xcode 项目、方案(目标),并使用编译命令获取 json。
$1 = path to .xcodeproj file
$2 = scheme (target)
$3 = path for generated json
#!/bin/bash
XCTOOL_DIR=/Documents/xctool-master #the location of your xctool
$XCTOOL_DIR/xctool.sh -workspace "$1"/project.xcworkspace \
-scheme "$2" \
-reporter json-compilation-database:"$3"/compile_commands.json build
compile_commands.json 是json 编译数据库
,它具有以下格式:
[
{ "directory": "/home/user/llvm/build",
"command": "/usr/bin/clang++ -Irelative -DSOMEDEF=\"With spaces, quotes and \\-es.\" -c -o file.o file.cc",
"file": "file.cc" },
...
]
你可以用通常的 json 解析器来解析它,你也可以使用其他的记者