Re: [cmake-developers] Custom commands with Ninja on Windows

2016-05-23 Thread Martin Ankerl
Thanks for the feedback!

Here is an updated patch that uses a hash as filename, .cmd as extension,
boolean argument, and some error checks.

Martin

On Fri, May 20, 2016 at 3:40 PM Brad King <brad.k...@kitware.com> wrote:

> On 05/20/2016 03:41 AM, Martin Ankerl wrote:
> > From what I have understood it seems more safe to use .bat and not
> > .cmd, because the behavior of the errorlevel is different. From
> >
> http://waynes-world-it.blogspot.co.at/2008/08/difference-between-bat-and-cmd.html
> :
> >
> >> The differences between .CMD and .BAT as far as CMD.EXE is concerned
> are:
> >> With extensions enabled, PATH/APPEND/PROMPT/SET/ASSOC in .CMD files
> will set
> >> ERRORLEVEL regardless of error. .BAT sets ERRORLEVEL only on errors.
>
> I read that to mean the opposite: cmd is better than bat because it will
> always set ERRORLEVEL even if it is to zero, so one can reliably determine
> whether a command worked (Git's wrapper on windows is git.cmd and not
> git.bat).
>
> > I've created a first attempt of this implementation, please see the
> attached
> > patch.
>
> Good start.
>
> > +  // TODO fail if command is too long and no file specified
>
> Several of the call sites of BuildCommandLine are constructing
> commands using ninja's $VAR reference/placeholder syntax.  For
> these call sites it is never safe to use a separate cmdFile.
> Fortunately they tend to be for compiler/linker invocations
> that can use the normal RSP_FILE approach.
>
> Instead of adding a cmdFile argument to BuildCommandLine, add
> a boolean (or enum) to indicate whether the commands hold any
> placeholders.  Only when no placeholders are used is it safe to
> activate the new behavior.  When activated, I think it is
> cleaner to use a hash of the command line as the cmdFile name.
> That way when the command changes Ninja will be aware of the
> change and re-run it.
>
> Thanks,
> -Brad
>
> --
Martin


0001-Support-for-many-custom-commands-in-Windows.patch
Description: Binary data
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Re: [cmake-developers] Custom commands with Ninja on Windows

2016-05-20 Thread Martin Ankerl
sorry, that DEP_FILE problem was my fault. It's working correctly.

Martin

On Fri, May 20, 2016 at 9:41 AM Martin Ankerl <martin.ank...@gmail.com>
wrote:

> From what I have understood it seems more safe to use .bat and not .cmd,
> because the behavior of the errorlevel is different. From
> http://waynes-world-it.blogspot.co.at/2008/08/difference-between-bat-and-cmd.html
> :
>
> > The differences between .CMD and .BAT as far as CMD.EXE is concerned
> are: With extensions enabled, PATH/APPEND/PROMPT/SET/ASSOC in .CMD files
> will set
> ERRORLEVEL regardless of error. .BAT sets ERRORLEVEL only on errors.
>
> I've created a first attempt of this implementation, please see the
> attached patch. It seems to do the trick for my test case, but I couldn't
> test it well because unfortunately I've run into a different unrelated
> problem: the slashes for the DEP_FILE are in the git version / instead of \
> which makes the ninja build fail. This was not the case with version 3.5.2
>
> Martin
>
>
>
> On Thu, May 19, 2016 at 10:46 PM Brad King <brad.k...@kitware.com> wrote:
>
>> On 05/19/2016 04:31 PM, Martin Ankerl wrote:
>> > I didn't think about just writing a .cmd (or .bat?) with cmake
>>
>> The ".cmd" extension is a modern version of ".bat".
>>
>> > that sounds like the simplest solution!
>>
>> Yes, assuming we never have a need for ninja placeholder substitution.
>> Why are one-line response files generated by Ninja not a solution?
>> Does cmd support them?
>>
>> > if %errorlevel% neq 0 exit /b %errorlevel%
>>
>> Yes.
>>
>> > I have no experience with cmake implementation though, how would you
>> > find a name for the filename?
>>
>> First, it can be made conditional on when the command line is really long.
>> Second, you could just put it in CMakeFiles/ and name it using a hash
>> of its content (or of the list of outputs).  See Source/cmCryptoHash.h
>> for example.
>>
>> Thanks,
>> -Brad
>>
>> --
> Martin
>
-- 
Martin
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Re: [cmake-developers] Custom commands with Ninja on Windows

2016-05-20 Thread Martin Ankerl
>From what I have understood it seems more safe to use .bat and not .cmd,
because the behavior of the errorlevel is different. From
http://waynes-world-it.blogspot.co.at/2008/08/difference-between-bat-and-cmd.html
:

> The differences between .CMD and .BAT as far as CMD.EXE is concerned are:
With extensions enabled, PATH/APPEND/PROMPT/SET/ASSOC in .CMD files will set
ERRORLEVEL regardless of error. .BAT sets ERRORLEVEL only on errors.

I've created a first attempt of this implementation, please see the
attached patch. It seems to do the trick for my test case, but I couldn't
test it well because unfortunately I've run into a different unrelated
problem: the slashes for the DEP_FILE are in the git version / instead of \
which makes the ninja build fail. This was not the case with version 3.5.2

Martin



On Thu, May 19, 2016 at 10:46 PM Brad King <brad.k...@kitware.com> wrote:

