-
-
Save ryuichis/755e6297aec13c900cdf to your computer and use it in GitHub Desktop.
source ~/.bash_profile | |
cd ${SRCROOT} | |
xcodebuild clean | |
xcodebuild | xcpretty -r json-compilation-database | |
oclint-json-compilation-database -- -report-type xcode |
cp: build/reports/compilation_db.json: No such file or directory
env: ruby_executable_hooks: No such file or directory
Hi all, I was having trouble getting this script to work as well. @bsameh's solution helped, but I still needed to make some tweaks to the parameters for the xcodebuild
command by specifying the scheme and workspace (I'm using Cocoapods). I also had to make sure to use the same parameters for the xcodebuild clean
command.
Here's what the final script looks like (substituting <projectName>
for the correct value, of course). You may also need to tweak some of the exclude
options for the oclint-json-compilation-database
command:
source ~/.bash_profile
cd ${SRCROOT}
xcodebuild -scheme <projectName> -workspace <projectName>.xcworkspace clean
xcodebuild -scheme <projectName> -workspace <projectName>.xcworkspace | xcpretty -r json-compilation-database --output compile_commands.json
oclint-json-compilation-database -exclude Pods -exclude build -exclude Internal -exclude ThirdParties -- -report-type xcode
✅ The solution of @tylermilner works for me!
I was recently having some trouble getting this working on a project using Xcode 10 and OCLint 0.13.1. Here's a summary of some of the errors I saw and how I resolved them:
- error: accessing build database "/Users/tyler.milner/Library/Developer/Xcode/DerivedData/<project_name>/Build/Intermediates.noindex/XCBuildData/build.db": disk I/O error
- Solved by switching from the New Build System to the Legacy Build System (File --> Workspace Settings in Xcode).
- oclint: error: one compiler command contains multiple jobs:
- Solved by adding the
COMPILER_INDEX_STORE_ENABLE=NO
build flag to my mainxcodebuild
step.
- Solved by adding the
- oclint: Not enough positional command line arguments specified!
- Solved by adding
unset LLVM_TARGET_TRIPLE_SUFFIX
to the top of the script.
- Solved by adding
I've got a working version of the script that contains the above fixes in my fork. Also including it below (again, you will need to replace <project_name>
with appropriate values and likely tweak the -exclude
flags):
source ~/.bash_profile
unset LLVM_TARGET_TRIPLE_SUFFIX
xcodebuild -scheme <project_name> -workspace <project_name>.xcworkspace clean
xcodebuild -scheme <project_name> -workspace <project_name>.xcworkspace COMPILER_INDEX_STORE_ENABLE=NO | xcpretty -r json-compilation-database --output compile_commands.json
maxPriority=15000
oclint-json-compilation-database -exclude Pods -exclude build -- -report-type xcode -max-priority-1=$maxPriority -max-priority-2=$maxPriority -max-priority-3=$maxPriority
worked with Xcode 11.2.1
source ~/.bash_profile
unset LLVM_TARGET_TRIPLE_SUFFIX
xcodebuild clean
xcodebuild COMPILER_INDEX_STORE_ENABLE=NO | xcpretty -r json-compilation-database --output compile_commands.json
# Rules
LINT_LONG_LINE=300
LINT_LONG_VARIABLE_NAME=64
LINT_LONG_METHOD=150
LINT_RULES="-rc LONG_LINE=${LINT_LONG_LINE} \
-rc LONG_VARIABLE_NAME=${LINT_LONG_VARIABLE_NAME} \
-rc LONG_METHOD=${LINT_LONG_METHOD}"
# Threshold.
LINT_PRIORITY_1_THRESHOLD=0
LINT_PRIORITY_2_THRESHOLD=20
LINT_PRIORITY_3_THRESHOLD=30
LINT_THRESHOLD = "-max-priority-1=${LINT_PRIORITY_1_THRESHOLD} \
-max-priority-2=${LINT_PRIORITY_2_THRESHOLD} \
-max-priority-3=${LINT_PRIORITY_3_THRESHOLD}"
# Excludes
# you can use grep-like regular expressions syntax,
LINT_EXCLUDES="Pods|lib"
oclint-json-compilation-database \
-exclude ${LINT_EXCLUDES} \
-- \
-report-type xcode \
${LINT_RULES} \
${LINT_THRESHOLD} \
I tried the following commands:
xcodebuild -target TARGET -configuration Debug -scheme SCHEME | xcpretty --report json-compilation-database --output compile_commands.json
or
xcodebuild -target TARGET -configuration Debug -scheme SCHEME | xcpretty -r json-compilation-database --output compile_commands.json
But I got "Error: compile_commands.json not found at current location." for both in XCode.