diff options
| author | ruki <[email protected]> | 2018-05-02 22:40:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-02 10:04:24 +0800 |
| commit | 36e4d8e69cdf7019485d5328810fe1c5720bad5d (patch) | |
| tree | 9a41a6f4d5209982aff65887160e2e87d27f7bb5 | |
| parent | d708c31c13ffdfab4eb5adf02ba906e4bf11648d (diff) | |
improve file rule
| -rw-r--r-- | tests/projects/wdk/kmdf/ioctl/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 144 | ||||
| -rw-r--r-- | xmake/rules/wdk/xmake.lua | 40 |
5 files changed, 124 insertions, 65 deletions
diff --git a/tests/projects/wdk/kmdf/ioctl/xmake.lua b/tests/projects/wdk/kmdf/ioctl/xmake.lua index 3ee226d17..d803d99cb 100644 --- a/tests/projects/wdk/kmdf/ioctl/xmake.lua +++ b/tests/projects/wdk/kmdf/ioctl/xmake.lua @@ -9,7 +9,7 @@ target("nonpnp") add_rules("wdk.kmdf.driver") -- add files - add_files("driver/*.c") + add_files("driver/*.c", {rule = "wdk.tracewpp"}) -- add target target("app") diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index f54198132..cb1e52f65 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -355,7 +355,7 @@ function project._load_targets() -- make targets local targets = {} for targetname, targetinfo in pairs(results) do - targets[targetname] = target.new(targetname, targetinfo) + targets[targetname] = target.new(targetname, targetinfo, project) end -- load and attach target deps and rules diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 6d35bc36a..52530ac5c 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -152,7 +152,6 @@ function rule.apis() { -- rule.set_xxx "rule.set_extensions" - , "rule.set_kind" -- rule.add_xxx , "rule.add_deps" , "rule.add_imports" diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 09d0a8ada..9ca8c8b44 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -126,7 +126,7 @@ function target.filename(targetname, targetkind, targetformat) end -- new a target instance -function target.new(name, info) +function target.new(name, info, project) -- init a target instance local instance = table.inherit(target) @@ -135,6 +135,7 @@ function target.new(name, info) -- save name and info instance._NAME = name instance._INFO = info + instance._PROJECT = project -- ok? return instance @@ -163,7 +164,7 @@ function target:set(name_or_info, ...) -- set values local name = name_or_info if #values > 0 then - self._INFO[name] = table.unwrap(table.unique(values)) + self._INFO[name] = table.unwrap(table.unique(table.join(unpack(values)))) else self._INFO[name] = nil end @@ -203,7 +204,7 @@ function target:add(name_or_info, ...) -- add values local name = name_or_info local info = table.wrap(self._INFO[name]) - self._INFO[name] = table.unwrap(table.unique(table.join(info, values))) + self._INFO[name] = table.unwrap(table.unique(table.join(info, unpack(values)))) -- save extra config if extra_config then @@ -341,27 +342,11 @@ function target:orderules() return self._ORDERULES end --- get target rule from the given source extension -function target:rule(extension) - - -- get it from cache first - local extension2rules = self._EXTENSION2RULES - if not extension2rules then - - -- make extension to rules - extension2rules = {} - for _, rule in pairs(table.wrap(self:rules())) do - for _, extension in ipairs(table.wrap(rule:get("extensions"))) do - extension2rules[extension] = rule - end - end +-- get target rule from the given rule name +function target:rule(name) + if self._RULES then + return self._RULES[name] end - - -- cache it - self._EXTENSION2RULES = extension2rules - - -- ok? - return extension2rules[extension] end -- is phony target? @@ -509,21 +494,42 @@ function target:headerdir() return self:get("headerdir") or config.buildir() end --- get the source file rule name -function target:filerule(sourcefile) +-- get rules of the source file +function target:filerules(sourcefile) - -- get file config + -- add rules from file config + local rules = {} local fileconfig = self:fileconfig(sourcefile) + if fileconfig then + local filerules = fileconfig.rules or fileconfig.rule + if filerules then + for _, rulename in ipairs(table.wrap(filerules)) do + local r = self._PROJECT.rule(rulename) or rule.rule(rulename) + if r then + table.insert(rules, r) + end + end + end + end - -- get rule name - if fileconfig and fileconfig.rule then - return fileconfig.rule - else - local rule = self:rule(path.extension(sourcefile)) - if rule then - return rule:name() + -- get target rule from the given source extension + local extension2rules = self._EXTENSION2RULES + if not extension2rules then + extension2rules = {} + for _, r in pairs(table.wrap(self:rules())) do + for _, extension in ipairs(table.wrap(r:get("extensions"))) do + extension2rules[extension] = extension2rules[extension] or {} + table.insert(extension2rules[extension], r) + end end + self._EXTENSION2RULES = extension2rules + end + for _, r in ipairs(table.wrap(extension2rules[path.extension(sourcefile)])) do + table.insert(rules, r) end + + -- done + return rules end -- get the config info of the given source file @@ -869,43 +875,59 @@ function target:sourcebatches() local sourcebatches = {} for _, sourcefile in ipairs(sourcefiles) do - -- get file rule - local filerule = self:filerule(sourcefile) + -- add file rules + local builtin_rule = true + for _, filerule in ipairs(self:filerules(sourcefile)) do - -- get source kind - local sourcekind = nil - if filerule then - sourcekind = "__rule_" .. filerule + -- get source kind + local sourcekind = "__rule_" .. filerule:name() + + -- make this batch + local sourcebatch = sourcebatches[sourcekind] or {sourcefiles = {}} + sourcebatches[sourcekind] = sourcebatch + + -- add source kind to this batch + sourcebatch.sourcekind = sourcekind + + -- add source rule to this batch + sourcebatch.rulename = filerule:name() + + -- 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 - if not sourcekind then + + -- add builtin rule + if builtin_rule then + + -- get source kind sourcekind = language.sourcekind_of(sourcefile) - end - if not sourcekind then - local sourcekind_ext = sourcekinds_ext[path.extension(sourcefile):lower()] - if sourcekind_ext then - sourcekind = sourcekind_ext + if not sourcekind then + local sourcekind_ext = sourcekinds_ext[path.extension(sourcefile):lower()] + if sourcekind_ext then + sourcekind = sourcekind_ext + end end - end - -- unknown source kind - if not sourcekind then - os.raise("unknown source file: %s", sourcefile) - end + -- unknown source kind + if not sourcekind then + os.raise("unknown source file: %s", sourcefile) + end - -- make this batch - local sourcebatch = sourcebatches[sourcekind] or {sourcefiles = {}} - sourcebatches[sourcekind] = sourcebatch + -- make this batch + local sourcebatch = sourcebatches[sourcekind] or {sourcefiles = {}} + sourcebatches[sourcekind] = sourcebatch - -- add source kind to this batch - sourcebatch.sourcekind = sourcekind + -- add source kind to this batch + sourcebatch.sourcekind = sourcekind - -- add source rule to this batch - if filerule then - sourcebatch.rulename = filerule + -- add source file to this batch + table.insert(sourcebatch.sourcefiles, sourcefile) end - - -- add source file to this batch - table.insert(sourcebatch.sourcefiles, sourcefile) end -- insert object files to source batches diff --git a/xmake/rules/wdk/xmake.lua b/xmake/rules/wdk/xmake.lua index 9344fbbcb..43a7a71c9 100644 --- a/xmake/rules/wdk/xmake.lua +++ b/xmake/rules/wdk/xmake.lua @@ -78,12 +78,50 @@ rule("wdk.inf") local stampinf = target:data("wdk.stampinf") -- update the timestamp - os.vrunv(stampinf, {"-d", "*", "-a", "arm64", "-v", "*", "-f", targetfile}, {wildcards = false}) + os.vrunv(stampinf, {"-d", "*", "-a", is_arch("x64") and "arm64" or "x86", "-v", "*", "-f", targetfile}, {wildcards = false}) -- add clean files target:data_add("wdk.cleanfiles", targetfile) end) +-- define rule: tracewpp +rule("wdk.tracewpp") + + -- add rule: wdk environment + add_deps("wdk.env") + + -- on load + on_load(function (target) + + -- imports + import("core.project.config") + + -- get arch + local arch = assert(config.arch(), "arch not found!") + + -- get tracewpp + local tracewpp = path.join(target:data("wdk").bindir, arch, is_host("windows") and "tracewpp.exe" or "tracewpp") + assert(tracewpp and os.isexec(tracewpp), "tracewpp not found!") + + -- save uic + target:data_set("wdk.tracewpp", tracewpp) + end) + + -- before build file + before_build_file(function (target, sourcefile) + + -- get tracewpp + local tracewpp = target:data("wdk.tracewpp") + + print(tracewpp, sourcefile) + + -- update the timestamp +-- os.vrunv(tracewpp, {"-d", "*", "-a", is_arch("x64") and "arm64" or "x86", "-v", "*", "-f", targetfile}, {wildcards = false}) + + -- add clean files +-- target:data_add("wdk.cleanfiles", targetfile) + end) + -- define rule: umdf driver rule("wdk.umdf.driver") |
