<br><br><div class="gmail_quote">2012/2/17 Bill Hoffman <span dir="ltr"><<a href="mailto:bill.hoffman@kitware.com">bill.hoffman@kitware.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">On 2/17/2012 3:16 PM, Nicolas Desprčs wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I think yes. It is just a matter of time. My weekend is already<br>
overloaded. I'll try to do it. If Peter or someone else in the community<br>
comes up with a patch before me everybody would be happy :-)<br>
<br>
I'll try to do my best.<br>
<br>
</blockquote></div>
I could give it a try if you pointed me to the right spot in the code...</blockquote><div><br></div><div>I think the first place to look at is cmGlobalNinjaGenerator.cxx. There are a bunch of class methods there that are used to write the statements in the .ninja files.</div>

<div><br></div><div>Look at WriteBuild() in particular. Many others are convenient methods based on this one. So the escaping logic should happen there. "build" statements in ninja are where most of the path are written.</div>

<div>Some problem may arise from WriteRule() since the path to the command is written by it.</div><div><br></div><div>Also there are:</div><div><div>  static std::string EncodeIdent(const std::string &ident, std::ostream &vars);</div>

<div>  static std::string EncodeLiteral(const std::string &lit);</div></div><div><br></div><div>which I don't really know since I haven't written them and they are not documented. Peter did. But their name are pretty explicit and their code trivial.</div>

<div><br></div><div>I think we should add an EncodePath() method to follow the same logic and use it in WriteBuild() and WriteRule().</div><div><br></div><div>In WriteBuild(), arguments like ouputs, explictDeps, implicitDeps, orderOnlyDeps must be encoded. The tricky part would be that some part of the value of the "variables" arguments (which is a hash_map) must be encoded because they may be a white space sparated list of word which may contains some paths...</div>

<div><br></div><div>For exemple look at this part of the build.ninja file generated for cmake:</div><div><br></div><div><div>build Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testXMLParser.cxx.o: CXX_COMPILER ../Tests/CMakeLib/testXMLParser.cxx || Source/libCMakeLib.a</div>

<div>  DEFINES = -DLIBARCHIVE_STATIC</div><div>  FLAGS = -Wall  -g -IUtilities -I../Utilities -ITests/CMakeLib -ISource -I../Source</div></div><div><br></div><div>or this one:</div><div><br></div><div><div># Link the executable Tests/CMakeLib/CMakeLibTests</div>

<div>build Tests/CMakeLib/CMakeLibTests: CXX_EXECUTABLE_LINKER Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/CMakeLibTests.cxx.o Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testGeneratedFileStream.cxx.o Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testSystemTools.cxx.o Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testUTF8.cxx.o Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testXMLParser.cxx.o Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testXMLSafe.cxx.o | Source/libCMakeLib.a Source/kwsys/libcmsys.a /usr/lib/libexpat.so Utilities/cmlibarchive/libarchive/libcmlibarchive.a /usr/lib/libz.so Utilities/cmbzip2/libcmbzip2.a Utilities/cmcompress/libcmcompress.a /usr/lib/libcurl.so</div>

<div>  FLAGS = -Wall  -fPIC</div><div>  LINK_LIBRARIES = -rdynamic Source/libCMakeLib.a Source/kwsys/libcmsys.a -ldl -lexpat Utilities/cmlibarchive/libarchive/libcmlibarchive.a -lz Utilities/cmbzip2/libcmbzip2.a Utilities/cmcompress/libcmcompress.a -lcurl</div>

<div>  POST_BUILD = :</div><div>  PRE_LINK = :</div></div><div><br></div><div>In this case I think the encoding should happen before the call to WriteBuild when the "variables" argument is built because WriteBuild would not have enough information to figure out which part of the variable value is a path or not, specially for things like: "-I../Utilities"</div>

</div><div><br></div><div>Hope this helps,</div><div>Cheers,</div><div>-Nico</div><div><br></div>