diff options
| author | ruki <[email protected]> | 2016-05-23 10:54:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-05-23 10:54:03 +0800 |
| commit | a1a5a8b7bf0e8b5e809bb03c72c4e5e0784dd39e (patch) | |
| tree | 164d896f539d17d9de7f243bd83fa7cb795e7bf8 | |
| parent | c8454a31c38bbf25b56d0dd4a9a7c8d71ca59419 (diff) | |
add merge object tests
| -rwxr-xr-x | tests/merge_object/src/interface.c | 6 | ||||
| -rwxr-xr-x | tests/merge_object/src/interface.h | 8 | ||||
| -rwxr-xr-x | tests/merge_object/src/test.c | 8 | ||||
| -rwxr-xr-x | tests/merge_object/xmake.lua | 45 | ||||
| -rwxr-xr-x | tests/tests | 3 | ||||
| -rwxr-xr-x | xmake/actions/build/builder.lua | 26 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 1 |
7 files changed, 88 insertions, 9 deletions
diff --git a/tests/merge_object/src/interface.c b/tests/merge_object/src/interface.c new file mode 100755 index 000000000..598d07560 --- /dev/null +++ b/tests/merge_object/src/interface.c @@ -0,0 +1,6 @@ +#include "interface.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/tests/merge_object/src/interface.h b/tests/merge_object/src/interface.h new file mode 100755 index 000000000..10ec0f856 --- /dev/null +++ b/tests/merge_object/src/interface.h @@ -0,0 +1,8 @@ +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int add(int a, int b); diff --git a/tests/merge_object/src/test.c b/tests/merge_object/src/test.c new file mode 100755 index 000000000..9505a2f75 --- /dev/null +++ b/tests/merge_object/src/test.c @@ -0,0 +1,8 @@ +#include "interface.h" +#include <stdio.h> + +int main(int argc, char** argv) +{ + printf("add(1, 2) = %d\n", add(1, 2)); + return 0; +} diff --git a/tests/merge_object/xmake.lua b/tests/merge_object/xmake.lua new file mode 100755 index 000000000..a17d5f6d0 --- /dev/null +++ b/tests/merge_object/xmake.lua @@ -0,0 +1,45 @@ +-- the debug mode +if is_mode("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if is_mode("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- add target +target("merge_object") + + -- set kind + set_kind("static") + + -- add files + add_files("src/interface.c") + +-- add target +target("test") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("merge_object") + + -- add files + add_files("src/test.c") + add_files("src/interface.o") + diff --git a/tests/tests b/tests/tests index 118f69268..a948eb60f 100755 --- a/tests/tests +++ b/tests/tests @@ -57,6 +57,9 @@ build "./tests/console_c++" build "./tests/static_library_c++" build "./tests/shared_library_c++" +# merge object +#build "./tests/merge_object" + # merge static library #build "./tests/merge_static_library" diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua index e9880eead..9027b5737 100755 --- a/xmake/actions/build/builder.lua +++ b/xmake/actions/build/builder.lua @@ -32,14 +32,22 @@ import("core.project.cache") import("core.platform.environment") -- build the object for the *.[o|obj] source file -function _build_object_for_object(target, srcfile, objfile) +function _build_object_for_object(target, sourcefile, objectfile, percent) - -- TODO - raise("not implemented") + -- trace + print("[%02d%%]: inserting.$(mode) %s", percent, sourcefile) + + -- trace verbose info + if option.get("verbose") then + print("cp %s %s", sourcefile, objectfile) + end + + -- insert this object file + os.cp(sourcefile, objectfile) end -- build the object for the *.[a|lib] source file -function _build_object_for_static(target, srcfile, objfile) +function _build_object_for_static(target, sourcefile, objectfile, percent) raise("not implemented") -- TODO @@ -64,12 +72,15 @@ function _build_object(target, index) -- get the source file type local filetype = path.extension(sourcefile):lower() + -- calculate percent + local percent = ((_g.targetindex + (index - 1) / #objectfiles) * 100 / _g.targetcount) + -- build the object for the *.o/obj source makefile if filetype == ".o" or filetype == ".obj" then - return _build_object_for_object(target, sourcefile, objectfile) + return _build_object_for_object(target, sourcefile, objectfile, percent) -- build the object for the *.[a|lib] source file elseif filetype == ".a" or filetype == ".lib" then - return _build_object_for_static(target, sourcefile, objectfile) + return _build_object_for_static(target, sourcefile, objectfile, percent) end -- make command @@ -79,9 +90,6 @@ function _build_object(target, index) command = ccache:append(command, " ") end - -- calculate percent - local percent = ((_g.targetindex + (index - 1) / #objectfiles) * 100 / _g.targetcount) - -- trace print("[%02d%%]: %scompiling.$(mode) %s", percent, ifelse(ccache, "ccache ", ""), sourcefile) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 547dbbb61..8a27e9ec1 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -26,6 +26,7 @@ local target = target or {} -- load modules local os = require("base/os") local path = require("base/path") +local utils = require("base/utils") local table = require("base/table") local option = require("project/option") local config = require("project/config") |
