summaryrefslogtreecommitdiff
path: root/xmake/core/project/target.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2018-06-05 00:29:15 +0800
committerruki <[email protected]>2018-06-04 20:55:33 +0800
commit20d0fc6706aab723049bc7ae148c4d74050cd8ab (patch)
tree9fac3f83c7319eff39ecda1a5f29357dcfe758f4 /xmake/core/project/target.lua
parent1d83b64076b174c4e5125cccd223a010a6a5a279 (diff)
load rule in target
Diffstat (limited to 'xmake/core/project/target.lua')
-rw-r--r--xmake/core/project/target.lua32
1 files changed, 30 insertions, 2 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 6d0aa648a..cbe226507 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -149,6 +149,34 @@ function target.new(name, info, project)
return instance
end
+-- load rule, move cache to target
+function target:_load_rule(ruleinst)
+
+ -- init cache
+ local key = ruleinst:name()
+ local cache = self._RULES_LOADED or {}
+
+ -- do load
+ if cache[key] == nil then
+ local on_load = ruleinst:script("load")
+ if on_load then
+ local ok, errors = sandbox.load(on_load, self)
+ cache[key] = {ok, errors}
+ else
+ cache[key] = {true}
+ end
+ end
+
+ -- save cache
+ self._RULES_LOADED = cache
+
+ -- return results
+ local results = cache[key]
+ if results then
+ return results[1], results[2]
+ end
+end
+
-- get the target info
function target:get(name)
return self._INFO[name]
@@ -568,14 +596,14 @@ function target:filerules(sourcefile)
-- load dependent rules if these rules have been not loaded
for _, deprule in pairs(r:orderdeps()) do
- local ok, errors = deprule:do_load(self)
+ 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 = r:do_load(self)
+ local ok, errors = self:_load_rule(r)
if not ok then
os.raise(errors)
end