summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-08-25 00:42:23 +0800
committerruki <[email protected]>2018-08-24 22:14:22 +0800
commite00c2e6bbc3b363f191e514dc553ac6041fe2e0e (patch)
tree9ee3d706f31e3f65970110e81f639a4e5bd18193
parent37d53d0646fd32ebc747dc22be0cc1390887bc3a (diff)
load repo xmake.lua
-rw-r--r--xmake/actions/require/repository.lua5
-rw-r--r--xmake/core/package/repository.lua140
-rw-r--r--xmake/core/sandbox/modules/import/core/package/repository.lua16
-rw-r--r--xmake/plugins/repo/main.lua11
4 files changed, 155 insertions, 17 deletions
diff --git a/xmake/actions/require/repository.lua b/xmake/actions/require/repository.lua
index a605acc83..39ccd7e50 100644
--- a/xmake/actions/require/repository.lua
+++ b/xmake/actions/require/repository.lua
@@ -46,8 +46,7 @@ end
-- the remote repositories have been pulled?
function pulled()
for _, repo in ipairs(repositories()) do
- local repodir = path.join(repository.directory(repo.global), repo.name)
- if not os.isdir(repodir) then
+ if not os.isdir(repo:directory()) then
return false
end
end
@@ -84,7 +83,7 @@ function packagedir(packagename, reponame)
for _, repo in ipairs(repositories()) do
-- the package directory
- local dir = path.join(repository.directory(repo.global), repo.name, "packages", (packagename:gsub('%.', path.seperator())))
+ local dir = path.join(repo:directory(), "packages", (packagename:gsub('%.', path.seperator())))
if os.isdir(dir) then
foundir = {dir, repo.global}
break
diff --git a/xmake/core/package/repository.lua b/xmake/core/package/repository.lua
index 69c629a32..88affe853 100644
--- a/xmake/core/package/repository.lua
+++ b/xmake/core/package/repository.lua
@@ -24,13 +24,65 @@
-- define module
local repository = repository or {}
+local _instance = _instance or {}
-- load modules
-local utils = require("base/utils")
-local string = require("base/string")
-local global = require("base/global")
-local cache = require("project/cache")
-local config = require("project/config")
+local utils = require("base/utils")
+local string = require("base/string")
+local global = require("base/global")
+local cache = require("project/cache")
+local config = require("project/config")
+local interpreter = require("base/interpreter")
+
+-- new an instance
+function _instance.new(name, info, 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
+
+ -- ok
+ return instance
+end
+
+-- get the repository configure
+function _instance:get(name)
+
+ -- the info
+ local info = self._INFO
+
+ -- get if from info first
+ local value = info[name]
+ if value ~= nil then
+ return value
+ end
+end
+
+-- get the repository name
+function _instance:name()
+ return self._NAME
+end
+
+-- get the repository url
+function _instance:url()
+ return self._URL
+end
+
+-- is global repository?
+function _instance:is_global()
+ return self._IS_GLOBAL
+end
+
+-- get the repository directory
+function _instance:directory()
+ return self._DIRECTORY
+end
-- get cache
function repository._cache(is_global)
@@ -51,7 +103,43 @@ function repository._cache(is_global)
return repository._CACHE[position]
end
--- get the local or global package directory
+-- the interpreter
+function repository._interpreter()
+
+ -- the interpreter has been initialized? return it directly
+ if repository._INTERPRETER then
+ return repository._INTERPRETER
+ end
+
+ -- init interpreter
+ local interp = interpreter.new()
+ assert(interp)
+
+ -- define apis
+ interp:api_define(repository.apis())
+
+ -- save interpreter
+ repository._INTERPRETER = interp
+
+ -- ok?
+ return interp
+end
+
+-- get repository apis
+function repository.apis()
+
+ return
+ {
+ values =
+ {
+ -- set_xxx
+ "set_xmakever"
+ , "set_description"
+ }
+ }
+end
+
+-- get the local or global repository directory
function repository.directory(is_global)
-- get directory
@@ -62,6 +150,46 @@ function repository.directory(is_global)
end
end
+-- load the repository
+function repository.load(name, url, is_global)
+
+ -- get it directly from cache first
+ repository._REPOS = repository._REPOS or {}
+ if repository._REPOS[name] then
+ return repository._REPOS[name]
+ 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
+
+ -- new an instance
+ local instance, errors = _instance.new(name, repoinfo, url, repodir, is_global)
+ if not instance then
+ return nil, errors
+ end
+
+ -- save instance to the cache
+ repository._REPOS[name] = instance
+
+ -- ok
+ return instance
+end
+
-- get repository url from the given name
function repository.get(name, is_global)
diff --git a/xmake/core/sandbox/modules/import/core/package/repository.lua b/xmake/core/sandbox/modules/import/core/package/repository.lua
index 0c5e2f4b4..2fc09e22b 100644
--- a/xmake/core/sandbox/modules/import/core/package/repository.lua
+++ b/xmake/core/sandbox/modules/import/core/package/repository.lua
@@ -90,13 +90,20 @@ function sandbox_core_package_repository.repositories(is_global)
-- add main urls
for _, mainurl in ipairs(mainurls) do
- table.insert(repositories, {name = "xmake-repo", url = mainurl, global = true})
+ local repo = repository.load("xmake-repo", mainurl, true)
+ if repo then
+ table.insert(repositories, repo)
+ end
end
end
+
-- load repositories from repository cache
for name, url in pairs(table.wrap(repository.repositories(is_global))) do
- table.insert(repositories, {name = name, url = url, global = is_global})
+ local repo = repository.load(name, url, is_global)
+ if repo then
+ table.insert(repositories, repo)
+ end
end
-- load repositories from project file
@@ -104,7 +111,10 @@ function sandbox_core_package_repository.repositories(is_global)
for _, repo in ipairs(table.wrap(project.get("repositories"))) do
local repoinfo = repo:split(' ')
if #repoinfo == 2 then
- table.insert(repositories, {name = repoinfo[1], url = repoinfo[2], global = is_global})
+ local repo = repository.load(repoinfo[1], repoinfo[2], is_global)
+ if repo then
+ table.insert(repositories, repo)
+ end
else
raise("invalid repository: %s", repo)
end
diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua
index 5bb8b6b27..25a405f2e 100644
--- a/xmake/plugins/repo/main.lua
+++ b/xmake/plugins/repo/main.lua
@@ -95,23 +95,23 @@ function _update()
for _, repo in ipairs(repos) do
-- the repository directory
- local repodir = path.join(repository.directory(repo.global), repo.name)
+ local repodir = repo:directory()
-- 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)
+ 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)
+ 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})
+ git.clone(repo:url(), {verbose = option.get("verbose"), branch = "master", outputdir = repodir})
end
-- pull this repository ok
@@ -164,7 +164,8 @@ function _list()
for _, repo in pairs(repository.repositories(position == "global")) do
-- trace
- print(" %s %s", repo.name, repo.url)
+ local description = repo:get("description")
+ print(" %s %s %s", repo:name(), repo:url(), description and ("(" .. description .. ")") or "")
-- update count
count = count + 1