summaryrefslogtreecommitdiff
path: root/xmake/core/package/repository.lua
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 /xmake/core/package/repository.lua
parent37d53d0646fd32ebc747dc22be0cc1390887bc3a (diff)
load repo xmake.lua
Diffstat (limited to 'xmake/core/package/repository.lua')
-rw-r--r--xmake/core/package/repository.lua140
1 files changed, 134 insertions, 6 deletions
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)