diff options
| author | ruki <[email protected]> | 2025-02-06 23:18:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-02-06 23:18:49 +0800 |
| commit | 378ce254ca617f0d2772be7d7acd4ccc2428aef1 (patch) | |
| tree | 9891afda469a25a21b8d5b7c3e795c7d071fc653 /tests | |
| parent | 6eaa4760792b4edf26ad9dc271225cf7b83d7633 (diff) | |
add ide integration test
Diffstat (limited to 'tests')
4 files changed, 94 insertions, 0 deletions
diff --git a/tests/projects/xmake_cli/ide_integration/assets/targetpath.lua b/tests/projects/xmake_cli/ide_integration/assets/targetpath.lua new file mode 100644 index 000000000..4217c5172 --- /dev/null +++ b/tests/projects/xmake_cli/ide_integration/assets/targetpath.lua @@ -0,0 +1,35 @@ +import("core.project.config") +import("core.project.project") + +function main (targetname) + config.load() + if not os.isfile(os.projectfile()) then + return + end + + local target = nil + if targetname then + target = project.target(targetname) + end + if not target then + for _, t in pairs(project.targets()) do + local default = t:get("default") + if (default == nil or default == true) and t:get("kind") == "binary" then + target = t + break + end + end + end + + print("__begin__") + + if target then + local targetfile = target:targetfile() + if not path.is_absolute(targetfile) then + targetfile = path.absolute(targetfile, os.projectdir()) + end + print(targetfile) + end + + print("__end__") +end diff --git a/tests/projects/xmake_cli/ide_integration/assets/targets.lua b/tests/projects/xmake_cli/ide_integration/assets/targets.lua new file mode 100644 index 000000000..87800392f --- /dev/null +++ b/tests/projects/xmake_cli/ide_integration/assets/targets.lua @@ -0,0 +1,22 @@ +-- imports +import("core.project.config") +import("core.project.project") +import("core.base.json") + +function main () + config.load() + + local names = {} + for name, _ in pairs((project.targets())) do + table.insert(names, name) + end + table.sort(names) + if json.mark_as_array then + json.mark_as_array(names) + end + local localjson = json.encode(names) + + print("__begin__") + print(localjson) + print("__end__") +end diff --git a/tests/projects/xmake_cli/ide_integration/src/main.c b/tests/projects/xmake_cli/ide_integration/src/main.c new file mode 100644 index 000000000..24e911fbe --- /dev/null +++ b/tests/projects/xmake_cli/ide_integration/src/main.c @@ -0,0 +1,30 @@ +#include <xmake/xmake.h> + +static tb_bool_t load_scriptfile(xm_engine_ref_t engine, tb_char_t const* filepath, tb_char_t const* arg1) { + tb_char_t* argv[] = {"xmake"}; + tb_char_t* taskargv[] = {"lua", "-D", (tb_char_t*)filepath, (tb_char_t*)arg1, tb_null}; + return xm_engine_main(engine, 1, argv, taskargv) == 0; +} + +static tb_void_t dump_targets(xm_engine_ref_t engine) { + tb_trace_i("------------------------- targets -------------------------"); + load_scriptfile(engine, "assets/targets.lua", tb_null); +} + +static tb_void_t dump_targetpath(xm_engine_ref_t engine) { + tb_trace_i("------------------------- targetpath -------------------------"); + load_scriptfile(engine, "assets/targetpath.lua", "ide"); +} + +tb_int_t main(tb_int_t argc, tb_char_t** argv) { + if (xm_init()) { + xm_engine_ref_t engine = xm_engine_init("xmake", tb_null); + if (engine) { + dump_targets(engine); + dump_targetpath(engine); + xm_engine_exit(engine); + } + xm_exit(); + } + return 0; +} diff --git a/tests/projects/xmake_cli/ide_integration/xmake.lua b/tests/projects/xmake_cli/ide_integration/xmake.lua new file mode 100644 index 000000000..6fe58d584 --- /dev/null +++ b/tests/projects/xmake_cli/ide_integration/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") +add_requires("libxmake") +target("ide") + add_files("src/*.c") + add_packages("libxmake") + set_rundir(".") + |
