diff options
Diffstat (limited to 'xmake/core/project/addons.lua')
| -rw-r--r-- | xmake/core/project/addons.lua | 110 |
1 files changed, 11 insertions, 99 deletions
diff --git a/xmake/core/project/addons.lua b/xmake/core/project/addons.lua index 169b7d033..c979a6f8d 100644 --- a/xmake/core/project/addons.lua +++ b/xmake/core/project/addons.lua @@ -29,23 +29,6 @@ local table = require("base/table") local semver = require("base/semver") local addon = require("package/addon") --- the file which declares the addons of a project, e.g. <projectdir>/xmake-addons.lua --- --- it's loaded before the project file, so that the addons are always installed when --- we load the project, e.g. includes("@addon/esp32-devel/board") --- --- e.g. --- add_addons("esp32-devel 1.0.x", "serial-tools") --- add_repositories("myrepo [email protected]:me/myrepo.git") --- -function addons.filename() - return "xmake-addons.lua" -end - -function addons.file(projectdir) - return path.join(projectdir or os.projectdir(), addons.filename()) -end - -- the lock file of the declared addons, e.g. <projectdir>/xmake-addons.lock -- -- @note it's independent of `xmake-requires.lock`, the addons are always locked, @@ -63,100 +46,29 @@ function addons.lockfile_version() return "1.0" end --- get the apis of the addons file --- --- @note it only declares which addons this project needs, the addon resources --- are always referenced from the project file, e.g. add_rules("@addon/esp32-devel/app") --- -function addons.apis() - return { - values = { - "add_addons" - -- the repositories which provide them, e.g. add_repositories("myrepo [email protected]:me/myrepo.git") - , "add_repositories" - } - } -end - --- the interpreter of the addons file -function addons._interpreter() - local interp = addons._INTERPRETER - if interp == nil then - -- we need to load it lazily, the interpreter also depends on the addon module - local interpreter = require("base/interpreter") - interp = interpreter.new() - interp:api_define(addons.apis()) - -- the sub-projects declare their addons in this file too, - -- e.g. includes("sub") -> sub/xmake-addons.lua - interp:includes_rootfilename_set(addons.filename()) - -- and we cannot reference the addons here, they have not been installed yet, - -- e.g. includes("@addon/esp32-devel/board") - interp:includes_references_set(false, "please move it to the project file(xmake.lua)!") - addons._INTERPRETER = interp - end - return interp -end - --- load the declared addons of the given project directory +-- check the addons which a project declares, e.g. add_addons("esp32-devel 1.0.x") -- --- @return the addons information and errors, it will be nil if this project declares nothing, --- e.g. {addons = {"esp32-devel 1.0.x"}, addons_extra = {...}} +-- @return true, or false and errors -- -function addons.load(projectdir) - local filepath = addons.file(projectdir) - if not os.isfile(filepath) then - return - end - - -- enter the project directory, the include paths are relative to it, - -- e.g. includes("sub") - local oldir, errors = os.cd(path.directory(filepath)) - if not oldir then - return nil, errors - end - - local rootinfo - local interp = addons._interpreter() - local ok, errors = interp:load(filepath) - if ok then - rootinfo, errors = interp:make("root", true, true) - end - os.cd(oldir) - if not rootinfo then - return nil, errors - end - - local addonsinfo = {addons = table.wrap(rootinfo:get("addons")), - addons_extra = rootinfo:extraconf("addons"), - repositories = table.wrap(rootinfo:get("repositories"))} - - -- check the declared addons +function addons.validate(requires) local declared = {} - for _, requirestr in ipairs(addonsinfo.addons) do - - -- this file is loaded before the addons are installed, so it cannot reference them - if requirestr:startswith("@") then - return nil, string.format("%s: cannot reference the addon resources(%s) here, please move it to the project file(xmake.lua)!", - filepath, requirestr) - end - + for _, requirestr in ipairs(requires) do local name = addons.requirename(requirestr) if name == "addon" or name == "self" then - return nil, string.format("%s: the addon name(%s) is reserved by xmake for the addon references, please rename it!", - filepath, name) + return false, string.format("add_addons(%s): the name is reserved by xmake for the addon references, please rename it!", name) end if name == "." or name == ".." or name:find("[/\\:]") then - return nil, string.format("%s: invalid addon name(%s)!", filepath, name) + return false, string.format("add_addons(%s): invalid addon name!", name) end -- we can only install one version of an addon for a project if declared[name] then - return nil, string.format("%s: the addon(%s) is declared twice, e.g. `%s` and `%s`, please merge them!", - filepath, name, declared[name], requirestr) + return false, string.format("add_addons(%s): it is declared twice, e.g. `%s` and `%s`, please merge them!", + name, declared[name], requirestr) end declared[name] = requirestr end - return addonsinfo + return true end -- split the given declaration into the name and the version range @@ -204,13 +116,13 @@ end -- @note we need to check it in-process for every command which loads the project, -- so we only check the locked versions here, the installer will resolve them again -- -function addons.satisfied(addonsinfo, projectdir) +function addons.satisfied(requires, projectdir) local locked = addons.locked(projectdir) if not locked then return false end local installed = addon.addons() - for _, requirestr in ipairs(addonsinfo.addons) do + for _, requirestr in ipairs(requires) do local name = addons.requirename(requirestr) local lockinfo = locked[name] if not addons.locked_valid(requirestr, lockinfo) then |
