diff options
| author | ruki <[email protected]> | 2018-06-05 00:29:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-06-04 20:55:33 +0800 |
| commit | 20d0fc6706aab723049bc7ae148c4d74050cd8ab (patch) | |
| tree | 9fac3f83c7319eff39ecda1a5f29357dcfe758f4 | |
| parent | 1d83b64076b174c4e5125cccd223a010a6a5a279 (diff) | |
load rule in target
| -rw-r--r-- | xmake/core/project/project.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 28 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 32 |
3 files changed, 31 insertions, 31 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index ac56439f1..1038d22e2 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -412,7 +412,7 @@ function project._load_targets() -- do load with target rules if ok then for _, r in pairs(t:orderules()) do - ok, errors = r:do_load(t) + ok, errors = t:_load_rule(r) if not ok then break end diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 7f8010d5d..52530ac5c 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -284,34 +284,6 @@ function rule:script(name, generic) return result end --- do load -function rule:do_load(target) - - -- init cache - local key = target:name() - local cache = self._LOADED or {} - - -- do load - if cache[key] == nil then - local on_load = self:script("load") - if on_load then - local ok, errors = sandbox.load(on_load, target) - cache[key] = {ok, errors} - else - cache[key] = {true} - end - end - - -- save cache - self._LOADED = cache - - -- return results - local results = cache[key] - if results then - return results[1], results[2] - end -end - -- get the given global rule function rule.rule(name) return rule.rules()[name] 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 |
