diff options
| author | ruki <[email protected]> | 2018-06-14 22:38:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-06-14 09:52:09 +0800 |
| commit | ec8068f4d052e4c4536fd485f9c9eb815e451397 (patch) | |
| tree | 22944defd9f3f91ccf16a1d277be151d0df164e9 | |
| parent | 16b501fbc388f1b207faf1475602388b9e09983e (diff) | |
add before_load and after_load for rule
| -rw-r--r-- | scripts/installer.nsi | 3 | ||||
| -rw-r--r-- | tests/projects/wdk/wdm/msdsm/xmake.lua | 7 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 67 | ||||
| -rw-r--r-- | xmake/modules/os/winver.lua (renamed from xmake/modules/utils/os/winver.lua) | 12 | ||||
| -rw-r--r-- | xmake/rules/wdk/env/load.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/wdk/load.lua | 1 | ||||
| -rw-r--r-- | xmake/rules/wdk/xmake.lua | 8 |
8 files changed, 73 insertions, 33 deletions
diff --git a/scripts/installer.nsi b/scripts/installer.nsi index e82a93d9d..7a672e55e 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -77,6 +77,9 @@ Section "xmake (required)" Installer ; Set output path to the installation directory.
SetOutPath $INSTDIR
+
+ ; Remove previous directories used
+ RMDir /r "$INSTDIR"
; Put file there
File /r /x ".DS_Store" /x "*.swp" "..\xmake\*.*"
diff --git a/tests/projects/wdk/wdm/msdsm/xmake.lua b/tests/projects/wdk/wdm/msdsm/xmake.lua index 069f69767..d7a8804c6 100644 --- a/tests/projects/wdk/wdm/msdsm/xmake.lua +++ b/tests/projects/wdk/wdm/msdsm/xmake.lua @@ -25,3 +25,10 @@ target("sampledsm") -- add links add_links("mpio") + on_load(function (target) + + import("core.project.config") + print(target:values("wdk.env.winver") or config.get("wdk_winver")) + local ntddi_version = import("os.winver").ntddi_version(target:values("wdk.env.winver") or config.get("wdk_winver")) + print(ntddi_version) + end) diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 52530ac5c..5945d91ca 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -170,6 +170,7 @@ function rule.apis() , "rule.on_uninstall" -- rule.before_xxx , "rule.before_run" + , "rule.before_load" , "rule.before_build" , "rule.before_build_file" , "rule.before_build_files" @@ -179,6 +180,7 @@ function rule.apis() , "rule.before_uninstall" -- rule.after_xxx , "rule.after_run" + , "rule.after_load" , "rule.after_build" , "rule.after_build_file" , "rule.after_build_files" diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index cbe226507..98623895b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -150,15 +150,15 @@ function target.new(name, info, project) end -- load rule, move cache to target -function target:_load_rule(ruleinst) +function target:_load_rule(ruleinst, suffix) -- init cache - local key = ruleinst:name() + local key = ruleinst:name() .. (suffix and ("_" .. suffix) or "") local cache = self._RULES_LOADED or {} -- do load if cache[key] == nil then - local on_load = ruleinst:script("load") + local on_load = ruleinst:script("load" .. (suffix and ("_" .. suffix) or "")) if on_load then local ok, errors = sandbox.load(on_load, self) cache[key] = {ok, errors} @@ -177,6 +177,51 @@ function target:_load_rule(ruleinst) end end +-- load rules +function target:_load_rules(suffix) + for _, r in pairs(self:orderules()) do + local ok, errors = self:_load_rule(r, suffix) + if not ok then + return false, errors + end + end + return true +end + +-- do load target and rules +function target:_load() + + -- do before_load with target rules + local ok, errors = self:_load_rules("before") + if not ok then + return false, errors + end + + -- do load for target + local on_load = self:script("load") + if on_load then + local ok, errors = sandbox.load(on_load, self) + if not ok then + return false, errors + end + end + + -- do load with target rules + local ok, errors = self:_load_rules() + if not ok then + return false, errors + end + + -- do after_load with target rules + local ok, errors = self:_load_rules("after") + if not ok then + return false, errors + end + + -- ok + return true +end + -- get the target info function target:get(name) return self._INFO[name] @@ -593,22 +638,6 @@ function target:filerules(sourcefile) for _, rulename in ipairs(table.wrap(filerules)) do local r = self._PROJECT.rule(rulename) or rule.rule(rulename) if r then - - -- load dependent rules if these rules have been not loaded - for _, deprule in pairs(r:orderdeps()) do - local ok, errors = self:_load_rule(deprule) - if not ok then - os.raise(errors) - end - end - - -- load file rule if this rule have been not loaded - local ok, errors = self:_load_rule(r) - if not ok then - os.raise(errors) - end - - -- add this rule table.insert(rules, r) end end diff --git a/xmake/modules/utils/os/winver.lua b/xmake/modules/os/winver.lua index 1579b4563..79587c6ed 100644 --- a/xmake/modules/utils/os/winver.lua +++ b/xmake/modules/os/winver.lua @@ -22,11 +22,11 @@ -- @file winver.lua -- --- get windows version value from name +-- get WINVER from name -- -- reference: https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx -- -function value(name) +function version(name) -- init values _g.values = _g.values or @@ -53,8 +53,8 @@ function value(name) return _g.values[name] end --- get ntddi value from name -function value_ntddi(name) +-- get NTDDI_VERSION from name +function ntddi_version(name) -- init subvalues _g.subvalues = _g.subvalues or @@ -77,7 +77,7 @@ function value_ntddi(name) end -- get value - local val = value(name) + local val = version(name) if val then val = val .. (subvalue or "0000") end @@ -86,7 +86,7 @@ end -- get windows system version -- --- $ xmake l utils.os.winver +-- $ xmake l os.winver -- -- - win10: 10.0.14393 -- - xp: 5.1.2600 diff --git a/xmake/rules/wdk/env/load.lua b/xmake/rules/wdk/env/load.lua index d36d5aa49..2f36745f3 100644 --- a/xmake/rules/wdk/env/load.lua +++ b/xmake/rules/wdk/env/load.lua @@ -24,16 +24,16 @@ -- imports import("core.project.config") -import("utils.os.winver", {alias = "os_winver"}) +import("os.winver", {alias = "os_winver"}) -- get windows version value function _winver(winver) - return os_winver.value(winver or "") or "0x0A00" + return os_winver.version(winver or "") or "0x0A00" end -- get windows ntddi version value function _winver_ntddi(winver) - return os_winver.value_ntddi(winver or "") or "0x0A000000" + return os_winver.ntddi_version(winver or "") or "0x0A000000" end -- get version of the library sub-directory diff --git a/xmake/rules/wdk/load.lua b/xmake/rules/wdk/load.lua index cd71a15f7..312fa3454 100644 --- a/xmake/rules/wdk/load.lua +++ b/xmake/rules/wdk/load.lua @@ -24,7 +24,6 @@ -- imports import("core.project.config") -import("utils.os.winver", {alias = "os_winver"}) -- get subsystem version defined value function _winver_subsystem(winver) diff --git a/xmake/rules/wdk/xmake.lua b/xmake/rules/wdk/xmake.lua index 4a9adbc0d..cc6bab715 100644 --- a/xmake/rules/wdk/xmake.lua +++ b/xmake/rules/wdk/xmake.lua @@ -26,7 +26,7 @@ rule("wdk.driver") -- add rules - add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.sign", "wdk.package.cab") + add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.tracewpp", "wdk.sign", "wdk.package.cab") -- on load on_load(function (target) @@ -67,7 +67,7 @@ rule("wdk.driver") rule("wdk.binary") -- add rules - add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof") + add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.tracewpp") -- on load on_load(function (target) @@ -84,7 +84,7 @@ rule("wdk.binary") rule("wdk.static") -- add rules - add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof") + add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.tracewpp") -- on load on_load(function (target) @@ -103,7 +103,7 @@ rule("wdk.static") rule("wdk.shared") -- add rules - add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof") + add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.tracewpp") -- on load on_load(function (target) |
