diff options
| author | ruki <[email protected]> | 2018-09-19 23:17:53 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-09-19 13:47:18 +0800 |
| commit | 3effabb03faacb09d5b566f8e72a5171bfaaa97e (patch) | |
| tree | 2170cc518e15d2e0eaec190bb125b6ab2b22d52c | |
| parent | dae812d748abf4b10812028acb81d6187fd5e2af (diff) | |
add search directories for prefix
| -rw-r--r-- | xmake/actions/require/package.lua | 5 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 9 | ||||
| -rw-r--r-- | xmake/core/platform/environment.lua | 42 |
3 files changed, 50 insertions, 6 deletions
diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua index 828241f4d..438f42219 100644 --- a/xmake/actions/require/package.lua +++ b/xmake/actions/require/package.lua @@ -423,13 +423,14 @@ function install_packages(requires, opt) -- load packages local packages = load_packages(requires, opt) + --[[ -- add path environment for fetch binary packages local pathes = os.getenv("PATH") for _, package in ipairs(packages) do if package:kind() == "binary" and package:supported() then os.addenv("PATH", package:installdir("bin")) end - end + end]] -- fetch packages (with system) from local first if not option.get("force") then @@ -513,7 +514,7 @@ function install_packages(requires, opt) end -- restore path environment - os.setenv("PATH", pathes) +-- os.setenv("PATH", pathes) -- ok return packages diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 85b259843..918db45b3 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -193,9 +193,9 @@ end -- get the prefix directory function _instance:prefixdir(...) - + -- make the given prefix directory - local dir = path.join(self:from("global") and global.directory() or config.directory(), "prefix", self:debug() and "debug" or "release", config.get("plat") or os.host(), config.get("arch") or os.arch(), ...) + local dir = path.join(package.prefixdir(self:from("global")), is_debug and "debug" or "release", config.get("plat") or os.host(), config.get("arch") or os.arch(), ...) -- ensure the prefix directory if not os.isdir(dir) then @@ -555,6 +555,11 @@ function package.cachedir() return path.join(global.directory(), "cache", "packages") end +-- get the prefix directory +function package.prefixdir(is_global) + return path.join(is_global and global.directory() or config.directory(), "prefix") +end + -- load the package from the system directories function package.load_from_system(packagename) diff --git a/xmake/core/platform/environment.lua b/xmake/core/platform/environment.lua index aad8318ff..d77ec0d85 100644 --- a/xmake/core/platform/environment.lua +++ b/xmake/core/platform/environment.lua @@ -26,13 +26,42 @@ local environment = environment or {} -- load modules +local os = require("base/os") local platform = require("platform/platform") local sandbox = require("sandbox/sandbox") +local package = require("package/package") + +-- enter the toolchains environment +function environment._enter_toolchains() + + -- save the toolchains environment + environment._PATHES = os.getenv("path") + + -- add search binary pathes of packages + os.addenv("PATH", path.join(package.prefixdir(true), "release", os.host(), os.arch(), "bin")) -- globaldir/release/../bin + os.addenv("PATH", path.join(package.prefixdir(false), "release", os.host(), os.arch(), "bin")) -- localdir/release/../bin +end + +-- leave the toolchains environment +function environment._leave_toolchains() + + -- leave the toolchains environment + os.setenv("path", environment._PATHES) +end -- enter the environment for the current platform function environment.enter(name) - -- enter it + -- the maps + local maps = {toolchains = environment._enter_toolchains} + + -- enter the common environment + local func = maps[name] + if func then + func() + end + + -- enter the environment of the given platform local module = platform.get("environment") if module then local ok, errors = sandbox.load(module.enter, name) @@ -48,7 +77,7 @@ end -- leave the environment for the current platform function environment.leave(name) - -- leave it + -- leave the environment of the given platform local module = platform.get("environment") if module then local ok, errors = sandbox.load(module.leave, name) @@ -57,6 +86,15 @@ function environment.leave(name) end end + -- the maps + local maps = {toolchains = environment._leave_toolchains} + + -- leave the common environment + local func = maps[name] + if func then + func() + end + -- ok return true end |
