diff options
| author | ruki <[email protected]> | 2022-09-27 22:37:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-09-27 22:37:12 +0800 |
| commit | 466896dac3710e145baa671c95af27a97dbb5ebe (patch) | |
| tree | e79248fb230c650f55f964bfe8ee0ecd4b3dfc1d | |
| parent | 701f42aec0dd4acb291a7c69582823687a5edf85 (diff) | |
impl target:rule_set
| -rw-r--r-- | xmake/core/base/private/instance_deps.lua | 62 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 40 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 9 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 26 |
4 files changed, 100 insertions, 37 deletions
diff --git a/xmake/core/base/private/instance_deps.lua b/xmake/core/base/private/instance_deps.lua new file mode 100644 index 000000000..7a5d9aada --- /dev/null +++ b/xmake/core/base/private/instance_deps.lua @@ -0,0 +1,62 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file instance_deps.lua +-- + +-- define module +local instance_deps = instance_deps or {} + +-- load modules +local option = require("base/option") +local string = require("base/string") + +-- load deps for instance: e.g. option, target and rule +-- +-- e.g. +-- +-- a.deps = b +-- b.deps = c +-- +-- orderdeps: c -> b -> a +-- +function instance_deps.load_deps(instance, instances, deps, orderdeps, depspath) + for _, dep in ipairs(table.wrap(instance:get("deps"))) do + local depinst = instances[dep] + if depinst then + local depspath_sub + if depspath then + for idx, name in ipairs(depspath) do + if name == dep then + local circular_deps = table.slice(depspath, idx) + table.insert(circular_deps, dep) + os.raise("circular dependency(%s) detected!", table.concat(circular_deps, ", ")) + end + end + depspath_sub = table.join(depspath, dep) + end + instance_deps.load_deps(depinst, instances, deps, orderdeps, depspath_sub) + if not deps[dep] then + deps[dep] = depinst + table.insert(orderdeps, depinst) + end + end + end +end + +-- return module +return instance_deps diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 3c4c39232..62e180a87 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -34,6 +34,7 @@ local hashset = require("base/hashset") local baseoption = require("base/option") local deprecated = require("base/deprecated") local interpreter = require("base/interpreter") +local instance_deps = require("base/private/instance_deps") local memcache = require("cache/memcache") local rule = require("project/rule") local target = require("project/target") @@ -207,39 +208,6 @@ function project._load(force, disable_filter) return true end --- load deps for instance: e.g. option, target and rule --- --- e.g. --- --- a.deps = b --- b.deps = c --- --- orderdeps: c -> b -> a --- -function project._load_deps(instance, instances, deps, orderdeps, depspath) - for _, dep in ipairs(table.wrap(instance:get("deps"))) do - local depinst = instances[dep] - if depinst then - local depspath_sub - if depspath then - for idx, name in ipairs(depspath) do - if name == dep then - local circular_deps = table.slice(depspath, idx) - table.insert(circular_deps, dep) - os.raise("circular dependency(%s) detected!", table.concat(circular_deps, ", ")) - end - end - depspath_sub = table.join(depspath, dep) - end - project._load_deps(depinst, instances, deps, orderdeps, depspath_sub) - if not deps[dep] then - deps[dep] = depinst - table.insert(orderdeps, depinst) - end - end - end -end - -- load scope from the project file function project._load_scope(scope_kind, deduplicate, enable_filter) @@ -330,7 +298,7 @@ function project._load_rules() if base then instance._BASE = instances[base] end - project._load_deps(instance, instances, instance._DEPS, instance._ORDERDEPS, {instance:name()}) + instance_deps.load_deps(instance, instances, instance._DEPS, instance._ORDERDEPS, {instance:name()}) end return rules end @@ -452,7 +420,7 @@ function project._load_targets() -- load deps t._DEPS = t._DEPS or {} t._ORDERDEPS = t._ORDERDEPS or {} - project._load_deps(t, targets, t._DEPS, t._ORDERDEPS, {t:name()}) + instance_deps.load_deps(t, targets, t._DEPS, t._ORDERDEPS, {t:name()}) end -- sort targets for all deps @@ -545,7 +513,7 @@ function project._load_options(disable_filter) for _, opt in pairs(options) do opt._DEPS = opt._DEPS or {} opt._ORDERDEPS = opt._ORDERDEPS or {} - project._load_deps(opt, options, opt._DEPS, opt._ORDERDEPS, {opt:name()}) + instance_deps.load_deps(opt, options, opt._DEPS, opt._ORDERDEPS, {opt:name()}) end return options end diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 1ac551ffd..39a7c49e3 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -39,6 +39,15 @@ function _instance:base() return self._BASE end +-- clone rule +function _instance:clone() + local instance = rule.new(self:name(), self._INFO:clone()) + -- TODO + instance._RULES = self._RULES + instance._ORDERDEPS = self._ORDERDEPS + return instance +end + -- get the rule info function _instance:get(name) local value = self._INFO:get(name) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 329eb53e3..a568fb15b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -685,7 +685,24 @@ end -- get target ordered rules function _instance:orderules() - return self._ORDERULES + local rules = self._RULES + local orderules = self._ORDERULES + if orderules == nil and rules then + orderules = {} + local rules_unique = {} + for _, r in pairs(rules) do + for _, deprule in ipairs(r:orderdeps()) do + local name = deprule:name() + if not rules_unique[name] then + rules_unique[name] = deprule + table.insert(orderules, deprule) + end + end + table.insert(orderules, r) + end + self._ORDERULES = orderules + end + return orderules end -- get target rule from the given rule name @@ -695,6 +712,13 @@ function _instance:rule(name) end end +-- set rule +function _instance:rule_set(name, ruleinst) + self._RULES = self._RULES or {} + self._RULES[name] = ruleinst + self._ORDERULES = nil +end + -- is phony target? function _instance:is_phony() local targetkind = self:kind() |
