diff options
| author | ruki <[email protected]> | 2020-10-06 00:50:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-10-06 00:50:32 +0800 |
| commit | 461f42144aae7ab04d1c342d63ade05eda7a4338 (patch) | |
| tree | 915575b1a8d92c5d4d3dce1c6a3069fded12667b | |
| parent | 6576473af7c58290402609c460eb1b1062f75d34 (diff) | |
fix load targets
| -rw-r--r-- | xmake/core/project/project.lua | 49 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 1 |
3 files changed, 39 insertions, 13 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 3e11ece7f..33d8d4233 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -445,9 +445,16 @@ function project._load_targets() end end + -- sort targets for all deps + local targetrefs = {} + local ordertargets = {} + for _, t in pairs(targets) do + project._sort_targets(targets, ordertargets, targetrefs, t) + end + -- do load for each target local ok = false - for _, t in pairs(targets) do + for _, t in ipairs(ordertargets) do ok, errors = t:_load() if not ok then break @@ -456,11 +463,9 @@ function project._load_targets() -- do load failed? if not ok then - return nil, errors + return nil, nil, errors end - - -- ok - return targets + return targets, ordertargets end -- load options @@ -621,6 +626,20 @@ function project._load_packages() return project._load_scope("package", true, false) end +-- sort targets for all deps +function project._sort_targets(targets, ordertargets, targetrefs, target) + for _, depname in ipairs(table.wrap(target:get("deps"))) do + local targetinst = targets[depname] + if targetinst then + project._sort_targets(targets, ordertargets, targetrefs, targetinst) + end + end + if not targetrefs[target:name()] then + targetrefs[target:name()] = true + table.insert(ordertargets, target) + end +end + -- get project apis function project.apis() @@ -872,22 +891,28 @@ function project.target(name) return project.targets()[name] end --- get the current configure for targets +-- get targets function project.targets() - - -- load targets if not project._TARGETS then - local targets, errors = project._load_targets() - if not targets then + local targets, ordertargets, errors = project._load_targets() + if not targets or not ordertargets then os.raise(errors) end project._TARGETS = targets + project._ORDERTARGETS = ordertargets end - - -- ok return project._TARGETS end +-- get order targets +function project.ordertargets() + if not project._ORDERTARGETS then + -- ensure _ORDERTARGETS to be initialized + project.targets() + end + return project._ORDERTARGETS +end + -- get the given option function project.option(name) return project.options()[name] diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ab6a90b51..af62b667b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -84,7 +84,7 @@ end -- load rules function _instance:_load_rules(suffix) - for _, r in pairs(self:orderules()) do + for _, r in ipairs(self:orderules()) do local ok, errors = self:_load_rule(r, suffix) if not ok then return false, errors diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 1a00d5935..775e6115a 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -43,6 +43,7 @@ sandbox_core_project.toolchain = project.toolchain sandbox_core_project.toolchains = project.toolchains sandbox_core_project.target = project.target sandbox_core_project.targets = project.targets +sandbox_core_project.ordertargets = project.ordertargets sandbox_core_project.option = project.option sandbox_core_project.options = project.options sandbox_core_project.rootfile = project.rootfile |
