diff options
| author | ruki <[email protected]> | 2018-08-25 00:51:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-08-24 23:11:25 +0800 |
| commit | 3834432a2fa50afc439288a4f7862261aedf41ae (patch) | |
| tree | 6080893188bc4791e3044fa1b53f4c95a2e77ee9 | |
| parent | e00c2e6bbc3b363f191e514dc553ac6041fe2e0e (diff) | |
improve to load repo and package
| -rw-r--r-- | xmake/actions/require/package.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/require/repository.lua | 55 | ||||
| -rw-r--r-- | xmake/actions/require/search.lua | 3 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 12 | ||||
| -rw-r--r-- | xmake/core/package/repository.lua | 43 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/package/package.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/package/repository.lua | 8 | ||||
| -rw-r--r-- | xmake/plugins/repo/main.lua | 12 | ||||
| -rw-r--r-- | xmake/repository/packages/cmake/xmake.lua (renamed from xmake/packages/cmake/xmake.lua) | 0 | ||||
| -rw-r--r-- | xmake/repository/packages/git/xmake.lua (renamed from xmake/packages/git/xmake.lua) | 0 | ||||
| -rw-r--r-- | xmake/repository/xmake.lua | 3 |
11 files changed, 72 insertions, 76 deletions
diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua index e48ce37fc..f111470ae 100644 --- a/xmake/actions/require/package.lua +++ b/xmake/actions/require/package.lua @@ -150,10 +150,10 @@ end function _load_package_from_repository(packagename, reponame) -- get package directory from the given package name - local packagedir, is_global = repository.packagedir(packagename, reponame) + local packagedir, repo = repository.packagedir(packagename, reponame) if packagedir then -- load it - return core_package.load_from_repository(packagename, is_global, packagedir) + return core_package.load_from_repository(packagename, repo, packagedir) end end @@ -219,8 +219,8 @@ function _search_package_from_repository(name) -- search package directories from the given package name local packages = {} - for packagename, packageinfo in pairs(repository.searchdirs(name)) do - local package = core_package.load_from_repository(packagename, packageinfo.is_global, packageinfo.packagedir) + for _, packageinfo in ipairs(repository.searchdirs(name)) do + local package = core_package.load_from_repository(packageinfo.name, packageinfo.repo, packageinfo.packagedir) if package then table.insert(packages, package) end diff --git a/xmake/actions/require/repository.lua b/xmake/actions/require/repository.lua index 39ccd7e50..371e1b012 100644 --- a/xmake/actions/require/repository.lua +++ b/xmake/actions/require/repository.lua @@ -63,39 +63,12 @@ function packagedir(packagename, reponame) return foundir[1], foundir[2] end - -- find the package directory from the given repository - if reponame then - for _, from in ipairs({"local", "global"}) do - local is_global = (from == "global") - for _, repodir in ipairs(repository.directory(is_global)) do - local dir = path.join(repodir, reponame, "packages", (packagename:gsub('%.', path.seperator()))) - if os.isdir(dir) then - foundir = {dir, is_global} - break - end - end - if foundir then - break - end - end - else - -- find the package directory from all repositories - for _, repo in ipairs(repositories()) do - - -- the package directory - local dir = path.join(repo:directory(), "packages", (packagename:gsub('%.', path.seperator()))) - if os.isdir(dir) then - foundir = {dir, repo.global} - break - end - end - end - - -- not found? find this package from the builtin packages directory - if not foundir then - local dir = path.join(os.programdir(), "packages", (packagename:gsub('%.', path.seperator()))) - if os.isdir(dir) then - foundir = {dir, true} + -- find the package directory from repositories + for _, repo in ipairs(repositories()) do + local dir = path.join(repo:directory(), "packages", (packagename:gsub('%.', path.seperator()))) + if os.isdir(dir) and (not reponame or reponame == repo:name()) then + foundir = {dir, repo} + break end end @@ -120,20 +93,18 @@ function searchdirs(name) local subdirs = "**" .. table.concat(name:split('%.'), "*" .. path.seperator() .. "*") .. "*" -- find the package directories from all repositories + local unique = {} local packageinfos = {} for _, repo in ipairs(repositories()) do - - -- the package directory pattern - for _, file in ipairs(os.files(path.join(repository.directory(repo.global), repo.name, "packages", subdirs, "xmake.lua"))) do - packageinfos[path.basename(path.directory(file))] = {is_global = repo.global, packagedir = path.directory(file)} + for _, file in ipairs(os.files(path.join(repo:directory(), "packages", subdirs, "xmake.lua"))) do + local packagename = path.basename(path.directory(file)) + if not unique[packagename] then + table.insert(packageinfos, {name = packagename, repo = repo, packagedir = path.directory(file)}) + unique[packagename] = true + end end end - -- search the package directories from the builtin packages directory - for _, file in ipairs(os.files(path.join(os.programdir(), "packages", subdirs, "xmake.lua"))) do - packageinfos[path.basename(path.directory(file))] = {is_global = repo.global, packagedir = path.directory(file)} - end - -- ok? return packageinfos end diff --git a/xmake/actions/require/search.lua b/xmake/actions/require/search.lua index 53fee8220..1397e2aff 100644 --- a/xmake/actions/require/search.lua +++ b/xmake/actions/require/search.lua @@ -57,7 +57,8 @@ function main(names) -- show packages for _, instance in ipairs(packages) do - cprint(" -> ${magenta}%s${clear}: %s", instance:fullname(), instance:get("description") or "") + local repo = instance:repo() + cprint(" -> ${magenta}%s${clear}: %s %s", instance:fullname(), instance:get("description") or "", repo and ("(in " .. repo:name() .. ")") or "") end end end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index f26884f58..24f15a2f7 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -84,6 +84,11 @@ function _instance:name() return self._NAME end +-- get the repository of this package +function _instance:repo() + return self._REPO +end + -- get the package alias function _instance:alias() local requireinfo = self:requireinfo() @@ -545,7 +550,7 @@ function package.load_from_project(packagename, project) end -- load the package from the package directory or package description file -function package.load_from_repository(packagename, is_global, packagedir, packagefile) +function package.load_from_repository(packagename, repo, packagedir, packagefile) -- get it directly from cache first package._PACKAGES = package._PACKAGES or {} @@ -587,8 +592,11 @@ function package.load_from_repository(packagename, is_global, packagedir, packag return nil, errors end + -- save repository + instance._REPO = repo + -- mark as global/project package? - instance._FROMKIND = utils.ifelse(is_global, "global", "local") + instance._FROMKIND = repo:is_global() and "global" or "local" -- save instance to the cache package._PACKAGES[packagename] = instance diff --git a/xmake/core/package/repository.lua b/xmake/core/package/repository.lua index 88affe853..fdce0b7af 100644 --- a/xmake/core/package/repository.lua +++ b/xmake/core/package/repository.lua @@ -35,14 +35,13 @@ local config = require("project/config") local interpreter = require("base/interpreter") -- new an instance -function _instance.new(name, info, url, directory, is_global) +function _instance.new(name, url, directory, is_global) -- new an instance local instance = table.inherit(_instance) -- init instance instance._NAME = name - instance._INFO = info instance._URL = url instance._DIRECTORY = directory instance._IS_GLOBAL = is_global @@ -56,9 +55,26 @@ function _instance:get(name) -- the info local info = self._INFO + if not info then - -- get if from info first - local value = info[name] + -- attempt to load info from the repository script (xmake.lua) + local scriptpath = path.join(self:directory(), "xmake.lua") + if os.isfile(scriptpath) then + + -- load repository and disable filter + local results, errors = repository._interpreter():load(scriptpath, nil, true, false) + if not results and os.isfile(scriptpath) then + os.raise(errors) + end + + -- save repository info + info = results + self._INFO = info + end + end + + -- get if from info + local value = info and info[name] or nil if value ~= nil then return value end @@ -160,25 +176,10 @@ function repository.load(name, url, is_global) end -- the repository directory - local repodir = path.join(repository.directory(is_global), name) - - -- get the repository script path - local repoinfo = {} - local scriptpath = path.join(repodir, "xmake.lua") - if os.isfile(scriptpath) then - - -- load repository and disable filter - local results, errors = repository._interpreter():load(scriptpath, nil, true, false) - if not results and os.isfile(scriptpath) then - return nil, errors - end - - -- save repository info - repoinfo = results - end + local repodir = os.isdir(url) and url or path.join(repository.directory(is_global), name) -- new an instance - local instance, errors = _instance.new(name, repoinfo, url, repodir, is_global) + local instance, errors = _instance.new(name, url, repodir, is_global) if not instance then return nil, errors end diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua index 5a507e20d..39da91a3f 100644 --- a/xmake/core/sandbox/modules/import/core/package/package.lua +++ b/xmake/core/sandbox/modules/import/core/package/package.lua @@ -67,10 +67,10 @@ function sandbox_core_package_package.load_from_system(packagename) end -- load the package from repositories -function sandbox_core_package_package.load_from_repository(packagename, is_global, packagedir, packagefile) +function sandbox_core_package_package.load_from_repository(packagename, repo, packagedir, packagefile) -- load package instance - local instance, errors = package.load_from_repository(packagename, is_global, packagedir, packagefile) + local instance, errors = package.load_from_repository(packagename, repo, packagedir, packagefile) if not instance then raise(errors) end diff --git a/xmake/core/sandbox/modules/import/core/package/repository.lua b/xmake/core/sandbox/modules/import/core/package/repository.lua index 2fc09e22b..16fab448a 100644 --- a/xmake/core/sandbox/modules/import/core/package/repository.lua +++ b/xmake/core/sandbox/modules/import/core/package/repository.lua @@ -121,6 +121,14 @@ function sandbox_core_package_repository.repositories(is_global) end end + -- load repository from builtin program directory + if is_global then + local repo = repository.load("builtin-repo", path.join(os.programdir(), "repository"), true) + if repo then + table.insert(repositories, repo) + end + end + -- get the repositories return repositories end diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua index 25a405f2e..91c64225c 100644 --- a/xmake/plugins/repo/main.lua +++ b/xmake/plugins/repo/main.lua @@ -100,12 +100,16 @@ function _update() -- remove repeat and only pull the first repository if not pulled[repodir] then if os.isdir(repodir) then + + -- update the local repository with the remote url + if not os.isdir(repo:url()) then - -- trace - vprint("pulling repository(%s): %s to %s ..", repo:name(), repo:url(), repodir) + -- 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}) + -- pull it + git.pull({verbose = option.get("verbose"), branch = "master", repodir = repodir}) + end else -- trace vprint("cloning repository(%s): %s to %s ..", repo:name(), repo:url(), repodir) diff --git a/xmake/packages/cmake/xmake.lua b/xmake/repository/packages/cmake/xmake.lua index c78f590fd..c78f590fd 100644 --- a/xmake/packages/cmake/xmake.lua +++ b/xmake/repository/packages/cmake/xmake.lua diff --git a/xmake/packages/git/xmake.lua b/xmake/repository/packages/git/xmake.lua index f6bbe8102..f6bbe8102 100644 --- a/xmake/packages/git/xmake.lua +++ b/xmake/repository/packages/git/xmake.lua diff --git a/xmake/repository/xmake.lua b/xmake/repository/xmake.lua new file mode 100644 index 000000000..01c381ed3 --- /dev/null +++ b/xmake/repository/xmake.lua @@ -0,0 +1,3 @@ + +-- set repository description +set_description("The official builtin package repository of xmake") |
