[cmake-developers] ninja spaces in the path do not work on linux

Nicolas Desprès nicolas.despres at gmail.com
Fri Feb 17 16:31:39 EST 2012


2012/2/17 Bill Hoffman <bill.hoffman at kitware.com>

> On 2/17/2012 3:16 PM, Nicolas Desprčs wrote:
>
>
>> I think yes. It is just a matter of time. My weekend is already
>> overloaded. I'll try to do it. If Peter or someone else in the community
>> comes up with a patch before me everybody would be happy :-)
>>
>> I'll try to do my best.
>>
>>  I could give it a try if you pointed me to the right spot in the code...


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.

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.
Some problem may arise from WriteRule() since the path to the command is
written by it.

Also there are:
  static std::string EncodeIdent(const std::string &ident, std::ostream
&vars);
  static std::string EncodeLiteral(const std::string &lit);

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.

I think we should add an EncodePath() method to follow the same logic and
use it in WriteBuild() and WriteRule().

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...

For exemple look at this part of the build.ninja file generated for cmake:

build Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testXMLParser.cxx.o:
CXX_COMPILER ../Tests/CMakeLib/testXMLParser.cxx || Source/libCMakeLib.a
  DEFINES = -DLIBARCHIVE_STATIC
  FLAGS = -Wall  -g -IUtilities -I../Utilities -ITests/CMakeLib -ISource
-I../Source

or this one:

# Link the executable Tests/CMakeLib/CMakeLibTests
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
  FLAGS = -Wall  -fPIC
  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
  POST_BUILD = :
  PRE_LINK = :

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"

Hope this helps,
Cheers,
-Nico
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20120217/6d1c504c/attachment.html>


More information about the cmake-developers mailing list