diff options
| author | ruki <[email protected]> | 2026-08-15 13:33:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-08-15 13:33:14 +0800 |
| commit | 8919a62d50c9c0a93d038b6e0591c0312ff2e0bb (patch) | |
| tree | 9ebf05484854929410c36655f70bd7eb77c62f2b | |
| parent | e4314dc3b2f483ef97b397ed5cf11fcdd397c9a0 (diff) | |
improve custom toolchain test
| -rw-r--r-- | tests/actions/addon/custom-toolchain/src/modules/core/tools/mycl6x.lua | 13 | ||||
| -rw-r--r-- | tests/actions/addon/projects/autofetch-build/src/main.c | 3 | ||||
| -rw-r--r-- | tests/actions/addon/test.lua | 19 |
3 files changed, 27 insertions, 8 deletions
diff --git a/tests/actions/addon/custom-toolchain/src/modules/core/tools/mycl6x.lua b/tests/actions/addon/custom-toolchain/src/modules/core/tools/mycl6x.lua index b58743d4b..972242c98 100644 --- a/tests/actions/addon/custom-toolchain/src/modules/core/tools/mycl6x.lua +++ b/tests/actions/addon/custom-toolchain/src/modules/core/tools/mycl6x.lua @@ -1,7 +1,12 @@ --- our compiler behaves like gcc, it's just a wrapper of the host one +-- the tool module of the my-c6000 toolchain +-- +-- @note our compiler behaves like gcc, it's just a wrapper of the host one, so we only +-- inherit it here, a real one implements the tool interfaces itself, e.g. `init`, +-- `nf_define`, `compargv`, `link`, @see tests/apis/custom_toolchain +-- inherit("core.tools.gcc") --- the marker of this module, the tests use it to check that it comes from the addon -function greeting() - return "hello from the custom toolchain addon" +-- init it +function init(self) + self:set("cxflags", "-DMY_C6000_TOOL") end diff --git a/tests/actions/addon/projects/autofetch-build/src/main.c b/tests/actions/addon/projects/autofetch-build/src/main.c index 112afe090..43509bfeb 100644 --- a/tests/actions/addon/projects/autofetch-build/src/main.c +++ b/tests/actions/addon/projects/autofetch-build/src/main.c @@ -5,6 +5,9 @@ #ifndef MY_C6000 # error the toolchain of the custom-toolchain addon is not used! #endif +#ifndef MY_C6000_TOOL +# error the tool module of the custom-toolchain addon is not used! +#endif int main(int argc, char** argv) { return 0; diff --git a/tests/actions/addon/test.lua b/tests/actions/addon/test.lua index d59ae6f4b..d1e054598 100644 --- a/tests/actions/addon/test.lua +++ b/tests/actions/addon/test.lua @@ -251,11 +251,14 @@ function test_toolchain(t) -- its tool modules are exported by the manifest, so the internal calls can import them -- with their plain names, e.g. add_globalmodules("core.tools.mycl6x") - local script2 = "import(\"core.tools.mycl6x\"); print(mycl6x.greeting()); " .. + -- + -- @note there is no builtin `mycl6x`, so they can only come from this addon + local script2 = "import(\"core.tools.mycl6x\"); assert(mycl6x.compargv, \"invalid tool module!\"); " .. "import(\"lib.detect.find_tool\"); assert(find_tool(\"mycl6x\"), \"mycl6x not found!\")" - t:require(os.iorunv("xmake", {"lua", "-c", script2}):find("hello from the custom toolchain addon", 1, true)) + os.runv("xmake", {"lua", "-c", script2}) - -- and a project can build with it + -- and a project can build with it, the flags of the toolchain and of its tool module + -- are both checked by the source file -- -- @note its compiler is just the host one, so we can only build with it if there is one if find_program("gcc") or find_program("clang") or find_program("cc") then @@ -264,7 +267,15 @@ target("test") set_kind("binary") set_toolchains("@addon/custom-toolchain/my-c6000") add_files("src/main.c") -]], {"build", "-y"}, {files = {["src/main.c"] = "int main(int argc, char** argv) { return 0; }\n"}}) +]], {"build", "-y"}, {files = {["src/main.c"] = [[ +#ifndef MY_C6000 +# error the flags of the addon toolchain are not used! +#endif +#ifndef MY_C6000_TOOL +# error the flags of its tool module are not used! +#endif +int main(int argc, char** argv) { return 0; } +]]}}) end end) end |
