diff options
| author | ruki <[email protected]> | 2025-09-20 17:06:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-09-20 17:06:57 +0800 |
| commit | 39308203867432767ba3cffd63201726f10024ab (patch) | |
| tree | 8a0b269854a84126b40e49eb58cf953c386b28e8 | |
| parent | c991a3b06cc58769c1ff94a5e43637f2e95c52b9 (diff) | |
improve envs
| -rw-r--r-- | xmake/modules/private/xrepo/action/env.lua | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 47d91b3b9..c4179b951 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -266,36 +266,36 @@ end function _package_getenvs(opt) local envs = os.getenvs() local packages, envfiles = _get_boundenvs(opt) - local has_envfile = #envfiles > 0 + local has_envfiles = #envfiles > 0 + local has_packages = #packages > 0 + local in_project = os.isfile(os.projectfile()) and not option.get("bind") local oldir = os.curdir() - if (os.isfile(os.projectfile()) and not option.get("bind")) or has_envfile then - if has_envfile then - _enter_project() + if has_envfiles or has_packages then + _enter_project() + if has_envfiles then table.join2(project.rcfiles(), envfiles) + else + local envfile = os.tmpfile() .. ".lua" + local file = io.open(envfile, "w") + for _, requirename in ipairs(packages) do + file:print("add_requires(\"%s\")", requirename) + end + file:close() + table.insert(project.rcfiles(), envfile) end + end + if in_project or has_envfiles or has_packages then task.run("config", {}, {disable_dump = true}) - _toolchain_addenvs(envs) + if in_project or has_envfiles then + _toolchain_addenvs(envs) + end local requires, requires_extra = get_requires() for _, instance in ipairs(package.load_packages(requires, {requires_extra = requires_extra})) do _package_addenvs(envs, instance) end - if not has_envfile then + if in_project then _target_addenvs(envs) end - elseif #packages > 0 then - _enter_project() - local envfile = os.tmpfile() .. ".lua" - local file = io.open(envfile, "w") - for _, requirename in ipairs(packages) do - file:print("add_requires(\"%s\")", requirename) - end - file:close() - table.insert(project.rcfiles(), envfile) - task.run("config", {}, {disable_dump = true}) - local requires, requires_extra = get_requires() - for _, instance in ipairs(package.load_packages(requires, {requires_extra = requires_extra})) do - _package_addenvs(envs, instance) - end end local results = {} for k, v in pairs(envs) do |
