summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-09-04 16:46:30 +0800
committerruki <[email protected]>2017-09-04 16:46:30 +0800
commit4fead28a91b650fd7268e708afdf4dc97935d454 (patch)
treeacbc0c9f1e34689d8b3858f76acfd87861bf2499
parent08ec1c7dcab891641f6b2fb6a61c2c3b210f5f55 (diff)
add require to build and optmize ping
-rw-r--r--xmake/actions/build/main.lua3
-rw-r--r--xmake/actions/config/main.lua8
-rw-r--r--xmake/actions/require/install.lua16
-rw-r--r--xmake/actions/require/repository.lua58
-rw-r--r--xmake/core/package/package.lua2
-rw-r--r--xmake/modules/net/fasturl.lua4
-rw-r--r--xmake/modules/net/ping.lua58
-rw-r--r--xmake/plugins/repo/main.lua65
-rw-r--r--xmake/plugins/repo/xmake.lua22
9 files changed, 145 insertions, 91 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 6206e5e4e..4f8fc4cfd 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -39,6 +39,9 @@ function main()
-- config it first
task.run("config", {target = targetname})
+ -- require all dependences
+ task.run("require")
+
-- enter project directory
local oldir = os.cd(project.directory())
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 054433e89..401015efc 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -140,9 +140,8 @@ end
function main()
-- avoid to run this task repeatly
- if _g.finished then
- return
- end
+ if _g.configured then return end
+ _g.configured = true
-- scan project and generate it if xmake.lua not exists
if not os.isfile(project.file()) then
@@ -284,7 +283,4 @@ function main()
if option.get("verbose") then
config.dump()
end
-
- -- finished
- _g.finished = true
end
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index cd1eda0ba..112cbcd15 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -24,6 +24,7 @@
-- imports
import("core.base.option")
+import("core.base.task")
import("core.project.project")
import("action")
import("package")
@@ -33,15 +34,22 @@ import("environment")
-- install packages
function main(requires)
+ -- init requires
+ requires = requires or project.requires()
+ if not requires or #requires == 0 then
+ return
+ end
+
-- enter environment
environment.enter()
- -- TODO need optimization
- -- pull all repositories first
- repository.pull()
+ -- pull all repositories first if not exists
+ if not repository.exists() then
+ task.run("repo", {update = true})
+ end
-- load packages
- local packages = package.load_packages(requires or project.requires())
+ local packages = package.load_packages(requires)
-- fetch packages from local first
local packages_remote = {}
diff --git a/xmake/actions/require/repository.lua b/xmake/actions/require/repository.lua
index 47953c513..9ded53932 100644
--- a/xmake/actions/require/repository.lua
+++ b/xmake/actions/require/repository.lua
@@ -23,9 +23,7 @@
--
-- imports
-import("core.base.option")
import("core.package.repository")
-import("devel.git")
-- get all repositories
function repositories()
@@ -45,57 +43,15 @@ function repositories()
return repos
end
--- pull repositories
-function pull(position)
-
- -- trace
- printf("updating repositories .. ")
- if option.get("verbose") then
- print("")
- end
-
- -- create a pull task
- local task = function ()
-
- -- pull all repositories
- local pulled = {}
- for _, repo in ipairs(repositories()) do
-
- -- the repository directory
- local repodir = path.join(repository.directory(repo.global), repo.name)
-
- -- remove repeat and only pull the first repository
- if not pulled[repodir] then
- if os.isdir(repodir) then
-
- -- trace
- vprint("pulling repository(%s): %s to %s ..", repo.name, repo.url, repodir)
-
- -- pull it
- git.pull({verbose = option.get("verbose"), branch = "master", repodir = repodir})
- else
- -- trace
- vprint("cloning repository(%s): %s to %s ..", repo.name, repo.url, repodir)
-
- -- clone it
- git.clone(repo.url, {verbose = option.get("verbose"), branch = "master", outputdir = repodir})
- end
-
- -- pull this repository ok
- pulled[repodir] = true
- end
+-- exists repositories
+function exists()
+ for _, repo in ipairs(repositories()) do
+ local repodir = path.join(repository.directory(repo.global), repo.name)
+ if not os.isdir(repodir) then
+ return false
end
end
-
- -- pull repositories
- if option.get("verbose") then
- task()
- else
- process.asyncrun(task)
- end
-
- -- trace
- cprint("${green}ok")
+ return true
end
-- get package directory from repositories
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 5b5597ce9..267594faa 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -249,7 +249,7 @@ function _instance:fetch()
-- find package
self._find_package = self._find_package or import("lib.detect.find_package", {anonymous = true})
- self._FETCHINFO = self._FETCHINFO or self._find_package(self:name(), {packagedirs = self:installdir(), force = true})
+ self._FETCHINFO = self._FETCHINFO or self._find_package(self:name(), {packagedirs = self:installdir()})
return self._FETCHINFO
end
diff --git a/xmake/modules/net/fasturl.lua b/xmake/modules/net/fasturl.lua
index 25ec19a4c..793b9ec9d 100644
--- a/xmake/modules/net/fasturl.lua
+++ b/xmake/modules/net/fasturl.lua
@@ -68,8 +68,8 @@ function sort(urls)
local pinghosts = table.unique(_g._PINGHOSTS or {})
if pinghosts and #pinghosts > 0 then
- -- ping them and test speed
- local pinginfo = ping(unpack(pinghosts))
+ -- ping them and test speed, enable cache by default
+ local pinginfo = ping(pinghosts)
-- merge to ping info
_g._PINGINFO = table.join(_g._PINGINFO or {}, pinginfo)
diff --git a/xmake/modules/net/ping.lua b/xmake/modules/net/ping.lua
index 0026d6da5..48f97e394 100644
--- a/xmake/modules/net/ping.lua
+++ b/xmake/modules/net/ping.lua
@@ -23,24 +23,34 @@
--
-- imports
+import("lib.detect.cache")
import("detect.tools.find_ping")
-- send ping to hosts
--
--- @param ... the hosts
+-- @param hosts the hosts
+-- @param opt the options
--
--- @return the time or -1
+-- @return the time or -1
--
-function main(...)
+function main(hosts, opt)
+
+ -- init options
+ opt = opt or {}
-- find ping
- local ping = find_ping()
+ local ping = find_ping(opt)
if not ping then
return {}
end
+ -- do not force ping? enable cache
+ local cacheinfo = nil
+ if not opt.force then
+ cacheinfo = cache.load("net.ping")
+ end
+
-- run tasks
- local hosts = {...}
local results = {}
process.runjobs(function (index)
local host = hosts[index]
@@ -49,24 +59,42 @@ function main(...)
{
function ()
- -- ping it
- local data = nil
- if os.host() == "windows" then
- data = os.iorun("%s -n 1 %s", ping, host)
- else
- data = os.iorun("%s -c 1 %s", ping, host)
+ -- get time value from cache first
+ local timeval = nil
+ if cacheinfo then
+ timeval = cacheinfo[host]
end
+ if timeval then
+ results[host] = timeval
+ else
+ -- ping it
+ local data = nil
+ if os.host() == "windows" then
+ data = os.iorun("%s -n 1 %s", ping, host)
+ else
+ data = os.iorun("%s -c 1 %s", ping, host)
+ end
- -- find time
- local time = data:match("time=(.-)ms", 1, true)
- if time then
- results[host] = tonumber(time:trim())
+ -- find time
+ local time = data:match("time=(.-)ms", 1, true)
+ if time then
+ local timeval = tonumber(time:trim())
+ results[host] = timeval
+ if cacheinfo then
+ cacheinfo[host] = timeval
+ end
+ end
end
end
}
end
end, #hosts)
+ -- save cache
+ if cacheinfo then
+ cache.save("net.ping", cacheinfo)
+ end
+
-- ok?
return results
end
diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua
index 565b8edac..344e4eb4e 100644
--- a/xmake/plugins/repo/main.lua
+++ b/xmake/plugins/repo/main.lua
@@ -65,6 +65,62 @@ function _remove(name, is_global)
cprint("${bright}remove %s repository(%s): %s ok!", ifelse(is_global, "global", "local"), name, url)
end
+-- update repositories
+function _update()
+
+ -- trace
+ printf("updating repositories .. ")
+ if option.get("verbose") then
+ print("")
+ end
+
+ -- create a pull task
+ local task = function ()
+
+ -- get all repositories (local first)
+ local repos = table.join(repository.repositories(false), repository.repositories(true))
+
+ -- pull all repositories
+ local pulled = {}
+ for _, repo in ipairs(repos) do
+
+ -- the repository directory
+ local repodir = path.join(repository.directory(repo.global), repo.name)
+
+ -- remove repeat and only pull the first repository
+ if not pulled[repodir] then
+ if os.isdir(repodir) then
+
+ -- trace
+ vprint("pulling repository(%s): %s to %s ..", repo.name, repo.url, repodir)
+
+ -- pull it
+ git.pull({verbose = option.get("verbose"), branch = "master", repodir = repodir})
+ else
+ -- trace
+ vprint("cloning repository(%s): %s to %s ..", repo.name, repo.url, repodir)
+
+ -- clone it
+ git.clone(repo.url, {verbose = option.get("verbose"), branch = "master", outputdir = repodir})
+ end
+
+ -- pull this repository ok
+ pulled[repodir] = true
+ end
+ end
+ end
+
+ -- pull repositories
+ if option.get("verbose") then
+ task()
+ else
+ process.asyncrun(task)
+ end
+
+ -- trace
+ cprint("${green}ok")
+end
+
-- clear all repositories
function _clear(is_global)
@@ -82,7 +138,7 @@ function _clear(is_global)
end
-- list all repositories
-function _list(is_global)
+function _list()
-- list all repositories
local count = 0
@@ -140,6 +196,11 @@ function main()
_remove(option.get("name"), option.get("global"))
+ -- update repository url
+ elseif option.get("update") then
+
+ _update()
+
-- clear all repositories
elseif option.get("clear") then
@@ -148,7 +209,7 @@ function main()
-- list all repositories
elseif option.get("list") then
- _list(option.get("global"))
+ _list()
-- show help
else
diff --git a/xmake/plugins/repo/xmake.lua b/xmake/plugins/repo/xmake.lua
index dafd7ae26..cb15e87fb 100644
--- a/xmake/plugins/repo/xmake.lua
+++ b/xmake/plugins/repo/xmake.lua
@@ -42,13 +42,15 @@ task("repo")
-- options
, options =
{
- {'a', "add", "k", nil, "Add the given remote repository url." }
- , {'r', "remove", "k", nil, "Remove the given remote repository url." }
- , {'l', "list", "k", nil, "List all added repositories." }
- , {'g', "global", "k", nil, "Save repository to global. (default: local)" }
- , {'c', "clear", "k", nil, "Clear all added repositories." }
- , { }
- , {nil, "name", "v", nil, "The repository name." }
- , {nil, "url", "v", nil, "The repository url" }
- }
- }
+ {'a', "add", "k", nil, "Add the given remote repository url." }
+ , {'r', "remove", "k", nil, "Remove the given remote repository url." }
+ , {'u', "update", "k", nil, "Update all local repositories from the remote." }
+ , {'c', "clear", "k", nil, "Clear all added repositories." }
+ , { }
+ , {'l', "list", "k", nil, "List all added repositories." }
+ , {'g', "global", "k", nil, "Save repository to global. (default: local)" }
+ , { }
+ , {nil, "name", "v", nil, "The repository name." }
+ , {nil, "url", "v", nil, "The repository url" }
+ }
+ }