summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorChris Wright <chris@inkyspider.co.uk>2023-04-21 16:47:19 +1000
committerCraig Scott <craig.scott@crascit.com>2023-04-26 16:30:36 +0800
commit550f63447d4c7d2db6ccbeaf1f6378aa6f7af4ed (patch)
tree2f9dca56e1a6891f614c52c78d8884f71c7e84ed /Tests
parente256e35daa79732a200883cef398fcd0f8227a3d (diff)
downloadcmake-550f63447d4c7d2db6ccbeaf1f6378aa6f7af4ed.tar.gz
ExternalProject/FetchContent: Support relative remote URLs
Teach `ExternalProject_Add` and `FetchContent_Declare` to resolve relative remote URLs provided via `GIT_REPOSITORY`. Add policy CMP0150 to maintain compatibility. Fixes: #24211 Co-Authored-By: Craig Scott <craig.scott@crascit.com>
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-NEW-build-stdout.txt7
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-NEW-resolve.cmake107
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-NEW-stdout.txt4
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-NEW.cmake45
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-OLD-build-stdout.txt3
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-OLD-common.cmake21
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-OLD-stdout.txt3
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-OLD.cmake2
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-WARN-build-stdout.txt3
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-WARN-stderr.txt25
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-WARN-stdout.txt3
-rw-r--r--Tests/RunCMake/CMP0150/CMP0150-WARN.cmake2
-rw-r--r--Tests/RunCMake/CMP0150/CMakeLists.txt27
-rw-r--r--Tests/RunCMake/CMP0150/CMakeLists.txt.in23
-rw-r--r--Tests/RunCMake/CMP0150/RunCMakeTest.cmake17
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
16 files changed, 293 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMP0150/CMP0150-NEW-build-stdout.txt b/Tests/RunCMake/CMP0150/CMP0150-NEW-build-stdout.txt
new file mode 100644
index 0000000000..9e71b731c7
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-NEW-build-stdout.txt
@@ -0,0 +1,7 @@
+.*-- Configured bottom project
+.*ExternalProject for ep-Y
+.*-- Configured bottom project
+[^\n]*-- Completed configuring project middle
+.*-- Configured bottom project
+.*ExternalProject for ep-X
+.*Non-ep top project
diff --git a/Tests/RunCMake/CMP0150/CMP0150-NEW-resolve.cmake b/Tests/RunCMake/CMP0150/CMP0150-NEW-resolve.cmake
new file mode 100644
index 0000000000..f43f3d5f7b
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-NEW-resolve.cmake
@@ -0,0 +1,107 @@
+include(ExternalProject/shared_internal_commands)
+
+function(test_resolve parentUrl relativeUrl expectedResult)
+ _ep_resolve_relative_git_remote(result "${parentUrl}" "${relativeUrl}")
+ if(NOT result STREQUAL expectedResult)
+ message(SEND_ERROR "URL resolved to unexpected result:\n"
+ " Expected: ${expectedResult}\n"
+ " Actual : ${result}"
+ )
+ endif()
+endfunction()
+
+test_resolve(
+ "https://example.com/group/parent"
+ "../other"
+ "https://example.com/group/other"
+)
+test_resolve(
+ "https://example.com/group/parent"
+ "../../alt/other"
+ "https://example.com/alt/other"
+)
+
+test_resolve(
+ "git@example.com:group/parent"
+ "../other"
+ "git@example.com:group/other"
+)
+test_resolve(
+ "git@example.com:group/parent"
+ "../../alt/other"
+ "git@example.com:alt/other"
+)
+test_resolve(
+ "git@example.com:/group/parent"
+ "../other"
+ "git@example.com:/group/other"
+)
+test_resolve(
+ "git@example.com:/group/parent"
+ "../../alt/other"
+ "git@example.com:/alt/other"
+)
+test_resolve(
+ "git+ssh://git@example.com:group/parent"
+ "../other"
+ "git+ssh://git@example.com:group/other"
+)
+test_resolve(
+ "ssh://git@example.com:1234/group/parent"
+ "../../alt/other"
+ "ssh://git@example.com:1234/alt/other"
+)
+
+test_resolve(
+ "file:///group/parent"
+ "../other"
+ "file:///group/other"
+)
+test_resolve(
+ "file:///group/parent"
+ "../../alt/other"
+ "file:///alt/other"
+)
+test_resolve(
+ "file:///~/group/parent"
+ "../../other"
+ "file:///~/other"
+)
+test_resolve(
+ "/group/parent"
+ "../other"
+ "/group/other"
+)
+test_resolve(
+ "/group/parent"
+ "../../alt/other"
+ "/alt/other"
+)
+test_resolve(
+ "C:/group/parent"
+ "../other"
+ "C:/group/other"
+)
+test_resolve(
+ "C:/group/parent"
+ "../../alt/other"
+ "C:/alt/other"
+)
+
+test_resolve(
+ "x-Test+v1.0://example.com/group/parent"
+ "../other"
+ "x-Test+v1.0://example.com/group/other"
+)
+
+# IPv6 literals
+test_resolve(
+ "http://[::1]/group/parent"
+ "../../alt/other"
+ "http://[::1]/alt/other"
+)
+test_resolve(
+ "git@[::1]:group/parent"
+ "../../alt/other"
+ "git@[::1]:alt/other"
+)
diff --git a/Tests/RunCMake/CMP0150/CMP0150-NEW-stdout.txt b/Tests/RunCMake/CMP0150/CMP0150-NEW-stdout.txt
new file mode 100644
index 0000000000..0f25fabf40
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-NEW-stdout.txt
@@ -0,0 +1,4 @@
+-- Configured bottom project
+-- Completed configuring project middle
+-- Completed configuring project top
+-- Configuring done
diff --git a/Tests/RunCMake/CMP0150/CMP0150-NEW.cmake b/Tests/RunCMake/CMP0150/CMP0150-NEW.cmake
new file mode 100644
index 0000000000..c1c5607af7
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-NEW.cmake
@@ -0,0 +1,45 @@
+set(policyCommand "cmake_policy(SET CMP0150 NEW)")
+
+# Need to keep paths and file names short to avoid hitting limits on Windows.
+# Directory names "a" through to "g" are used here according to the following:
+# a = Top project
+# b/c = Middle project
+# d = Bottom project
+# e/f = Cloned Top project
+# g = Build directory for cloned Top project
+#
+# Dependency names map as follows:
+# X = middle dependency
+# Y = bottom dependency
+
+set(projName top)
+set(depName X)
+set(epRelativeGitRepo ../b/c)
+set(fcRelativeGitRepo ../b/c)
+configure_file(CMakeLists.txt.in a/CMakeLists.txt @ONLY)
+initGitRepo("${CMAKE_CURRENT_BINARY_DIR}/a")
+
+set(projName middle)
+set(depName Y)
+set(epRelativeGitRepo ../../d)
+set(fcRelativeGitRepo ../../d)
+configure_file(CMakeLists.txt.in b/c/CMakeLists.txt @ONLY)
+initGitRepo("${CMAKE_CURRENT_BINARY_DIR}/b/c")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/d")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/d/CMakeLists.txt" [[
+cmake_minimum_required(VERSION 3.26)
+project(bottom LANGUAGES NONE)
+message(STATUS "Configured bottom project")
+]])
+initGitRepo("${CMAKE_CURRENT_BINARY_DIR}/d")
+
+set(clonedTopDir "${CMAKE_CURRENT_BINARY_DIR}/e/f")
+file(MAKE_DIRECTORY "${clonedTopDir}")
+execGitCommand(${CMAKE_CURRENT_BINARY_DIR} clone --quiet "file://${CMAKE_CURRENT_BINARY_DIR}/a" "${clonedTopDir}")
+add_subdirectory("${clonedTopDir}" "${CMAKE_CURRENT_BINARY_DIR}/g")
+
+# Ensure build order is predictable
+add_custom_target(non-ep-top ALL COMMAND ${CMAKE_COMMAND} -E echo "Non-ep top project")
+add_dependencies(non-ep-top ep-X)
+add_dependencies(ep-X ep-Y)
diff --git a/Tests/RunCMake/CMP0150/CMP0150-OLD-build-stdout.txt b/Tests/RunCMake/CMP0150/CMP0150-OLD-build-stdout.txt
new file mode 100644
index 0000000000..0150af769b
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-OLD-build-stdout.txt
@@ -0,0 +1,3 @@
+.*-- Configured bottom project
+.*ExternalProject for ep-bottom
+.*Non-ep top project
diff --git a/Tests/RunCMake/CMP0150/CMP0150-OLD-common.cmake b/Tests/RunCMake/CMP0150/CMP0150-OLD-common.cmake
new file mode 100644
index 0000000000..69748f7325
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-OLD-common.cmake
@@ -0,0 +1,21 @@
+# There's no point testing more than one level for OLD, since the behavior only
+# depends on the current build, not anything about the parent git repo, etc.
+set(projName top)
+set(depName bottom)
+set(epRelativeGitRepo ../../../Bottom)
+set(fcRelativeGitRepo ../Bottom)
+configure_file(CMakeLists.txt.in Top/CMakeLists.txt @ONLY)
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Bottom")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/Bottom/CMakeLists.txt" [[
+cmake_minimum_required(VERSION 3.26)
+project(bottom LANGUAGES NONE)
+message(STATUS "Configured bottom project")
+]])
+initGitRepo("${CMAKE_CURRENT_BINARY_DIR}/Bottom")
+
+add_subdirectory("${CMAKE_CURRENT_BINARY_DIR}/Top" "${CMAKE_CURRENT_BINARY_DIR}/Top-build")
+
+# Ensure build order is predictable
+add_custom_target(non-ep-top ALL COMMAND ${CMAKE_COMMAND} -E echo "Non-ep top project")
+add_dependencies(non-ep-top ep-bottom)
diff --git a/Tests/RunCMake/CMP0150/CMP0150-OLD-stdout.txt b/Tests/RunCMake/CMP0150/CMP0150-OLD-stdout.txt
new file mode 100644
index 0000000000..680f9c1d3d
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-OLD-stdout.txt
@@ -0,0 +1,3 @@
+-- Configured bottom project
+-- Completed configuring project top
+-- Configuring done
diff --git a/Tests/RunCMake/CMP0150/CMP0150-OLD.cmake b/Tests/RunCMake/CMP0150/CMP0150-OLD.cmake
new file mode 100644
index 0000000000..6b58e70c83
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-OLD.cmake
@@ -0,0 +1,2 @@
+set(policyCommand "cmake_policy(SET CMP0150 OLD)")
+include(CMP0150-OLD-common.cmake)
diff --git a/Tests/RunCMake/CMP0150/CMP0150-WARN-build-stdout.txt b/Tests/RunCMake/CMP0150/CMP0150-WARN-build-stdout.txt
new file mode 100644
index 0000000000..0150af769b
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-WARN-build-stdout.txt
@@ -0,0 +1,3 @@
+.*-- Configured bottom project
+.*ExternalProject for ep-bottom
+.*Non-ep top project
diff --git a/Tests/RunCMake/CMP0150/CMP0150-WARN-stderr.txt b/Tests/RunCMake/CMP0150/CMP0150-WARN-stderr.txt
new file mode 100644
index 0000000000..74c932aaa2
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-WARN-stderr.txt
@@ -0,0 +1,25 @@
+CMake Warning \(dev\) at .*/Modules/ExternalProject/shared_internal_commands\.cmake:[0-9]+ \(message\):
+ Policy CMP0150 is not set: ExternalProject_Add and FetchContent_Declare
+ commands treat relative GIT_REPOSITORY paths as being relative to the
+ parent project's remote\. Run "cmake --help-policy CMP0150" for policy
+ details\. Use the cmake_policy command to set the policy and suppress this
+ warning\.
+
+ A relative GIT_REPOSITORY path was detected\. This will be interpreted as a
+ local path to where the project is being cloned\. Set GIT_REPOSITORY to an
+ absolute path or set policy CMP0150 to NEW to avoid this warning\.
+Call Stack \(most recent call first\):
+ .*/Modules/ExternalProject\.cmake:[0-9]+ \(_ep_resolve_git_remote\)
+.*
+CMake Warning \(dev\) at .*/Modules/ExternalProject/shared_internal_commands\.cmake:[0-9]+ \(message\):
+ Policy CMP0150 is not set: ExternalProject_Add and FetchContent_Declare
+ commands treat relative GIT_REPOSITORY paths as being relative to the
+ parent project's remote\. Run "cmake --help-policy CMP0150" for policy
+ details\. Use the cmake_policy command to set the policy and suppress this
+ warning\.
+
+ A relative GIT_REPOSITORY path was detected\. This will be interpreted as a
+ local path to where the project is being cloned\. Set GIT_REPOSITORY to an
+ absolute path or set policy CMP0150 to NEW to avoid this warning\.
+Call Stack \(most recent call first\):
+ .*/Modules/FetchContent\.cmake:[0-9]+ \(_ep_resolve_git_remote\)
diff --git a/Tests/RunCMake/CMP0150/CMP0150-WARN-stdout.txt b/Tests/RunCMake/CMP0150/CMP0150-WARN-stdout.txt
new file mode 100644
index 0000000000..680f9c1d3d
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-WARN-stdout.txt
@@ -0,0 +1,3 @@
+-- Configured bottom project
+-- Completed configuring project top
+-- Configuring done
diff --git a/Tests/RunCMake/CMP0150/CMP0150-WARN.cmake b/Tests/RunCMake/CMP0150/CMP0150-WARN.cmake
new file mode 100644
index 0000000000..20fd45d4e6
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMP0150-WARN.cmake
@@ -0,0 +1,2 @@
+set(policyCommand "")
+include(CMP0150-OLD-common.cmake)
diff --git a/Tests/RunCMake/CMP0150/CMakeLists.txt b/Tests/RunCMake/CMP0150/CMakeLists.txt
new file mode 100644
index 0000000000..371dccc7b2
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMakeLists.txt
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 3.25)
+project(${RunCMake_TEST} NONE)
+
+find_package(Git REQUIRED)
+
+function(execGitCommand workDir)
+ execute_process(
+ WORKING_DIRECTORY "${workDir}"
+ COMMAND "${GIT_EXECUTABLE}" ${ARGN}
+ COMMAND_ECHO STDOUT
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+endfunction()
+
+function(initGitRepo workDir)
+ # init.defaultBranch only works with git 2.28 or later, so we must use the
+ # historical default branch name "master". Force the old default in case test
+ # sites have overridden the default to something else.
+ execGitCommand("${workDir}" -c init.defaultBranch=master init)
+ execGitCommand("${workDir}" config user.email "testauthor@cmake.org")
+ execGitCommand("${workDir}" config user.name testauthor)
+ execGitCommand("${workDir}" config core.autocrlf false)
+ execGitCommand("${workDir}" add CMakeLists.txt)
+ execGitCommand("${workDir}" commit -m "Initial commit")
+endfunction()
+
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0150/CMakeLists.txt.in b/Tests/RunCMake/CMP0150/CMakeLists.txt.in
new file mode 100644
index 0000000000..db6cfc76e0
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/CMakeLists.txt.in
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 3.25)
+project(@projName@ LANGUAGES NONE)
+
+@policyCommand@
+
+include(ExternalProject)
+ExternalProject_Add(ep-@depName@
+ GIT_REPOSITORY @epRelativeGitRepo@
+ GIT_TAG master
+ GIT_CONFIG init.defaultBranch=master
+ TEST_COMMAND ""
+ INSTALL_COMMAND "${CMAKE_COMMAND}" -E echo "ExternalProject for ep-@depName@"
+)
+
+include(FetchContent)
+FetchContent_Declare(@depName@
+ GIT_REPOSITORY @fcRelativeGitRepo@
+ GIT_TAG master
+ GIT_CONFIG init.defaultBranch=master
+)
+FetchContent_MakeAvailable(@depName@)
+
+message(STATUS "Completed configuring project @projName@")
diff --git a/Tests/RunCMake/CMP0150/RunCMakeTest.cmake b/Tests/RunCMake/CMP0150/RunCMakeTest.cmake
new file mode 100644
index 0000000000..940c33e65b
--- /dev/null
+++ b/Tests/RunCMake/CMP0150/RunCMakeTest.cmake
@@ -0,0 +1,17 @@
+include(RunCMake)
+
+function(test_CMP0150 val)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${val}-build)
+ run_cmake(CMP0150-${val})
+ set(RunCMake_TEST_NO_CLEAN TRUE)
+ # Some git versions write clone messages to stderr. These would cause the
+ # test to fail, so we need to merge them into stdout.
+ set(RunCMake_TEST_OUTPUT_MERGE TRUE)
+ run_cmake_command(CMP0150-${val}-build ${CMAKE_COMMAND} --build .)
+endfunction()
+
+test_CMP0150(WARN)
+test_CMP0150(OLD)
+test_CMP0150(NEW)
+
+run_cmake_script(CMP0150-NEW-resolve)
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index f05f784d7d..bd41ff895c 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -160,6 +160,7 @@ endif()
add_RunCMake_test(CMP0132)
add_RunCMake_test(CMP0135)
add_RunCMake_test(CMP0139)
+add_RunCMake_test(CMP0150)
# The test for Policy 65 requires the use of the
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode