diff options
| author | ruki <[email protected]> | 2022-09-28 23:32:11 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-09-28 23:32:11 +0800 |
| commit | 82bfc71e7810157e8f71d43d4a2d82b609c17bf9 (patch) | |
| tree | b4423cbcb251fa833f3773242f37af6b899768fd | |
| parent | 39237af067f83918549427b27e95b0f479984e47 (diff) | |
improve to load targets
| -rw-r--r-- | xmake/core/project/project.lua | 13 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 45 |
2 files changed, 13 insertions, 45 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 40ae3a74f..e47463a89 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -875,6 +875,7 @@ end -- get targets function project.targets() + local loading = false local targets = project._memcache():get("targets") if not targets then local errors @@ -883,6 +884,18 @@ function project.targets() os.raise(errors) end project._memcache():set("targets", targets) + loading = true + end + if loading then + -- do after_load() for targets + -- @note we must call it after finishing to cache targets + -- because we maybe will call project.targets() in after_load, we need avoid dead recursion loop + for _, t in ipairs(project.ordertargets()) do + local ok, errors = t:_load_after() + if not ok then + os.raise(errors or string.format("load target %s failed", t:name())) + end + end end return targets end diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index b1d1101ba..a5778bc9e 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -71,24 +71,6 @@ sandbox_core_project.tmpdir = project.tmpdir sandbox_core_project.tmpfile = project.tmpfile sandbox_core_project.is_loaded = project.is_loaded --- load project targets -function sandbox_core_project._load_targets() - local loaded = sandbox_core_project._TARGETS_LOADED - if not loaded then - -- do after_load() for targets - -- @note we cannot call it in project.targets(), - -- because we maybe will call project.targets() in after_load - for _, t in ipairs(project.ordertargets()) do - local ok, errors = t:_load_after() - if not ok then - return false, errors - end - end - sandbox_core_project._TARGETS_LOADED = true - end - return true -end - -- check project options function sandbox_core_project.check() @@ -189,32 +171,5 @@ function sandbox_core_project.chdir(projectdir, projectfile) config._DIRECTORY = nil end --- get project target -function sandbox_core_project.target(name) - local ok, errors = sandbox_core_project._load_targets() - if not ok then - raise(errors) - end - return project.target(name) -end - --- get project targets -function sandbox_core_project.targets() - local ok, errors = sandbox_core_project._load_targets() - if not ok then - raise(errors) - end - return project.targets() -end - --- get project order targets -function sandbox_core_project.ordertargets() - local ok, errors = sandbox_core_project._load_targets() - if not ok then - raise(errors) - end - return project.ordertargets() -end - -- return module return sandbox_core_project |
