diff options
| author | ruki <[email protected]> | 2019-08-30 23:42:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-30 16:13:50 +0800 |
| commit | 2202a09519c6e0e719735c7c5b1f3be225056080 (patch) | |
| tree | 417c9ee5c032da0b47cf8c4e1b16de3129324707 | |
| parent | b0c07c2400b98edbdc1ab18bc15a809adf4e959e (diff) | |
remove some codes in build action
| -rw-r--r-- | xmake/actions/build/kinds/binary.lua | 59 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/object.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/shared.lua | 59 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/static.lua | 59 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 98 |
5 files changed, 32 insertions, 251 deletions
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua index a9ff2ad69..7a7683d02 100644 --- a/xmake/actions/build/kinds/binary.lua +++ b/xmake/actions/build/kinds/binary.lua @@ -149,8 +149,8 @@ function _link_target(target, opt) end end --- build target from objects -function _build_from_objects(target, buildinfo) +-- build binary target +function build(target, buildinfo) -- build objects object.build(target, buildinfo) @@ -161,58 +161,3 @@ function _build_from_objects(target, buildinfo) -- link target _link_target(target, {progress = progress}) end - --- build target from sources -function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) - - -- the target file - local targetfile = target:targetfile() - - -- is verbose? - local verbose = option.get("verbose") - - -- trace progress into - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) - if verbose then - cprint("${dim color.build.target}linking.$(mode) %s", path.filename(targetfile)) - else - cprint("${color.build.target}linking.$(mode) %s", path.filename(targetfile)) - end - - -- trace verbose info - if verbose then - print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind})) - end - - -- flush io buffer to update progress info - io.flush() - - -- build it - compiler.build(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind}) -end - --- build binary target -function build(target, buildinfo) - - -- only one source kind? - local kindcount = 0 - local sourcekind = nil - local sourcebatch = nil - for kind, batch in pairs(target:sourcebatches()) do - if not batch.rulename then - sourcekind = kind - sourcebatch = batch - kindcount = kindcount + 1 - if kindcount > 1 then - break - end - end - end - - -- build target - if kindcount == 1 and compiler.buildmode(sourcekind, "binary:sources", {target = target}) then - _build_from_sources(target, buildinfo, sourcebatch, sourcekind) - else - _build_from_objects(target, buildinfo) - end -end diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index d6b98514e..e730c69b6 100644 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -20,20 +20,14 @@ -- imports import("core.base.option") -import("core.project.rule") import("core.project.config") import("core.project.project") -- build source files with the custom rule function _build_files_with_rule(target, sourcebatch, opt, suffix) - -- get rule name - local rulename = sourcebatch.rulename - assert(rulename, "unknown source rule!") - -- get rule instance - local ruleinst = project.rule(rulename) or rule.rule(rulename) - assert(ruleinst, "unknown rule: %s", rulename) + local ruleinst = assert(sourcebatch.rule, "unknown rule!") -- on_build_files? local on_build_files = ruleinst:script("build_files" .. (suffix and ("_" .. suffix) or "")) diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua index 598d7da8a..5a5846a58 100644 --- a/xmake/actions/build/kinds/shared.lua +++ b/xmake/actions/build/kinds/shared.lua @@ -162,8 +162,8 @@ function _link_target(target, opt) end end --- build target from objects -function _build_from_objects(target, buildinfo) +-- build shared target +function build(target, buildinfo) -- build objects object.build(target, buildinfo) @@ -174,58 +174,3 @@ function _build_from_objects(target, buildinfo) -- link target _link_target(target, {progress = progress}) end - --- build target from sources -function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) - - -- the target file - local targetfile = target:targetfile() - - -- is verbose? - local verbose = option.get("verbose") - - -- trace progress into - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) - if verbose then - cprint("${dim color.build.target}linking.$(mode) %s", path.filename(targetfile)) - else - cprint("${color.build.target}linking.$(mode) %s", path.filename(targetfile)) - end - - -- trace verbose info - if verbose then - print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind})) - end - - -- flush io buffer to update progress info - io.flush() - - -- build it - compiler.build(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind}) -end - --- build shared target -function build(target, buildinfo) - - -- only one source kind? - local kindcount = 0 - local sourcekind = nil - local sourcebatch = nil - for kind, batch in pairs(target:sourcebatches()) do - if not batch.rulename then - sourcekind = kind - sourcebatch = batch - kindcount = kindcount + 1 - if kindcount > 1 then - break - end - end - end - - -- build target - if kindcount == 1 and compiler.buildmode(sourcekind, "shared:sources", {target = target}) then - _build_from_sources(target, buildinfo, sourcebatch, sourcekind) - else - _build_from_objects(target, buildinfo) - end -end diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua index dfd07f4e9..1e4f30825 100644 --- a/xmake/actions/build/kinds/static.lua +++ b/xmake/actions/build/kinds/static.lua @@ -158,8 +158,8 @@ function _link_target(target, opt) end end --- build target from objects -function _build_from_objects(target, buildinfo) +-- build static target +function build(target, buildinfo) -- build objects object.build(target, buildinfo) @@ -170,58 +170,3 @@ function _build_from_objects(target, buildinfo) -- link target _link_target(target, {progress = progress}) end - --- build target from sources -function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) - - -- the target file - local targetfile = target:targetfile() - - -- is verbose? - local verbose = option.get("verbose") - - -- trace progress into - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) - if verbose then - cprint("${dim color.build.target}archiving.$(mode) %s", path.filename(targetfile)) - else - cprint("${color.build.target}archiving.$(mode) %s", path.filename(targetfile)) - end - - -- trace verbose info - if verbose then - print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind})) - end - - -- flush io buffer to update progress info - io.flush() - - -- build it - compiler.build(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind}) -end - --- build static target -function build(target, buildinfo) - - -- only one source kind? - local kindcount = 0 - local sourcekind = nil - local sourcebatch = nil - for kind, batch in pairs(target:sourcebatches()) do - if not batch.rulename then - sourcekind = kind - sourcebatch = batch - kindcount = kindcount + 1 - if kindcount > 1 then - break - end - end - end - - -- build target - if kindcount == 1 and compiler.buildmode(sourcekind, "static:sources", {target = target}) then - _build_from_sources(target, buildinfo, sourcebatch, sourcekind) - else - _build_from_objects(target, buildinfo) - end -end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index daebbc91b..2a15482f9 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1050,10 +1050,8 @@ function _instance:objectfiles() -- get object files from source batches local objectfiles = {} - for sourcekind, sourcebatch in pairs(self:sourcebatches()) do - if not sourcebatch.rulename then - table.join2(objectfiles, sourcebatch.objectfiles) - end + for _, sourcebatch in pairs(self:sourcebatches()) do + table.join2(objectfiles, sourcebatch.objectfiles) end -- get object files from all dependent targets (object kind) @@ -1260,10 +1258,8 @@ function _instance:dependfiles() -- get dependent files from source batches local dependfiles = {} - for sourcekind, sourcebatch in pairs(self:sourcebatches()) do - if not sourcebatch.rulename then - table.join2(dependfiles, sourcebatch.dependfiles) - end + for _, sourcebatch in pairs(self:sourcebatches()) do + table.join2(dependfiles, sourcebatch.dependfiles) end -- cache it @@ -1325,85 +1321,41 @@ function _instance:sourcebatches() local sourcebatches = {} for _, sourcefile in ipairs(sourcefiles) do - -- add file rules - local builtin_rule = true + -- get file rules local filerules = self:filerules(sourcefile) + if #filerules == 0 then + os.raise("unknown source file: %s", sourcefile) + end + + -- add source batch for the file rules for _, filerule in ipairs(filerules) do - -- get source kind - local sourcekind = "__rule_" .. filerule:name() + -- get rule name + local rulename = filerule:name() -- make this batch - local sourcebatch = sourcebatches[sourcekind] or {sourcefiles = {}} - sourcebatches[sourcekind] = sourcebatch - - -- add source kind to this batch - sourcebatch.sourcekind = sourcekind + local sourcebatch = sourcebatches[rulename] or {sourcefiles = {}} + sourcebatches[rulename] = sourcebatch - -- add source rule to this batch - sourcebatch.rulename = filerule:name() + -- add file rule to this batch + sourcebatch.rule = filerule -- add source file to this batch table.insert(sourcebatch.sourcefiles, sourcefile) - -- override `on_build_xxx` in filerules? disable the builtin-rule - if filerule:get("build_file") or filerule:get("build_files") or filerule:get("build") then - builtin_rule = false - end - end - - -- add builtin rule - if builtin_rule then - - -- get source kind - sourcekind = language.sourcekind_of(sourcefile) + -- attempt to get source kind from the builtin languages + local sourcekind = language.sourcekind_of(sourcefile) if sourcekind then - -- make this batch - local sourcebatch = sourcebatches[sourcekind] or {sourcefiles = {}} - sourcebatches[sourcekind] = sourcebatch - - -- add source kind to this batch + -- save source kind sourcebatch.sourcekind = sourcekind - -- add source file to this batch - table.insert(sourcebatch.sourcefiles, sourcefile) - - elseif #filerules == 0 then - os.raise("unknown source file: %s", sourcefile) - end - end - end - - -- insert object files to source batches - for sourcekind, sourcebatch in pairs(sourcebatches) do - - -- skip source files with the custom rule - if not sourcebatch.rulename then - - -- this batch support to compile multiple objects at the same time? - local instance = compiler.load(sourcekind, self) - if instance and instance:buildmode("object:sources") then - - -- get the first source file - local sourcefile = sourcebatch.sourcefiles[1] - - -- insert single object file for all source files - sourcebatch.objectfiles = self:objectfile(path.join(path.directory(sourcefile), "__" .. sourcekind)) - - -- insert single dependent file for all source files - sourcebatch.dependfiles = self:dependfile(sourcebatch.objectfiles) - - else - - -- insert object files for each source files - sourcebatch.objectfiles = {} - sourcebatch.dependfiles = {} - for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local objectfile = self:objectfile(sourcefile) - table.insert(sourcebatch.objectfiles, objectfile) - table.insert(sourcebatch.dependfiles, self:dependfile(objectfile)) - end + -- insert object files to source batches + sourcebatch.objectfiles = sourcebatch.objectfiles or {} + sourcebatch.dependfiles = sourcebatch.dependfiles or {} + local objectfile = self:objectfile(sourcefile) + table.insert(sourcebatch.objectfiles, objectfile) + table.insert(sourcebatch.dependfiles, self:dependfile(objectfile)) end end end |
