Command line encoding in JSON Compilation Database

According to http://clang.llvm.org/docs/JSONCompilationDatabase.html, the JSON Compilation Database uses a single string to describe the actual compile command, and not an array. Is this string subject to any kind of shell expansion? How is it supposed to be parsed into an argv array?

If I recall the reasoning that went into it, it had to do with some of the build system limitations.

If the build system doesn’t have an array, and instead has a string which happens to be properly quoted for the system’s shell to expand, I wouldn’t want the producer of the JSON database to be responsible for correctly parsing this into an array. Essentially, we didn’t want produces to have to have a working parser for a line of shell. Sadly, I think there are quite a few systems in this category where there isn’t a clear argument array intrinsically available.

I see three options:

  1. Keep this as it is. What use cases would you have for changing it? What does it hurt the way it is now? Just that you have to run the string through the shell?

  2. Allow either form – a string or an array. I don’t really like this because people would want to take advantage of the array form but it wouldn’t always be there.

  3. Require the array form. Maybe it’s easier than I’m imagining to parse the strings into an array for each build system. If so, we could just go all the way here.

Hi Florian,

Within the clang environment, you do not need to parse it to an argv by
yourself : the CompilationDatabase stuff does that for you. Regarding
shell expansion, Manuel can probably shed some light on that part.

Cheers,

According to http://clang.llvm.org/docs/JSONCompilationDatabase.html,
the JSON Compilation Database uses a single string to describe the
actual compile command, and not an array. Is this string subject to any
kind of shell expansion? How is it supposed to be parsed into an argv
array?

I thought I remembered that we had a discussion around exactly this question, but I can’t find it any more =[ I have that thought at the back of my head that we wanted to do this, but there was a really good reason why not to do it.

In general, I agree with what Chandler says.

Cheers,
/Manuel

Correct. The string is “shell escaped”, but " and \ are the only special characters. No expansion is happening.

Cheers,
/Manuel

Thank you all for your explanations, it makes sense. Perhaps a few words can be added to the documentation?

Updated: http://clang.llvm.org/docs/JSONCompilationDatabase.html
Please let me know if that's what you were looking for.

Thanks!
/Manuel

Looks good, thanks.