summaryrefslogtreecommitdiff
path: root/xmake/core/project
diff options
context:
space:
mode:
authorruki <[email protected]>2018-06-14 22:38:41 +0800
committerruki <[email protected]>2018-06-14 09:52:09 +0800
commitec8068f4d052e4c4536fd485f9c9eb815e451397 (patch)
tree22944defd9f3f91ccf16a1d277be151d0df164e9 /xmake/core/project
parent16b501fbc388f1b207faf1475602388b9e09983e (diff)
add before_load and after_load for rule
Diffstat (limited to 'xmake/core/project')
-rw-r--r--xmake/core/project/rule.lua2
-rw-r--r--xmake/core/project/target.lua67
2 files changed, 50 insertions, 19 deletions
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