0

My makeprg is set to:

cd build/ && cmake --build . --config Debug && ctest && gdb -q -ex run ./a

This allows me to build application, run tests and start debugging session sequentially in one command.

But I can't get gcc error report into quckfix:

...
make: *** [Makefile:115: all] Error 2

shell returned 2

Press ENTER or type command to continue

and then getting an error:

E40: Can't open errorfile /tmp/vkL411R/82
Press ENTER or type command to continue

How I would make quickfix working and being able to parse compiler output in this case?

  • I think makeprg is supposed to be set to a single command which takes whatever parameters are supplied to :make. You might be able to get away with that by surrounding the whole thing with { .... ; } (note spaces padding the brackets and the semicolon which must follow the end/last command). Better idea would be to put that all in an executable shell script and call that. Even then with your mix of cmake and gdb I don't know...there really should just be a cmake call in there, I would think. Only things that output the format vim expects to see. – B Layer May 16 at 15:52
  • If you absolutely had to have things other than cmake in there then you should send their output somewhere other than stdout....that's going to take some shell know-how. Really should move all that other stuff to separate step(s) (or part of the make target?). – B Layer May 16 at 15:59
  • @BLayer Yeah, surrounding with brackets works well in case if there compilation errors and execution chain breaks on make command. Thank you! But as side effect of that, make loses color highlighting for unknown reasons (while cmake itself not). As i know, Quickfix reads from stdout, and as I suppose vim shell output is stdout too. And if I'd redirect output somewhere else as you said, I think I wouldn't able to see it in vim shell or interact with it. Ok, I think the easiest way for now would be using makeprg that as it intended to used be - running make program only. – Alex May 16 at 18:03
  • You can do some tricks with sh -c, and you can parse temporary files into the quickfix list (eg, the -q argument or one of the related functions). To actually solve your problem, though, we’ll need more information (and you may need to do some troubleshooting to see what’s going on) – D. Ben Knoble May 16 at 20:48
1

Method #1

After some search I found similar question on SO.

According Mike's answer and other's notices in comments I modified that code slightly:

let &mp='cd build && cmake --build . --config Debug'

au QuickfixCmdPost make call TestAndRun()
function! TestAndRun()
  if len(filter(getqflist(), 'v:val.valid && v:val.type != "E"')) == 0
    !cd build/ && ctest && gdb -q -ex run ./a
  endif
endfunction

Method #2

Before that I did some research on vim help and wrote this:

set makeef=/tmp/vim.err
set shellpipe=
let &mp='cd build && (make 2>&1\| tee ' . &makeef . ') && ctest && gdb -q -ex run ./a'

It works too, but very hacky.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.