Debian Codegraph @

debian/core-test/cmake/ec_sort.cmake

raw
1 # ec_sort.cmake: Run editorconfig and sort its output
2 # For use in editorconfig; see
3 # https://github.com/editorconfig/editorconfig/issues/375 .
4
5 # Call as, e.g.:
6 # cmake -D EDITORCONFIG_CMD="../editorconfig" -D ECARGS:LIST="-f;.editorconfig;foo" -P cmake/ec_sort.cmake
7 # EDITORCONFIG_CMD may also be list-valued. EDITORCONFIG_CMD and ECARGS
8 # are put together on the command line, in that order, and split by CMake.
9
10 # BSD-2-Clause
11 # Copyright 2018 Christopher White (cxw42 at GitHub; http://devwrench.com)
12 # All rights reserved
13 #
14 # Redistribution and use in source and binary forms, with or without
15 # modification, are permitted provided that the following conditions are met:
16 #
17 # 1. Redistributions of source code must retain the above copyright notice,
18 # this list of conditions and the following disclaimer.
19 # 2. Redistributions in binary form must reproduce the above copyright notice,
20 # this list of conditions and the following disclaimer in the documentation
21 # and/or other materials provided with the distribution.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34
35 cmake_minimum_required(VERSION 3.16.3)
36
37 # See documentation links at https://stackoverflow.com/q/12802377/2877364
38 set(tests_cmake_ec_sort_dir "${CMAKE_CURRENT_LIST_DIR}")
39 list(APPEND CMAKE_MODULE_PATH "${tests_cmake_ec_sort_dir}/../cmake")
40 include(runandsort)
41
42 # Required parameters are in variables: EDITORCONFIG_CMD and ECARGS
43 if("${EDITORCONFIG_CMD}" STREQUAL "")
44 message(FATAL_ERROR "No EDITORCONFIG_CMD parameter specified")
45 return()
46 endif()
47
48 if("${ECARGS}" STREQUAL "")
49 message(FATAL_ERROR "No ECARGS parameter specified")
50 return()
51 endif()
52
53 # Uncomment for debugging
54 #message(FATAL_ERROR " Running ${EDITORCONFIG_CMD} with ${ECARGS}")
55
56 run_and_sort(RETVAL lines RETVAL_FAILURE did_fail
57 CMDLINE ${EDITORCONFIG_CMD} ${ECARGS}
58 )
59
60 if(${did_fail})
61 message(FATAL_ERROR "${EDITORCONFIG_CMD} ${ECARGS} returned a nonzero exit code")
62 return()
63 endif()
64
65 # message() will give us an extra \n, so trim one if we can.
66 string(REGEX REPLACE "(\r\n|\r|\n)$" "" lines "${lines}")
67
68 # Output **to stderr**. If we used message(STATUS...), it would print to
69 # stdout but also emit a leading "--".
70 message("${lines}")