From df5cb9cce6cbb757c12f07677edf27b4be219f48 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Tue, 23 Jul 2024 23:25:48 +0200 Subject: prompt an error when multiple module with the same names are detected --- .../modules/duplicate_name_detection/src/bar.mpp | 5 ++ .../modules/duplicate_name_detection/src/foo.mpp | 5 ++ .../modules/duplicate_name_detection/src/main.cpp | 5 ++ .../c++/modules/duplicate_name_detection/test.lua | 70 ++++++++++++++++++++++ .../c++/modules/duplicate_name_detection/xmake.lua | 20 +++++++ tests/projects/c++/modules/link_order/src/bar.mpp | 5 -- tests/projects/c++/modules/link_order/src/foo.mpp | 5 -- tests/projects/c++/modules/link_order/src/main.cpp | 5 -- tests/projects/c++/modules/link_order/test.lua | 1 - tests/projects/c++/modules/link_order/xmake.lua | 20 ------- 10 files changed, 105 insertions(+), 36 deletions(-) create mode 100644 tests/projects/c++/modules/duplicate_name_detection/src/bar.mpp create mode 100644 tests/projects/c++/modules/duplicate_name_detection/src/foo.mpp create mode 100644 tests/projects/c++/modules/duplicate_name_detection/src/main.cpp create mode 100644 tests/projects/c++/modules/duplicate_name_detection/test.lua create mode 100644 tests/projects/c++/modules/duplicate_name_detection/xmake.lua delete mode 100644 tests/projects/c++/modules/link_order/src/bar.mpp delete mode 100644 tests/projects/c++/modules/link_order/src/foo.mpp delete mode 100644 tests/projects/c++/modules/link_order/src/main.cpp delete mode 100644 tests/projects/c++/modules/link_order/test.lua delete mode 100644 tests/projects/c++/modules/link_order/xmake.lua (limited to 'tests/projects/c++/modules') diff --git a/tests/projects/c++/modules/duplicate_name_detection/src/bar.mpp b/tests/projects/c++/modules/duplicate_name_detection/src/bar.mpp new file mode 100644 index 000000000..a51969b8f --- /dev/null +++ b/tests/projects/c++/modules/duplicate_name_detection/src/bar.mpp @@ -0,0 +1,5 @@ +export module foo; + +export int value() { + return 1; +} diff --git a/tests/projects/c++/modules/duplicate_name_detection/src/foo.mpp b/tests/projects/c++/modules/duplicate_name_detection/src/foo.mpp new file mode 100644 index 000000000..d97e5f085 --- /dev/null +++ b/tests/projects/c++/modules/duplicate_name_detection/src/foo.mpp @@ -0,0 +1,5 @@ +export module foo; + +export int value() { + return 0; +} diff --git a/tests/projects/c++/modules/duplicate_name_detection/src/main.cpp b/tests/projects/c++/modules/duplicate_name_detection/src/main.cpp new file mode 100644 index 000000000..50ddf1fdd --- /dev/null +++ b/tests/projects/c++/modules/duplicate_name_detection/src/main.cpp @@ -0,0 +1,5 @@ +import foo; + +int main() { + return value(); +} diff --git a/tests/projects/c++/modules/duplicate_name_detection/test.lua b/tests/projects/c++/modules/duplicate_name_detection/test.lua new file mode 100644 index 000000000..5215735b5 --- /dev/null +++ b/tests/projects/c++/modules/duplicate_name_detection/test.lua @@ -0,0 +1,70 @@ +import("lib.detect.find_tool") +import("core.base.semver") +import("utils.ci.is_running", {alias = "ci_is_running"}) + +function _build() + try {function() + if ci_is_running() then + os.iorun("xmake -rvD") + else + os.iorun("xmake -r") + end + end, catch {function(errors) + errors = errors.errors + if not errors or not errors:find("detected") then + raise("Modules duplicate name detection does not work\n%s", errors.errors) + end + end}} +end + +function can_build() + if is_subhost("windows") then + return true + elseif is_subhost("msys") then + return true + elseif is_host("linux") then + local gcc = find_tool("gcc", {version = true}) + if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + return true + end + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + return true + end + end +end + +function main(t) + if is_subhost("windows") then + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "17.0") >= 0 then + os.exec("xmake f --toolchain=clang -c --yes") + _build() + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") + _build() + end + + os.exec("xmake clean -a") + os.exec("xmake f -c --yes") + _build() + elseif is_subhost("msys") then + os.exec("xmake f -c -p mingw --yes") + _build() + elseif is_host("linux") then + local gcc = find_tool("gcc", {version = true}) +if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + os.exec("xmake f -c --yes") + _build() + end + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang -c --yes") + _build() + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") + _build() + end + end +end diff --git a/tests/projects/c++/modules/duplicate_name_detection/xmake.lua b/tests/projects/c++/modules/duplicate_name_detection/xmake.lua new file mode 100644 index 000000000..f4539695c --- /dev/null +++ b/tests/projects/c++/modules/duplicate_name_detection/xmake.lua @@ -0,0 +1,20 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +target("foo") + set_kind("moduleonly") + add_files("src/foo.mpp") + +target("bar") + set_kind("moduleonly") + add_files("src/bar.mpp") + +target("duplicate_name_detection_1") + set_kind("binary") + add_deps("foo", "bar") + add_files("src/main.cpp") + +target("duplicate_name_detection_2") + set_kind("binary") + add_deps("bar", "foo") + add_files("src/main.cpp") diff --git a/tests/projects/c++/modules/link_order/src/bar.mpp b/tests/projects/c++/modules/link_order/src/bar.mpp deleted file mode 100644 index dc7c14ec8..000000000 --- a/tests/projects/c++/modules/link_order/src/bar.mpp +++ /dev/null @@ -1,5 +0,0 @@ -export module duplicate; - -export int value() { - return 1; -} diff --git a/tests/projects/c++/modules/link_order/src/foo.mpp b/tests/projects/c++/modules/link_order/src/foo.mpp deleted file mode 100644 index eba3a4223..000000000 --- a/tests/projects/c++/modules/link_order/src/foo.mpp +++ /dev/null @@ -1,5 +0,0 @@ -export module duplicate; - -export int value() { - return 0; -} diff --git a/tests/projects/c++/modules/link_order/src/main.cpp b/tests/projects/c++/modules/link_order/src/main.cpp deleted file mode 100644 index cd9524d8b..000000000 --- a/tests/projects/c++/modules/link_order/src/main.cpp +++ /dev/null @@ -1,5 +0,0 @@ -import duplicate; - -int main() { - return value(); -} diff --git a/tests/projects/c++/modules/link_order/test.lua b/tests/projects/c++/modules/link_order/test.lua deleted file mode 100644 index 7717f8049..000000000 --- a/tests/projects/c++/modules/link_order/test.lua +++ /dev/null @@ -1 +0,0 @@ -inherit(".test_base") diff --git a/tests/projects/c++/modules/link_order/xmake.lua b/tests/projects/c++/modules/link_order/xmake.lua deleted file mode 100644 index 4cb2af87f..000000000 --- a/tests/projects/c++/modules/link_order/xmake.lua +++ /dev/null @@ -1,20 +0,0 @@ -add_rules("mode.release", "mode.debug") -set_languages("c++20") - -target("foo") - set_kind("moduleonly") - add_files("src/foo.mpp") - -target("bar") - set_kind("moduleonly") - add_files("src/bar.mpp") - -target("link_order_1") - set_kind("binary") - add_deps("foo", "bar") - add_files("src/main.cpp") - -target("link_order_2") - set_kind("binary") - add_deps("bar", "foo") - add_files("src/main.cpp") -- cgit v1.3.1