summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-06-03 23:48:23 +0800
committerruki <[email protected]>2021-06-03 23:48:23 +0800
commitca0fb0236b6036f03e87e05a290c0873de2e50f0 (patch)
tree7051257fe9369d69871d79007dff46f21511eb95
parent34150862caa0fb8f01d9e607e07093773363a927 (diff)
improve package envs
-rw-r--r--xmake/actions/build/statistics.lua4
-rw-r--r--xmake/modules/private/action/require/impl/environment.lua32
-rw-r--r--xmake/modules/private/action/require/impl/packagenv.lua31
3 files changed, 21 insertions, 46 deletions
diff --git a/xmake/actions/build/statistics.lua b/xmake/actions/build/statistics.lua
index 84a2a5cc5..d345b0fb4 100644
--- a/xmake/actions/build/statistics.lua
+++ b/xmake/actions/build/statistics.lua
@@ -111,7 +111,7 @@ function main()
platform.load(config.plat())
-- enter the environments of git
- packagenv.enter("git")
+ local oldenvs = packagenv.enter("git")
-- get the project directory name
local projectname = path.basename(os.projectdir())
@@ -139,5 +139,5 @@ function main()
end
-- leave the environments of git
- packagenv.leave("git")
+ os.setenvs(oldenvs)
end
diff --git a/xmake/modules/private/action/require/impl/environment.lua b/xmake/modules/private/action/require/impl/environment.lua
index 115f263aa..bf878876b 100644
--- a/xmake/modules/private/action/require/impl/environment.lua
+++ b/xmake/modules/private/action/require/impl/environment.lua
@@ -38,37 +38,39 @@ function enter()
end
-- enter the environments of git
- packagenv.enter("git")
+ _g._OLDENVS = packagenv.enter("git")
-- git not found? install it first
local packages = {}
- if not find_tool("git") then
+ local git = find_tool("git")
+ if not git then
table.join2(packages, install_packages("git"))
- find_tool("git", {force = true}) -- we need force to detect and flush detect cache
end
-- missing the necessary unarchivers for *.gz, *.7z? install them first, e.g. gzip, 7z, tar ..
- if not ((find_tool("gzip") and find_tool("tar")) or find_tool("7z")) then
+ local zip = (find_tool("gzip") and find_tool("tar")) or find_tool("7z")
+ if not zip then
table.join2(packages, install_packages("7z"))
- find_tool("7z", {force = true})
end
-- enter the environments of installed packages
- _g._OLDENVS = os.getenvs()
for _, instance in ipairs(packages) do
instance:envs_enter()
end
- _g._PACKAGES = packages
+
+ -- we need force to detect and flush detect cache after loading all environments
+ if not git then
+ find_tool("git", {force = true})
+ end
+ if not zip then
+ find_tool("7z", {force = true})
+ end
end
-- leave environment
function leave()
-
- -- leave the environments of installed packages
- os.setenvs(_g._OLDENVS)
- _g._OLDENVS = nil
- _g._PACKAGES = nil
-
- -- leave the environments of git
- packagenv.leave("git")
+ local oldenvs = _g._OLDENVS
+ if oldenvs then
+ os.setenvs(oldenvs)
+ end
end
diff --git a/xmake/modules/private/action/require/impl/packagenv.lua b/xmake/modules/private/action/require/impl/packagenv.lua
index 232670b54..12a98d36f 100644
--- a/xmake/modules/private/action/require/impl/packagenv.lua
+++ b/xmake/modules/private/action/require/impl/packagenv.lua
@@ -23,18 +23,7 @@ import("core.package.package", {alias = "core_package"})
-- enter the package environments
function _enter_package(package_name, envs, installdir)
-
- -- save the old environments
- _g._OLDENVS = _g._OLDENVS or {}
- local oldenvs = _g._OLDENVS[package_name]
- if not oldenvs then
- oldenvs = {}
- _g._OLDENVS[package_name] = oldenvs
- end
-
- -- add the new environments
for name, values in pairs(envs) do
- oldenvs[name] = oldenvs[name] or os.getenv(name)
if name == "PATH" or name == "LD_LIBRARY_PATH" or name == "DYLD_LIBRARY_PATH" then
for _, value in ipairs(values) do
if path.is_absolute(value) then
@@ -49,20 +38,9 @@ function _enter_package(package_name, envs, installdir)
end
end
--- leave the package environments
-function _leave_package(package_name)
- _g._OLDENVS = _g._OLDENVS or {}
- local oldenvs = _g._OLDENVS[package_name]
- if oldenvs then
- for name, values in pairs(oldenvs) do
- os.setenv(name, values)
- end
- _g._OLDENVS[package_name] = nil
- end
-end
-
-- enter environment of the given binary packages, git, 7z, ..
function enter(...)
+ local oldenvs = os.getenvs()
for _, name in ipairs({...}) do
for _, manifest_file in ipairs(os.files(path.join(core_package.installdir(), name:sub(1, 1), name, "*", "*", "manifest.txt"))) do
local manifest = io.load(manifest_file)
@@ -71,11 +49,6 @@ function enter(...)
end
end
end
+ return oldenvs
end
--- leave environment of the given binary packages, git, 7z, ..
-function leave(...)
- for _, name in ipairs({...}) do
- _leave_package(name)
- end
-end