From 0a28b2729deb5b2568f1f4427699724e2bfd3fc7 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 11 Apr 2024 22:34:44 +0800 Subject: add autogen shared module test --- .../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_module/.gitignore | 8 ----- .../autogen_module/modules/autogen/.gitignore | 8 ----- .../autogen_module/modules/autogen/src/main.cpp | 29 --------------- .../other/autogen_module/modules/autogen/xmake.lua | 6 ---- tests/projects/other/autogen_module/src/data.in | 1 - tests/projects/other/autogen_module/src/main.cpp | 10 ------ tests/projects/other/autogen_module/test.lua | 3 -- tests/projects/other/autogen_module/xmake.lua | 32 ----------------- .../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 +++++++++++++++++ 24 files changed, 207 insertions(+), 97 deletions(-) create mode 100644 tests/projects/other/autogen_binary_module/.gitignore create mode 100644 tests/projects/other/autogen_binary_module/modules/autogen/foo/.gitignore create mode 100644 tests/projects/other/autogen_binary_module/modules/autogen/foo/src/main.cpp create mode 100644 tests/projects/other/autogen_binary_module/modules/autogen/foo/xmake.lua create mode 100644 tests/projects/other/autogen_binary_module/src/data.in create mode 100644 tests/projects/other/autogen_binary_module/src/main.cpp create mode 100644 tests/projects/other/autogen_binary_module/test.lua create mode 100644 tests/projects/other/autogen_binary_module/xmake.lua delete mode 100644 tests/projects/other/autogen_module/.gitignore delete mode 100644 tests/projects/other/autogen_module/modules/autogen/.gitignore delete mode 100644 tests/projects/other/autogen_module/modules/autogen/src/main.cpp delete mode 100644 tests/projects/other/autogen_module/modules/autogen/xmake.lua delete mode 100644 tests/projects/other/autogen_module/src/data.in delete mode 100644 tests/projects/other/autogen_module/src/main.cpp delete mode 100644 tests/projects/other/autogen_module/test.lua delete mode 100644 tests/projects/other/autogen_module/xmake.lua create mode 100644 tests/projects/other/autogen_shared_module/.gitignore create mode 100644 tests/projects/other/autogen_shared_module/modules/autogen/foo/.gitignore create mode 100644 tests/projects/other/autogen_shared_module/modules/autogen/foo/src/main.cpp create mode 100644 tests/projects/other/autogen_shared_module/modules/autogen/foo/xmake.lua create mode 100644 tests/projects/other/autogen_shared_module/src/data.in create mode 100644 tests/projects/other/autogen_shared_module/src/main.cpp create mode 100644 tests/projects/other/autogen_shared_module/test.lua create mode 100644 tests/projects/other/autogen_shared_module/xmake.lua diff --git a/tests/projects/other/autogen_binary_module/.gitignore b/tests/projects/other/autogen_binary_module/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen_binary_module/.gitignore @@ -0,0 +1,8 @@ +# 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 new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/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_binary_module/modules/autogen/foo/src/main.cpp b/tests/projects/other/autogen_binary_module/modules/autogen/foo/src/main.cpp new file mode 100644 index 000000000..c5150cdbd --- /dev/null +++ b/tests/projects/other/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_binary_module/modules/autogen/foo/xmake.lua b/tests/projects/other/autogen_binary_module/modules/autogen/foo/xmake.lua new file mode 100644 index 000000000..677da3e2d --- /dev/null +++ b/tests/projects/other/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_binary_module/src/data.in b/tests/projects/other/autogen_binary_module/src/data.in new file mode 100644 index 000000000..a04238969 --- /dev/null +++ b/tests/projects/other/autogen_binary_module/src/data.in @@ -0,0 +1 @@ +hello world! diff --git a/tests/projects/other/autogen_binary_module/src/main.cpp b/tests/projects/other/autogen_binary_module/src/main.cpp new file mode 100644 index 000000000..3241308f7 --- /dev/null +++ b/tests/projects/other/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_binary_module/test.lua b/tests/projects/other/autogen_binary_module/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen_binary_module/test.lua @@ -0,0 +1,3 @@ +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 new file mode 100644 index 000000000..b1617e543 --- /dev/null +++ b/tests/projects/other/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_module/.gitignore b/tests/projects/other/autogen_module/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/autogen_module/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/autogen_module/modules/autogen/.gitignore b/tests/projects/other/autogen_module/modules/autogen/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/autogen_module/modules/autogen/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/autogen_module/modules/autogen/src/main.cpp b/tests/projects/other/autogen_module/modules/autogen/src/main.cpp deleted file mode 100644 index c5150cdbd..000000000 --- a/tests/projects/other/autogen_module/modules/autogen/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_module/modules/autogen/xmake.lua b/tests/projects/other/autogen_module/modules/autogen/xmake.lua deleted file mode 100644 index 677da3e2d..000000000 --- a/tests/projects/other/autogen_module/modules/autogen/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_module/src/data.in b/tests/projects/other/autogen_module/src/data.in deleted file mode 100644 index a04238969..000000000 --- a/tests/projects/other/autogen_module/src/data.in +++ /dev/null @@ -1 +0,0 @@ -hello world! diff --git a/tests/projects/other/autogen_module/src/main.cpp b/tests/projects/other/autogen_module/src/main.cpp deleted file mode 100644 index 3241308f7..000000000 --- a/tests/projects/other/autogen_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_module/test.lua b/tests/projects/other/autogen_module/test.lua deleted file mode 100644 index b57362078..000000000 --- a/tests/projects/other/autogen_module/test.lua +++ /dev/null @@ -1,3 +0,0 @@ -function main(t) - t:build() -end diff --git a/tests/projects/other/autogen_module/xmake.lua b/tests/projects/other/autogen_module/xmake.lua deleted file mode 100644 index c5b194d2e..000000000 --- a/tests/projects/other/autogen_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") - - 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)) - autogen.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_shared_module/.gitignore b/tests/projects/other/autogen_shared_module/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen_shared_module/.gitignore @@ -0,0 +1,8 @@ +# 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 new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/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_shared_module/modules/autogen/foo/src/main.cpp b/tests/projects/other/autogen_shared_module/modules/autogen/foo/src/main.cpp new file mode 100644 index 000000000..b0f06dc3f --- /dev/null +++ b/tests/projects/other/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_shared_module/modules/autogen/foo/xmake.lua b/tests/projects/other/autogen_shared_module/modules/autogen/foo/xmake.lua new file mode 100644 index 000000000..6c9c9282e --- /dev/null +++ b/tests/projects/other/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_shared_module/src/data.in b/tests/projects/other/autogen_shared_module/src/data.in new file mode 100644 index 000000000..a04238969 --- /dev/null +++ b/tests/projects/other/autogen_shared_module/src/data.in @@ -0,0 +1 @@ +hello world! diff --git a/tests/projects/other/autogen_shared_module/src/main.cpp b/tests/projects/other/autogen_shared_module/src/main.cpp new file mode 100644 index 000000000..3241308f7 --- /dev/null +++ b/tests/projects/other/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_shared_module/test.lua b/tests/projects/other/autogen_shared_module/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen_shared_module/test.lua @@ -0,0 +1,3 @@ +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 new file mode 100644 index 000000000..b1617e543 --- /dev/null +++ b/tests/projects/other/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") + -- cgit v1.3.1