diff options
| author | ruki <[email protected]> | 2024-04-11 22:34:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-04-11 22:34:44 +0800 |
| commit | 0a28b2729deb5b2568f1f4427699724e2bfd3fc7 (patch) | |
| tree | 8bccdd80c09e84bf794575ee78b787b4d3c27773 | |
| parent | b559b4c1591e448b0f3faaa5928fc79e8286b8c3 (diff) | |
add autogen shared module test
16 files changed, 112 insertions, 2 deletions
diff --git a/tests/projects/other/autogen_module/.gitignore b/tests/projects/other/autogen_binary_module/.gitignore index 152105761..152105761 100644 --- a/tests/projects/other/autogen_module/.gitignore +++ b/tests/projects/other/autogen_binary_module/.gitignore diff --git a/tests/projects/other/autogen_module/modules/autogen/.gitignore b/tests/projects/other/autogen_binary_module/modules/autogen/foo/.gitignore index 152105761..152105761 100644 --- a/tests/projects/other/autogen_module/modules/autogen/.gitignore +++ b/tests/projects/other/autogen_binary_module/modules/autogen/foo/.gitignore diff --git a/tests/projects/other/autogen_module/modules/autogen/src/main.cpp b/tests/projects/other/autogen_binary_module/modules/autogen/foo/src/main.cpp index c5150cdbd..c5150cdbd 100644 --- a/tests/projects/other/autogen_module/modules/autogen/src/main.cpp +++ b/tests/projects/other/autogen_binary_module/modules/autogen/foo/src/main.cpp diff --git a/tests/projects/other/autogen_module/modules/autogen/xmake.lua b/tests/projects/other/autogen_binary_module/modules/autogen/foo/xmake.lua index 677da3e2d..677da3e2d 100644 --- a/tests/projects/other/autogen_module/modules/autogen/xmake.lua +++ b/tests/projects/other/autogen_binary_module/modules/autogen/foo/xmake.lua diff --git a/tests/projects/other/autogen_module/src/data.in b/tests/projects/other/autogen_binary_module/src/data.in index a04238969..a04238969 100644 --- a/tests/projects/other/autogen_module/src/data.in +++ b/tests/projects/other/autogen_binary_module/src/data.in diff --git a/tests/projects/other/autogen_module/src/main.cpp b/tests/projects/other/autogen_binary_module/src/main.cpp index 3241308f7..3241308f7 100644 --- a/tests/projects/other/autogen_module/src/main.cpp +++ b/tests/projects/other/autogen_binary_module/src/main.cpp diff --git a/tests/projects/other/autogen_module/test.lua b/tests/projects/other/autogen_binary_module/test.lua index b57362078..b57362078 100644 --- a/tests/projects/other/autogen_module/test.lua +++ b/tests/projects/other/autogen_binary_module/test.lua diff --git a/tests/projects/other/autogen_module/xmake.lua b/tests/projects/other/autogen_binary_module/xmake.lua index c5b194d2e..b1617e543 100644 --- a/tests/projects/other/autogen_module/xmake.lua +++ b/tests/projects/other/autogen_binary_module/xmake.lua @@ -8,7 +8,7 @@ rule("autogen") import("utils.progress") import("core.project.depend") import("core.tool.compiler") - import("autogen") + 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) @@ -17,7 +17,7 @@ rule("autogen") 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) + foo.generate(sourcefile, sourcefile_cx) compiler.compile(sourcefile_cx, objectfile, {target = target}) end, {dependfile = target:dependfile(objectfile), files = sourcefile, 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 <xmi.h> +#include <iostream> +#include <fstream> +#include <vector> + +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<char> buffer(istreambuf_iterator<char>(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 <iostream> + +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") + |
