From c7c412f6458f5aceeb02e9bfc292dc7aac0852d3 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 25 Jul 2024 00:54:13 +0800 Subject: move autogen tests --- .../other/autogen/autogen_binary_module/.gitignore | 8 +++++ .../modules/autogen/foo/.gitignore | 8 +++++ .../modules/autogen/foo/src/main.cpp | 29 +++++++++++++++ .../modules/autogen/foo/xmake.lua | 6 ++++ .../autogen/autogen_binary_module/src/data.in | 1 + .../autogen/autogen_binary_module/src/main.cpp | 10 ++++++ .../other/autogen/autogen_binary_module/test.lua | 3 ++ .../other/autogen/autogen_binary_module/xmake.lua | 32 +++++++++++++++++ .../projects/other/autogen/autogen_code/.gitignore | 8 +++++ tests/projects/other/autogen/autogen_code/test.lua | 3 ++ .../projects/other/autogen/autogen_code/xmake.lua | 17 +++++++++ .../other/autogen/autogen_codedep/.gitignore | 8 +++++ .../other/autogen/autogen_codedep/src/autogen.cpp | 28 +++++++++++++++ .../other/autogen/autogen_codedep/src/data.in | 1 + .../other/autogen/autogen_codedep/src/main.cpp | 10 ++++++ .../other/autogen/autogen_codedep/test.lua | 3 ++ .../other/autogen/autogen_codedep/xmake.lua | 35 ++++++++++++++++++ .../other/autogen/autogen_shared_module/.gitignore | 8 +++++ .../modules/autogen/foo/.gitignore | 8 +++++ .../modules/autogen/foo/src/main.cpp | 42 ++++++++++++++++++++++ .../modules/autogen/foo/xmake.lua | 6 ++++ .../autogen/autogen_shared_module/src/data.in | 1 + .../autogen/autogen_shared_module/src/main.cpp | 10 ++++++ .../other/autogen/autogen_shared_module/test.lua | 3 ++ .../other/autogen/autogen_shared_module/xmake.lua | 32 +++++++++++++++++ .../other/autogen_binary_module/.gitignore | 8 ----- .../modules/autogen/foo/.gitignore | 8 ----- .../modules/autogen/foo/src/main.cpp | 29 --------------- .../modules/autogen/foo/xmake.lua | 6 ---- .../other/autogen_binary_module/src/data.in | 1 - .../other/autogen_binary_module/src/main.cpp | 10 ------ .../projects/other/autogen_binary_module/test.lua | 3 -- .../projects/other/autogen_binary_module/xmake.lua | 32 ----------------- tests/projects/other/autogen_code/.gitignore | 8 ----- tests/projects/other/autogen_code/test.lua | 3 -- tests/projects/other/autogen_code/xmake.lua | 17 --------- tests/projects/other/autogen_codedep/.gitignore | 8 ----- .../projects/other/autogen_codedep/src/autogen.cpp | 28 --------------- tests/projects/other/autogen_codedep/src/data.in | 1 - tests/projects/other/autogen_codedep/src/main.cpp | 10 ------ tests/projects/other/autogen_codedep/test.lua | 3 -- tests/projects/other/autogen_codedep/xmake.lua | 35 ------------------ .../other/autogen_shared_module/.gitignore | 8 ----- .../modules/autogen/foo/.gitignore | 8 ----- .../modules/autogen/foo/src/main.cpp | 42 ---------------------- .../modules/autogen/foo/xmake.lua | 6 ---- .../other/autogen_shared_module/src/data.in | 1 - .../other/autogen_shared_module/src/main.cpp | 10 ------ .../projects/other/autogen_shared_module/test.lua | 3 -- .../projects/other/autogen_shared_module/xmake.lua | 32 ----------------- tests/projects/other/native_module/.gitignore | 8 ----- .../projects/other/native_module/cjson/.gitignore | 8 +++++ .../cjson/modules/lua/cjson/src/cjson.c | 7 ++++ .../cjson/modules/lua/cjson/xmake.lua | 19 ++++++++++ .../other/native_module/cjson/src/main.cpp | 6 ++++ tests/projects/other/native_module/cjson/test.lua | 3 ++ tests/projects/other/native_module/cjson/xmake.lua | 12 +++++++ .../projects/other/native_module/hello/.gitignore | 8 +++++ .../hello/modules/binary/bar/.gitignore | 8 +++++ .../hello/modules/binary/bar/src/add.cpp | 9 +++++ .../hello/modules/binary/bar/src/sub.cpp | 10 ++++++ .../hello/modules/binary/bar/xmake.lua | 10 ++++++ .../hello/modules/shared/foo/src/foo.c | 26 ++++++++++++++ .../hello/modules/shared/foo/xmake.lua | 6 ++++ .../other/native_module/hello/src/main.cpp | 6 ++++ tests/projects/other/native_module/hello/test.lua | 3 ++ tests/projects/other/native_module/hello/xmake.lua | 16 +++++++++ .../native_module/modules/binary/bar/.gitignore | 8 ----- .../native_module/modules/binary/bar/src/add.cpp | 9 ----- .../native_module/modules/binary/bar/src/sub.cpp | 10 ------ .../native_module/modules/binary/bar/xmake.lua | 10 ------ .../native_module/modules/shared/foo/src/foo.c | 26 -------------- .../native_module/modules/shared/foo/xmake.lua | 6 ---- tests/projects/other/native_module/src/main.cpp | 6 ---- tests/projects/other/native_module/test.lua | 3 -- tests/projects/other/native_module/xmake.lua | 16 --------- .../projects/other/native_module_cjson/.gitignore | 8 ----- .../modules/lua/cjson/src/cjson.c | 7 ---- .../modules/lua/cjson/xmake.lua | 19 ---------- .../other/native_module_cjson/src/main.cpp | 6 ---- tests/projects/other/native_module_cjson/test.lua | 3 -- tests/projects/other/native_module_cjson/xmake.lua | 12 ------- 82 files changed, 477 insertions(+), 477 deletions(-) create mode 100644 tests/projects/other/autogen/autogen_binary_module/.gitignore create mode 100644 tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/.gitignore create mode 100644 tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/src/main.cpp create mode 100644 tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/xmake.lua create mode 100644 tests/projects/other/autogen/autogen_binary_module/src/data.in create mode 100644 tests/projects/other/autogen/autogen_binary_module/src/main.cpp create mode 100644 tests/projects/other/autogen/autogen_binary_module/test.lua create mode 100644 tests/projects/other/autogen/autogen_binary_module/xmake.lua create mode 100644 tests/projects/other/autogen/autogen_code/.gitignore create mode 100644 tests/projects/other/autogen/autogen_code/test.lua create mode 100644 tests/projects/other/autogen/autogen_code/xmake.lua create mode 100644 tests/projects/other/autogen/autogen_codedep/.gitignore create mode 100644 tests/projects/other/autogen/autogen_codedep/src/autogen.cpp create mode 100644 tests/projects/other/autogen/autogen_codedep/src/data.in create mode 100644 tests/projects/other/autogen/autogen_codedep/src/main.cpp create mode 100644 tests/projects/other/autogen/autogen_codedep/test.lua create mode 100644 tests/projects/other/autogen/autogen_codedep/xmake.lua create mode 100644 tests/projects/other/autogen/autogen_shared_module/.gitignore create mode 100644 tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/.gitignore create mode 100644 tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/src/main.cpp create mode 100644 tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/xmake.lua create mode 100644 tests/projects/other/autogen/autogen_shared_module/src/data.in create mode 100644 tests/projects/other/autogen/autogen_shared_module/src/main.cpp create mode 100644 tests/projects/other/autogen/autogen_shared_module/test.lua create mode 100644 tests/projects/other/autogen/autogen_shared_module/xmake.lua delete mode 100644 tests/projects/other/autogen_binary_module/.gitignore delete mode 100644 tests/projects/other/autogen_binary_module/modules/autogen/foo/.gitignore delete mode 100644 tests/projects/other/autogen_binary_module/modules/autogen/foo/src/main.cpp delete mode 100644 tests/projects/other/autogen_binary_module/modules/autogen/foo/xmake.lua delete mode 100644 tests/projects/other/autogen_binary_module/src/data.in delete mode 100644 tests/projects/other/autogen_binary_module/src/main.cpp delete mode 100644 tests/projects/other/autogen_binary_module/test.lua delete mode 100644 tests/projects/other/autogen_binary_module/xmake.lua delete mode 100644 tests/projects/other/autogen_code/.gitignore delete mode 100644 tests/projects/other/autogen_code/test.lua delete mode 100644 tests/projects/other/autogen_code/xmake.lua delete mode 100644 tests/projects/other/autogen_codedep/.gitignore delete mode 100644 tests/projects/other/autogen_codedep/src/autogen.cpp delete mode 100644 tests/projects/other/autogen_codedep/src/data.in delete mode 100644 tests/projects/other/autogen_codedep/src/main.cpp delete mode 100644 tests/projects/other/autogen_codedep/test.lua delete mode 100644 tests/projects/other/autogen_codedep/xmake.lua delete mode 100644 tests/projects/other/autogen_shared_module/.gitignore delete mode 100644 tests/projects/other/autogen_shared_module/modules/autogen/foo/.gitignore delete mode 100644 tests/projects/other/autogen_shared_module/modules/autogen/foo/src/main.cpp delete mode 100644 tests/projects/other/autogen_shared_module/modules/autogen/foo/xmake.lua delete mode 100644 tests/projects/other/autogen_shared_module/src/data.in delete mode 100644 tests/projects/other/autogen_shared_module/src/main.cpp delete mode 100644 tests/projects/other/autogen_shared_module/test.lua delete mode 100644 tests/projects/other/autogen_shared_module/xmake.lua delete mode 100644 tests/projects/other/native_module/.gitignore create mode 100644 tests/projects/other/native_module/cjson/.gitignore create mode 100644 tests/projects/other/native_module/cjson/modules/lua/cjson/src/cjson.c create mode 100644 tests/projects/other/native_module/cjson/modules/lua/cjson/xmake.lua create mode 100644 tests/projects/other/native_module/cjson/src/main.cpp create mode 100644 tests/projects/other/native_module/cjson/test.lua create mode 100644 tests/projects/other/native_module/cjson/xmake.lua create mode 100644 tests/projects/other/native_module/hello/.gitignore create mode 100644 tests/projects/other/native_module/hello/modules/binary/bar/.gitignore create mode 100644 tests/projects/other/native_module/hello/modules/binary/bar/src/add.cpp create mode 100644 tests/projects/other/native_module/hello/modules/binary/bar/src/sub.cpp create mode 100644 tests/projects/other/native_module/hello/modules/binary/bar/xmake.lua create mode 100644 tests/projects/other/native_module/hello/modules/shared/foo/src/foo.c create mode 100644 tests/projects/other/native_module/hello/modules/shared/foo/xmake.lua create mode 100644 tests/projects/other/native_module/hello/src/main.cpp create mode 100644 tests/projects/other/native_module/hello/test.lua create mode 100644 tests/projects/other/native_module/hello/xmake.lua delete mode 100644 tests/projects/other/native_module/modules/binary/bar/.gitignore delete mode 100644 tests/projects/other/native_module/modules/binary/bar/src/add.cpp delete mode 100644 tests/projects/other/native_module/modules/binary/bar/src/sub.cpp delete mode 100644 tests/projects/other/native_module/modules/binary/bar/xmake.lua delete mode 100644 tests/projects/other/native_module/modules/shared/foo/src/foo.c delete mode 100644 tests/projects/other/native_module/modules/shared/foo/xmake.lua delete mode 100644 tests/projects/other/native_module/src/main.cpp delete mode 100644 tests/projects/other/native_module/test.lua delete mode 100644 tests/projects/other/native_module/xmake.lua delete mode 100644 tests/projects/other/native_module_cjson/.gitignore delete mode 100644 tests/projects/other/native_module_cjson/modules/lua/cjson/src/cjson.c delete mode 100644 tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua delete mode 100644 tests/projects/other/native_module_cjson/src/main.cpp delete mode 100644 tests/projects/other/native_module_cjson/test.lua delete mode 100644 tests/projects/other/native_module_cjson/xmake.lua diff --git a/tests/projects/other/autogen/autogen_binary_module/.gitignore b/tests/projects/other/autogen/autogen_binary_module/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen/autogen_binary_module/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/.gitignore b/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/src/main.cpp b/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/src/main.cpp new file mode 100644 index 000000000..c5150cdbd --- /dev/null +++ b/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/src/main.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +using namespace std; + +int main(int argc, char** argv) { + ifstream src_file(argv[1], ios::in | ios::binary); + if (!src_file) { + return 1; + } + vector buffer(istreambuf_iterator(src_file), {}); + src_file.close(); + + ofstream dst_file(argv[2], ios::out); + if (!dst_file) { + return 1; + } + + dst_file << "unsigned char g_codegen_data[] = {"; + for (auto byte : buffer) { + dst_file << "0x" << hex << (int)(unsigned char)byte << ","; + } + dst_file << "0};" << endl; + dst_file.close(); + return 0; +} + + diff --git a/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/xmake.lua b/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/xmake.lua new file mode 100644 index 000000000..677da3e2d --- /dev/null +++ b/tests/projects/other/autogen/autogen_binary_module/modules/autogen/foo/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("generate") + add_rules("module.binary") + add_files("src/*.cpp") + set_languages("c++11") diff --git a/tests/projects/other/autogen/autogen_binary_module/src/data.in b/tests/projects/other/autogen/autogen_binary_module/src/data.in new file mode 100644 index 000000000..a04238969 --- /dev/null +++ b/tests/projects/other/autogen/autogen_binary_module/src/data.in @@ -0,0 +1 @@ +hello world! diff --git a/tests/projects/other/autogen/autogen_binary_module/src/main.cpp b/tests/projects/other/autogen/autogen_binary_module/src/main.cpp new file mode 100644 index 000000000..3241308f7 --- /dev/null +++ b/tests/projects/other/autogen/autogen_binary_module/src/main.cpp @@ -0,0 +1,10 @@ +#include + +using namespace std; + +extern unsigned char g_codegen_data[]; + +int main(int argc, char** argv) { + cout << (const char*)g_codegen_data << endl; + return 0; +} diff --git a/tests/projects/other/autogen/autogen_binary_module/test.lua b/tests/projects/other/autogen/autogen_binary_module/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen/autogen_binary_module/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/autogen/autogen_binary_module/xmake.lua b/tests/projects/other/autogen/autogen_binary_module/xmake.lua new file mode 100644 index 000000000..b1617e543 --- /dev/null +++ b/tests/projects/other/autogen/autogen_binary_module/xmake.lua @@ -0,0 +1,32 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +rule("autogen") + set_extensions(".in") + before_build_file(function (target, sourcefile, opt) + import("utils.progress") + import("core.project.depend") + import("core.tool.compiler") + import("autogen.foo", {always_build = true}) + + local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp") + local objectfile = target:objectfile(sourcefile_cx) + table.insert(target:objectfiles(), objectfile) + + depend.on_changed(function () + progress.show(opt.progress, "${color.build.object}compiling.autogen %s", sourcefile) + os.mkdir(path.directory(sourcefile_cx)) + foo.generate(sourcefile, sourcefile_cx) + compiler.compile(sourcefile_cx, objectfile, {target = target}) + end, {dependfile = target:dependfile(objectfile), + files = sourcefile, + changed = target:is_rebuilt()}) + end) + +target("test") + set_kind("binary") + add_rules("autogen") + add_files("src/main.cpp") + add_files("src/*.in") + diff --git a/tests/projects/other/autogen/autogen_code/.gitignore b/tests/projects/other/autogen/autogen_code/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen/autogen_code/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen/autogen_code/test.lua b/tests/projects/other/autogen/autogen_code/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen/autogen_code/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/autogen/autogen_code/xmake.lua b/tests/projects/other/autogen/autogen_code/xmake.lua new file mode 100644 index 000000000..9bfe25d9f --- /dev/null +++ b/tests/projects/other/autogen/autogen_code/xmake.lua @@ -0,0 +1,17 @@ +add_rules("mode.debug", "mode.release") + +target("test") + set_kind("binary") + add_files("$(buildir)/autogen.cpp", {always_added = true}) + before_build(function (target) + io.writefile("$(buildir)/autogen.cpp", [[ +#include +using namespace std; +int main(int argc, char** argv) { + cout << "hello world!" << endl; + return 0; +} + ]]) + end) + + diff --git a/tests/projects/other/autogen/autogen_codedep/.gitignore b/tests/projects/other/autogen/autogen_codedep/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen/autogen_codedep/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen/autogen_codedep/src/autogen.cpp b/tests/projects/other/autogen/autogen_codedep/src/autogen.cpp new file mode 100644 index 000000000..cf556ad99 --- /dev/null +++ b/tests/projects/other/autogen/autogen_codedep/src/autogen.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +using namespace std; + +int main(int argc, char** argv) { + ifstream src_file(argv[1], ios::in | ios::binary); + if (!src_file) { + return 1; + } + vector buffer(istreambuf_iterator(src_file), {}); + src_file.close(); + + ofstream dst_file(argv[2], ios::out); + if (!dst_file) { + return 1; + } + + dst_file << "unsigned char g_codegen_data[] = {"; + for (auto byte : buffer) { + dst_file << "0x" << hex << (int)(unsigned char)byte << ","; + } + dst_file << "0};" << endl; + dst_file.close(); + return 0; +} + diff --git a/tests/projects/other/autogen/autogen_codedep/src/data.in b/tests/projects/other/autogen/autogen_codedep/src/data.in new file mode 100644 index 000000000..a04238969 --- /dev/null +++ b/tests/projects/other/autogen/autogen_codedep/src/data.in @@ -0,0 +1 @@ +hello world! diff --git a/tests/projects/other/autogen/autogen_codedep/src/main.cpp b/tests/projects/other/autogen/autogen_codedep/src/main.cpp new file mode 100644 index 000000000..3241308f7 --- /dev/null +++ b/tests/projects/other/autogen/autogen_codedep/src/main.cpp @@ -0,0 +1,10 @@ +#include + +using namespace std; + +extern unsigned char g_codegen_data[]; + +int main(int argc, char** argv) { + cout << (const char*)g_codegen_data << endl; + return 0; +} diff --git a/tests/projects/other/autogen/autogen_codedep/test.lua b/tests/projects/other/autogen/autogen_codedep/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen/autogen_codedep/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/autogen/autogen_codedep/xmake.lua b/tests/projects/other/autogen/autogen_codedep/xmake.lua new file mode 100644 index 000000000..5f2c76d67 --- /dev/null +++ b/tests/projects/other/autogen/autogen_codedep/xmake.lua @@ -0,0 +1,35 @@ +add_rules("mode.debug", "mode.release") + +rule("autogen") + set_extensions(".in") + before_buildcmd_file(function (target, batchcmds, sourcefile, opt) + local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp") + local objectfile = target:objectfile(sourcefile_cx) + table.insert(target:objectfiles(), objectfile) + + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.autogen %s", sourcefile) + batchcmds:mkdir(path.directory(sourcefile_cx)) + batchcmds:vrunv(target:dep("autogen"):targetfile(), {sourcefile, sourcefile_cx}) + batchcmds:compile(sourcefile_cx, objectfile) + + batchcmds:add_depfiles(sourcefile, target:dep("autogen"):targetfile()) + batchcmds:set_depmtime(os.mtime(objectfile)) + batchcmds:set_depcache(target:dependfile(objectfile)) + end) + +target("autogen") + set_default(false) + set_kind("binary") + set_plat(os.host()) + set_arch(os.arch()) + add_files("src/autogen.cpp") + set_languages("c++11") + set_policy("build.fence", true) + +target("test") + set_kind("binary") + add_deps("autogen") + add_rules("autogen") + add_files("src/main.cpp") + add_files("src/*.in") + diff --git a/tests/projects/other/autogen/autogen_shared_module/.gitignore b/tests/projects/other/autogen/autogen_shared_module/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen/autogen_shared_module/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/.gitignore b/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/src/main.cpp b/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/src/main.cpp new file mode 100644 index 000000000..b0f06dc3f --- /dev/null +++ b/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/src/main.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +using namespace std; + +static int generate(lua_State* lua) { + const char* inputfile = lua_tostring(lua, 1); + const char* outputfile = lua_tostring(lua, 2); + + ifstream src_file(inputfile, ios::in | ios::binary); + if (!src_file) { + return 1; + } + vector buffer(istreambuf_iterator(src_file), {}); + src_file.close(); + + ofstream dst_file(outputfile, ios::out); + if (!dst_file) { + return 1; + } + + dst_file << "unsigned char g_codegen_data[] = {"; + for (auto byte : buffer) { + dst_file << "0x" << hex << (int)(unsigned char)byte << ","; + } + dst_file << "0};" << endl; + dst_file.close(); + return 0; +} + +int luaopen(foo, lua_State* lua) { + static const luaL_Reg funcs[] = { + {"generate", generate}, + {NULL, NULL} + }; + lua_newtable(lua); + luaL_setfuncs(lua, funcs, 0); + return 1; +} + diff --git a/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/xmake.lua b/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/xmake.lua new file mode 100644 index 000000000..6c9c9282e --- /dev/null +++ b/tests/projects/other/autogen/autogen_shared_module/modules/autogen/foo/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + add_rules("module.shared") + add_files("src/*.cpp") + set_languages("c++11") diff --git a/tests/projects/other/autogen/autogen_shared_module/src/data.in b/tests/projects/other/autogen/autogen_shared_module/src/data.in new file mode 100644 index 000000000..a04238969 --- /dev/null +++ b/tests/projects/other/autogen/autogen_shared_module/src/data.in @@ -0,0 +1 @@ +hello world! diff --git a/tests/projects/other/autogen/autogen_shared_module/src/main.cpp b/tests/projects/other/autogen/autogen_shared_module/src/main.cpp new file mode 100644 index 000000000..3241308f7 --- /dev/null +++ b/tests/projects/other/autogen/autogen_shared_module/src/main.cpp @@ -0,0 +1,10 @@ +#include + +using namespace std; + +extern unsigned char g_codegen_data[]; + +int main(int argc, char** argv) { + cout << (const char*)g_codegen_data << endl; + return 0; +} diff --git a/tests/projects/other/autogen/autogen_shared_module/test.lua b/tests/projects/other/autogen/autogen_shared_module/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen/autogen_shared_module/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/autogen/autogen_shared_module/xmake.lua b/tests/projects/other/autogen/autogen_shared_module/xmake.lua new file mode 100644 index 000000000..b1617e543 --- /dev/null +++ b/tests/projects/other/autogen/autogen_shared_module/xmake.lua @@ -0,0 +1,32 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +rule("autogen") + set_extensions(".in") + before_build_file(function (target, sourcefile, opt) + import("utils.progress") + import("core.project.depend") + import("core.tool.compiler") + import("autogen.foo", {always_build = true}) + + local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp") + local objectfile = target:objectfile(sourcefile_cx) + table.insert(target:objectfiles(), objectfile) + + depend.on_changed(function () + progress.show(opt.progress, "${color.build.object}compiling.autogen %s", sourcefile) + os.mkdir(path.directory(sourcefile_cx)) + foo.generate(sourcefile, sourcefile_cx) + compiler.compile(sourcefile_cx, objectfile, {target = target}) + end, {dependfile = target:dependfile(objectfile), + files = sourcefile, + changed = target:is_rebuilt()}) + end) + +target("test") + set_kind("binary") + add_rules("autogen") + add_files("src/main.cpp") + add_files("src/*.in") + diff --git a/tests/projects/other/autogen_binary_module/.gitignore b/tests/projects/other/autogen_binary_module/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/autogen_binary_module/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/autogen_binary_module/modules/autogen/foo/.gitignore b/tests/projects/other/autogen_binary_module/modules/autogen/foo/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/autogen_binary_module/modules/autogen/foo/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/autogen_binary_module/modules/autogen/foo/src/main.cpp b/tests/projects/other/autogen_binary_module/modules/autogen/foo/src/main.cpp deleted file mode 100644 index c5150cdbd..000000000 --- a/tests/projects/other/autogen_binary_module/modules/autogen/foo/src/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main(int argc, char** argv) { - ifstream src_file(argv[1], ios::in | ios::binary); - if (!src_file) { - return 1; - } - vector buffer(istreambuf_iterator(src_file), {}); - src_file.close(); - - ofstream dst_file(argv[2], ios::out); - if (!dst_file) { - return 1; - } - - dst_file << "unsigned char g_codegen_data[] = {"; - for (auto byte : buffer) { - dst_file << "0x" << hex << (int)(unsigned char)byte << ","; - } - dst_file << "0};" << endl; - dst_file.close(); - return 0; -} - - diff --git a/tests/projects/other/autogen_binary_module/modules/autogen/foo/xmake.lua b/tests/projects/other/autogen_binary_module/modules/autogen/foo/xmake.lua deleted file mode 100644 index 677da3e2d..000000000 --- a/tests/projects/other/autogen_binary_module/modules/autogen/foo/xmake.lua +++ /dev/null @@ -1,6 +0,0 @@ -add_rules("mode.debug", "mode.release") - -target("generate") - add_rules("module.binary") - add_files("src/*.cpp") - set_languages("c++11") diff --git a/tests/projects/other/autogen_binary_module/src/data.in b/tests/projects/other/autogen_binary_module/src/data.in deleted file mode 100644 index a04238969..000000000 --- a/tests/projects/other/autogen_binary_module/src/data.in +++ /dev/null @@ -1 +0,0 @@ -hello world! diff --git a/tests/projects/other/autogen_binary_module/src/main.cpp b/tests/projects/other/autogen_binary_module/src/main.cpp deleted file mode 100644 index 3241308f7..000000000 --- a/tests/projects/other/autogen_binary_module/src/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -using namespace std; - -extern unsigned char g_codegen_data[]; - -int main(int argc, char** argv) { - cout << (const char*)g_codegen_data << endl; - return 0; -} diff --git a/tests/projects/other/autogen_binary_module/test.lua b/tests/projects/other/autogen_binary_module/test.lua deleted file mode 100644 index b57362078..000000000 --- a/tests/projects/other/autogen_binary_module/test.lua +++ /dev/null @@ -1,3 +0,0 @@ -function main(t) - t:build() -end diff --git a/tests/projects/other/autogen_binary_module/xmake.lua b/tests/projects/other/autogen_binary_module/xmake.lua deleted file mode 100644 index b1617e543..000000000 --- a/tests/projects/other/autogen_binary_module/xmake.lua +++ /dev/null @@ -1,32 +0,0 @@ -add_rules("mode.debug", "mode.release") - -add_moduledirs("modules") - -rule("autogen") - set_extensions(".in") - before_build_file(function (target, sourcefile, opt) - import("utils.progress") - import("core.project.depend") - import("core.tool.compiler") - import("autogen.foo", {always_build = true}) - - local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp") - local objectfile = target:objectfile(sourcefile_cx) - table.insert(target:objectfiles(), objectfile) - - depend.on_changed(function () - progress.show(opt.progress, "${color.build.object}compiling.autogen %s", sourcefile) - os.mkdir(path.directory(sourcefile_cx)) - foo.generate(sourcefile, sourcefile_cx) - compiler.compile(sourcefile_cx, objectfile, {target = target}) - end, {dependfile = target:dependfile(objectfile), - files = sourcefile, - changed = target:is_rebuilt()}) - end) - -target("test") - set_kind("binary") - add_rules("autogen") - add_files("src/main.cpp") - add_files("src/*.in") - diff --git a/tests/projects/other/autogen_code/.gitignore b/tests/projects/other/autogen_code/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/autogen_code/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/autogen_code/test.lua b/tests/projects/other/autogen_code/test.lua deleted file mode 100644 index b57362078..000000000 --- a/tests/projects/other/autogen_code/test.lua +++ /dev/null @@ -1,3 +0,0 @@ -function main(t) - t:build() -end diff --git a/tests/projects/other/autogen_code/xmake.lua b/tests/projects/other/autogen_code/xmake.lua deleted file mode 100644 index 9bfe25d9f..000000000 --- a/tests/projects/other/autogen_code/xmake.lua +++ /dev/null @@ -1,17 +0,0 @@ -add_rules("mode.debug", "mode.release") - -target("test") - set_kind("binary") - add_files("$(buildir)/autogen.cpp", {always_added = true}) - before_build(function (target) - io.writefile("$(buildir)/autogen.cpp", [[ -#include -using namespace std; -int main(int argc, char** argv) { - cout << "hello world!" << endl; - return 0; -} - ]]) - end) - - diff --git a/tests/projects/other/autogen_codedep/.gitignore b/tests/projects/other/autogen_codedep/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/autogen_codedep/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/autogen_codedep/src/autogen.cpp b/tests/projects/other/autogen_codedep/src/autogen.cpp deleted file mode 100644 index cf556ad99..000000000 --- a/tests/projects/other/autogen_codedep/src/autogen.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main(int argc, char** argv) { - ifstream src_file(argv[1], ios::in | ios::binary); - if (!src_file) { - return 1; - } - vector buffer(istreambuf_iterator(src_file), {}); - src_file.close(); - - ofstream dst_file(argv[2], ios::out); - if (!dst_file) { - return 1; - } - - dst_file << "unsigned char g_codegen_data[] = {"; - for (auto byte : buffer) { - dst_file << "0x" << hex << (int)(unsigned char)byte << ","; - } - dst_file << "0};" << endl; - dst_file.close(); - return 0; -} - diff --git a/tests/projects/other/autogen_codedep/src/data.in b/tests/projects/other/autogen_codedep/src/data.in deleted file mode 100644 index a04238969..000000000 --- a/tests/projects/other/autogen_codedep/src/data.in +++ /dev/null @@ -1 +0,0 @@ -hello world! diff --git a/tests/projects/other/autogen_codedep/src/main.cpp b/tests/projects/other/autogen_codedep/src/main.cpp deleted file mode 100644 index 3241308f7..000000000 --- a/tests/projects/other/autogen_codedep/src/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -using namespace std; - -extern unsigned char g_codegen_data[]; - -int main(int argc, char** argv) { - cout << (const char*)g_codegen_data << endl; - return 0; -} diff --git a/tests/projects/other/autogen_codedep/test.lua b/tests/projects/other/autogen_codedep/test.lua deleted file mode 100644 index b57362078..000000000 --- a/tests/projects/other/autogen_codedep/test.lua +++ /dev/null @@ -1,3 +0,0 @@ -function main(t) - t:build() -end diff --git a/tests/projects/other/autogen_codedep/xmake.lua b/tests/projects/other/autogen_codedep/xmake.lua deleted file mode 100644 index 5f2c76d67..000000000 --- a/tests/projects/other/autogen_codedep/xmake.lua +++ /dev/null @@ -1,35 +0,0 @@ -add_rules("mode.debug", "mode.release") - -rule("autogen") - set_extensions(".in") - before_buildcmd_file(function (target, batchcmds, sourcefile, opt) - local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp") - local objectfile = target:objectfile(sourcefile_cx) - table.insert(target:objectfiles(), objectfile) - - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.autogen %s", sourcefile) - batchcmds:mkdir(path.directory(sourcefile_cx)) - batchcmds:vrunv(target:dep("autogen"):targetfile(), {sourcefile, sourcefile_cx}) - batchcmds:compile(sourcefile_cx, objectfile) - - batchcmds:add_depfiles(sourcefile, target:dep("autogen"):targetfile()) - batchcmds:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(objectfile)) - end) - -target("autogen") - set_default(false) - set_kind("binary") - set_plat(os.host()) - set_arch(os.arch()) - add_files("src/autogen.cpp") - set_languages("c++11") - set_policy("build.fence", true) - -target("test") - set_kind("binary") - add_deps("autogen") - add_rules("autogen") - add_files("src/main.cpp") - add_files("src/*.in") - diff --git a/tests/projects/other/autogen_shared_module/.gitignore b/tests/projects/other/autogen_shared_module/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/autogen_shared_module/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/autogen_shared_module/modules/autogen/foo/.gitignore b/tests/projects/other/autogen_shared_module/modules/autogen/foo/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/autogen_shared_module/modules/autogen/foo/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/autogen_shared_module/modules/autogen/foo/src/main.cpp b/tests/projects/other/autogen_shared_module/modules/autogen/foo/src/main.cpp deleted file mode 100644 index b0f06dc3f..000000000 --- a/tests/projects/other/autogen_shared_module/modules/autogen/foo/src/main.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include - -using namespace std; - -static int generate(lua_State* lua) { - const char* inputfile = lua_tostring(lua, 1); - const char* outputfile = lua_tostring(lua, 2); - - ifstream src_file(inputfile, ios::in | ios::binary); - if (!src_file) { - return 1; - } - vector buffer(istreambuf_iterator(src_file), {}); - src_file.close(); - - ofstream dst_file(outputfile, ios::out); - if (!dst_file) { - return 1; - } - - dst_file << "unsigned char g_codegen_data[] = {"; - for (auto byte : buffer) { - dst_file << "0x" << hex << (int)(unsigned char)byte << ","; - } - dst_file << "0};" << endl; - dst_file.close(); - return 0; -} - -int luaopen(foo, lua_State* lua) { - static const luaL_Reg funcs[] = { - {"generate", generate}, - {NULL, NULL} - }; - lua_newtable(lua); - luaL_setfuncs(lua, funcs, 0); - return 1; -} - diff --git a/tests/projects/other/autogen_shared_module/modules/autogen/foo/xmake.lua b/tests/projects/other/autogen_shared_module/modules/autogen/foo/xmake.lua deleted file mode 100644 index 6c9c9282e..000000000 --- a/tests/projects/other/autogen_shared_module/modules/autogen/foo/xmake.lua +++ /dev/null @@ -1,6 +0,0 @@ -add_rules("mode.debug", "mode.release") - -target("foo") - add_rules("module.shared") - add_files("src/*.cpp") - set_languages("c++11") diff --git a/tests/projects/other/autogen_shared_module/src/data.in b/tests/projects/other/autogen_shared_module/src/data.in deleted file mode 100644 index a04238969..000000000 --- a/tests/projects/other/autogen_shared_module/src/data.in +++ /dev/null @@ -1 +0,0 @@ -hello world! diff --git a/tests/projects/other/autogen_shared_module/src/main.cpp b/tests/projects/other/autogen_shared_module/src/main.cpp deleted file mode 100644 index 3241308f7..000000000 --- a/tests/projects/other/autogen_shared_module/src/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -using namespace std; - -extern unsigned char g_codegen_data[]; - -int main(int argc, char** argv) { - cout << (const char*)g_codegen_data << endl; - return 0; -} diff --git a/tests/projects/other/autogen_shared_module/test.lua b/tests/projects/other/autogen_shared_module/test.lua deleted file mode 100644 index b57362078..000000000 --- a/tests/projects/other/autogen_shared_module/test.lua +++ /dev/null @@ -1,3 +0,0 @@ -function main(t) - t:build() -end diff --git a/tests/projects/other/autogen_shared_module/xmake.lua b/tests/projects/other/autogen_shared_module/xmake.lua deleted file mode 100644 index b1617e543..000000000 --- a/tests/projects/other/autogen_shared_module/xmake.lua +++ /dev/null @@ -1,32 +0,0 @@ -add_rules("mode.debug", "mode.release") - -add_moduledirs("modules") - -rule("autogen") - set_extensions(".in") - before_build_file(function (target, sourcefile, opt) - import("utils.progress") - import("core.project.depend") - import("core.tool.compiler") - import("autogen.foo", {always_build = true}) - - local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp") - local objectfile = target:objectfile(sourcefile_cx) - table.insert(target:objectfiles(), objectfile) - - depend.on_changed(function () - progress.show(opt.progress, "${color.build.object}compiling.autogen %s", sourcefile) - os.mkdir(path.directory(sourcefile_cx)) - foo.generate(sourcefile, sourcefile_cx) - compiler.compile(sourcefile_cx, objectfile, {target = target}) - end, {dependfile = target:dependfile(objectfile), - files = sourcefile, - changed = target:is_rebuilt()}) - end) - -target("test") - set_kind("binary") - add_rules("autogen") - add_files("src/main.cpp") - add_files("src/*.in") - diff --git a/tests/projects/other/native_module/.gitignore b/tests/projects/other/native_module/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/native_module/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/native_module/cjson/.gitignore b/tests/projects/other/native_module/cjson/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/native_module/cjson/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/native_module/cjson/modules/lua/cjson/src/cjson.c b/tests/projects/other/native_module/cjson/modules/lua/cjson/src/cjson.c new file mode 100644 index 000000000..d8c2e49ef --- /dev/null +++ b/tests/projects/other/native_module/cjson/modules/lua/cjson/src/cjson.c @@ -0,0 +1,7 @@ +#include + +int luaopen_cjson(lua_State* lua); + +int luaopen(cjson, lua_State* lua) { + return luaopen_cjson(lua); +} diff --git a/tests/projects/other/native_module/cjson/modules/lua/cjson/xmake.lua b/tests/projects/other/native_module/cjson/modules/lua/cjson/xmake.lua new file mode 100644 index 000000000..434746541 --- /dev/null +++ b/tests/projects/other/native_module/cjson/modules/lua/cjson/xmake.lua @@ -0,0 +1,19 @@ +add_rules("mode.debug", "mode.release") + +target("cjson") + add_rules("module.shared") + set_warnings("all") + if is_plat("windows") then + set_languages("c89") + end + add_files("src/*.c") + add_files("../../../../../../../core/src/lua-cjson/lua-cjson/*.c|fpconv.c") + -- Use internal strtod() / g_fmt() code for performance and disable multi-thread + add_defines("NDEBUG", "USE_INTERNAL_FPCONV") + add_defines("XM_CONFIG_API_HAVE_LUA_CJSON") + if is_plat("windows") then + -- Windows sprintf()/strtod() handle NaN/inf differently. Not supported. + add_defines("DISABLE_INVALID_NUMBERS") + add_defines("inline=__inline") + end + diff --git a/tests/projects/other/native_module/cjson/src/main.cpp b/tests/projects/other/native_module/cjson/src/main.cpp new file mode 100644 index 000000000..7c775d288 --- /dev/null +++ b/tests/projects/other/native_module/cjson/src/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char** argv) { + std::cout << "hello world!" << std::endl; + return 0; +} diff --git a/tests/projects/other/native_module/cjson/test.lua b/tests/projects/other/native_module/cjson/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/native_module/cjson/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/native_module/cjson/xmake.lua b/tests/projects/other/native_module/cjson/xmake.lua new file mode 100644 index 000000000..8768aca3e --- /dev/null +++ b/tests/projects/other/native_module/cjson/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("test") + set_kind("binary") + add_files("src/*.cpp") + on_config(function (target) + import("lua.cjson", {always_build = true}) + print(cjson.decode('{"foo": 1, "bar": [1, 2, 3]}')) + end) + diff --git a/tests/projects/other/native_module/hello/.gitignore b/tests/projects/other/native_module/hello/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/native_module/hello/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/native_module/hello/modules/binary/bar/.gitignore b/tests/projects/other/native_module/hello/modules/binary/bar/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/native_module/hello/modules/binary/bar/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/native_module/hello/modules/binary/bar/src/add.cpp b/tests/projects/other/native_module/hello/modules/binary/bar/src/add.cpp new file mode 100644 index 000000000..e19d07e12 --- /dev/null +++ b/tests/projects/other/native_module/hello/modules/binary/bar/src/add.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char** argv) { + int a = atoi(argv[1]); + int b = atoi(argv[2]); + printf("%d", a + b); + return 0; +} diff --git a/tests/projects/other/native_module/hello/modules/binary/bar/src/sub.cpp b/tests/projects/other/native_module/hello/modules/binary/bar/src/sub.cpp new file mode 100644 index 000000000..980289d1a --- /dev/null +++ b/tests/projects/other/native_module/hello/modules/binary/bar/src/sub.cpp @@ -0,0 +1,10 @@ +#include +#include + +int main(int argc, char** argv) { + int a = atoi(argv[1]); + int b = atoi(argv[2]); + printf("%d", a - b); + return 0; +} + diff --git a/tests/projects/other/native_module/hello/modules/binary/bar/xmake.lua b/tests/projects/other/native_module/hello/modules/binary/bar/xmake.lua new file mode 100644 index 000000000..add3c6e97 --- /dev/null +++ b/tests/projects/other/native_module/hello/modules/binary/bar/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +target("add") + add_rules("module.binary") + add_files("src/add.cpp") + +target("sub") + add_rules("module.binary") + add_files("src/sub.cpp") + diff --git a/tests/projects/other/native_module/hello/modules/shared/foo/src/foo.c b/tests/projects/other/native_module/hello/modules/shared/foo/src/foo.c new file mode 100644 index 000000000..0555b071f --- /dev/null +++ b/tests/projects/other/native_module/hello/modules/shared/foo/src/foo.c @@ -0,0 +1,26 @@ +#include + +static int add(lua_State* lua) { + int a = lua_tointeger(lua, 1); + int b = lua_tointeger(lua, 2); + lua_pushinteger(lua, a + b); + return 1; +} + +static int sub(lua_State* lua) { + int a = lua_tointeger(lua, 1); + int b = lua_tointeger(lua, 2); + lua_pushinteger(lua, a - b); + return 1; +} + +int luaopen(foo, lua_State* lua) { + static const luaL_Reg funcs[] = { + {"add", add}, + {"sub", sub}, + {NULL, NULL} + }; + lua_newtable(lua); + luaL_setfuncs(lua, funcs, 0); + return 1; +} diff --git a/tests/projects/other/native_module/hello/modules/shared/foo/xmake.lua b/tests/projects/other/native_module/hello/modules/shared/foo/xmake.lua new file mode 100644 index 000000000..035573d9f --- /dev/null +++ b/tests/projects/other/native_module/hello/modules/shared/foo/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + add_rules("module.shared") + add_files("src/foo.c") + diff --git a/tests/projects/other/native_module/hello/src/main.cpp b/tests/projects/other/native_module/hello/src/main.cpp new file mode 100644 index 000000000..7c775d288 --- /dev/null +++ b/tests/projects/other/native_module/hello/src/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char** argv) { + std::cout << "hello world!" << std::endl; + return 0; +} diff --git a/tests/projects/other/native_module/hello/test.lua b/tests/projects/other/native_module/hello/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/native_module/hello/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/native_module/hello/xmake.lua b/tests/projects/other/native_module/hello/xmake.lua new file mode 100644 index 000000000..211e839d3 --- /dev/null +++ b/tests/projects/other/native_module/hello/xmake.lua @@ -0,0 +1,16 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("test") + set_kind("binary") + add_files("src/*.cpp") + on_config(function (target) + import("shared.foo", {always_build = true}) + import("binary.bar") + print("foo: 1 + 1 = %d", foo.add(1, 1)) + print("foo: 1 - 1 = %d", foo.sub(1, 1)) + print("bar: 1 + 1 = %s", bar.add(1, 1)) + print("bar: 1 - 1 = %s", bar.sub(1, 1)) + end) + diff --git a/tests/projects/other/native_module/modules/binary/bar/.gitignore b/tests/projects/other/native_module/modules/binary/bar/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/native_module/modules/binary/bar/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/native_module/modules/binary/bar/src/add.cpp b/tests/projects/other/native_module/modules/binary/bar/src/add.cpp deleted file mode 100644 index e19d07e12..000000000 --- a/tests/projects/other/native_module/modules/binary/bar/src/add.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int main(int argc, char** argv) { - int a = atoi(argv[1]); - int b = atoi(argv[2]); - printf("%d", a + b); - return 0; -} diff --git a/tests/projects/other/native_module/modules/binary/bar/src/sub.cpp b/tests/projects/other/native_module/modules/binary/bar/src/sub.cpp deleted file mode 100644 index 980289d1a..000000000 --- a/tests/projects/other/native_module/modules/binary/bar/src/sub.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int main(int argc, char** argv) { - int a = atoi(argv[1]); - int b = atoi(argv[2]); - printf("%d", a - b); - return 0; -} - diff --git a/tests/projects/other/native_module/modules/binary/bar/xmake.lua b/tests/projects/other/native_module/modules/binary/bar/xmake.lua deleted file mode 100644 index add3c6e97..000000000 --- a/tests/projects/other/native_module/modules/binary/bar/xmake.lua +++ /dev/null @@ -1,10 +0,0 @@ -add_rules("mode.debug", "mode.release") - -target("add") - add_rules("module.binary") - add_files("src/add.cpp") - -target("sub") - add_rules("module.binary") - add_files("src/sub.cpp") - diff --git a/tests/projects/other/native_module/modules/shared/foo/src/foo.c b/tests/projects/other/native_module/modules/shared/foo/src/foo.c deleted file mode 100644 index 0555b071f..000000000 --- a/tests/projects/other/native_module/modules/shared/foo/src/foo.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -static int add(lua_State* lua) { - int a = lua_tointeger(lua, 1); - int b = lua_tointeger(lua, 2); - lua_pushinteger(lua, a + b); - return 1; -} - -static int sub(lua_State* lua) { - int a = lua_tointeger(lua, 1); - int b = lua_tointeger(lua, 2); - lua_pushinteger(lua, a - b); - return 1; -} - -int luaopen(foo, lua_State* lua) { - static const luaL_Reg funcs[] = { - {"add", add}, - {"sub", sub}, - {NULL, NULL} - }; - lua_newtable(lua); - luaL_setfuncs(lua, funcs, 0); - return 1; -} diff --git a/tests/projects/other/native_module/modules/shared/foo/xmake.lua b/tests/projects/other/native_module/modules/shared/foo/xmake.lua deleted file mode 100644 index 035573d9f..000000000 --- a/tests/projects/other/native_module/modules/shared/foo/xmake.lua +++ /dev/null @@ -1,6 +0,0 @@ -add_rules("mode.debug", "mode.release") - -target("foo") - add_rules("module.shared") - add_files("src/foo.c") - diff --git a/tests/projects/other/native_module/src/main.cpp b/tests/projects/other/native_module/src/main.cpp deleted file mode 100644 index 7c775d288..000000000 --- a/tests/projects/other/native_module/src/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char** argv) { - std::cout << "hello world!" << std::endl; - return 0; -} diff --git a/tests/projects/other/native_module/test.lua b/tests/projects/other/native_module/test.lua deleted file mode 100644 index b57362078..000000000 --- a/tests/projects/other/native_module/test.lua +++ /dev/null @@ -1,3 +0,0 @@ -function main(t) - t:build() -end diff --git a/tests/projects/other/native_module/xmake.lua b/tests/projects/other/native_module/xmake.lua deleted file mode 100644 index 211e839d3..000000000 --- a/tests/projects/other/native_module/xmake.lua +++ /dev/null @@ -1,16 +0,0 @@ -add_rules("mode.debug", "mode.release") - -add_moduledirs("modules") - -target("test") - set_kind("binary") - add_files("src/*.cpp") - on_config(function (target) - import("shared.foo", {always_build = true}) - import("binary.bar") - print("foo: 1 + 1 = %d", foo.add(1, 1)) - print("foo: 1 - 1 = %d", foo.sub(1, 1)) - print("bar: 1 + 1 = %s", bar.add(1, 1)) - print("bar: 1 - 1 = %s", bar.sub(1, 1)) - end) - diff --git a/tests/projects/other/native_module_cjson/.gitignore b/tests/projects/other/native_module_cjson/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/native_module_cjson/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/native_module_cjson/modules/lua/cjson/src/cjson.c b/tests/projects/other/native_module_cjson/modules/lua/cjson/src/cjson.c deleted file mode 100644 index d8c2e49ef..000000000 --- a/tests/projects/other/native_module_cjson/modules/lua/cjson/src/cjson.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int luaopen_cjson(lua_State* lua); - -int luaopen(cjson, lua_State* lua) { - return luaopen_cjson(lua); -} diff --git a/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua b/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua deleted file mode 100644 index 434746541..000000000 --- a/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua +++ /dev/null @@ -1,19 +0,0 @@ -add_rules("mode.debug", "mode.release") - -target("cjson") - add_rules("module.shared") - set_warnings("all") - if is_plat("windows") then - set_languages("c89") - end - add_files("src/*.c") - add_files("../../../../../../../core/src/lua-cjson/lua-cjson/*.c|fpconv.c") - -- Use internal strtod() / g_fmt() code for performance and disable multi-thread - add_defines("NDEBUG", "USE_INTERNAL_FPCONV") - add_defines("XM_CONFIG_API_HAVE_LUA_CJSON") - if is_plat("windows") then - -- Windows sprintf()/strtod() handle NaN/inf differently. Not supported. - add_defines("DISABLE_INVALID_NUMBERS") - add_defines("inline=__inline") - end - diff --git a/tests/projects/other/native_module_cjson/src/main.cpp b/tests/projects/other/native_module_cjson/src/main.cpp deleted file mode 100644 index 7c775d288..000000000 --- a/tests/projects/other/native_module_cjson/src/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char** argv) { - std::cout << "hello world!" << std::endl; - return 0; -} diff --git a/tests/projects/other/native_module_cjson/test.lua b/tests/projects/other/native_module_cjson/test.lua deleted file mode 100644 index b57362078..000000000 --- a/tests/projects/other/native_module_cjson/test.lua +++ /dev/null @@ -1,3 +0,0 @@ -function main(t) - t:build() -end diff --git a/tests/projects/other/native_module_cjson/xmake.lua b/tests/projects/other/native_module_cjson/xmake.lua deleted file mode 100644 index 8768aca3e..000000000 --- a/tests/projects/other/native_module_cjson/xmake.lua +++ /dev/null @@ -1,12 +0,0 @@ -add_rules("mode.debug", "mode.release") - -add_moduledirs("modules") - -target("test") - set_kind("binary") - add_files("src/*.cpp") - on_config(function (target) - import("lua.cjson", {always_build = true}) - print(cjson.decode('{"foo": 1, "bar": [1, 2, 3]}')) - end) - -- cgit v1.3.1