summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-12 23:33:04 +0800
committerruki <[email protected]>2021-09-12 23:33:04 +0800
commit7b931b248bcb5328b993637b6ebda3e9fa7c25ff (patch)
tree565a38409abea6e8c9214bb524a6c4952eb0a34d
parent7313e0dae040ed0cff6cad8ca934649721cb46da (diff)
improve load target
-rw-r--r--xmake/core/project/project.lua60
1 files changed, 21 insertions, 39 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 91982e64a..311a9a260 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -353,29 +353,6 @@ function project._load_toolchains()
return toolchains
end
--- load target
-function project._load_target(t, requires)
-
- -- do before_load() for target and all rules
- local ok, errors = t:_load_before()
- if not ok then
- return false, errors
- end
-
- -- do on_load() for target and all rules
- ok, errors = t:_load()
- if not ok then
- return false, errors
- end
-
- -- do after_load() for target and all rules
- ok, errors = t:_load_after()
- if not ok then
- return false, errors
- end
- return true
-end
-
-- load targets
function project._load_targets()
@@ -409,11 +386,6 @@ function project._load_targets()
-- load and attach target deps, rules and packages
for _, t in pairs(targets) do
- -- load deps
- t._DEPS = t._DEPS or {}
- t._ORDERDEPS = t._ORDERDEPS or {}
- project._load_deps(t, targets, t._DEPS, t._ORDERDEPS, {t:name()})
-
-- load rules from target and language
--
-- e.g.
@@ -458,6 +430,24 @@ function project._load_targets()
return nil, nil, string.format("unknown rule(%s) in target(%s)!", rulename, t:name())
end
end
+
+ -- do before_load()
+ ok, errors = t:_load_before()
+ if not ok then
+ return nil, nil, errors
+ end
+
+ -- we need call on_load() before building deps/rules,
+ -- so we can use `target:add("deps", "xxx")` to add deps in on_load
+ ok, errors = t:_load()
+ if not ok then
+ return nil, nil, errors
+ end
+
+ -- load deps
+ t._DEPS = t._DEPS or {}
+ t._ORDERDEPS = t._ORDERDEPS or {}
+ project._load_deps(t, targets, t._DEPS, t._ORDERDEPS, {t:name()})
end
-- sort targets for all deps
@@ -467,19 +457,13 @@ function project._load_targets()
project._sort_targets(targets, ordertargets, targetrefs, t)
end
- -- do load for each target
- local ok = false
+ -- do after_load() for targets
for _, t in ipairs(ordertargets) do
- ok, errors = project._load_target(t, requires)
+ ok, errors = t:_load_after()
if not ok then
- break
+ return nil, nil, errors
end
end
-
- -- do load failed?
- if not ok then
- return nil, nil, errors
- end
return targets, ordertargets
end
@@ -558,8 +542,6 @@ function project._load_options(disable_filter)
opt._ORDERDEPS = opt._ORDERDEPS or {}
project._load_deps(opt, options, opt._DEPS, opt._ORDERDEPS, {opt:name()})
end
-
- -- ok?
return options
end