summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-06-23 00:53:36 +0800
committerruki <[email protected]>2020-06-22 23:21:41 +0800
commit5ec511fe879412c905d4b5adc2145600fe9bd8d8 (patch)
tree837906c635e944de935203755583e2c836601d3a
parent38158df077019782c3a56feea4f6f9913b785d1a (diff)
support search packages
-rw-r--r--xmake/actions/config/xmake.lua22
-rw-r--r--xmake/actions/global/xmake.lua20
-rw-r--r--xmake/actions/require/impl/action/download.lua38
-rw-r--r--xmake/actions/require/impl/action/download_resources.lua11
-rw-r--r--xmake/actions/require/info.lua16
-rw-r--r--xmake/core/package/package.lua10
-rw-r--r--xmake/core/sandbox/modules/import/core/package/package.lua5
7 files changed, 98 insertions, 24 deletions
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index 28c6ebb50..c53844e5c 100644
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -43,14 +43,6 @@ task("config")
{
{'c', "clean", "k", nil , "Clean the cached configure and configure all again." }
, {nil, "menu", "k", nil , "Configure project with a menu-driven user interface." }
- , {nil, "require", "kv", nil , "Require all dependent packages?"
- , values = function (complete)
- if complete then
- return {"yes", "no"}
- else
- return {"y: force to enable", "n: disable" }
- end
- end }
, {category = "."}
, {'p', "plat", "kv", "$(subhost)" , "Compile for the given platform."
, values = function (complete, opt)
@@ -128,6 +120,20 @@ task("config")
, values = {"static", "shared", "binary"} }
, {nil, "host", "kv", "$(host)" , "The Current Host Environment." }
+ -- package configuration
+ , {category = "Package Configuration"}
+ , {nil, "require", "kv", nil , "Require all dependent packages?"
+ , values = function (complete)
+ if complete then
+ return {"yes", "no"}
+ else
+ return {"y: force to enable", "n: disable" }
+ end
+ end }
+ , {nil, "pkg_searchdirs", "kv", nil , "The search directories of the remote package."
+ , " e.g."
+ , " - xmake f --pkg_searchdirs=/dir1" .. path.envsep() .. "/dir2"}
+
-- show project menu options
, function ()
diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua
index f294d2804..89293e75e 100644
--- a/xmake/actions/global/xmake.lua
+++ b/xmake/actions/global/xmake.lua
@@ -41,15 +41,21 @@ task("global")
-- options
, options =
{
- {'c', "clean", "k" , nil , "Clean the cached configure and configure all again." }
- , {nil, "menu", "k" , nil , "Configure with a menu-driven user interface." }
-
+ {'c', "clean", "k" , nil , "Clean the cached configure and configure all again." }
+ , {nil, "menu", "k" , nil , "Configure with a menu-driven user interface." }
, {category = "."}
- , {nil, "theme", "kv", "default" , "The theme name."
- , values = function ()
+ , {nil, "theme", "kv", "default" , "The theme name."
+ , values = function ()
return import("core.theme.theme.names")()
- end }
- , {nil, "debugger", "kv", "auto" , "The Debugger Program Path." }
+ end}
+ , {nil, "debugger", "kv", "auto" , "The debugger program path." }
+
+ -- package configuration
+ , {category = "Package Configuration"}
+ , {nil, "pkg_searchdirs", "kv", nil , "The search directories of the remote package."
+ , " e.g."
+ , " - xmake g --pkg_searchdirs=/dir1" .. path.envsep() .. "/dir2"}
+ , {nil, "pkg_installdir", "kv", nil , "The install root directory of the remote package." }
-- show platform menu options
, {category = "Platform Configuration"}
diff --git a/xmake/actions/require/impl/action/download.lua b/xmake/actions/require/impl/action/download.lua
index c958180a3..cb973ba3b 100644
--- a/xmake/actions/require/impl/action/download.lua
+++ b/xmake/actions/require/impl/action/download.lua
@@ -21,7 +21,11 @@
-- imports
import("core.base.option")
import("core.base.tty")
+import("core.base.hashset")
import("core.project.config")
+import("core.package.package", {alias = "core_package"})
+import("lib.detect.find_file")
+import("lib.detect.find_directory")
import(".utils.filter")
import("net.http")
import("devel.git")
@@ -41,6 +45,14 @@ function _checkout(package, url, sourcedir, url_alias)
return
end
+ -- we can use local package from the search directories directly if network is too slow
+ local localdir = find_directory(package:name() .. archive.extension(url), core_package.searchdirs())
+ if localdir and os.isdir(localdir) then
+ git.clean({repodir = localdir, force = true})
+ tty.erase_line_to_start().cr()
+ return
+ end
+
-- remove temporary directory
os.rm(sourcedir .. ".tmp")
@@ -91,11 +103,11 @@ function _download(package, url, sourcedir, url_alias, url_excludes)
os.tryrm(packagefile)
-- download or copy package file
- local localfile = path.join(config.buildir(), path.filename(packagefile))
+ local localfile = find_file(path.filename(packagefile), core_package.searchdirs())
if os.isfile(url) then
os.cp(url, packagefile)
- elseif os.isfile(localfile) then
- -- we can download package to build/filename manually if network is too slow
+ elseif localfile and os.isfile(localfile) then
+ -- we can use local package from the search directories directly if network is too slow
os.cp(localfile, packagefile)
else
http.download(url, packagefile)
@@ -107,7 +119,6 @@ function _download(package, url, sourcedir, url_alias, url_excludes)
end
end
- print(os.curdir(), os.isdir(sourcedir .. ".tmp"))
-- extract package file
os.rm(sourcedir .. ".tmp")
if archive.extract(packagefile, sourcedir .. ".tmp", {excludes = url_excludes}) then
@@ -170,6 +181,7 @@ function main(package)
-- download package from urls
local ok = false
+ local urls_failed = {}
for idx, url in ipairs(urls) do
-- get url alias
@@ -212,11 +224,27 @@ function main(package)
cprint("${yellow} => ${clear}clone %s %s .. ${color.failure}${text.failure}", url, package:version_str())
else
cprint("${yellow} => ${clear}download %s .. ${color.failure}${text.failure}", url)
- wprint("we can also download ${bright}%s${clear} to ${bright}$(buildir)/%s${clear} manually and try it again!", url, package:name() .. "-" .. package:version_str() .. archive.extension(url))
end
+ table.insert(urls_failed, url)
-- failed? break it
if idx == #urls and not package:optional() then
+ if #urls_failed > 0 then
+ print("")
+ print("we can also download these packages manually:")
+ local searchnames = hashset.new()
+ for _, url_failed in ipairs(urls_failed) do
+ cprint(" ${yellow}- %s", url_failed)
+ if git.checkurl(url_failed) then
+ searchnames:insert(package:name() .. archive.extension(url_failed))
+ else
+ searchnames:insert(package:name() .. "-" .. package:version_str() .. archive.extension(url_failed))
+ end
+ end
+ cprint("to the local search directories: ${bright}%s", table.concat(table.wrap(core_package.searchdirs()), path.envsep()))
+ cprint(" ${bright}- %s", table.concat(searchnames:to_array(), ", "))
+ cprint("and we can run `xmake g --pkg_searchdirs=/xxx` to set the search directories.")
+ end
raise("download failed!")
end
end
diff --git a/xmake/actions/require/impl/action/download_resources.lua b/xmake/actions/require/impl/action/download_resources.lua
index 7371f270f..df560b3d3 100644
--- a/xmake/actions/require/impl/action/download_resources.lua
+++ b/xmake/actions/require/impl/action/download_resources.lua
@@ -20,6 +20,8 @@
-- imports
import("core.base.option")
+import("core.package.package", {alias = "core_package"})
+import("lib.detect.find_file")
import("net.http")
import("utils.archive")
@@ -42,8 +44,12 @@ function _download(package, resource_name, resource_url, resource_hash)
-- attempt to remove the previous file first
os.tryrm(resource_file)
- -- download the resource file
- if resource_url:find(string.ipattern("https-://")) or resource_url:find(string.ipattern("ftps-://")) then
+ -- download or copy the resource file
+ local localfile = find_file(path.filename(resource_file), core_package.searchdirs())
+ if localfile and os.isfile(localfile) then
+ -- we can use local resource from the search directories directly if network is too slow
+ os.cp(localfile, resource_file)
+ elseif resource_url:find(string.ipattern("https-://")) or resource_url:find(string.ipattern("ftps-://")) then
http.download(resource_url, resource_file)
else
raise("invalid resource url(%s)", resource_url)
@@ -70,7 +76,6 @@ end
-- download all resources of the given package
function main(package)
-
-- no resources?
local resources = package:resources()
if not resources then
diff --git a/xmake/actions/require/info.lua b/xmake/actions/require/info.lua
index c6b3f6995..f0a7ba939 100644
--- a/xmake/actions/require/info.lua
+++ b/xmake/actions/require/info.lua
@@ -21,7 +21,11 @@
-- imports
import("core.base.task")
import("core.base.option")
+import("core.base.hashset")
import("core.project.project")
+import("core.package.package", {alias = "core_package"})
+import("devel.git")
+import("utils.archive")
import("impl.utils.filter")
import("impl.package")
import("impl.repository")
@@ -133,6 +137,18 @@ function main(requires_raw)
-- show install directory
cprint(" -> ${magenta}installdir${clear}: %s", instance:installdir())
+ -- show search directories and search names
+ cprint(" -> ${magenta}searchdirs${clear}: %s", table.concat(table.wrap(core_package.searchdirs()), path.envsep()))
+ local searchnames = hashset.new()
+ for _, url in ipairs(instance:urls()) do
+ if git.checkurl(url) then
+ searchnames:insert(instance:name() .. archive.extension(url))
+ else
+ searchnames:insert(instance:name() .. "-" .. instance:version_str() .. archive.extension(url))
+ end
+ end
+ cprint(" -> ${magenta}searchnames${clear}: %s", table.concat(searchnames:to_array(), ", "))
+
-- show fetch info
cprint(" -> ${magenta}fetchinfo${clear}: %s", _info(instance))
local fetchinfo = instance:fetch()
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 5dabc8f0b..f31abcc6e 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1163,7 +1163,15 @@ end
-- the install directory
function package.installdir()
- return path.join(global.directory(), "packages")
+ return global.get("pkg_installdir") or path.join(global.directory(), "packages")
+end
+
+-- the search directories
+function package.searchdirs()
+ local searchdirs = global.get("pkg_searchdirs")
+ if searchdirs then
+ return path.splitenv(searchdirs)
+ end
end
-- load the package from the system directories
diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua
index 5d37554da..13bc1a900 100644
--- a/xmake/core/sandbox/modules/import/core/package/package.lua
+++ b/xmake/core/sandbox/modules/import/core/package/package.lua
@@ -36,6 +36,11 @@ function sandbox_core_package_package.installdir()
return package.installdir()
end
+-- the search directories
+function sandbox_core_package_package.searchdirs()
+ return package.searchdirs()
+end
+
-- load the package from the project file
function sandbox_core_package_package.load_from_project(packagename)