summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-09-27 23:19:51 +0800
committerruki <[email protected]>2017-09-27 13:59:10 +0800
commitbee50fa70e44973ff43d2c6adeb96a18f4b38148 (patch)
treed70e4d2a28216793d65c0f79e936fcad5b71b17b
parentca581595f689b8ec3de720560ab3946745889936 (diff)
fix repo environment
-rw-r--r--xmake/actions/require/environment.lua7
-rw-r--r--xmake/actions/require/install.lua130
-rw-r--r--xmake/actions/require/package.lua156
-rw-r--r--xmake/packages/git/xmake.lua8
-rw-r--r--xmake/plugins/repo/main.lua13
5 files changed, 164 insertions, 150 deletions
diff --git a/xmake/actions/require/environment.lua b/xmake/actions/require/environment.lua
index bbbe1e587..7c6bdfc68 100644
--- a/xmake/actions/require/environment.lua
+++ b/xmake/actions/require/environment.lua
@@ -24,6 +24,8 @@
-- imports
import("core.platform.environment")
+import("lib.detect.find_tool")
+import("package")
-- enter environment
--
@@ -36,6 +38,11 @@ function enter()
-- set search pathes of toolchains
environment.enter("toolchains")
+ -- git not found? install it first
+ if not find_tool("git") then
+ package.install_packages("git")
+ end
+
-- TODO set toolchains for CC, LD, ..
-- TODO set flags of toolchains
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index 83b76babf..83dc402a0 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -27,7 +27,6 @@ import("core.base.option")
import("core.base.task")
import("core.project.project")
import("lib.detect.find_tool")
-import("action")
import("package")
import("repository")
import("environment")
@@ -98,124 +97,6 @@ function _check_missing_packages(packages)
_g.optional_missing = optional_missing
end
--- get user confirm
-function _get_confirm(packages)
-
- -- init confirmed packages
- local confirmed_packages = {}
- for _, instance in ipairs(packages) do
- if (option.get("force") or not instance:exists()) and (#instance:urls() > 0 or instance:script("install")) then
- table.insert(confirmed_packages, instance)
- end
- end
- if #confirmed_packages == 0 then
- return true
- end
-
- -- get confirm
- local confirm = option.get("yes")
- if confirm == nil then
-
- -- show tips
- cprint("${bright yellow}note: ${default yellow}try installing all required packages (pass -y to skip confirm)?")
- for _, instance in ipairs(confirmed_packages) do
- print(" -> %s %s", instance:fullname(), instance:version_str() or "")
- end
- cprint("please input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
-
- -- ok?
- return confirm
-end
-
--- install packages
-function _install_packages(requires, requires_extra)
-
- -- pull all repositories first if not exists
- --
- -- attempt to install git from the builtin-packages first if git not found
- --
- if find_tool("git") and not repository.pulled() then
- task.run("repo", {update = true})
- end
-
- -- load packages
- local packages = package.load_packages(requires, requires_extra)
-
- -- fetch packages from local first
- local packages_remote = {}
- if option.get("force") then
- for _, instance in ipairs(packages) do
- if instance and #instance:urls() > 0 then
- table.insert(packages_remote, instance)
- end
- end
- else
- process.runjobs(function (index)
- local instance = packages[index]
- if instance and not instance:fetch() and #instance:urls() > 0 then -- @note fetch first for only system packge
- table.insert(packages_remote, instance)
- end
- end, #packages)
- end
-
- -- get user confirm
- if not _get_confirm(packages) then
- return
- end
-
- -- download remote packages
- local waitindex = 0
- local waitchars = {'\\', '|', '/', '-'}
- process.runjobs(function (index)
-
- local instance = packages_remote[index]
- if instance then
- action.download(instance)
- end
-
- end, #packages_remote, ifelse(option.get("verbose"), 1, 4), 300, function (indices)
-
- -- do not print progress info if be verbose
- if option.get("verbose") then
- return
- end
-
- -- update waitchar index
- waitindex = ((waitindex + 1) % #waitchars)
-
- -- make downloading packages list
- local downloading = {}
- for _, index in ipairs(indices) do
- local instance = packages_remote[index]
- if instance then
- table.insert(downloading, instance:fullname())
- end
- end
-
- -- trace
- cprintf("\r${yellow} => ${clear}downloading %s .. %s", table.concat(downloading, ", "), waitchars[waitindex + 1])
- io.flush()
- end)
-
- -- install all required packages from repositories
- for _, instance in ipairs(packages) do
- if (option.get("force") or not instance:exists()) and (#instance:urls() > 0 or instance:script("install")) then
- action.install(instance)
- end
- end
-
- -- ok
- return packages
-end
-
-- install packages
function main(requires)
@@ -235,13 +116,16 @@ function main(requires)
-- enter environment
environment.enter()
- -- git not found? install it first
- if not find_tool("git") then
- _install_packages("git")
+ -- pull all repositories first if not exists
+ --
+ -- attempt to install git from the builtin-packages first if git not found
+ --
+ if find_tool("git") and not repository.pulled() then
+ task.run("repo", {update = true})
end
-- install packages
- local packages = _install_packages(requires, requires_extra)
+ local packages = package.install_packages(requires, requires_extra)
if packages then
-- check missing packages
diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua
index 26b5954c6..06ec16d34 100644
--- a/xmake/actions/require/package.lua
+++ b/xmake/actions/require/package.lua
@@ -29,6 +29,7 @@ import("core.base.global")
import("core.project.cache")
import("core.project.project")
import("core.package.package", {alias = "core_package"})
+import("action")
import("devel.git")
import("net.fasturl")
import("repository")
@@ -129,22 +130,22 @@ function _parse_require(require_str, requires_extra)
return required.packagename, required.requireinfo
end
--- load package instance from the given package url
+-- load package package from the given package url
function _load_package_from_url(packagename, packageurl)
return core_package.load_from_url(packagename, packageurl)
end
--- load package instance from system
+-- load package package from system
function _load_package_from_system(packagename)
return core_package.load_from_system(packagename)
end
--- load package instance from project
+-- load package package from project
function _load_package_from_project(packagename)
return core_package.load_from_project(packagename)
end
--- load package instance from repositories
+-- load package package from repositories
function _load_package_from_repository(packagename, reponame)
-- get package directory from the given package name
@@ -160,51 +161,51 @@ function _load_package(packagename, requireinfo)
-- attempt to get it from cache first
local packages = _g._PACKAGES or {}
- local instance = packages[packagename]
- if instance then
+ local package = packages[packagename]
+ if package then
-- satisfy required version?
- local version_str = instance:version_str()
+ local version_str = package:version_str()
if version_str and not semver.satisfies(version_str, requireinfo.version) then
raise("package(%s): version conflict, '%s' does not satisfy '%s'!", packagename, version_str, requireinfo.version)
end
-- ok
- return instance
+ return package
end
- -- load package instance
- instance = nil
+ -- load package package
+ package = nil
if requireinfo.packageurl then
-- load package from the given package url
- instance = _load_package_from_url(packagename, requireinfo.packageurl)
+ package = _load_package_from_url(packagename, requireinfo.packageurl)
else
-- load package from project first
- instance = _load_package_from_project(packagename)
+ package = _load_package_from_project(packagename)
-- load package from repositories
- if not instance then
- instance = _load_package_from_repository(packagename, requireinfo.reponame)
+ if not package then
+ package = _load_package_from_repository(packagename, requireinfo.reponame)
end
-- load package from system
- if not instance then
- instance = _load_package_from_system(packagename)
+ if not package then
+ package = _load_package_from_system(packagename)
end
end
-- check
- assert(instance, "package(%s) not found!", packagename)
+ assert(package, "package(%s) not found!", packagename)
-- save require info to package
- instance:requireinfo_set(requireinfo)
+ package:requireinfo_set(requireinfo)
- -- save this package instance to cache
- packages[packagename] = instance
+ -- save this package package to cache
+ packages[packagename] = package
_g._PACKAGES = packages
-- ok
- return instance
+ return package
end
-- sort package deps
@@ -233,7 +234,7 @@ function _load_packages(requires, requires_extra)
local packageopt = project.option(packagename)
if packageopt == nil or packageopt:enabled() then -- this package is enabled?
- -- load package instance
+ -- load package package
local package = _load_package(packagename, requireinfo)
-- maybe package not found and optional
@@ -251,7 +252,7 @@ function _load_packages(requires, requires_extra)
package._ORDERDEPS = table.unique(_sort_packagedeps(package))
end
- -- save this package instance
+ -- save this package package
table.insert(packages, package)
end
end
@@ -359,6 +360,43 @@ function _select_packages_version(packages)
end
end
+-- get user confirm
+function _get_confirm(packages)
+
+ -- init confirmed packages
+ local confirmed_packages = {}
+ for _, package in ipairs(packages) do
+ if (option.get("force") or not package:exists()) and (#package:urls() > 0 or package:script("install")) then
+ table.insert(confirmed_packages, package)
+ end
+ end
+ if #confirmed_packages == 0 then
+ return true
+ end
+
+ -- get confirm
+ local confirm = option.get("yes")
+ if confirm == nil then
+
+ -- show tips
+ cprint("${bright yellow}note: ${default yellow}try installing all required packages (pass -y to skip confirm)?")
+ for _, package in ipairs(confirmed_packages) do
+ print(" -> %s %s", package:fullname(), package:version_str() or "")
+ end
+ cprint("please input: y (y/n)")
+
+ -- get answer
+ io.flush()
+ local answer = io.read()
+ if answer == 'y' or answer == '' then
+ confirm = true
+ end
+ end
+
+ -- ok?
+ return confirm
+end
+
-- the cache directory
function cachedir()
return path.join(global.directory(), "cache", "packages")
@@ -398,3 +436,75 @@ function load_packages(requires, requires_extra)
return packages
end
+-- install packages
+function install_packages(requires, requires_extra)
+
+ -- load packages
+ local packages = load_packages(requires, requires_extra)
+
+ -- fetch packages from local first
+ local packages_remote = {}
+ if option.get("force") then
+ for _, package in ipairs(packages) do
+ if package and #package:urls() > 0 then
+ table.insert(packages_remote, package)
+ end
+ end
+ else
+ process.runjobs(function (index)
+ local package = packages[index]
+ if package and not package:fetch() and #package:urls() > 0 then -- @note fetch first for only system packge
+ table.insert(packages_remote, package)
+ end
+ end, #packages)
+ end
+
+ -- get user confirm
+ if not _get_confirm(packages) then
+ return
+ end
+
+ -- download remote packages
+ local waitindex = 0
+ local waitchars = {'\\', '|', '/', '-'}
+ process.runjobs(function (index)
+
+ local package = packages_remote[index]
+ if package then
+ action.download(package)
+ end
+
+ end, #packages_remote, ifelse(option.get("verbose"), 1, 4), 300, function (indices)
+
+ -- do not print progress info if be verbose
+ if option.get("verbose") then
+ return
+ end
+
+ -- update waitchar index
+ waitindex = ((waitindex + 1) % #waitchars)
+
+ -- make downloading packages list
+ local downloading = {}
+ for _, index in ipairs(indices) do
+ local package = packages_remote[index]
+ if package then
+ table.insert(downloading, package:fullname())
+ end
+ end
+
+ -- trace
+ cprintf("\r${yellow} => ${clear}downloading %s .. %s", table.concat(downloading, ", "), waitchars[waitindex + 1])
+ io.flush()
+ end)
+
+ -- install all required packages from repositories
+ for _, package in ipairs(packages) do
+ if (option.get("force") or not package:exists()) and (#package:urls() > 0 or package:script("install")) then
+ action.install(package)
+ end
+ end
+
+ -- ok
+ return packages
+end
diff --git a/xmake/packages/git/xmake.lua b/xmake/packages/git/xmake.lua
index 77e8575c2..5c7bfbfe9 100644
--- a/xmake/packages/git/xmake.lua
+++ b/xmake/packages/git/xmake.lua
@@ -7,14 +7,14 @@ package("git")
if os.host() == "windows" then
if os.arch() == "x64" then
- add_urls("https://coding.net/u/waruqi/p/xmake-win64env/git/archive/$(version).zip", {alias = "coding"})
+-- add_urls("https://coding.net/u/waruqi/p/xmake-win64env/git/archive/$(version).zip", {alias = "coding"})
add_urls("https://github.com/tboox/xmake-win64env/archive/$(version).zip", {alias = "github"})
- add_sha256s("[email protected]", "1071c5e43613ff591bad7f5ad90fe1621a070cf20c56f06d5177e095f88c9a74")
+-- add_sha256s("[email protected]", "1071c5e43613ff591bad7f5ad90fe1621a070cf20c56f06d5177e095f88c9a74")
add_sha256s("[email protected]", "95170b1d144ebb30961611fd87b1e9404bbe37d2d904adb15f3e202bb3e19c21")
else
- add_urls("https://coding.net/u/waruqi/p/xmake-win32env/git/archive/$(version).zip", {alias = "coding"})
+-- add_urls("https://coding.net/u/waruqi/p/xmake-win32env/git/archive/$(version).zip", {alias = "coding"})
add_urls("https://github.com/tboox/xmake-win32env/archive/$(version).zip", {alias = "github"})
- add_sha256s("[email protected]", "de8623309f956619f70a8681201ecacfb99b7694070b63c4d53756de8855697e")
+-- add_sha256s("[email protected]", "de8623309f956619f70a8681201ecacfb99b7694070b63c4d53756de8855697e")
add_sha256s("[email protected]", "3c46983379329a246596a2b5f0ff971b55e3eccbbfd34272e7121e13fb346db5")
end
else
diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua
index 344e4eb4e..e80bad1c2 100644
--- a/xmake/plugins/repo/main.lua
+++ b/xmake/plugins/repo/main.lua
@@ -29,6 +29,7 @@ import("core.project.project")
import("core.platform.platform")
import("core.package.repository")
import("devel.git")
+import("actions.require.environment", {rootdir = os.programdir()})
-- add repository url
function _add(name, url, is_global)
@@ -42,11 +43,17 @@ function _add(name, url, is_global)
os.rmdir(repodir)
end
+ -- enter environment
+ environment.enter()
+
-- clone repository
git.clone(url, {verbose = option.get("verbose"), branch = "master", outputdir = repodir})
-- trace
cprint("${bright}add %s repository(%s): %s ok!", ifelse(is_global, "global", "local"), name, url)
+
+ -- leave environment
+ environment.leave()
end
-- remove repository url
@@ -68,6 +75,9 @@ end
-- update repositories
function _update()
+ -- enter environment
+ environment.enter()
+
-- trace
printf("updating repositories .. ")
if option.get("verbose") then
@@ -117,6 +127,9 @@ function _update()
process.asyncrun(task)
end
+ -- leave environment
+ environment.leave()
+
-- trace
cprint("${green}ok")
end