diff options
| author | ruki <[email protected]> | 2019-09-29 08:07:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-09-29 08:07:13 +0800 |
| commit | 07c8483607759f79cb3cfbf7351ee07cc714d8b9 (patch) | |
| tree | bbfa0bddff65cea434a08eab27e240113d1b3f0a | |
| parent | 4df867463bac4c5987441696eabbf6a1f43ea9e4 (diff) | |
load git package env
| -rw-r--r-- | xmake/actions/build/statistics.lua | 20 | ||||
| -rw-r--r-- | xmake/actions/require/impl/environment.lua | 65 | ||||
| -rw-r--r-- | xmake/modules/devel/git/apply.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/branches.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/devel/git/checkout.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/clean.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/clone.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/ls_remote.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/pull.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/submodule/update.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/tags.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/packagenv.lua | 82 |
12 files changed, 108 insertions, 98 deletions
diff --git a/xmake/actions/build/statistics.lua b/xmake/actions/build/statistics.lua index e070f0805..f42eb01af 100644 --- a/xmake/actions/build/statistics.lua +++ b/xmake/actions/build/statistics.lua @@ -24,6 +24,7 @@ import("core.project.config") import("core.platform.platform") import("core.platform.environment") import("private.action.update.fetch_version") +import("private.action.require.packagenv") -- statistics is enabled? function _is_enabled() @@ -109,21 +110,29 @@ function main() -- enter environment environment.enter("toolchains") + -- enter the environments of git + packagenv.enter("git") + -- get the project directory name local projectname = path.basename(os.projectdir()) -- clone the xmake-stats repo to update the traffic(git clones) info in github local outputdir = path.join(os.tmpdir(), "stats", os.date("%y%m%d"), projectname) if not os.isdir(outputdir) then - import("devel.git.clone") - clone("https://github.com/xmake-io/xmake-stats.git", {depth = 1, branch = "master", outputdir = outputdir}) - print("post to traffic ok!") + try + { + function () + import("devel.git.clone") + clone("https://github.com/xmake-io/xmake-stats.git", {depth = 1, branch = "master", outputdir = outputdir}) + print("post to traffic ok!") + end + } end -- fetch the lastest version local versionfile = path.join(os.tmpdir(), "lastest_version") if not os.isfile(versionfile) then - local fetchinfo = fetch_version() + local fetchinfo = try { function () return fetch_version() end } if fetchinfo then io.save(versionfile, fetchinfo) end @@ -137,6 +146,9 @@ function main() print("post to releases ok!") end + -- leave the environments of git + packagenv.leave("git") + -- leave environment environment.leave("toolchains") end diff --git a/xmake/actions/require/impl/environment.lua b/xmake/actions/require/impl/environment.lua index 65d39e52e..bcf2822c4 100644 --- a/xmake/actions/require/impl/environment.lua +++ b/xmake/actions/require/impl/environment.lua @@ -23,68 +23,9 @@ import("core.project.config") import("core.platform.environment") import("core.package.package", {alias = "core_package"}) import("lib.detect.find_tool") +import("private.action.require.packagenv") import("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_packages(...) - 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_packages(...) - for _, name in ipairs({...}) do - _leave_package(name) - end -end - -- enter environment -- -- ensure that we can find some basic tools: git, unzip, ... @@ -102,7 +43,7 @@ function enter() end -- enter the environments of git and 7z - _enter_packages("git", "7z") + packagenv.enter("git", "7z") -- git not found? install it first local packages = {} @@ -132,7 +73,7 @@ function leave() _g._PACKAGES = nil -- leave the environments of git and 7z - _leave_packages("7z", "git") + packagenv.leave("7z", "git") -- restore search pathes of toolchains environment.leave("toolchains") 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 |
