diff options
| author | ruki <[email protected]> | 2026-08-16 11:32:08 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-08-16 11:32:08 +0800 |
| commit | 2fa10294d414d3701fed76df6a786a0fe65c90b8 (patch) | |
| tree | 5e5de9a90decf8a22b1565157e739b00fb1aa004 | |
| parent | 65854acd5e7080dae4cac3e3b3ec1ce01e902ae7 (diff) | |
| parent | 58f6d2dd060b78afb0f1002c5586fc85dfca0629 (diff) | |
Merge pull request #7707 from xmake-io/repo
add packages test for addon
6 files changed, 52 insertions, 0 deletions
diff --git a/tests/actions/addon/custom-package/addon.lua b/tests/actions/addon/custom-package/addon.lua new file mode 100644 index 000000000..56d8300f3 --- /dev/null +++ b/tests/actions/addon/custom-package/addon.lua @@ -0,0 +1,2 @@ +addon("custom-package") + set_description("the addon which provides a custom package") diff --git a/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h b/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h new file mode 100644 index 000000000..ca969acd2 --- /dev/null +++ b/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h @@ -0,0 +1,6 @@ +#pragma once +#include <stdio.h> + +static inline void hello_utils_greeting(void) { + printf("hello from the custom package!\n"); +} diff --git a/tests/actions/addon/custom-package/includes/packages/xmake.lua b/tests/actions/addon/custom-package/includes/packages/xmake.lua new file mode 100644 index 000000000..5a02187fd --- /dev/null +++ b/tests/actions/addon/custom-package/includes/packages/xmake.lua @@ -0,0 +1,13 @@ +-- an addon can ship the package definitions, so that a project only needs +-- includes("@addon/custom-package/packages") and add_requires("hello-utils") +package("hello-utils") + set_kind("library", {headeronly = true}) + set_description("the custom package of the tests") + + -- the sources are shipped by this addon, so it can be installed offline + set_sourcedir(path.join(os.scriptdir(), "src")) + + on_install(function (package) + os.cp("include", package:installdir()) + end) +package_end() diff --git a/tests/actions/addon/projects/custom-package/src/main.c b/tests/actions/addon/projects/custom-package/src/main.c new file mode 100644 index 000000000..12208c880 --- /dev/null +++ b/tests/actions/addon/projects/custom-package/src/main.c @@ -0,0 +1,6 @@ +#include <hello_utils.h> + +int main(int argc, char** argv) { + hello_utils_greeting(); + return 0; +} diff --git a/tests/actions/addon/projects/custom-package/xmake.lua b/tests/actions/addon/projects/custom-package/xmake.lua new file mode 100644 index 000000000..1c967020d --- /dev/null +++ b/tests/actions/addon/projects/custom-package/xmake.lua @@ -0,0 +1,9 @@ +-- the package definitions come from the addon +includes("@addon/custom-package/packages") + +add_requires("hello-utils") + +target("test") + set_kind("binary") + add_files("src/main.c") + add_packages("hello-utils") diff --git a/tests/actions/addon/test.lua b/tests/actions/addon/test.lua index 192230b08..0b80a62e9 100644 --- a/tests/actions/addon/test.lua +++ b/tests/actions/addon/test.lua @@ -239,6 +239,22 @@ function test_template(t) end) end +-- an addon can ship the package definitions in its includes file, so that a project +-- only needs `add_requires`, @see tests/actions/addon/custom-package +function test_include_packages(t) + + -- @note we need a compiler here, the project links against the package + if not (find_program("gcc") or find_program("clang") or find_program("cc")) then + return + end + _with_addons({"custom-package"}, function () + _with_project("custom-package", function () + t:require(os.iorunv("xmake", {"build", "-y"}):find("build ok", 1, true)) + t:require(os.iorunv("xmake", {"run"}):find("hello from the custom package", 1, true)) + end) + end) +end + -- an addon can provide a toolchain and its tool modules -- -- @see tests/apis/custom_toolchain for the same toolchain maintained inside a project |
