diff options
| author | ruki <[email protected]> | 2023-04-30 21:25:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-04-30 21:25:04 +0800 |
| commit | a2d57245289f89bc0473caa3cf9b0dad60cc6342 (patch) | |
| tree | 40ed223a26b1ea03888fc45a662c1bd158fc9526 | |
| parent | 5075fc82edcb714df4f34f4dec34268ee2914d49 (diff) | |
add autogen test
| -rw-r--r-- | tests/projects/other/autogen_code/xmake.lua | 7 | ||||
| -rw-r--r-- | tests/projects/other/autogen_codedep/.gitignore | 8 | ||||
| -rw-r--r-- | tests/projects/other/autogen_codedep/src/autogen.cpp | 28 | ||||
| -rw-r--r-- | tests/projects/other/autogen_codedep/src/data.in | 1 | ||||
| -rw-r--r-- | tests/projects/other/autogen_codedep/src/main.cpp | 10 | ||||
| -rw-r--r-- | tests/projects/other/autogen_codedep/test.lua | 3 | ||||
| -rw-r--r-- | tests/projects/other/autogen_codedep/xmake.lua | 39 |
7 files changed, 91 insertions, 5 deletions
diff --git a/tests/projects/other/autogen_code/xmake.lua b/tests/projects/other/autogen_code/xmake.lua index fb40d8e9c..9bfe25d9f 100644 --- a/tests/projects/other/autogen_code/xmake.lua +++ b/tests/projects/other/autogen_code/xmake.lua @@ -1,16 +1,13 @@ add_rules("mode.debug", "mode.release") -target("autogen_code") +target("test") set_kind("binary") add_files("$(buildir)/autogen.cpp", {always_added = true}) before_build(function (target) io.writefile("$(buildir)/autogen.cpp", [[ #include <iostream> - using namespace std; - -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { cout << "hello world!" << endl; return 0; } diff --git a/tests/projects/other/autogen_codedep/.gitignore b/tests/projects/other/autogen_codedep/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen_codedep/.gitignore @@ -0,0 +1,8 @@ +# 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 new file mode 100644 index 000000000..cb5ef84f9 --- /dev/null +++ b/tests/projects/other/autogen_codedep/src/autogen.cpp @@ -0,0 +1,28 @@ +#include <iostream> +#include <fstream> +#include <vector> + +using namespace std; + +int main(int argc, char** argv) { + ifstream src_file(argv[1], ios::in | ios::binary); + if (!src_file) { + return 1; + } + vector<char> buffer(istreambuf_iterator<char>(src_file), {}); + src_file.close(); + + ofstream dst_file(argv[2], ios::out); + if (!dst_file) { + return 1; + } + + dst_file << "unsigned char 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 new file mode 100644 index 000000000..a04238969 --- /dev/null +++ b/tests/projects/other/autogen_codedep/src/data.in @@ -0,0 +1 @@ +hello world! diff --git a/tests/projects/other/autogen_codedep/src/main.cpp b/tests/projects/other/autogen_codedep/src/main.cpp new file mode 100644 index 000000000..53f141f46 --- /dev/null +++ b/tests/projects/other/autogen_codedep/src/main.cpp @@ -0,0 +1,10 @@ +#include <iostream> + +using namespace std; + +extern unsigned char data[]; + +int main(int argc, char** argv) { + cout << (const char*)data << endl; + return 0; +} diff --git a/tests/projects/other/autogen_codedep/test.lua b/tests/projects/other/autogen_codedep/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen_codedep/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/autogen_codedep/xmake.lua b/tests/projects/other/autogen_codedep/xmake.lua new file mode 100644 index 000000000..98f695f78 --- /dev/null +++ b/tests/projects/other/autogen_codedep/xmake.lua @@ -0,0 +1,39 @@ +add_rules("mode.debug", "mode.release") +set_policy("build.across_targets_in_parallel", false) + +rule("autogen") + set_extensions(".in") + before_buildcmd_file(function (target, batchcmds, sourcefile, opt) + + -- add objectfile + local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp") + local objectfile = target:objectfile(sourcefile_cx) + table.insert(target:objectfiles(), objectfile) + + -- add commands + 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) + + -- add deps + batchcmds:add_depfiles(sourcefile) + 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") + +target("test") + set_kind("binary") + add_deps("autogen") + add_rules("autogen") + add_files("src/main.cpp") + add_files("src/*.in") + |
