Skip to content

Commit

Permalink
Support list-valued EDITORCONFIG_CMD
Browse files Browse the repository at this point in the history
In run_and_sort, instead of taking a separate program and arguments,
take an undifferentiated command line.  This permits either
EDITORCONFIG_CMD or ECARGS to be either list- or string-valued.
  • Loading branch information
Chris White committed Nov 21, 2018
1 parent dd9e054 commit eccf9d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 8 additions & 2 deletions cmake/ec_sort.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Call as, e.g.:
# cmake -D EDITORCONFIG_CMD="../editorconfig" -D ECARGS:LIST="-f;.editorconfig;foo" -P cmake/ec_sort.cmake
# EDITORCONFIG_CMD may also be list-valued. EDITORCONFIG_CMD and ECARGS
# are put together on the command line, in that order, and split by CMake.

# BSD-2-Clause
# Copyright 2018 Christopher White (cxw42 at GitHub; http://devwrench.com)
Expand Down Expand Up @@ -38,6 +40,11 @@ list(APPEND CMAKE_MODULE_PATH "${tests_cmake_ec_sort_dir}/../cmake")
include(runandsort)

# Required parameters are in variables: EDITORCONFIG_CMD and ECARGS
if("${EDITORCONFIG_CMD}" STREQUAL "")
message(FATAL_ERROR "No EDITORCONFIG_CMD parameter specified")
return()
endif()

if("${ECARGS}" STREQUAL "")
message(FATAL_ERROR "No ECARGS parameter specified")
return()
Expand All @@ -47,8 +54,7 @@ endif()
#message(FATAL_ERROR " Running ${EDITORCONFIG_CMD} with ${ECARGS}")

run_and_sort(RETVAL lines RETVAL_FAILURE did_fail
PGM "${EDITORCONFIG_CMD}"
ARGS ${ECARGS}
CMDLINE ${EDITORCONFIG_CMD} ${ECARGS}
)

if(${did_fail})
Expand Down
11 changes: 5 additions & 6 deletions cmake/runandsort.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ cmake_minimum_required(VERSION 3.5)

# Arguments:
# RETVAL . . . . . . . The name of the variable to store the result in
# PGM . . . . . . . . The program to run
# ARGS . . . . . . . . Any arguments to pass to the program
# CMDLINE . . . . . . . The program to run, and any arguments
# RETVAL_FAILURE . . . . If present, a variable that will be set to TRUE
# if PGM returns a non-zero exit code.
# CAPTURE_STDERR . . . . If present, capture stderr instead of stdout
Expand All @@ -64,13 +63,13 @@ cmake_minimum_required(VERSION 3.5)
function(run_and_sort)
# Argument parsing
set(option_keywords CAPTURE_STDERR TRIM_INITIAL_LEADING_SPACE)
set(one_value_keywords RETVAL RETVAL_FAILURE PGM)
set(multi_value_keywords ARGS)
set(one_value_keywords RETVAL RETVAL_FAILURE)
set(multi_value_keywords CMDLINE ARGS)
cmake_parse_arguments(P "${option_keywords}" "${one_value_keywords}"
"${multi_value_keywords}" ${ARGN})

#message(STATUS "Running ${P_PGM} with ${P_ARGS}")
execute_process(COMMAND "${P_PGM}" ${P_ARGS}
#message(STATUS "Running ${P_CMDLINE}")
execute_process(COMMAND ${P_CMDLINE}
RESULT_VARIABLE ep_retval
OUTPUT_VARIABLE ep_stdout
ERROR_VARIABLE ep_stderr
Expand Down
4 changes: 2 additions & 2 deletions meta/sample.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ include( runandsort )

run_and_sort( RETVAL lines RETVAL_FAILURE did_fail
CAPTURE_STDERR TRIM_INITIAL_LEADING_SPACE # since we're using almostcat
PGM "cmake"
ARGS "-DWHICH:STRING=${tests_meta_sample_dir}/sample.txt" "-P" "${tests_meta_sample_dir}/../cmake/almostcat.cmake"
CMDLINE "cmake" "-DWHICH:STRING=${tests_meta_sample_dir}/sample.txt"
"-P" "${tests_meta_sample_dir}/../cmake/almostcat.cmake"
) # Don't use cat(1) since we might be running on Windows

if( ${did_fail} )
Expand Down

0 comments on commit eccf9d4

Please sign in to comment.