diff options
| author | ruki <[email protected]> | 2019-08-29 23:39:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-29 15:54:25 +0800 |
| commit | c0f92573236c13b2dc395dcc4030ad9a6db11784 (patch) | |
| tree | b6f7cae868bd3146568e0b25382c06cd146c42ad | |
| parent | 6f8d4b91cf019662a58f822c700d894d82a2c76d (diff) | |
remove some files
| -rw-r--r-- | xmake/actions/build/kinds/object.lua | 253 | ||||
| -rw-r--r-- | xmake/rules/c++/cache/xmake.lua | 46 | ||||
| -rw-r--r-- | xmake/rules/c++/pcheader/build.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/c++/xmake.lua | 12 |
4 files changed, 6 insertions, 329 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index 31f1d8cc0..d4ee0bda8 100644 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -20,228 +20,9 @@ -- imports import("core.base.option") -import("core.theme.theme") -import("core.tool.compiler") -import("core.tool.extractor") import("core.project.rule") import("core.project.config") -import("core.project.depend") import("core.project.project") -import("core.language.language") - --- build the object from the *.[o|obj] source file -function _build_from_object(target, sourcefile, objectfile, progress) - - -- is verbose? - local verbose = option.get("verbose") - - -- trace progress info - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) - if verbose then - cprint("${dim color.build.object}inserting.$(mode) %s", sourcefile) - else - cprint("${clear}${color.build.object}inserting.$(mode) %s", sourcefile) - end - - -- trace verbose info - if verbose then - print("cp %s %s", sourcefile, objectfile) - end - - -- flush io buffer to update progress info - io.flush() - - -- insert this object file - os.cp(sourcefile, objectfile) -end - --- build the object from the *.[a|lib] source file -function _build_from_static(target, sourcefile, objectfile, progress) - - -- is verbose? - local verbose = option.get("verbose") - - -- trace progress info - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) - if verbose then - cprint("${dim color.build.object}inserting.$(mode) %s", sourcefile) - else - cprint("${color.build.object}inserting.$(mode) %s", sourcefile) - end - - -- trace verbose info - if verbose then - print("ex %s %s", sourcefile, objectfile) - end - - -- flush io buffer to update progress info - io.flush() - - -- extract the static library to object directory - extractor.extract(sourcefile, path.directory(objectfile)) -end - --- do build file -function _do_build_file(target, sourcefile, opt) - - -- get build info - local buildinfo = _g.buildinfo - local objectfile = opt.objectfile - local dependfile = opt.dependfile - local sourcekind = opt.sourcekind - local progress = opt.progress - - -- build the object for the *.o/obj source makefile - if sourcekind == "obj" then - return _build_from_object(target, sourcefile, objectfile, progress) - -- build the object for the *.[a|lib] source file - elseif sourcekind == "lib" then - return _build_from_static(target, sourcefile, objectfile, progress) - end - - -- load compiler - local compinst = compiler.load(sourcekind, {target = target}) - - -- get compile flags - local compflags = compinst:compflags({target = target, sourcefile = sourcefile}) - - -- load dependent info - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local depvalues = {compinst:program(), compflags} - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then - return - end - - -- is verbose? - local verbose = option.get("verbose") - - -- get build prefix - local build_prefix = target:data("build.object.prefix") - build_prefix = build_prefix and (build_prefix .. " ") or "" - - -- trace progress info - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) - if verbose then - cprint("${dim color.build.object}%scompiling.$(mode) %s", build_prefix, sourcefile) - else - cprint("${color.build.object}%scompiling.$(mode) %s", build_prefix, sourcefile) - end - - -- trace verbose info - if verbose then - print(compinst:compcmd(sourcefile, objectfile, {compflags = compflags})) - end - - -- flush io buffer to update progress info - io.flush() - - -- compile it - dependinfo.files = {} - assert(compinst:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = compflags})) - - -- update files and values to the dependent file - dependinfo.values = depvalues - table.join2(dependinfo.files, sourcefile, target:pcoutputfile("cxx") or {}, target:pcoutputfile("c")) - depend.save(dependinfo, dependfile) -end - --- build object -function _build_object(target, index, sourcebatch) - - -- get the object and source with the given index - local buildinfo = _g.buildinfo - local sourcefile = sourcebatch.sourcefiles[index] - local objectfile = sourcebatch.objectfiles[index] - local dependfile = sourcebatch.dependfiles[index] - local sourcekind = sourcebatch.sourcekind - - -- calculate progress - local progress = ((buildinfo.targetindex + (buildinfo.sourceindex + index - 1) / buildinfo.sourcecount) * 100 / buildinfo.targetcount) - - -- init build option - local opt = {objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = progress} - - -- do before build - local before_build_file = target:script("build_file_before") - if before_build_file then - before_build_file(target, sourcefile, opt) - end - - -- do build - local on_build_file = target:script("build_file") - if on_build_file then - opt.origin = _do_build_file - on_build_file(target, sourcefile, opt) - opt.origin = nil - else - _do_build_file(target, sourcefile, opt) - end - - -- do after build - local after_build_file = target:script("build_file_after") - if after_build_file then - after_build_file(target, sourcefile, opt) - end -end - --- build each objects from the given source batch -function _build_files_for_each(target, sourcebatch, jobs) - - -- run build jobs for each source file - local curdir = os.curdir() - process.runjobs(function (index) - - -- force to set the current directory first because the other jobs maybe changed it - os.cd(curdir) - - -- build object - _build_object(target, index, sourcebatch) - - end, #sourcebatch.sourcefiles, jobs) -end - --- compile source files to single object at the same time -function _build_files_for_single(target, sourcebatch, jobs) - - -- is verbose? - local verbose = option.get("verbose") - - -- get source and object files - local sourcefiles = sourcebatch.sourcefiles - local objectfiles = sourcebatch.objectfiles - local dependfiles = sourcebatch.dependfiles - local sourcekind = sourcebatch.sourcekind - - -- get build prefix - local build_prefix = target:data("build.object.prefix") - build_prefix = build_prefix and (build_prefix .. " ") or "" - - -- trace progress info - local buildinfo = _g.buildinfo - for index, sourcefile in ipairs(sourcefiles) do - - -- calculate progress - local progress = ((buildinfo.targetindex + (buildinfo.sourceindex + index - 1) / buildinfo.sourcecount) * 100 / buildinfo.targetcount) - - -- trace progress info - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) - if verbose then - cprint("${dim color.build.object}%scompiling.$(mode) %s", build_prefix, sourcefile) - else - cprint("${color.build.object}%scompiling.$(mode) %s", build_prefix, sourcefile) - end - end - - -- trace verbose info - if verbose then - print(compiler.compcmd(sourcefiles, objectfiles, {target = target, sourcekind = sourcekind})) - end - - -- compile them - compiler.compile(sourcefiles, objectfiles, {dependfiles = dependfiles, target = target, sourcekind = sourcekind}) -end -- build source files with the custom rule function _build_files_for_rule(target, sourcebatch, jobs, suffix) @@ -298,11 +79,6 @@ function _do_build_files(target, sourcebatch, opt) -- compile source files with custom rule if sourcebatch.rulename then _build_files_for_rule(target, sourcebatch, opt.jobs) - -- compile source files to single object at once - elseif type(sourcebatch.objectfiles) == "string" then - _build_files_for_single(target, sourcebatch, opt.jobs) - else - _build_files_for_each(target, sourcebatch, opt.jobs) end end @@ -342,32 +118,6 @@ function _build_files(target, sourcebatch, jobs) end end --- build precompiled header files (only for c/c++) -function _build_pcheaderfiles(target, buildinfo) - - -- for c/c++ - _g.buildinfo = buildinfo - for _, langkind in ipairs({"c", "cxx"}) do - - -- get the precompiled header - local pcheaderfile = target:pcheaderfile(langkind) - if pcheaderfile then - - -- init sourcefile, objectfile and dependfile - local sourcefile = pcheaderfile - local objectfile = target:pcoutputfile(langkind) - local dependfile = target:dependfile(objectfile) - local sourcekind = language.langkinds()[langkind] - - -- init source batch - local sourcebatch = {sourcekind = sourcekind, sourcefiles = {sourcefile}, objectfiles = {objectfile}, dependfiles = {dependfile}} - - -- build this precompiled header - _build_object(target, 1, sourcebatch, false) - end - end -end - -- build source files function build_sourcefiles(target, buildinfo, sourcebatches) @@ -404,9 +154,6 @@ function build(target, buildinfo) buildinfo.sourceindex = 0 buildinfo.sourcecount = target:sourcecount() - -- build precompiled headers - _build_pcheaderfiles(target, buildinfo) - -- build source files build_sourcefiles(target, buildinfo, target:sourcebatches()) end diff --git a/xmake/rules/c++/cache/xmake.lua b/xmake/rules/c++/cache/xmake.lua deleted file mode 100644 index 38cf390d3..000000000 --- a/xmake/rules/c++/cache/xmake.lua +++ /dev/null @@ -1,46 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file xmake.lua --- - --- define rule: cpp.cache -rule("cpp.cache") - - -- we attempt to use ccache now - -- maybe we will implement cross-platform cache in the future - before_load(function (target) - - -- imports - import("lib.detect.find_tool") - - -- find ccache - local ccache = target:data("cpp.ccache") - if not ccache and config.get("ccache") then - ccache = find_tool("ccache") - target:data_set("cpp.ccache", ccache) - end - - -- add the prefix information of building object - -- - -- e.g. - -- [ 0%]: ccache compiling.release src/xxx.c - -- - if ccache then - target:data_set("build.object.prefix", "ccache") - end - end) diff --git a/xmake/rules/c++/pcheader/build.lua b/xmake/rules/c++/pcheader/build.lua deleted file mode 100644 index cd6929681..000000000 --- a/xmake/rules/c++/pcheader/build.lua +++ /dev/null @@ -1,24 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file build.lua --- - --- build the precompiled header -function (target) - -- TODO -end diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 3105d69dc..fa67f7da5 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -18,13 +18,13 @@ -- @file xmake.lua -- --- define rule: cpp.pcheader -rule("cpp.pcheader") - add_deps("cpp.cache") - before_build(function (target, opt) - import("pcheader.build")(target, opt) +-- define rule: cpp.build +rule("cpp.build") + set_extensions(".c", ".cpp", ".cc", ".cxx") + on_build_files(function (target, sourcefiles, opt) + import("build.object")(target, sourcefiles, opt) end) -- define rule: cpp rule("cpp") - add_deps("cpp.pcheader", "cpp.cache") + add_deps("cpp.build") |
