From a716ed88e7db0858ac184efb1c717dfd1be961a8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 12 Apr 2024 09:45:08 -0400 Subject: [PATCH] Tests: Avoid unnecessary copy of cmake in RunCMake.separate_arguments The `cmake` binary can be quite large in debug builds. Inspired-by: Rolf Eike Beer --- .../separate_arguments/ProgramCommand.cmake | 17 ++++++++--------- .../ProgramCommandWithSeparateArgs.cmake | 13 ++++++------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Tests/RunCMake/separate_arguments/ProgramCommand.cmake b/Tests/RunCMake/separate_arguments/ProgramCommand.cmake index bdf5810b45..cbd44bf2d5 100644 --- a/Tests/RunCMake/separate_arguments/ProgramCommand.cmake +++ b/Tests/RunCMake/separate_arguments/ProgramCommand.cmake @@ -4,12 +4,11 @@ if (out) message (SEND_ERROR "unexpected result with nonexistent program") endif() -set (TEST_EXE_DIR "${CMAKE_CURRENT_BINARY_DIR}/TestExe") -file(MAKE_DIRECTORY "${TEST_EXE_DIR}") -file(COPY "${CMAKE_COMMAND}" DESTINATION "${TEST_EXE_DIR}") -cmake_path (GET CMAKE_COMMAND FILENAME cmake_exe) +get_filename_component(cmake_command "${CMAKE_COMMAND}" ABSOLUTE) +cmake_path (GET cmake_command FILENAME cmake_exe) +cmake_path (GET cmake_command PARENT_PATH cmake_dir) -set (ENV{PATH} "${TEST_EXE_DIR}") +set (ENV{PATH} "${cmake_dir}") separate_arguments (out UNIX_COMMAND PROGRAM "${cmake_exe}") @@ -22,8 +21,8 @@ if (NOT length EQUAL 2) endif() list(GET out 0 cmake) list(GET out 1 args) -if (NOT cmake STREQUAL "${TEST_EXE_DIR}/${cmake_exe}") - message (SEND_ERROR "bad path for program: '${cmake}' instead of '${TEST_EXE_DIR}/${cmake_exe}'") +if (NOT cmake STREQUAL "${cmake_dir}/${cmake_exe}") + message (SEND_ERROR "bad path for program: '${cmake}' instead of '${cmake_dir}/${cmake_exe}'") endif() if (NOT args STREQUAL "") message (SEND_ERROR "bad value for args: '${args}' instead of ''") @@ -40,8 +39,8 @@ if (NOT length EQUAL 2) endif() list(GET out 0 cmake) list(GET out 1 args) -if (NOT cmake STREQUAL "${TEST_EXE_DIR}/${cmake_exe}") - message (SEND_ERROR "bad path for program: '${cmake}' instead of '${TEST_EXE_DIR}/${cmake_exe}'") +if (NOT cmake STREQUAL "${cmake_dir}/${cmake_exe}") + message (SEND_ERROR "bad path for program: '${cmake}' instead of '${cmake_dir}/${cmake_exe}'") endif() if (NOT args STREQUAL " a b c") message (SEND_ERROR "bad value for args: '${args}' instead of ' a b c'") diff --git a/Tests/RunCMake/separate_arguments/ProgramCommandWithSeparateArgs.cmake b/Tests/RunCMake/separate_arguments/ProgramCommandWithSeparateArgs.cmake index 2826cc9461..b93b42c420 100644 --- a/Tests/RunCMake/separate_arguments/ProgramCommandWithSeparateArgs.cmake +++ b/Tests/RunCMake/separate_arguments/ProgramCommandWithSeparateArgs.cmake @@ -4,12 +4,11 @@ if (out) message (SEND_ERROR "unexpected result with nonexistent program") endif() -set (TEST_EXE_DIR "${CMAKE_CURRENT_BINARY_DIR}/TestExe") -file(MAKE_DIRECTORY "${TEST_EXE_DIR}") -file(COPY "${CMAKE_COMMAND}" DESTINATION "${TEST_EXE_DIR}") -cmake_path (GET CMAKE_COMMAND FILENAME cmake_exe) +get_filename_component(cmake_command "${CMAKE_COMMAND}" ABSOLUTE) +cmake_path (GET cmake_command FILENAME cmake_exe) +cmake_path (GET cmake_command PARENT_PATH cmake_dir) -set (ENV{PATH} "${TEST_EXE_DIR}") +set (ENV{PATH} "${cmake_dir}") separate_arguments (out UNIX_COMMAND PROGRAM SEPARATE_ARGS "${cmake_exe} a b c") list (LENGTH out length) @@ -20,8 +19,8 @@ if (NOT length EQUAL 4) message(FATAL_ERROR "unexpected arguments") endif() list(POP_FRONT out cmake) -if (NOT cmake STREQUAL "${TEST_EXE_DIR}/${cmake_exe}") - message (SEND_ERROR "bad path for program: '${cmake}' instead of '${TEST_EXE_DIR}/${cmake_exe}'") +if (NOT cmake STREQUAL "${cmake_dir}/${cmake_exe}") + message (SEND_ERROR "bad path for program: '${cmake}' instead of '${cmake_dir}/${cmake_exe}'") endif() if (NOT out STREQUAL "a;b;c") message (SEND_ERROR "bad path for args: '${out}' instead of 'a;b;c'")