Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

json-compilation-database generates empty compile_commands.json #270

Closed
PavelKatunin opened this issue Dec 2, 2013 · 24 comments
Closed

Comments

@PavelKatunin
Copy link
Contributor

To generate not empty compile_commands.json deleting projects DerivedData is requred now. If you do not delete derive data from project, xctool generates empty compile_commands.json

@fpotter
Copy link
Contributor

fpotter commented Dec 2, 2013

cc @lqi. Do you know about this? I don't use this reporter myself.

@maplesteve
Copy link

I have OClint running as a Jenkins job with this script:

#!/bin/sh 
#
# do the oclint stuff
cd /Volumes/Jenkins/workspace/ProjectName/src

/Volumes/Jenkins/tools/xctool/bin/xctool -project ProjectName.xcodeproj -scheme ProjectName -configuration Release -reporter json-compilation-database:compile_commands.json clean
/Volumes/Jenkins/tools/xctool/bin/xctool -project ProjectName.xcodeproj -scheme ProjectName -configuration Release -reporter json-compilation-database:compile_commands.json build

/Volumes/Jenkins/tools/oclint/bin/oclint-json-compilation-database -e CocoaLumberjack/ -- -stats -report-type pmd -o ../build/oclint.xml

Works perfect. I don't explicitly take care of DerivedData.

@lqi
Copy link
Contributor

lqi commented Dec 3, 2013

@PavelKatunin I was thinking about the same thing as @maplesteve suggested. Would you try running xctool <args> clean against your project before generating compile_commands.json file?

@PavelKatunin
Copy link
Contributor Author

@lqi "xctool clean" does not help. Deleting derive data helps on some projects, but not on all projects. What can be cause of creating empty compile_commands.json?

@lqi
Copy link
Contributor

lqi commented Dec 14, 2013

@PavelKatunin May I have the output of your project from json-stream reporter? I need some context in order to have a better understanding.

@PavelKatunin
Copy link
Contributor Author

@lqi It is just empty JSON array, if I correctly understand your question.

[

]

@PavelKatunin
Copy link
Contributor Author

@lqi , @maplesteve , @fpotter I found the place in code where it is happens

NSTextCheckingResult *pchMatch = [rawCompilerCommand firstMatch:@[@"-include "(.+?.pch)"", @"-include (.+?.pch)"]];
if (sourceFileMatch && workingDirectoryMatch && pchMatch) {
}
return nil;

in JSONCompilationDatabaseReporter.m

in my project I have not .pch files, thats why it generates empty JSON,
may I fix it by my self, and push changes to the project?

also I noticed that some times didFinishReporting is called twice, I am going to find the cause of that.

@maplesteve
Copy link

@PavelKatunin I now get the same error with DP2 of Xcode 5.1. Which Xcode are you using?

@PavelKatunin
Copy link
Contributor Author

@maplesteve Version 5.0.2 , do you have .pch file in your xcode project ? Are you talking about "didFinishReporting is called twice" error, or about "empty compilation sb" error ?

@maplesteve
Copy link

@PavelKatunin I'm talking about the empty compile_commands.json and yes, my project has a .pch file.
A xctool ... build runs fine without errors; when I use the reporter, the json file is like the example you showed above.
BTW: Deleting DerivedData doesn't help.

@maplesteve
Copy link

@fpotter, @lqi, @PavelKatunin
Do you have some ideas, why exactly this started failing? I reverted back to Xcode 5.0.1 and compile_commands.json is still empty. I really don't have a clue, why this happens; I pretty sure, that I didn't change anything - besides normal code edits. I also looked at the commits that I made at the time, when it stopped working; nothing suspicious there.
I'm stuck...

@paulstringer
Copy link

We've seen the same issue but only after updating to Xcode 5.1

@PavelKatunin
Copy link
Contributor Author

I don't now exactly what can be cause of your problem, but you can put some logs in jsoncompilationdatabasereporter.m to see what is going wrong. If you will find the cause of bug, please send message. Thank you.

@ignazioc
Copy link

Same issue.
Xcode 5.1, a project with cocoaposd and a workspace.
The compile_commands.json file is empty. I'm using xctool to run OCLint.

@rhodgkins
Copy link

Has there been any movement on this - it still seems present in the latest release

@itsthejb
Copy link

Seem to be experiencing this issue now myself. In my case the json file isn't empty, but only contains information for two files, in a project with hundreds. I believe it also started around the time of XCode 5.1

CORRECTION: doing a clean build instead of just build seems to fix this for me

@rhodgkins
Copy link

@itsthejb are you using master? I still get an empty array.

I'll create a demo project to try reproduce it.

@rhodgkins
Copy link

I created a test project where it can be reproduced.

xctool -project XctoolReporterTest.xcodeproj -scheme XctoolReporterTest -reporter json-compilation-database:compile_commands.json clean build
Produces an empty JSON array in compile_commands.json.

But doing it all manually
xcodebuild -project XctoolReporterTest.xcodeproj -scheme XctoolReporterTest clean build > xcodebuild.log
oclint-xcodebuild
Produces the following complie_commands.json

I'm using the latest HEAD on master through brew.
brew reinstall xctool --HEAD

I haven't got time now to download the repo and build it myself, but I don't see there being any difference?

@itsthejb
Copy link

@rhodgkins, yes HEAD from homebrew like you. I guess my case is a non-event though, especially if you can create a test project 👍

@rhodgkins
Copy link

@lqi any ideas now we can reproduce it?

@ignazioc
Copy link

@rhodgkins It works for me.
This is the script I've created in order to generate the right json file.
I've created also a pull request for your project.

 #!/bin/bash
 xctool -project XctoolReporterTest.xcodeproj \
        -scheme XctoolReporterTest \
        -sdk iphonesimulator \
        reporter json-compilation-database:compile_commands.json clean build


oclint-json-compilation-database -v oclint_args "-report-type html -o report.html -rc=LONG_LINE=120"
open compile_commands.json
open report.html

xctool --version output is 0.1.15

@rhodgkins
Copy link

Oh no! Well this is embarrassing, it didn't work for me but when I tried xctool --version it was 0.1.14 - turns out I had a build in ~/bin, no idea when (or why!) that got there considering I was using brew!

@ignazioc thanks for your help 👍 both your script and my original command are now working perfectly!

@LegNeato
Copy link
Contributor

LegNeato commented Oct 1, 2014

No longer valid

@LegNeato LegNeato closed this as completed Oct 1, 2014
@vvlong-can
Copy link

I meet this problem too, may be you should try xcpretty tool. And you should take care for it, when you generate the compilation_command.json, you need to choose the right build config Debug or Release ~ I did it successfully~ good luck

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants