summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2019-09-29 08:07:13 +0800
committerruki <[email protected]>2019-09-29 08:07:13 +0800
commit07c8483607759f79cb3cfbf7351ee07cc714d8b9 (patch)
treebbfa0bddff65cea434a08eab27e240113d1b3f0a /xmake/modules
parent4df867463bac4c5987441696eabbf6a1f43ea9e4 (diff)
load git package env
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/devel/git/apply.lua5
-rw-r--r--xmake/modules/devel/git/branches.lua2
-rw-r--r--xmake/modules/devel/git/checkout.lua5
-rw-r--r--xmake/modules/devel/git/clean.lua5
-rw-r--r--xmake/modules/devel/git/clone.lua5
-rw-r--r--xmake/modules/devel/git/ls_remote.lua5
-rw-r--r--xmake/modules/devel/git/pull.lua5
-rw-r--r--xmake/modules/devel/git/submodule/update.lua5
-rw-r--r--xmake/modules/devel/git/tags.lua2
-rw-r--r--xmake/modules/private/action/require/packagenv.lua82
10 files changed, 89 insertions, 32 deletions
diff --git a/xmake/modules/devel/git/apply.lua b/xmake/modules/devel/git/apply.lua
index e47f31adc..c52aeeb3c 100644
--- a/xmake/modules/devel/git/apply.lua
+++ b/xmake/modules/devel/git/apply.lua
@@ -38,10 +38,7 @@ import("lib.detect.find_tool")
function main(patchfile, opt)
-- find git
- local git = find_tool("git")
- if not git then
- return
- end
+ local git = assert(find_tool("git"), "git not found!")
-- init argv
opt = opt or {}
diff --git a/xmake/modules/devel/git/branches.lua b/xmake/modules/devel/git/branches.lua
index f02ab851d..705d48153 100644
--- a/xmake/modules/devel/git/branches.lua
+++ b/xmake/modules/devel/git/branches.lua
@@ -37,7 +37,5 @@ import("ls_remote")
-- @endcode
--
function main(url)
-
- -- get branches
return ls_remote("heads", url)
end
diff --git a/xmake/modules/devel/git/checkout.lua b/xmake/modules/devel/git/checkout.lua
index 4a4c92bae..8fc62e66f 100644
--- a/xmake/modules/devel/git/checkout.lua
+++ b/xmake/modules/devel/git/checkout.lua
@@ -42,10 +42,7 @@ function main(commit, opt)
opt = opt or {}
-- find git
- local git = find_tool("git")
- if not git then
- return
- end
+ local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {"checkout", commit}
diff --git a/xmake/modules/devel/git/clean.lua b/xmake/modules/devel/git/clean.lua
index 4ed39a20f..35f20a3d8 100644
--- a/xmake/modules/devel/git/clean.lua
+++ b/xmake/modules/devel/git/clean.lua
@@ -41,10 +41,7 @@ function main(opt)
opt = opt or {}
-- find git
- local git = find_tool("git")
- if not git then
- return
- end
+ local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {"clean", "-d"}
diff --git a/xmake/modules/devel/git/clone.lua b/xmake/modules/devel/git/clone.lua
index 4a77abbf5..706148154 100644
--- a/xmake/modules/devel/git/clone.lua
+++ b/xmake/modules/devel/git/clone.lua
@@ -39,10 +39,7 @@ import("lib.detect.find_tool")
function main(url, opt)
-- find git
- local git = find_tool("git")
- if not git then
- return
- end
+ local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {"clone", url}
diff --git a/xmake/modules/devel/git/ls_remote.lua b/xmake/modules/devel/git/ls_remote.lua
index e946a054a..723372bec 100644
--- a/xmake/modules/devel/git/ls_remote.lua
+++ b/xmake/modules/devel/git/ls_remote.lua
@@ -42,10 +42,7 @@ import("lib.detect.find_tool")
function main(reftype, url)
-- find git
- local git = find_tool("git")
- if not git then
- return
- end
+ local git = assert(find_tool("git"), "git not found!")
-- init reference type
reftype = reftype or "refs"
diff --git a/xmake/modules/devel/git/pull.lua b/xmake/modules/devel/git/pull.lua
index 4c274a70b..6be175bf9 100644
--- a/xmake/modules/devel/git/pull.lua
+++ b/xmake/modules/devel/git/pull.lua
@@ -41,10 +41,7 @@ function main(opt)
opt = opt or {}
-- find git
- local git = find_tool("git")
- if not git then
- return
- end
+ local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {"pull"}
diff --git a/xmake/modules/devel/git/submodule/update.lua b/xmake/modules/devel/git/submodule/update.lua
index 403bf112d..c73880c0a 100644
--- a/xmake/modules/devel/git/submodule/update.lua
+++ b/xmake/modules/devel/git/submodule/update.lua
@@ -41,10 +41,7 @@ function main(opt)
opt = opt or {}
-- find git
- local git = find_tool("git")
- if not git then
- return
- end
+ local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {"submodule", "update"}
diff --git a/xmake/modules/devel/git/tags.lua b/xmake/modules/devel/git/tags.lua
index 0d28af9e0..84a9a6df1 100644
--- a/xmake/modules/devel/git/tags.lua
+++ b/xmake/modules/devel/git/tags.lua
@@ -37,7 +37,5 @@ import("ls_remote")
-- @endcode
--
function main(url)
-
- -- get tags
return ls_remote("tags", url)
end
diff --git a/xmake/modules/private/action/require/packagenv.lua b/xmake/modules/private/action/require/packagenv.lua
new file mode 100644
index 000000000..dd95eff7e
--- /dev/null
+++ b/xmake/modules/private/action/require/packagenv.lua
@@ -0,0 +1,82 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file packagenv.lua
+--
+
+-- imports
+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
+ oldenvs.PATH = os.getenv("PATH")
+ 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
+ end
+ else
+ os.addenv(name, unpack(table.wrap(values)))
+ end
+ 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(...)
+ 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)
+ if manifest and manifest.plat == os.host() and manifest.arch == os.arch() then
+ _enter_package(name, manifest.envs, path.directory(manifest_file))
+ end
+ end
+ end
+end
+
+-- leave environment of the given binary packages, git, 7z, ..
+function leave(...)
+ for _, name in ipairs({...}) do
+ _leave_package(name)
+ end
+end