diff options
| author | ruki <[email protected]> | 2017-08-30 11:11:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-08-30 11:11:52 +0800 |
| commit | 28e152d756f81976c035ca7db8e1017c6463928c (patch) | |
| tree | 77d07192bf3256f0a4097a0874672e6e71a5a1d9 | |
| parent | a08ffe4df25199ca038a768d5dfae96a2a54ee41 (diff) | |
fetch local installed packages
| -rw-r--r-- | xmake/actions/require/action/build.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/require/action/download.lua | 9 | ||||
| -rw-r--r-- | xmake/actions/require/action/install.lua | 12 | ||||
| -rw-r--r-- | xmake/actions/require/install.lua | 31 | ||||
| -rw-r--r-- | xmake/actions/require/package.lua | 10 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 49 |
6 files changed, 75 insertions, 38 deletions
diff --git a/xmake/actions/require/action/build.lua b/xmake/actions/require/action/build.lua index 8c2f7ddb4..1ae65a8b4 100644 --- a/xmake/actions/require/action/build.lua +++ b/xmake/actions/require/action/build.lua @@ -148,7 +148,7 @@ function _on_build_package(package) end -- failed - raise("attempt to build package %s failed!", package:name()) + raise("attempt to build package %s failed!", package:fullname()) end -- run script diff --git a/xmake/actions/require/action/download.lua b/xmake/actions/require/action/download.lua index 1b6192793..51d8bc91b 100644 --- a/xmake/actions/require/action/download.lua +++ b/xmake/actions/require/action/download.lua @@ -46,7 +46,7 @@ end function _checkout(package, url, sourcedir) -- use previous source directory if exists - local packagedir = path.join(sourcedir, package:name()) + local packagedir = path.join(sourcedir, package:fullname()) if os.isdir(packagedir) and not option.get("force") then -- clean the previous build files @@ -58,7 +58,7 @@ function _checkout(package, url, sourcedir) os.rm(sourcedir .. ".tmp") -- download package from branches? - packagedir = path.join(sourcedir .. ".tmp", package:name()) + packagedir = path.join(sourcedir .. ".tmp", package:fullname()) if package:version_from("branches") then -- only shadow clone this branch @@ -140,11 +140,6 @@ end -- download the given package function main(package) - -- skip phony package without urls - if #package:urls() == 0 then - return - end - -- get working directory of this package local workdir = package:cachedir() diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua index 2db3f01b8..ce87f9c35 100644 --- a/xmake/actions/require/action/install.lua +++ b/xmake/actions/require/action/install.lua @@ -171,17 +171,12 @@ function _on_install_package(package) end -- failed - raise("attempt to install package %s failed!", package:name()) + raise("attempt to install package %s failed!", package:fullname()) end -- install the given package function main(package) - -- skip phony package without urls - if #package:urls() == 0 then - return - end - -- get working directory of this package local workdir = package:cachedir() @@ -193,7 +188,7 @@ function main(package) end -- trace - cprintf("${yellow} => ${clear}installing %s-%s .. ", package:name(), package:version_str()) + cprintf("${yellow} => ${clear}installing %s-%s .. ", package:fullname(), package:version_str()) if option.get("verbose") then print("") end @@ -233,6 +228,9 @@ function main(package) process.asyncrun(installtask) end + -- fetch package + assert(package:fetch(), "fetch %s-%s failed!", package:fullname(), package:version_str()) + -- trace cprint("${green}ok") end, diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua index 4ea72fdad..cd1eda0ba 100644 --- a/xmake/actions/require/install.lua +++ b/xmake/actions/require/install.lua @@ -43,19 +43,34 @@ function main(requires) -- load packages local packages = package.load_packages(requires or project.requires()) - -- download packages + -- fetch packages from local first + local packages_remote = {} + if option.get("force") then + for _, instance in ipairs(packages) do + if instance and not instance:phony() then + table.insert(packages_remote, instance) + end + end + else + process.runjobs(function (index) + local instance = packages[index] + if instance and not instance:phony() and not instance:fetch() then + table.insert(packages_remote, instance) + end + end, #packages) + end + + -- download remote packages local waitindex = 0 local waitchars = {'\\', '|', '/', '-'} process.runjobs(function (index) - local instance = packages[index] + local instance = packages_remote[index] if instance then - - -- download package action.download(instance) end - end, #packages, ifelse(option.get("verbose"), 1, 4), 300, function (indices) + 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 @@ -68,9 +83,9 @@ function main(requires) -- make downloading packages list local downloading = {} for _, index in ipairs(indices) do - local instance = packages[index] + local instance = packages_remote[index] if instance then - table.insert(downloading, instance:name()) + table.insert(downloading, instance:fullname()) end end @@ -80,7 +95,7 @@ function main(requires) end) -- install all required packages from repositories - for _, instance in ipairs(packages) do + for _, instance in ipairs(packages_remote) do action.install(instance) end diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua index 09346b64b..3b872d800 100644 --- a/xmake/actions/require/package.lua +++ b/xmake/actions/require/package.lua @@ -251,9 +251,9 @@ function _load_packages_gitrefs(packages) if package then -- attempt to get refs from cache first - local refs = gitrefs[package:name()] + local refs = gitrefs[package:fullname()] if refs then - results[package:name()] = {tags = refs.tags, branches = refs.branches} + results[package:fullname()] = {tags = refs.tags, branches = refs.branches} else -- attempt to get refs from the git url local tags = {} @@ -265,10 +265,10 @@ function _load_packages_gitrefs(packages) tags, branches = git.refs(url) -- save result - results[package:name()] = {tags = tags, branches = branches} + results[package:fullname()] = {tags = tags, branches = branches} -- cache result - gitrefs[package:name()] = {tags = tags, branches = branches} + gitrefs[package:fullname()] = {tags = tags, branches = branches} break end end @@ -293,7 +293,7 @@ function _select_package_version(package, required_ver, gitrefs) -- attempt to get tags and branches from the git url local refs = {} if gitrefs then - refs = gitrefs[package:name()] or {} + refs = gitrefs[package:fullname()] or {} end -- select required version diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index a79a7753c..5b5597ce9 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -39,6 +39,7 @@ local sandbox = require("sandbox/sandbox") local config = require("project/config") local project = require("project/project") local platform = require("platform/platform") +local import = require("sandbox/modules/import") -- new an instance function _instance.new(name, info, rootdir) @@ -46,8 +47,13 @@ function _instance.new(name, info, rootdir) -- new an instance local instance = table.inherit(_instance) + -- parse name .e.g vendor.name + local nameinfo = name:split("%.") + -- init instance - instance._NAME = name + instance._FULLNAME = name + instance._NAME = nameinfo[2] or name + instance._VENDOR = nameinfo[1] instance._INFO = info instance._ROOTDIR = rootdir instance._FILTER = filter.new() @@ -82,11 +88,21 @@ function _instance:get(name) end end --- get the package name +-- get the package full name with vendor +function _instance:fullname() + return self._FULLNAME +end + +-- get the package name without vendor function _instance:name() return self._NAME end +-- get the package vendor +function _instance:vendor() + return self._VENDOR +end + -- get the package filter function _instance:filter() return self._FILTER @@ -102,6 +118,11 @@ function _instance:urls_set(urls) self._URLS = urls end +-- phony package? +function _instance:phony() + return #self:urls() == 0 +end + -- get sha256 function _instance:sha256() @@ -134,32 +155,26 @@ end -- is optional package? function _instance:optional() - - -- optional? return self._REQUIREINFO.mode == "optional" end -- get the cached directory of this package function _instance:cachedir() - return path.join(package.cachedir(), self:name() .. "-" .. (self:version_str() or "group")) + return path.join(package.cachedir(), self:fullname() .. "-" .. (self:version_str() or "group")) end -- get the installed directory of this package function _instance:installdir() - return path.join(package.installdir(self:global()), self:name() .. "-" .. (self:version_str() or "group")) + return path.join(package.installdir(self:global()), self:fullname() .. "-" .. (self:version_str() or "group")) end -- get the version function _instance:version() - - -- get it return self._VERSION or {} end -- get the version string function _instance:version_str() - - -- get it return self:version().raw or self:version().version end @@ -229,6 +244,20 @@ function _instance:script(name, generic) return generic end +-- fetch package info from the local packages +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}) + return self._FETCHINFO +end + +-- exists this package in local +function _instance:exists() + return self._FETCHINFO +end + -- the interpreter function package._interpreter() |
