Skip to content
Snippets Groups Projects

[cmake] Add dune_execute_process with better error checking

Merged Dominic Kempf requested to merge feature/dune-execute-process into master
1 unresolved thread

CMake by default does not check the return codes of any commands invoked through execute_process. This can lead to very undesirable behaviour. Manually checking the return code is tedious, so this commit introduces a dune-prefixed version, which does the job.

This will be used by the python build system integration soon to be migrated to dune-common.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
6 # :single:
7 #
8 # Error message to show if command exited with non-zero exit code.
9 # Note, that if this is omitted, no return code checking is done.
10 #
11 # A thin wrapper around the cmake command :code:`execute_process`, that
12 # exits on non-zero exit codes. All arguments are forwarded to the actual
13 # cmake command.
14 #
15
16 function(dune_execute_process)
17 include(CMakeParseArguments)
18 cmake_parse_arguments(EXECUTE "" "ERROR_MESSAGE;RESULT_VARIABLE;OUTPUT_VARIABLE;ERROR_VARIABLE" "" ${ARGN})
19
20 # Decide whether stdout and stderr have to be split
21 if(EXECUTE_OUTPUT_VARIABLE AND EXECUTE_ERROR_VARIABLE)
  • @gruenich I had a script script.sh that reads something like

    #!/bin/bash
    exit 1

    Then do:

    dune_execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/script.sh
                                          ERROR_MESSAGE "This failed!"
                                          )

    You can now play with the script and the {OUTPUT,ERROR}_VARIABLE etc. to retrieve stdout, stderr and return code.

  • Ansgar Burchardt
  • Dominic Kempf added 1 commit

    added 1 commit

    • da08e916 - [doc] Document that error message will also cause cmake to fail.

    Compare with previous version

  • I am merging this one now to get a bit of movement into my pipeline.

  • Dominic Kempf mentioned in commit 11b3d7f6

    mentioned in commit 11b3d7f6

  • merged

  • Dominic Kempf mentioned in commit 1e4980a0

    mentioned in commit 1e4980a0

  • Please register or sign in to reply
    Loading