diff --git a/tests/projects/other/autogen_module/.gitignore b/tests/projects/other/autogen_binary_module/.gitignore similarity index 100% rename from tests/projects/other/autogen_module/.gitignore rename to 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 similarity index 100% rename from tests/projects/other/autogen_module/modules/autogen/.gitignore rename to 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 similarity index 100% rename from tests/projects/other/autogen_module/modules/autogen/src/main.cpp rename to 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 similarity index 100% rename from tests/projects/other/autogen_module/modules/autogen/xmake.lua rename to 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 similarity index 100% rename from tests/projects/other/autogen_module/src/data.in rename to 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 similarity index 100% rename from tests/projects/other/autogen_module/src/main.cpp rename to 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 similarity index 100% rename from tests/projects/other/autogen_module/test.lua rename to 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 similarity index 90% rename from tests/projects/other/autogen_module/xmake.lua rename to tests/projects/other/autogen_binary_module/xmake.lua index c5b194d2e25..b1617e54398 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 00000000000..15210576129 --- /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 00000000000..15210576129 --- /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 00000000000..b0f06dc3f76 --- /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 00000000000..6c9c9282eb7 --- /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 00000000000..a0423896973 --- /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 00000000000..3241308f771 --- /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 00000000000..b5736207817 --- /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 00000000000..b1617e54398 --- /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") +