diff options
| author | ruki <[email protected]> | 2017-11-11 11:52:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-11-11 11:52:48 +0800 |
| commit | fc0ac813b07b28abdbd2b40c5ba78ee76dcc09d7 (patch) | |
| tree | 1288d79e7b51615d7f4f9235496dd46b379d5d0a | |
| parent | 47e6e15e84968c6b0f1ebf6c939157fb027a1c4f (diff) | |
build rule
| -rw-r--r-- | tests/apis/rules/xmake.lua | 20 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/object.lua | 43 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 18 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/rule.lua | 4 |
4 files changed, 27 insertions, 58 deletions
diff --git a/tests/apis/rules/xmake.lua b/tests/apis/rules/xmake.lua index 1971e20fe..fd25ba94f 100644 --- a/tests/apis/rules/xmake.lua +++ b/tests/apis/rules/xmake.lua @@ -1,19 +1,21 @@ -- define rule: markdown rule("markdown") - on_build(function (target, sourcefile) - print("compiling %s", sourcefile) - os.cp(sourcefile, path.join(target:objectdir(), path.basename(sourcefile) .. ".html")) + on_build(function (target, sourcefiles) + for _, sourcefile in ipairs(sourcefiles) do + print("compiling %s", sourcefile) + os.cp(sourcefile, path.join(target:objectdir(), path.basename(sourcefile) .. ".html")) + end end) -- define rule: man rule("man") add_imports("core.project.rule") - on_build_all(function (target, sourcefiles) + on_build(function (target, sourcefiles) for _, sourcefile in ipairs(sourcefiles) do print("generating %s", sourcefile) end - rule.build_all("markdown", target, sourcefiles) + rule.build("markdown", target, sourcefiles) end) -- define rule: c code @@ -21,9 +23,11 @@ rule("c code") add_imports("core.tool.compiler") on_build(function (target, sourcefile) print("compiling %s", sourcefile) - local objectfile = os.tmpfile() .. ".o" - compiler.compile(sourcefile, objectfile, {sourcekind = "cc"}) - table.insert(target:objectfiles(), objectfile) + local objectfile_o = os.tmpfile() .. ".o" + local sourcefile_c = os.tmpfile() .. ".c" + os.cp(sourcefile, sourcefile_c) + compiler.compile(sourcefile_c, objectfile_o) + table.insert(target:objectfiles(), objectfile_o) end) -- define rule: stub diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index de99b1675..a6e8a9050 100644 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -293,48 +293,31 @@ function _build_pcheaderfiles(target, buildinfo) end end --- build each objects from the given source batch with the custom rule -function _build_each_objects_with_rule(target, buildinfo, sourcebatch, jobs, rule) - print("each", sourcebatch.rulename) -end +-- build source files with the custom rule +function _build_rule(target, buildinfo, sourcebatch, jobs) --- compile source files to single object at the same time with the custom rule -function _build_single_object_with_rule(target, buildinfo, sourcebatch, jobs, rule) + -- get rule + local rule = project.rule(sourcebatch.rulename) + assert(rule, "unknown rule: %s", sourcebatch.rule) -- the rule scripts local scripts = { - rule:script("build_all_before") - , rule:script("build_all") - , rule:script("build_all_after") + rule:script("build_before") + , rule:script("build") + , rule:script("build_after") } -- run the rule scripts for i = 1, 3 do local script = scripts[i] if script ~= nil then - script(target, sourcebatch.sourcefiles) + script(target, table.unwrap(sourcebatch.sourcefiles)) end end -end - --- build objects with the custom rule -function _build_objects_with_rule(target, buildinfo, sourcebatch, jobs) - - -- get rule - local rule = project.rule(sourcebatch.rulename) - assert(rule, "unknown rule: %s", sourcebatch.rule) - - -- build all source files at once - if rule:get("build_all") then - - -- build single object - _build_single_object_with_rule(target, buildinfo, sourcebatch, jobs, rule) - else - -- build each objects - _build_each_objects_with_rule(target, buildinfo, sourcebatch, jobs, rule) - end + -- update object index + _g.sourceindex = _g.sourceindex + #sourcebatch.sourcefiles end -- build objects for the given target @@ -362,8 +345,8 @@ function build(target, buildinfo) -- compile source files using the custom rule if sourcebatch.rulename then - -- build objects with the custom rule - _build_objects_with_rule(target, buildinfo, sourcebatch, jobs) + -- build source files with the custom rule + _build_rule(target, buildinfo, sourcebatch, jobs) -- compile source files to single object at once elseif type(sourcebatch.objectfiles) == "string" then diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 13ab82ac0..51df6a6c2 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -63,24 +63,6 @@ function rule.apis() , "rule.after_package" , "rule.after_install" , "rule.after_uninstall" - -- rule.on_xxx_all - , "rule.on_build_all" - , "rule.on_clean_all" - , "rule.on_package_all" - , "rule.on_install_all" - , "rule.on_uninstall_all" - -- rule.before_xxx_all - , "rule.before_build_all" - , "rule.before_clean_all" - , "rule.before_package_all" - , "rule.before_install_all" - , "rule.before_uninstall_all" - -- rule.after_xxx_all - , "rule.after_build_all" - , "rule.after_clean_all" - , "rule.after_package_all" - , "rule.after_install_all" - , "rule.after_uninstall_all" } } end diff --git a/xmake/core/sandbox/modules/import/core/project/rule.lua b/xmake/core/sandbox/modules/import/core/project/rule.lua index 81a8db412..32d5cac03 100644 --- a/xmake/core/sandbox/modules/import/core/project/rule.lua +++ b/xmake/core/sandbox/modules/import/core/project/rule.lua @@ -29,8 +29,8 @@ local sandbox_core_project_rule = sandbox_core_project_rule or {} local rule = require("project/rule") local raise = require("sandbox/modules/raise") --- build all source files -function sandbox_core_project_rule.build_all(rulename, target, sourcefiles) +-- build source files +function sandbox_core_project_rule.build(rulename, target, sourcefiles) end |
