From 39308203867432767ba3cffd63201726f10024ab Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Sep 2025 17:06:57 +0800 Subject: improve envs --- xmake/modules/private/xrepo/action/env.lua | 40 +++++++++++++++--------------- 1 file 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 -- cgit v1.3.1 From 4c80a8b424b5433a375653e31a5f98f8863fdfb3 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Sep 2025 17:14:49 +0800 Subject: fix enter project --- xmake/modules/private/xrepo/action/env.lua | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index c4179b951..ddc7d5f96 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -270,19 +270,20 @@ function _package_getenvs(opt) local has_packages = #packages > 0 local in_project = os.isfile(os.projectfile()) and not option.get("bind") local oldir = os.curdir() - if has_envfiles or has_packages then + if not in_project 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 + if has_envfiles then + table.join2(project.rcfiles(), envfiles) + end + if has_packages then + 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 if in_project or has_envfiles or has_packages then task.run("config", {}, {disable_dump = true}) -- cgit v1.3.1