Invoking an NMAKE build

I’m trying to automate our build on Windows. Our requirement is to validate changes for the target platform combination: Windows + Visual Studio tools, so it’s no good using GCC or Clang for this. We specifically need to check compilation with Microsoft’s compiler, and indeed NMAKE.

So I’m trying to invoke CMD.EXE to run our make using Visual Studio tools. But I can’t seem to get a literal string through to CMD. Here is what I’m trying:

MSYS2_ARG_CONV_EXCL="*" cmd /k '"C:\Program Files (x86)\Microsoft Visual Studio 2017\BuildTools\Common7\Tools\VsDevCmd.bat" && cd code && nmake'

But what I get back is an error from CMD like:

'\"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat\"' is not recognized...

So you see something is inserting extra backslash escapes into the string I want to pass to CMD. This alone works:

MSYS2_ARG_CONV_EXCL="*" cmd /k 'C:\Program Files (x86)\Microsoft Visual Studio 2017\BuildTools\Common7\Tools\VsDevCmd.bat'

but of course it does not kick off the build.

What’s going on here? Suggestions?


If any Travis CI folks read this: we want CMD (or maybe Powershell) and the Microsoft compilers to be first-class! We need to build using Visual Studio. Thanks!

MSYS2_ARG_CONV_EXCL="*" cmd /k 'C:\Program Files (x86)\Microsoft Visual Studio 2017\BuildTools\Common7\Tools\VsDevCmd.bat & cd code & nmake'

Basically invoke nmake in the same cmd.exe environment that you ran VsDevCmd.bat in.

Thanks, but that is how I started, and it fails with CMD saying: ‘C:\Program’ is not recognized.

I have solved this problem in a different way and will post details soon for other people.

I have solved this problem by creating an auxiliary BAT script, so avoiding all the quoting madness between MSYS2, Bash, and CMD.

The script is in code/w3i6mv.bat:

@rem w3i6mv.bat -- set up and invoke build from raw CMD on Windows
@rem This can be invoked from a plain CMD from the MPS workspace
@rem like this::
@rem code\w3i6mv.bat
@rem or from Git Bash in Travis CI build machines like this::
@rem MSYS2_ARG_CONV_EXCL='*' cmd /k 'code\w3i6mv.bat'
@rem which is how it's invoked from .travis.yml
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
cd code
nmake /f w3i6mv.nmk

and it’s invoked from .travis.yml like this:

    - os: windows
      arch: amd64
      compiler: clang # This is a lie since we invoke MV (Microsoft C)
      script: MSYS2_ARG_CONV_EXCL='*' cmd /c 'code\w3i6mv.bat'

So we have to lie to Travis CI about the toolchain, which is a shame, but this is only a few lines of extra stuff, so it keeps Travis integration lightweight, which is what we need.

Hi @rptb1,

As stated, probably the best way:

MSYS2_ARG_CONV_EXCL="*" cmd /c call <path\to\bat> \&\& nmake
1 Like

Just for the benefit of other readers, this doesn’t work either.