diff options
| author | ruki <[email protected]> | 2019-03-17 22:46:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-03-17 22:46:36 +0800 |
| commit | ecdb953daa77c74a7475c7486d8df6d96d0d0c4d (patch) | |
| tree | 5720d5b5de715400591fc18a9417a9da2a189e28 | |
| parent | e35215c72fa78df798a88ca1cd9bed9bb36013d5 (diff) | |
bind package envs to run
| -rw-r--r-- | xmake/actions/require/impl/environment.lua | 5 | ||||
| -rw-r--r-- | xmake/actions/require/install.lua | 50 | ||||
| -rw-r--r-- | xmake/actions/run/main.lua | 12 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 13 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 22 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_program.lua | 3 |
6 files changed, 80 insertions, 25 deletions
diff --git a/xmake/actions/require/impl/environment.lua b/xmake/actions/require/impl/environment.lua index b303f631a..5c0ba0844 100644 --- a/xmake/actions/require/impl/environment.lua +++ b/xmake/actions/require/impl/environment.lua @@ -42,11 +42,12 @@ function _enter_package(package_name, envs, installdir) -- add the new environments oldenvs.PATH = os.getenv("PATH") - os.addenv("PATH", path.join(installdir, "bin")) for name, values in pairs(envs) do oldenvs[name] = oldenvs[name] or os.getenv(name) if name == "PATH" then - for _, value in ipairs(values) do + if path.is_absolute(value) then + os.addenv(name, value) + else os.addenv(name, path.join(installdir, value)) end else diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua index df327d2ab..5e692f5de 100644 --- a/xmake/actions/require/install.lua +++ b/xmake/actions/require/install.lua @@ -38,18 +38,40 @@ function _register_required_package(instance, requireinfo) if _g.optional_missing[instance:name()] then requireinfo:enable(false) else - -- add this package info + -- clear require info first requireinfo:clear() - requireinfo:add(instance:fetch()) - -- add all dependent packages info - local orderdeps = instance:orderdeps() - if orderdeps then - local total = #orderdeps - for idx, _ in ipairs(orderdeps) do - local dep = orderdeps[total + 1 - idx] - if dep then - requireinfo:add((dep:fetch())) + -- add this packages info + if instance:kind() == "binary" then + -- add path environments + local envs = {} + local installdir = instance:installdir() + for name, values in pairs(instance:envs()) do + if name == "PATH" then + for _, value in ipairs(values) do + envs[name] = envs[name] or {} + if path.is_absolute(value) then + table.insert(envs[name], value) + else + table.insert(envs[name], path.join(installdir, value)) + end + end + else + envs[name] = values + end + end + requireinfo:add({envs = envs}) + else + -- add include and links info + requireinfo:add(instance:fetch()) + local orderdeps = instance:orderdeps() + if orderdeps then + local total = #orderdeps + for idx, _ in ipairs(orderdeps) do + local dep = orderdeps[total + 1 - idx] + if dep then + requireinfo:add((dep:fetch())) + end end end end @@ -75,11 +97,9 @@ function _register_required_packages(packages) if not group or not registered_in_group[group] then -- do not register binary package - if instance:kind() ~= "binary" then - local requireinfo = project.require(instance:alias() or instance:name()) - if requireinfo then - _register_required_package(instance, requireinfo) - end + local requireinfo = project.require(instance:alias() or instance:name()) + if requireinfo then + _register_required_package(instance, requireinfo) end -- mark as registered in group diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 21783a125..156170871 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -103,6 +103,13 @@ end -- run the given target function _run(target) + -- enter the environments of the target packages + local oldenvs = {} + for name, values in pairs(target:pkgenvs()) do + oldenvs[name] = os.getenv(name) + os.addenv(name, unpack(values)) + end + -- the target scripts local scripts = { @@ -148,6 +155,11 @@ function _run(target) script(target, {origin = (i == 3 and _do_run_target or nil)}) end end + + -- leave the environments of the target packages + for name, values in pairs(oldenvs) do + os.setenv(name, values) + end end -- run the all dependent targets diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index fead86f1c..baa8319b1 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -319,6 +319,9 @@ function _instance:envs() local envs = self._ENVS if not envs then envs = {} + if self:kind() == "binary" then + envs.PATH = {"bin"} + end self._ENVS = envs end return envs @@ -336,15 +339,15 @@ function _instance:envs_enter() -- add the new environments local installdir = self:installdir() - if self:kind() == "binary" then - oldenvs.PATH = os.getenv("PATH") - os.addenv("PATH", path.join(installdir, "bin")) - end for name, values in pairs(self:envs()) do oldenvs[name] = oldenvs[name] or os.getenv(name) if name == "PATH" then for _, value in ipairs(values) do - os.addenv(name, path.join(installdir, value)) + if path.is_absolute(value) then + os.addenv(name, value) + else + os.addenv(name, path.join(installdir, value)) + end end else os.addenv(name, unpack(values)) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 1bf85014d..a47291b5c 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -572,6 +572,28 @@ function _instance:orderpkgs() return self._ORDERPKGS_ENABLED end +-- get the environments of packages +function _instance:pkgenvs() + local pkgenvs = self._PKGENVS + if not pkgenvs then + pkgenvs = {} + self._PKGENVS = pkgenvs + for _, pkgname in ipairs(table.wrap(self:get("packages"))) do + local pkg = self:pkg(pkgname) + if pkg then + local envs = pkg:get("envs") + if envs then + for name, values in pairs(envs) do + pkgenvs[name] = pkgenvs[name] or {} + table.join2(pkgenvs[name], values) + end + end + end + end + end + return pkgenvs +end + -- get the config info of the given package function _instance:pkgconfig(pkgname) local extra_packages = self:get("__extra_packages") diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua index e7f6a5d0d..1cb1c1a81 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -131,9 +131,6 @@ function sandbox_lib_detect_find_program._find_from_packages(name, opt) -- init pathes local pathes = {} - table.insert(pathes, path.join(installdir, "bin")) - - -- load manifest info local manifest = io.load(manifest_file) if manifest and manifest.envs then local pathenvs = manifest.envs.PATH |