> On 05/19/2016 04:31 PM, Martin Ankerl wrote:
> > I didn't think about just writing a .cmd (or .bat?) with cmake
>
> The ".cmd" extension is a modern version of ".bat".
>
> > that sounds like the simplest solution!
>
> Yes, assuming we never have a need for ninja placeholder substitution.
> Why are one-line response files generated by Ninja not a solution?
> Does cmd support them?
>
> > if %errorlevel% neq 0 exit /b %errorlevel%
>
> Yes.
>
> > I have no experience with cmake implementation though, how would you
> > find a name for the filename?
>
> First, it can be made conditional on when the command line is really long.
> Second, you could just put it in CMakeFiles/ and name it using a hash
> of its content (or of the list of outputs).  See Source/cmCryptoHash.h
> for example.
>
> Thanks,
> -Brad
>
> --
Martin


0001-Support-for-many-custom-commands-in-Windows.patch
Description: Binary data
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Re: [cmake-developers] Custom commands with Ninja on Windows

2016-05-19 Thread Martin Ankerl
I didn't think about just writing a .cmd (or .bat?) with cmake, that sounds
like the simplest solution!
After each each custom command we just need to add something like this to
have the same behaviour as the &&:

if %errorlevel% neq 0 exit /b %errorlevel%

I have no experience with cmake implementation though, how would you find a
name for the filename?

Martin

On Thu, May 19, 2016 at 4:03 PM Brad King <brad.k...@kitware.com> wrote:

> On 05/19/2016 01:43 AM, Martin Ankerl wrote:
> > It seems to me that there are two possible solution:
> >
> > * use a response file (rspfile and rspfile_content).
>
> Can cmd.exe /C even use a response file?  Perhaps the whole command could
> simply be written to a .cmd file instead.  I don't think our generated
> custom commands ever use ninja placeholders so we could have CMake write
> the commands to a file instead.  Ninja would only see a call to that file.
> The drawback is that we may not see the whole command from `ninja -v`.
>
> > only possible when modifying ninja to support multiline response files
>
> In what case do we end up with a multiline command?  Isn't it just
> one long command line with && chaining?
>
> > * Add a build target for each custom command, e.g. instead of
>
> It may be tricky to get the same build semantics with that approach.
>
> Thanks,
> -Brad
>
> --
Martin
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

[cmake-developers] Custom commands with Ninja on Windows

2016-05-18 Thread Martin Ankerl
Hi!

I've run into the same problem with many custom commands as discussed here:
http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/13434
Which is referenced in this bug report:
https://cmake.org/Bug/view.php?id=15612#c38924

I've had a look at this problem because this is the only thing that blocks
us from using ninja.

It seems to me that there are two possible solution:


* use a response file (rspfile and rspfile_content). This unfortunately is
only possible when modifying ninja to support multiline response files. As
far as I know this is not possible now. (the $in_newline does not work in
this case)


* Add a build target for each custom command, e.g. instead of

E.g. instead of an output like this:

build CMakeFiles\copy_czmq_3.0.2.util: CUSTOM_COMMAND
  COMMAND = cmd.exe /C "cd /D C:\dev\ras_robvis\vc140_x64_ninja &&
"c:\Program Files (x86)\CMake\bin\cmake.exe" -E copy_if_different
"C:/dev/ras_robvis/src/ext/lib_czmq/3.0.2/vc140_x64/czmq.dll"
"C:/dev/ras_robvis/vc140_x64_ninja/bin/./czmq.dll" && cd /D
C:\dev\ras_robvis\vc140_x64_ninja && "c:\Program Files
(x86)\CMake\bin\cmake.exe" -E copy_if_different
"C:/dev/ras_robvis/src/ext/lib_czmq/3.0.2/vc140_x64/czmqd.dll"
"C:/dev/ras_robvis/vc140_x64_ninja/bin/./czmqd.dll""
  DESC = Running utility command for copy_czmq_3.0.2
  restat = 1
build copy_czmq_3.0.2: phony CMakeFiles\copy_czmq_3.0.2.util


produce an output like this:

build CMakeFiles\copy_czmq_3.0.2.util.1: CUSTOM_COMMAND
  COMMAND = cmd.exe /C "cd /D C:\dev\ras_robvis\vc140_x64_ninja &&
"c:\Program Files (x86)\CMake\bin\cmake.exe" -E copy_if_different
"C:/dev/ras_robvis/src/ext/lib_czmq/3.0.2/vc140_x64/czmq.dll"
"C:/dev/ras_robvis/vc140_x64_ninja/bin/./czmq.dll""
  restat = 1

build CMakeFiles\copy_czmq_3.0.2.util.2: CUSTOM_COMMAND
  COMMAND = cmd.exe /C "cd /D C:\dev\ras_robvis\vc140_x64_ninja &&
"c:\Program Files (x86)\CMake\bin\cmake.exe" -E copy_if_different
"C:/dev/ras_robvis/src/ext/lib_czmq/3.0.2/vc140_x64/czmqd.dll"
"C:/dev/ras_robvis/vc140_x64_ninja/bin/./czmqd.dll""
  restat = 1

build CMakeFiles\copy_czmq_3.0.2.util: phony |
CMakeFiles\copy_czmq_3.0.2.util.1 CMakeFiles\copy_czmq_3.0.2.util.2
  DESC = Running utility command for copy_czmq_3.0.2

build copy_czmq_3.0.2: phony CMakeFiles\copy_czmq_3.0.2.util



I did not yet have a look at the cmake code so I am not sure how difficult
it is to implement this, or even if this is the best way to solve this.

Any comments? is this reasonable?

Martin

-- 
Martin
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers