From 4e3967d123432b2352b450ed892fcb1b8f3b37d2 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 Oct 2021 21:02:26 +0800 Subject: rename to unity build --- tests/projects/c/unit_build/src/bar/test4.c | 8 -- tests/projects/c/unit_build/src/bar/test5.c | 8 -- tests/projects/c/unit_build/src/foo/test1.c | 8 -- tests/projects/c/unit_build/src/foo/test2.c | 8 -- tests/projects/c/unit_build/src/header.h | 10 --- tests/projects/c/unit_build/src/main.c | 7 -- tests/projects/c/unit_build/src/test.cpp | 4 - tests/projects/c/unit_build/src/test2.c | 8 -- tests/projects/c/unit_build/src/test6.c | 8 -- tests/projects/c/unit_build/src/test7.c | 8 -- tests/projects/c/unit_build/src/test8.c | 8 -- tests/projects/c/unit_build/test.lua | 6 -- tests/projects/c/unit_build/xmake.lua | 8 -- tests/projects/c/unity_build/src/bar/test4.c | 8 ++ tests/projects/c/unity_build/src/bar/test5.c | 8 ++ tests/projects/c/unity_build/src/foo/test1.c | 8 ++ tests/projects/c/unity_build/src/foo/test2.c | 8 ++ tests/projects/c/unity_build/src/header.h | 10 +++ tests/projects/c/unity_build/src/main.c | 7 ++ tests/projects/c/unity_build/src/test.cpp | 4 + tests/projects/c/unity_build/src/test2.c | 8 ++ tests/projects/c/unity_build/src/test6.c | 8 ++ tests/projects/c/unity_build/src/test7.c | 8 ++ tests/projects/c/unity_build/src/test8.c | 8 ++ tests/projects/c/unity_build/test.lua | 6 ++ tests/projects/c/unity_build/xmake.lua | 8 ++ xmake/rules/c++/unit_build/unit_build.lua | 123 --------------------------- xmake/rules/c++/unit_build/xmake.lua | 45 ---------- xmake/rules/c++/unity_build/unity_build.lua | 123 +++++++++++++++++++++++++++ xmake/rules/c++/unity_build/xmake.lua | 45 ++++++++++ 30 files changed, 267 insertions(+), 267 deletions(-) delete mode 100644 tests/projects/c/unit_build/src/bar/test4.c delete mode 100644 tests/projects/c/unit_build/src/bar/test5.c delete mode 100644 tests/projects/c/unit_build/src/foo/test1.c delete mode 100644 tests/projects/c/unit_build/src/foo/test2.c delete mode 100644 tests/projects/c/unit_build/src/header.h delete mode 100644 tests/projects/c/unit_build/src/main.c delete mode 100644 tests/projects/c/unit_build/src/test.cpp delete mode 100644 tests/projects/c/unit_build/src/test2.c delete mode 100644 tests/projects/c/unit_build/src/test6.c delete mode 100644 tests/projects/c/unit_build/src/test7.c delete mode 100644 tests/projects/c/unit_build/src/test8.c delete mode 100644 tests/projects/c/unit_build/test.lua delete mode 100644 tests/projects/c/unit_build/xmake.lua create mode 100644 tests/projects/c/unity_build/src/bar/test4.c create mode 100644 tests/projects/c/unity_build/src/bar/test5.c create mode 100644 tests/projects/c/unity_build/src/foo/test1.c create mode 100644 tests/projects/c/unity_build/src/foo/test2.c create mode 100644 tests/projects/c/unity_build/src/header.h create mode 100644 tests/projects/c/unity_build/src/main.c create mode 100644 tests/projects/c/unity_build/src/test.cpp create mode 100644 tests/projects/c/unity_build/src/test2.c create mode 100644 tests/projects/c/unity_build/src/test6.c create mode 100644 tests/projects/c/unity_build/src/test7.c create mode 100644 tests/projects/c/unity_build/src/test8.c create mode 100644 tests/projects/c/unity_build/test.lua create mode 100644 tests/projects/c/unity_build/xmake.lua delete mode 100644 xmake/rules/c++/unit_build/unit_build.lua delete mode 100644 xmake/rules/c++/unit_build/xmake.lua create mode 100644 xmake/rules/c++/unity_build/unity_build.lua create mode 100644 xmake/rules/c++/unity_build/xmake.lua diff --git a/tests/projects/c/unit_build/src/bar/test4.c b/tests/projects/c/unit_build/src/bar/test4.c deleted file mode 100644 index a92803eb7..000000000 --- a/tests/projects/c/unit_build/src/bar/test4.c +++ /dev/null @@ -1,8 +0,0 @@ - -// main.cpp -#include "header.h" - -int test4() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/src/bar/test5.c b/tests/projects/c/unit_build/src/bar/test5.c deleted file mode 100644 index 2a3e7066c..000000000 --- a/tests/projects/c/unit_build/src/bar/test5.c +++ /dev/null @@ -1,8 +0,0 @@ - -// main.cpp -#include "header.h" - -int test5() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/src/foo/test1.c b/tests/projects/c/unit_build/src/foo/test1.c deleted file mode 100644 index e9d6c83d9..000000000 --- a/tests/projects/c/unit_build/src/foo/test1.c +++ /dev/null @@ -1,8 +0,0 @@ - -// main.cpp -#include "header.h" - -int test() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/src/foo/test2.c b/tests/projects/c/unit_build/src/foo/test2.c deleted file mode 100644 index b4ce69b0f..000000000 --- a/tests/projects/c/unit_build/src/foo/test2.c +++ /dev/null @@ -1,8 +0,0 @@ - -// main.cpp -#include "header.h" - -int test3() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/src/header.h b/tests/projects/c/unit_build/src/header.h deleted file mode 100644 index 29bfc5870..000000000 --- a/tests/projects/c/unit_build/src/header.h +++ /dev/null @@ -1,10 +0,0 @@ -// header.h -#ifndef HEADER_H -#define HEADER_H - -#include -#include -#include - -#endif - diff --git a/tests/projects/c/unit_build/src/main.c b/tests/projects/c/unit_build/src/main.c deleted file mode 100644 index f0408cdf8..000000000 --- a/tests/projects/c/unit_build/src/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "header.h" - -int main(int argc, char** argv) -{ - printf("hello xmake!\n"); - return 0; -} diff --git a/tests/projects/c/unit_build/src/test.cpp b/tests/projects/c/unit_build/src/test.cpp deleted file mode 100644 index 1cedddad9..000000000 --- a/tests/projects/c/unit_build/src/test.cpp +++ /dev/null @@ -1,4 +0,0 @@ -int test_cpp() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/src/test2.c b/tests/projects/c/unit_build/src/test2.c deleted file mode 100644 index 596359cd2..000000000 --- a/tests/projects/c/unit_build/src/test2.c +++ /dev/null @@ -1,8 +0,0 @@ - -// main.cpp -#include "header.h" - -int test2() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/src/test6.c b/tests/projects/c/unit_build/src/test6.c deleted file mode 100644 index efbd7c6c1..000000000 --- a/tests/projects/c/unit_build/src/test6.c +++ /dev/null @@ -1,8 +0,0 @@ - -// main.cpp -#include "header.h" - -int test6() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/src/test7.c b/tests/projects/c/unit_build/src/test7.c deleted file mode 100644 index 24aeff619..000000000 --- a/tests/projects/c/unit_build/src/test7.c +++ /dev/null @@ -1,8 +0,0 @@ - -// main.cpp -#include "header.h" - -int test7() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/src/test8.c b/tests/projects/c/unit_build/src/test8.c deleted file mode 100644 index 6ad5680a6..000000000 --- a/tests/projects/c/unit_build/src/test8.c +++ /dev/null @@ -1,8 +0,0 @@ - -// main.cpp -#include "header.h" - -int test8() -{ - return 0; -} diff --git a/tests/projects/c/unit_build/test.lua b/tests/projects/c/unit_build/test.lua deleted file mode 100644 index b76241be2..000000000 --- a/tests/projects/c/unit_build/test.lua +++ /dev/null @@ -1,6 +0,0 @@ --- main entry -function main(t) - - -- build project - t:build() -end diff --git a/tests/projects/c/unit_build/xmake.lua b/tests/projects/c/unit_build/xmake.lua deleted file mode 100644 index 1df67c0ec..000000000 --- a/tests/projects/c/unit_build/xmake.lua +++ /dev/null @@ -1,8 +0,0 @@ -target("test") - set_kind("binary") - add_includedirs("src") - add_rules("c++.unit_build", {batchsize = 2}) - add_files("src/*.c", "src/*.cpp") - add_files("src/foo/*.c", {unit_group = "foo"}) - add_files("src/bar/*.c", {unit_group = "bar"}) - diff --git a/tests/projects/c/unity_build/src/bar/test4.c b/tests/projects/c/unity_build/src/bar/test4.c new file mode 100644 index 000000000..a92803eb7 --- /dev/null +++ b/tests/projects/c/unity_build/src/bar/test4.c @@ -0,0 +1,8 @@ + +// main.cpp +#include "header.h" + +int test4() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/src/bar/test5.c b/tests/projects/c/unity_build/src/bar/test5.c new file mode 100644 index 000000000..2a3e7066c --- /dev/null +++ b/tests/projects/c/unity_build/src/bar/test5.c @@ -0,0 +1,8 @@ + +// main.cpp +#include "header.h" + +int test5() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/src/foo/test1.c b/tests/projects/c/unity_build/src/foo/test1.c new file mode 100644 index 000000000..e9d6c83d9 --- /dev/null +++ b/tests/projects/c/unity_build/src/foo/test1.c @@ -0,0 +1,8 @@ + +// main.cpp +#include "header.h" + +int test() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/src/foo/test2.c b/tests/projects/c/unity_build/src/foo/test2.c new file mode 100644 index 000000000..b4ce69b0f --- /dev/null +++ b/tests/projects/c/unity_build/src/foo/test2.c @@ -0,0 +1,8 @@ + +// main.cpp +#include "header.h" + +int test3() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/src/header.h b/tests/projects/c/unity_build/src/header.h new file mode 100644 index 000000000..29bfc5870 --- /dev/null +++ b/tests/projects/c/unity_build/src/header.h @@ -0,0 +1,10 @@ +// header.h +#ifndef HEADER_H +#define HEADER_H + +#include +#include +#include + +#endif + diff --git a/tests/projects/c/unity_build/src/main.c b/tests/projects/c/unity_build/src/main.c new file mode 100644 index 000000000..f0408cdf8 --- /dev/null +++ b/tests/projects/c/unity_build/src/main.c @@ -0,0 +1,7 @@ +#include "header.h" + +int main(int argc, char** argv) +{ + printf("hello xmake!\n"); + return 0; +} diff --git a/tests/projects/c/unity_build/src/test.cpp b/tests/projects/c/unity_build/src/test.cpp new file mode 100644 index 000000000..1cedddad9 --- /dev/null +++ b/tests/projects/c/unity_build/src/test.cpp @@ -0,0 +1,4 @@ +int test_cpp() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/src/test2.c b/tests/projects/c/unity_build/src/test2.c new file mode 100644 index 000000000..596359cd2 --- /dev/null +++ b/tests/projects/c/unity_build/src/test2.c @@ -0,0 +1,8 @@ + +// main.cpp +#include "header.h" + +int test2() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/src/test6.c b/tests/projects/c/unity_build/src/test6.c new file mode 100644 index 000000000..efbd7c6c1 --- /dev/null +++ b/tests/projects/c/unity_build/src/test6.c @@ -0,0 +1,8 @@ + +// main.cpp +#include "header.h" + +int test6() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/src/test7.c b/tests/projects/c/unity_build/src/test7.c new file mode 100644 index 000000000..24aeff619 --- /dev/null +++ b/tests/projects/c/unity_build/src/test7.c @@ -0,0 +1,8 @@ + +// main.cpp +#include "header.h" + +int test7() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/src/test8.c b/tests/projects/c/unity_build/src/test8.c new file mode 100644 index 000000000..6ad5680a6 --- /dev/null +++ b/tests/projects/c/unity_build/src/test8.c @@ -0,0 +1,8 @@ + +// main.cpp +#include "header.h" + +int test8() +{ + return 0; +} diff --git a/tests/projects/c/unity_build/test.lua b/tests/projects/c/unity_build/test.lua new file mode 100644 index 000000000..b76241be2 --- /dev/null +++ b/tests/projects/c/unity_build/test.lua @@ -0,0 +1,6 @@ +-- main entry +function main(t) + + -- build project + t:build() +end diff --git a/tests/projects/c/unity_build/xmake.lua b/tests/projects/c/unity_build/xmake.lua new file mode 100644 index 000000000..447960db5 --- /dev/null +++ b/tests/projects/c/unity_build/xmake.lua @@ -0,0 +1,8 @@ +target("test") + set_kind("binary") + add_includedirs("src") + add_rules("c++.unity_build", {batchsize = 2}) + add_files("src/*.c", "src/*.cpp") + add_files("src/foo/*.c", {unity_group = "foo"}) + add_files("src/bar/*.c", {unity_group = "bar"}) + diff --git a/xmake/rules/c++/unit_build/unit_build.lua b/xmake/rules/c++/unit_build/unit_build.lua deleted file mode 100644 index 7fd50b596..000000000 --- a/xmake/rules/c++/unit_build/unit_build.lua +++ /dev/null @@ -1,123 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file unit_build.lua --- - --- imports -import("core.project.depend") - -function _merge_unitfile(target, sourcefile_unit, sourcefiles, opt) - local dependfile = target:dependfile(sourcefile_unit) - depend.on_changed(function () - - -- trace - vprint("generating.unitfile %s", sourcefile_unit) - - -- do merge - local unitfile = io.open(sourcefile_unit, "w") - for _, sourcefile in ipairs(sourcefiles) do - sourcefile = path.absolute(sourcefile) - sourcefile_unit = path.absolute(sourcefile_unit) - sourcefile = path.relative(sourcefile, path.directory(sourcefile_unit)) - unitfile:print("#include \"%s\"", sourcefile) - end - unitfile:close() - - end, {dependfile = dependfile, files = sourcefiles}) -end - -function generate_unitfiles(target, sourcebatch, opt) - local unitbatch = target:data("unit_build.unitbatch." .. sourcebatch.rulename) - if unitbatch then - for _, sourcefile_unit in ipairs(sourcebatch.sourcefiles) do - local sourceinfo = unitbatch[sourcefile_unit] - if sourceinfo then - local sourcefiles = sourceinfo.sourcefiles - if sourcefiles then - _merge_unitfile(target, sourcefile_unit, sourcefiles, opt) - end - end - end - end -end - --- use unit build --- --- e.g. --- add_rules("c++.unit_build", {batchsize = 2}) --- add_files("src/*.c", "src/*.cpp", {unit_ignored = true}) --- add_files("src/foo/*.c", {unit_group = "foo"}) --- add_files("src/bar/*.c", {unit_group = "bar"}) --- -function main(target, sourcebatch) - - -- get unit batch sources - local extraconf = target:extraconf("rules", "c++.unit_build") - local batchsize = extraconf and extraconf.batchsize - local id = 1 - local count = 0 - local unitbatch = {} - local sourcefiles = {} - local objectfiles = {} - local dependfiles = {} - local sourcedir = path.join(target:autogendir({root = true}), "unit_build") - for idx, sourcefile in pairs(sourcebatch.sourcefiles) do - local sourcefile_unit - local objectfile = sourcebatch.objectfiles[idx] - local dependfile = sourcebatch.dependfiles[idx] - local fileconfig = target:fileconfig(sourcefile) - if fileconfig and fileconfig.unit_group then - sourcefile_unit = path.join(sourcedir, "unit_" .. fileconfig.unit_group .. path.extension(sourcefile)) - elseif fileconfig and fileconfig.unit_ignored then - -- we do not add these files to unit file - table.insert(sourcefiles, sourcefile) - table.insert(objectfiles, objectfile) - table.insert(dependfiles, dependfile) - else - if batchsize and count > batchsize then - id = id + 1 - end - sourcefile_unit = path.join(sourcedir, "unit_" .. hash.uuid(tostring(id)):split("-", {plain = true})[1] .. path.extension(sourcefile)) - count = count + 1 - end - if sourcefile_unit then - local sourceinfo = unitbatch[sourcefile_unit] - if not sourceinfo then - sourceinfo = {} - sourceinfo.objectfile = target:objectfile(sourcefile_unit) - sourceinfo.dependfile = target:dependfile(sourceinfo.objectfile) - unitbatch[sourcefile_unit] = sourceinfo - end - sourceinfo.sourcefiles = sourceinfo.sourcefiles or {} - table.insert(sourceinfo.sourcefiles, sourcefile) - end - end - - -- use unit batch - for sourcefile_unit, sourceinfo in pairs(unitbatch) do - table.insert(sourcefiles, sourcefile_unit) - table.insert(objectfiles, sourceinfo.objectfile) - table.insert(dependfiles, sourceinfo.dependfile) - end - sourcebatch.sourcefiles = sourcefiles - sourcebatch.objectfiles = objectfiles - sourcebatch.dependfiles = dependfiles - - -- save unit batch - target:data_set("unit_build.unitbatch." .. sourcebatch.rulename, unitbatch) -end diff --git a/xmake/rules/c++/unit_build/xmake.lua b/xmake/rules/c++/unit_build/xmake.lua deleted file mode 100644 index b0eb7b39a..000000000 --- a/xmake/rules/c++/unit_build/xmake.lua +++ /dev/null @@ -1,45 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file xmake.lua --- - -rule("c++.unit_build") - after_load(function (target) - import("unit_build") - local sourcebatches = target:sourcebatches() - if sourcebatches then - for _, rulename in ipairs({"c.build", "c++.build"}) do - local sourcebatch = sourcebatches[rulename] - if sourcebatch then - unit_build(target, sourcebatch) - end - end - end - end) - before_build(function (target, opt) - import("unit_build") - local sourcebatches = target:sourcebatches() - if sourcebatches then - for _, rulename in ipairs({"c.build", "c++.build"}) do - local sourcebatch = sourcebatches[rulename] - if sourcebatch then - unit_build.generate_unitfiles(target, sourcebatch, opt) - end - end - end - end) diff --git a/xmake/rules/c++/unity_build/unity_build.lua b/xmake/rules/c++/unity_build/unity_build.lua new file mode 100644 index 000000000..57bff99a0 --- /dev/null +++ b/xmake/rules/c++/unity_build/unity_build.lua @@ -0,0 +1,123 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file unity_build.lua +-- + +-- imports +import("core.project.depend") + +function _merge_unityfile(target, sourcefile_unity, sourcefiles, opt) + local dependfile = target:dependfile(sourcefile_unity) + depend.on_changed(function () + + -- trace + vprint("generating.unityfile %s", sourcefile_unity) + + -- do merge + local unityfile = io.open(sourcefile_unity, "w") + for _, sourcefile in ipairs(sourcefiles) do + sourcefile = path.absolute(sourcefile) + sourcefile_unity = path.absolute(sourcefile_unity) + sourcefile = path.relative(sourcefile, path.directory(sourcefile_unity)) + unityfile:print("#include \"%s\"", sourcefile) + end + unityfile:close() + + end, {dependfile = dependfile, files = sourcefiles}) +end + +function generate_unityfiles(target, sourcebatch, opt) + local unity_batch = target:data("unity_build.unity_batch." .. sourcebatch.rulename) + if unity_batch then + for _, sourcefile_unity in ipairs(sourcebatch.sourcefiles) do + local sourceinfo = unity_batch[sourcefile_unity] + if sourceinfo then + local sourcefiles = sourceinfo.sourcefiles + if sourcefiles then + _merge_unityfile(target, sourcefile_unity, sourcefiles, opt) + end + end + end + end +end + +-- use unity build +-- +-- e.g. +-- add_rules("c++.unity_build", {batchsize = 2}) +-- add_files("src/*.c", "src/*.cpp", {unity_ignored = true}) +-- add_files("src/foo/*.c", {unity_group = "foo"}) +-- add_files("src/bar/*.c", {unity_group = "bar"}) +-- +function main(target, sourcebatch) + + -- get unit batch sources + local extraconf = target:extraconf("rules", "c++.unity_build") + local batchsize = extraconf and extraconf.batchsize + local id = 1 + local count = 0 + local unity_batch = {} + local sourcefiles = {} + local objectfiles = {} + local dependfiles = {} + local sourcedir = path.join(target:autogendir({root = true}), "unity_build") + for idx, sourcefile in pairs(sourcebatch.sourcefiles) do + local sourcefile_unity + local objectfile = sourcebatch.objectfiles[idx] + local dependfile = sourcebatch.dependfiles[idx] + local fileconfig = target:fileconfig(sourcefile) + if fileconfig and fileconfig.unity_group then + sourcefile_unity = path.join(sourcedir, "unity_" .. fileconfig.unity_group .. path.extension(sourcefile)) + elseif fileconfig and fileconfig.unity_ignored then + -- we do not add these files to unit file + table.insert(sourcefiles, sourcefile) + table.insert(objectfiles, objectfile) + table.insert(dependfiles, dependfile) + else + if batchsize and count > batchsize then + id = id + 1 + end + sourcefile_unity = path.join(sourcedir, "unity_" .. hash.uuid(tostring(id)):split("-", {plain = true})[1] .. path.extension(sourcefile)) + count = count + 1 + end + if sourcefile_unity then + local sourceinfo = unity_batch[sourcefile_unity] + if not sourceinfo then + sourceinfo = {} + sourceinfo.objectfile = target:objectfile(sourcefile_unity) + sourceinfo.dependfile = target:dependfile(sourceinfo.objectfile) + unity_batch[sourcefile_unity] = sourceinfo + end + sourceinfo.sourcefiles = sourceinfo.sourcefiles or {} + table.insert(sourceinfo.sourcefiles, sourcefile) + end + end + + -- use unit batch + for sourcefile_unity, sourceinfo in pairs(unity_batch) do + table.insert(sourcefiles, sourcefile_unity) + table.insert(objectfiles, sourceinfo.objectfile) + table.insert(dependfiles, sourceinfo.dependfile) + end + sourcebatch.sourcefiles = sourcefiles + sourcebatch.objectfiles = objectfiles + sourcebatch.dependfiles = dependfiles + + -- save unit batch + target:data_set("unity_build.unity_batch." .. sourcebatch.rulename, unity_batch) +end diff --git a/xmake/rules/c++/unity_build/xmake.lua b/xmake/rules/c++/unity_build/xmake.lua new file mode 100644 index 000000000..838f8a097 --- /dev/null +++ b/xmake/rules/c++/unity_build/xmake.lua @@ -0,0 +1,45 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +rule("c++.unity_build") + after_load(function (target) + import("unity_build") + local sourcebatches = target:sourcebatches() + if sourcebatches then + for _, rulename in ipairs({"c.build", "c++.build"}) do + local sourcebatch = sourcebatches[rulename] + if sourcebatch then + unity_build(target, sourcebatch) + end + end + end + end) + before_build(function (target, opt) + import("unity_build") + local sourcebatches = target:sourcebatches() + if sourcebatches then + for _, rulename in ipairs({"c.build", "c++.build"}) do + local sourcebatch = sourcebatches[rulename] + if sourcebatch then + unity_build.generate_unitfiles(target, sourcebatch, opt) + end + end + end + end) -- cgit v1.3.1