<div dir="ltr">hi there,<div><br></div><div>i'm also writing a tool (Bear) which generate the compilation database. and had a few bugs in my code about escaping the command. if it's not too late i would also propose a format for the problem. ;)</div><div><br></div><div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><span style="font-size:13.1999998092651px;line-height:19.7999992370605px">{ </span><br></div></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><div style="font-size:small;line-height:normal"><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"> directory: "/my/path"</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"> cmd: ["path to binary", "-c", "filename"],</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">...</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">}</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">which would reformat the command field as a JSON array. would still give the readability of the command and keep the order of the arguments. (i'm not sure that the recommended multiple "argument" key would be correct JSON.)</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">how does it sound for you?</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">regards,</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">Laszlo</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 6, 2015 at 1:11 AM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Also, I think we want to introduce a new keyword for the binary.<div>So both of these should work:<br><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">{ </div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"> directory: "/my/path"</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"> binary: "path to binary"</div><span class=""><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"> argument: "-c"</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"> argument: "filename"</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">...</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">}</div></span><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">or the shell-escaped command inside the json escaped string:</div></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">{ </div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"> directory: "/my/path"</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"> command: "path\\ to\\ binary -c filename"</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">...</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">}</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">The thing to note is that both shell escaping and shell unescaping are sufficiently hard on non-unix platforms, and even on unix platforms it's just not nice to go from one to the other.</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">Cheers,</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">/Manuel</div></div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote">On Sun, Apr 5, 2015 at 4:01 PM Manuel Klimek <<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Yes, I think it's easy enough to make compatible</p>
<br><div class="gmail_quote">On Sun, Apr 5, 2015, 8:42 AM Daniel Dilts <<a href="mailto:diltsman@gmail.com" target="_blank">diltsman@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I like that a lot better. I will look at what that is going to take.</div><div><br></div><div>If it goes that direction, will it be necessary to also support the older format? I know there are tools, like CMake, that can produce this file format.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 5, 2015 at 8:26 AM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span>On Sun, Apr 5, 2015 at 8:19 AM Daniel Dilts <<a href="mailto:diltsman@gmail.com" target="_blank">diltsman@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div>So, escape the backslashes once for JSON and a second time for Clang?</div></div></blockquote><div><br></div></span><div>Well, a second time for "shell".</div><div>A different idea that has come up was to just add (optional) 'arg' fields to the json, instead of the shell escaping, which seems much more pleasant to work with across platforms, like this:</div><div>{ </div><div> directory: '/my/path'</div><div> command: 'just the exec'</div><div> argument: '-c'</div><div> argument: 'filename'</div><div>...</div><div>}</div><div>Patches for that would be welcome :)</div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div><br></div><div>If this is going to be necessary on Windows, it probably ought to be added to the documentation for the compilation database file format.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 3, 2015 at 7:49 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><p dir="ltr">Why not escape the backslashes when writing the compilation db?<br>
</p><div><div>
<br><div class="gmail_quote">On Fri, Apr 3, 2015, 1:54 PM Daniel Dilts <<a href="mailto:diltsman@gmail.com" target="_blank">diltsman@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div>I finally had the opportunity to look into this.</div><div><br></div><div>CommandLineArgumentParser in JSONCompilationDatabase.cpp deals with escapes by discarding all backslash characters. I imagine that this works pretty well on Linux, not perfectly, but well enough.</div><div><br></div><div>Windows uses backslash as a separator in file paths, so this breaks most file paths on Windows.</div><div><br></div><div>How would one go about fixing this so it works on both Windows and Linux? Obviously the different escape sequences need to be implemented. What I really mean is, how do you make it so that it uses the correct set of escapes depending on platform?</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 17, 2015 at 12:57 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr">I haven't had time to look.<br></div><div><div><br><div class="gmail_quote">On Tue, Mar 17, 2015 at 6:06 PM Daniel Dilts <<a href="mailto:diltsman@gmail.com" target="_blank">diltsman@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr">What appears to be the exact problem? Are relative paths just not properly implemented, or is the problem more specific than that?</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 17, 2015 at 4:07 AM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr">I think this is a known problem. Patches very welcome :)<br></div><br><div class="gmail_quote"><div><div>On Tue, Mar 17, 2015 at 1:14 AM Daniel Dilts <<a href="mailto:diltsman@gmail.com" target="_blank">diltsman@gmail.com</a>> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div><div><div dir="ltr"><div>I am calling runClangTidy using a JSONCompilationDatabase that I generate from a string. Everything works perfectly until I have a relative path.</div><div><br></div><div>With the following database I use "D:\\CMakeTest\\bld\\..\\src\\<u></u>main.cpp" as the file to open:</div><div>[<br> {<br> "directory": "D:\\CMakeTest\\bld\\",<br> "command" : "D:/llvm/build/Debug/bin/<u></u>clang.exe -I\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\include\" -I\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\atlmfc\\include\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\um\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\shared\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\winrt\" -I\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\include\" -I\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\atlmfc\\include\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\um\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\shared\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\winrt\" -DWIN32 -D_WINDOWS -D_DEBUG -DCMAKE_INTDIR=\"Debug\" ..\\src\\main.cpp",<br> "file" : "..\\src\\main.cpp"<br> },<br>]</div><div><br></div><div>This gives me an output of "Error while processing D:\\CMakeTest\\bld\\..\\src\\<u></u>main.cpp."</div><div><br></div><div>When I use the following database with "D:\\CMakeTest\\src\\main.cpp" as the file to open, everything works.</div><div><br></div><div>[<br> {<br> "directory": "D:\\CMakeTest\\src\\",<br> "command" : "D:/llvm/build/Debug/bin/<u></u>clang.exe -I\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\include\" -I\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\atlmfc\\include\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\um\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\shared\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\winrt\" -I\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\include\" -I\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\atlmfc\\include\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\um\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\shared\" -I\"C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\winrt\" -DWIN32 -D_WINDOWS -D_DEBUG -DCMAKE_INTDIR=\"Debug\" main.cpp",<br> "file" : "main.cpp"<br> },<br>]</div><div><br></div><div><br></div><div>Is there something that I am doing wrong? The only changes between the two compilation databases are the directory and file entries. Both should refer to the same absolute path.</div></div></div></div>
______________________________<u></u><u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailm<u></u>an/listinfo/cfe-dev</a><br>
</blockquote></div>
</blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>
</blockquote></div></div></div></div>
</blockquote></div><br></div>
</blockquote></div></blockquote></div>
</div></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>