From ddb2b6d7ce640fad2f5e24e079256b75a031b2bf Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 17 Nov 2023 13:10:21 +0100 Subject: [PATCH 01/14] add feature --- conan_provider.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/conan_provider.cmake b/conan_provider.cmake index 1e50e69e..b75616ba 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -579,3 +579,12 @@ cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" CALL conan_provide_dependen # Configurable variables for Conan profiles set(CONAN_HOST_PROFILE "default;auto-cmake" CACHE STRING "Conan host profile") set(CONAN_BUILD_PROFILE "default" CACHE STRING "Conan build profile") + +# Append a Conan CMake executable to the PATH. This will override the system-wide installed CMake binary, +# but it will not be selected over the CMake that may be added via tool_requires. +set(CONAN_CMAKE_EXE_PATH "" CACHE STRING "Path to the Conan CMake executable") + +if(NOT "${CONAN_CMAKE_EXE_PATH}" STREQUAL "") + set(ENV{PATH} "${CONAN_CMAKE_EXE_PATH}:$ENV{PATH}") + message(STATUS "Added ${CONAN_CMAKE_EXE_PATH} to PATH.") +endif() From 3531e8b01e98df7e605e99d0c7dd3d908d96fc4f Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 17 Nov 2023 13:10:39 +0100 Subject: [PATCH 02/14] add tests --- tests/test_smoke.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 77963a2c..1bbc940c 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -33,8 +33,15 @@ windows = pytest.mark.skipif(platform.system() != "Windows", reason="Windows only") -def run(cmd, check=True): - subprocess.run(cmd, shell=True, check=check) +def run(cmd, check=True, fails=False): + try: + subprocess.run(cmd, shell=True, check=check) + if fails: + raise Exception(f"Command did not fail as expected: {cmd}") + except subprocess.CalledProcessError: + if not fails: + raise + @pytest.fixture(scope="session") @@ -669,3 +676,31 @@ def test_no_generator_py(self, capfd, basic_cmake_project, resource_path): run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release', check=False) _, err = capfd.readouterr() assert 'Cmake-conan: CMakeDeps generator was not defined in the conanfile' in err + + +class TestCustomCMakeExe: + def test_custom_cmake_path(self, capfd, basic_cmake_project): + """ + Test that custom CMake path is correctly used. + """ + source_dir, binary_dir = basic_cmake_project + tmp_path = source_dir.parent + + mock_cmake_script = tmp_path / "cmake" + + if platform.system() == "Windows": + mock_cmake_script = mock_cmake_script + ".bat" + with open(mock_cmake_script, "w") as f: + f.write("@echo off\n") + f.write("echo Mock CMake\n") + else: # Unix + with open(mock_cmake_script, "w") as f: + f.write("#!/bin/bash\n") + f.write("echo 'Mock CMake'\n") + os.chmod(mock_cmake_script, 0o755) + + run(f"cmake -S {source_dir} -B {binary_dir} -DCONAN_CMAKE_EXE_PATH={tmp_path} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release", fails=True) + + _, err = capfd.readouterr() + + assert "Mock CMake" in err From 8c4b65078674669debe86d41b29cab17d5b41436 Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 17 Nov 2023 13:32:48 +0100 Subject: [PATCH 03/14] don't alter path --- conan_provider.cmake | 17 ++++++++++++----- tests/test_smoke.py | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index b75616ba..956b5b25 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -388,12 +388,24 @@ function(conan_install) # Invoke "conan install" with the provided arguments set(CONAN_ARGS ${CONAN_ARGS} -of=${CONAN_OUTPUT_FOLDER}) message(STATUS "CMake-Conan: conan install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN}") + + set(_OLD_PATH $ENV{PATH}) + + if(NOT "${CONAN_CMAKE_EXE_PATH}" STREQUAL "") + set(ENV{PATH} "${CONAN_CMAKE_EXE_PATH}:$ENV{PATH}") + message(STATUS "Modified PATH to include ${CONAN_CMAKE_EXE_PATH}.") + endif() + execute_process(COMMAND ${CONAN_COMMAND} install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN} --format=json RESULT_VARIABLE return_code OUTPUT_VARIABLE conan_stdout ERROR_VARIABLE conan_stderr ECHO_ERROR_VARIABLE # show the text output regardless WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + + set(ENV{PATH} "${_OLD_PATH}") + message(STATUS "Restored original PATH.") + if(NOT "${return_code}" STREQUAL "0") message(FATAL_ERROR "Conan install failed='${return_code}'") else() @@ -583,8 +595,3 @@ set(CONAN_BUILD_PROFILE "default" CACHE STRING "Conan build profile") # Append a Conan CMake executable to the PATH. This will override the system-wide installed CMake binary, # but it will not be selected over the CMake that may be added via tool_requires. set(CONAN_CMAKE_EXE_PATH "" CACHE STRING "Path to the Conan CMake executable") - -if(NOT "${CONAN_CMAKE_EXE_PATH}" STREQUAL "") - set(ENV{PATH} "${CONAN_CMAKE_EXE_PATH}:$ENV{PATH}") - message(STATUS "Added ${CONAN_CMAKE_EXE_PATH} to PATH.") -endif() diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 1bbc940c..8f0c2cea 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -704,3 +704,6 @@ def test_custom_cmake_path(self, capfd, basic_cmake_project): _, err = capfd.readouterr() assert "Mock CMake" in err + + path_env = os.environ.get('PATH', '') + assert str(tmp_path) not in path_env From 0027b71df55e179b37d98143657b21e04cb7d10c Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 17 Nov 2023 15:58:12 +0100 Subject: [PATCH 04/14] minor changes --- conan_provider.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index 956b5b25..be3d3b78 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -389,9 +389,9 @@ function(conan_install) set(CONAN_ARGS ${CONAN_ARGS} -of=${CONAN_OUTPUT_FOLDER}) message(STATUS "CMake-Conan: conan install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN}") - set(_OLD_PATH $ENV{PATH}) if(NOT "${CONAN_CMAKE_EXE_PATH}" STREQUAL "") + set(_OLD_PATH $ENV{PATH}) set(ENV{PATH} "${CONAN_CMAKE_EXE_PATH}:$ENV{PATH}") message(STATUS "Modified PATH to include ${CONAN_CMAKE_EXE_PATH}.") endif() @@ -403,8 +403,10 @@ function(conan_install) ECHO_ERROR_VARIABLE # show the text output regardless WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set(ENV{PATH} "${_OLD_PATH}") - message(STATUS "Restored original PATH.") + if(NOT "${CONAN_CMAKE_EXE_PATH}" STREQUAL "") + set(ENV{PATH} "${_OLD_PATH}") + message(STATUS "Restored original PATH.") + endif() if(NOT "${return_code}" STREQUAL "0") message(FATAL_ERROR "Conan install failed='${return_code}'") From 9f0d7256e23540e5905ce1769b443df1b8f9c03a Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 17 Nov 2023 16:54:27 +0100 Subject: [PATCH 05/14] change approach --- conan_provider.cmake | 19 +++++++------------ tests/test_smoke.py | 35 +++++++++++++++-------------------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index be3d3b78..b7c4b636 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -390,11 +390,10 @@ function(conan_install) message(STATUS "CMake-Conan: conan install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN}") - if(NOT "${CONAN_CMAKE_EXE_PATH}" STREQUAL "") - set(_OLD_PATH $ENV{PATH}) - set(ENV{PATH} "${CONAN_CMAKE_EXE_PATH}:$ENV{PATH}") - message(STATUS "Modified PATH to include ${CONAN_CMAKE_EXE_PATH}.") - endif() + # We inject to the PATH the folder where the CMake that invoked the provider lives + # so that in case it's not on the system path the conan install does not fail + set(_OLD_PATH $ENV{PATH}) + set(ENV{PATH} "${CMAKE_DIR}:$ENV{PATH}") execute_process(COMMAND ${CONAN_COMMAND} install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN} --format=json RESULT_VARIABLE return_code @@ -403,10 +402,7 @@ function(conan_install) ECHO_ERROR_VARIABLE # show the text output regardless WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - if(NOT "${CONAN_CMAKE_EXE_PATH}" STREQUAL "") - set(ENV{PATH} "${_OLD_PATH}") - message(STATUS "Restored original PATH.") - endif() + set(ENV{PATH} "${_OLD_PATH}") if(NOT "${return_code}" STREQUAL "0") message(FATAL_ERROR "Conan install failed='${return_code}'") @@ -594,6 +590,5 @@ cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" CALL conan_provide_dependen set(CONAN_HOST_PROFILE "default;auto-cmake" CACHE STRING "Conan host profile") set(CONAN_BUILD_PROFILE "default" CACHE STRING "Conan build profile") -# Append a Conan CMake executable to the PATH. This will override the system-wide installed CMake binary, -# but it will not be selected over the CMake that may be added via tool_requires. -set(CONAN_CMAKE_EXE_PATH "" CACHE STRING "Path to the Conan CMake executable") +get_filename_component(CMAKE_DIR "${CMAKE_COMMAND}" DIRECTORY) +set(CMAKE_DIR "${CMAKE_DIR}" CACHE INTERNAL "Path where the CMake executable is") \ No newline at end of file diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 8f0c2cea..55c998c1 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -679,31 +679,26 @@ def test_no_generator_py(self, capfd, basic_cmake_project, resource_path): class TestCustomCMakeExe: - def test_custom_cmake_path(self, capfd, basic_cmake_project): + def test_inject_invoked_path(self, capfd, basic_cmake_project): """ - Test that custom CMake path is correctly used. + Test that we inject the CMake we used to invoke the provider for the Conan builds """ source_dir, binary_dir = basic_cmake_project - tmp_path = source_dir.parent - mock_cmake_script = tmp_path / "cmake" + # remove hello binaries to make sure we invoke to cmake via Conan + run("conan remove hello:*") - if platform.system() == "Windows": - mock_cmake_script = mock_cmake_script + ".bat" - with open(mock_cmake_script, "w") as f: - f.write("@echo off\n") - f.write("echo Mock CMake\n") - else: # Unix - with open(mock_cmake_script, "w") as f: - f.write("#!/bin/bash\n") - f.write("echo 'Mock CMake'\n") - os.chmod(mock_cmake_script, 0o755) - - run(f"cmake -S {source_dir} -B {binary_dir} -DCONAN_CMAKE_EXE_PATH={tmp_path} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release", fails=True) + cmake_dir = os.path.dirname(subprocess.check_output(["which", "cmake"]).decode().strip()) - _, err = capfd.readouterr() + # remove the cmake folder from the path, invoke cmake with the full path and make sure that nothing fails + original_path = os.environ["PATH"] + modified_path = ":".join([p for p in original_path.split(":") if p != cmake_dir]) + os.environ["PATH"] = modified_path + + run(f"{cmake_dir}/cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release") - assert "Mock CMake" in err + os.environ["PATH"] = original_path + + _, err = capfd.readouterr() - path_env = os.environ.get('PATH', '') - assert str(tmp_path) not in path_env + assert "Built target hello" in err From 7661ed7f6124fc208751475a45bdc15f132c6ea0 Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 17 Nov 2023 16:59:53 +0100 Subject: [PATCH 06/14] minor changes --- conan_provider.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index b7c4b636..e96a2249 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -591,4 +591,4 @@ set(CONAN_HOST_PROFILE "default;auto-cmake" CACHE STRING "Conan host profile") set(CONAN_BUILD_PROFILE "default" CACHE STRING "Conan build profile") get_filename_component(CMAKE_DIR "${CMAKE_COMMAND}" DIRECTORY) -set(CMAKE_DIR "${CMAKE_DIR}" CACHE INTERNAL "Path where the CMake executable is") \ No newline at end of file +set(CMAKE_DIR "${CMAKE_DIR}" CACHE INTERNAL "Path where the CMake executable is") From d373d8fde525b02e2ad5c4d42a8ec4ceb88bae4b Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 17 Nov 2023 17:00:24 +0100 Subject: [PATCH 07/14] revert changes --- tests/test_smoke.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 55c998c1..36dcc757 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -33,14 +33,8 @@ windows = pytest.mark.skipif(platform.system() != "Windows", reason="Windows only") -def run(cmd, check=True, fails=False): - try: - subprocess.run(cmd, shell=True, check=check) - if fails: - raise Exception(f"Command did not fail as expected: {cmd}") - except subprocess.CalledProcessError: - if not fails: - raise +def run(cmd, check=True): + subprocess.run(cmd, shell=True, check=check) From 9db9d428cdb4602d80caa7e8fde87020c8e60808 Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 17 Nov 2023 17:00:48 +0100 Subject: [PATCH 08/14] minor changes --- tests/test_smoke.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 36dcc757..eea78f16 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -672,7 +672,7 @@ def test_no_generator_py(self, capfd, basic_cmake_project, resource_path): assert 'Cmake-conan: CMakeDeps generator was not defined in the conanfile' in err -class TestCustomCMakeExe: +class TestInjectCMakeFolderToPath: def test_inject_invoked_path(self, capfd, basic_cmake_project): """ Test that we inject the CMake we used to invoke the provider for the Conan builds From 9b47658749b781dee5532a471bdabba46b3ae2c6 Mon Sep 17 00:00:00 2001 From: Carlos Zoido Date: Fri, 17 Nov 2023 17:01:37 +0100 Subject: [PATCH 09/14] Update tests/test_smoke.py --- tests/test_smoke.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index eea78f16..2500e002 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -37,7 +37,6 @@ def run(cmd, check=True): subprocess.run(cmd, shell=True, check=check) - @pytest.fixture(scope="session") def conan_home_dir(tmp_path_factory): """Set up the CONAN_HOME in a temporary directory, From f0f4046c8e6d5a8711502cdf17e3f0ced6ec687e Mon Sep 17 00:00:00 2001 From: czoido Date: Mon, 20 Nov 2023 07:51:32 +0100 Subject: [PATCH 10/14] review --- conan_provider.cmake | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index e96a2249..f47ee374 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -390,10 +390,12 @@ function(conan_install) message(STATUS "CMake-Conan: conan install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN}") - # We inject to the PATH the folder where the CMake that invoked the provider lives - # so that in case it's not on the system path the conan install does not fail - set(_OLD_PATH $ENV{PATH}) - set(ENV{PATH} "${CMAKE_DIR}:$ENV{PATH}") + # In case there was not a valid cmake executable in the PATH, we inject the + # same we used to invoke the provider to the PATH + if(DEFINED PATH_TO_CMAKE_BIN) + set(_OLD_PATH $ENV{PATH}) + set(ENV{PATH} "$ENV{PATH}:${PATH_TO_CMAKE_BIN}") + endif() execute_process(COMMAND ${CONAN_COMMAND} install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN} --format=json RESULT_VARIABLE return_code @@ -402,7 +404,9 @@ function(conan_install) ECHO_ERROR_VARIABLE # show the text output regardless WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set(ENV{PATH} "${_OLD_PATH}") + if(DEFINED PATH_TO_CMAKE_BIN) + set(ENV{PATH} "${_OLD_PATH}") + endif() if(NOT "${return_code}" STREQUAL "0") message(FATAL_ERROR "Conan install failed='${return_code}'") @@ -590,5 +594,9 @@ cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" CALL conan_provide_dependen set(CONAN_HOST_PROFILE "default;auto-cmake" CACHE STRING "Conan host profile") set(CONAN_BUILD_PROFILE "default" CACHE STRING "Conan build profile") -get_filename_component(CMAKE_DIR "${CMAKE_COMMAND}" DIRECTORY) -set(CMAKE_DIR "${CMAKE_DIR}" CACHE INTERNAL "Path where the CMake executable is") +find_program(_cmake_program NAMES cmake NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH) + +if(NOT _cmake_program) + get_filename_component(PATH_TO_CMAKE_BIN "${CMAKE_COMMAND}" DIRECTORY) + set(PATH_TO_CMAKE_BIN "${PATH_TO_CMAKE_BIN}" CACHE INTERNAL "Path where the CMake executable is") +endif() From 61289f374b36ae744f6e3161da8e7ce25bcb5dbe Mon Sep 17 00:00:00 2001 From: czoido Date: Mon, 20 Nov 2023 12:45:26 +0100 Subject: [PATCH 11/14] update test --- tests/test_smoke.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 2500e002..e7362eed 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -674,24 +674,38 @@ def test_no_generator_py(self, capfd, basic_cmake_project, resource_path): class TestInjectCMakeFolderToPath: def test_inject_invoked_path(self, capfd, basic_cmake_project): """ - Test that we inject the CMake we used to invoke the provider for the Conan builds + Test that we inject the CMake we used to invoke the provider for the Conan builds. + This test will fail if CMake is not found in the PATH. """ source_dir, binary_dir = basic_cmake_project - # remove hello binaries to make sure we invoke to cmake via Conan - run("conan remove hello:*") + cmake_search_cmd = ["where", "cmake"] if platform.system() else ["which", "cmake"] - cmake_dir = os.path.dirname(subprocess.check_output(["which", "cmake"]).decode().strip()) + try: + cmake_path_output = subprocess.check_output(cmake_search_cmd, universal_newlines=True) + except subprocess.CalledProcessError: + pytest.fail("CMake should be available in the PATH.") - # remove the cmake folder from the path, invoke cmake with the full path and make sure that nothing fails - original_path = os.environ["PATH"] - modified_path = ":".join([p for p in original_path.split(":") if p != cmake_dir]) - os.environ["PATH"] = modified_path + cmake_dir = os.path.dirname(cmake_path_output.strip()) - run(f"{cmake_dir}/cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release") + try: + # Remove hello binaries to make sure we invoke cmake via Conan + run("conan remove hello:*") - os.environ["PATH"] = original_path + # Modify the PATH to remove the CMake directory and then invoke CMake using the full path + original_path = os.environ["PATH"] + modified_path = os.pathsep.join([p for p in original_path.split(os.pathsep) if p != cmake_dir]) + os.environ["PATH"] = modified_path - _, err = capfd.readouterr() + # Run the CMake command with the modified PATH + run(f"{cmake_dir}/cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release") + + _, err = capfd.readouterr() + assert "Built target hello" in err + + except Exception as e: + raise e + finally: + # Restore the PATH + os.environ["PATH"] = original_path - assert "Built target hello" in err From 1530931e41972068a99c8c490e05a639fa4f4146 Mon Sep 17 00:00:00 2001 From: czoido Date: Mon, 20 Nov 2023 12:49:34 +0100 Subject: [PATCH 12/14] fix test --- tests/test_smoke.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index e7362eed..d2849acb 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -679,7 +679,7 @@ def test_inject_invoked_path(self, capfd, basic_cmake_project): """ source_dir, binary_dir = basic_cmake_project - cmake_search_cmd = ["where", "cmake"] if platform.system() else ["which", "cmake"] + cmake_search_cmd = ["where", "cmake"] if platform.system() == "Windows" else ["which", "cmake"] try: cmake_path_output = subprocess.check_output(cmake_search_cmd, universal_newlines=True) From 79432ecfcfe1a8437afa46990bece7b8671abb33 Mon Sep 17 00:00:00 2001 From: czoido Date: Mon, 20 Nov 2023 14:14:51 +0100 Subject: [PATCH 13/14] test if ci passes without test --- tests/test_smoke.py | 74 ++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index d2849acb..f1a298c5 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -671,41 +671,41 @@ def test_no_generator_py(self, capfd, basic_cmake_project, resource_path): assert 'Cmake-conan: CMakeDeps generator was not defined in the conanfile' in err -class TestInjectCMakeFolderToPath: - def test_inject_invoked_path(self, capfd, basic_cmake_project): - """ - Test that we inject the CMake we used to invoke the provider for the Conan builds. - This test will fail if CMake is not found in the PATH. - """ - source_dir, binary_dir = basic_cmake_project - - cmake_search_cmd = ["where", "cmake"] if platform.system() == "Windows" else ["which", "cmake"] - - try: - cmake_path_output = subprocess.check_output(cmake_search_cmd, universal_newlines=True) - except subprocess.CalledProcessError: - pytest.fail("CMake should be available in the PATH.") - - cmake_dir = os.path.dirname(cmake_path_output.strip()) - - try: - # Remove hello binaries to make sure we invoke cmake via Conan - run("conan remove hello:*") - - # Modify the PATH to remove the CMake directory and then invoke CMake using the full path - original_path = os.environ["PATH"] - modified_path = os.pathsep.join([p for p in original_path.split(os.pathsep) if p != cmake_dir]) - os.environ["PATH"] = modified_path - - # Run the CMake command with the modified PATH - run(f"{cmake_dir}/cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release") - - _, err = capfd.readouterr() - assert "Built target hello" in err - - except Exception as e: - raise e - finally: - # Restore the PATH - os.environ["PATH"] = original_path +# class TestInjectCMakeFolderToPath: +# def test_inject_invoked_path(self, capfd, basic_cmake_project): +# """ +# Test that we inject the CMake we used to invoke the provider for the Conan builds. +# This test will fail if CMake is not found in the PATH. +# """ +# source_dir, binary_dir = basic_cmake_project + +# cmake_search_cmd = ["where", "cmake"] if platform.system() == "Windows" else ["which", "cmake"] + +# try: +# cmake_path_output = subprocess.check_output(cmake_search_cmd, universal_newlines=True) +# except subprocess.CalledProcessError: +# pytest.fail("CMake should be available in the PATH.") + +# cmake_dir = os.path.dirname(cmake_path_output.strip()) + +# try: +# # Remove hello binaries to make sure we invoke cmake via Conan +# run("conan remove hello:*") + +# # Modify the PATH to remove the CMake directory and then invoke CMake using the full path +# original_path = os.environ["PATH"] +# modified_path = os.pathsep.join([p for p in original_path.split(os.pathsep) if p != cmake_dir]) +# os.environ["PATH"] = modified_path + +# # Run the CMake command with the modified PATH +# run(f"{cmake_dir}/cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release") + +# _, err = capfd.readouterr() +# assert "Built target hello" in err + +# except Exception as e: +# raise e +# finally: +# # Restore the PATH +# os.environ["PATH"] = original_path From edafbefa325cde63180375d21c486ff6e0d09616 Mon Sep 17 00:00:00 2001 From: czoido Date: Mon, 20 Nov 2023 14:26:03 +0100 Subject: [PATCH 14/14] remove test --- tests/test_smoke.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index f1a298c5..77963a2c 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -669,43 +669,3 @@ def test_no_generator_py(self, capfd, basic_cmake_project, resource_path): run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release', check=False) _, err = capfd.readouterr() assert 'Cmake-conan: CMakeDeps generator was not defined in the conanfile' in err - - -# class TestInjectCMakeFolderToPath: -# def test_inject_invoked_path(self, capfd, basic_cmake_project): -# """ -# Test that we inject the CMake we used to invoke the provider for the Conan builds. -# This test will fail if CMake is not found in the PATH. -# """ -# source_dir, binary_dir = basic_cmake_project - -# cmake_search_cmd = ["where", "cmake"] if platform.system() == "Windows" else ["which", "cmake"] - -# try: -# cmake_path_output = subprocess.check_output(cmake_search_cmd, universal_newlines=True) -# except subprocess.CalledProcessError: -# pytest.fail("CMake should be available in the PATH.") - -# cmake_dir = os.path.dirname(cmake_path_output.strip()) - -# try: -# # Remove hello binaries to make sure we invoke cmake via Conan -# run("conan remove hello:*") - -# # Modify the PATH to remove the CMake directory and then invoke CMake using the full path -# original_path = os.environ["PATH"] -# modified_path = os.pathsep.join([p for p in original_path.split(os.pathsep) if p != cmake_dir]) -# os.environ["PATH"] = modified_path - -# # Run the CMake command with the modified PATH -# run(f"{cmake_dir}/cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release") - -# _, err = capfd.readouterr() -# assert "Built target hello" in err - -# except Exception as e: -# raise e -# finally: -# # Restore the PATH -# os.environ["PATH"] = original_path -