summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-06-25 22:42:55 +0800
committerruki <[email protected]>2021-06-25 22:42:55 +0800
commite90da39112c300c003cc9482acfcec7f28e85efc (patch)
treee47d4afd373ae07d54daa9d95b8b5e1a750c24a5
parentcfdd992044c10dce5c181a3b61e38021926c399a (diff)
install precompiled artifacts
-rw-r--r--xmake/core/package/package.lua27
-rw-r--r--xmake/core/sandbox/modules/import/core/package/repository.lua31
-rw-r--r--xmake/modules/private/action/require/impl/actions/download_resources.lua5
-rw-r--r--xmake/modules/private/action/require/impl/actions/patch_sources.lua5
-rw-r--r--xmake/modules/private/action/require/impl/package.lua20
-rw-r--r--xmake/modules/private/action/require/impl/repository.lua16
6 files changed, 93 insertions, 11 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 3ad23f67f..76084f392 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -237,6 +237,30 @@ function _instance:url_excludes(url)
return self:extraconf("urls", url, "excludes")
end
+-- set artifacts info
+function _instance:artifacts_set(artifacts_info)
+ local versions = self:get("versions")
+ if versions then
+ -- we switch to urls of the precompiled artifacts
+ self:urls_set(table.wrap(artifacts_info.urls))
+ versions[self:version_str()] = artifacts_info.sha256
+ self:set("install", function (package)
+ sandbox_module.import("lib.detect.find_path")
+ local rootdir = find_path("manifest.txt", path.join(os.curdir(), "*", "*", "*"))
+ if not rootdir then
+ os.raise("package(%s): manifest.txt not found when installing artifacts!", self:displayname())
+ end
+ os.cp(path.join(rootdir, "*"), package:installdir())
+ end)
+ self._IS_PRECOMPILED = true
+ end
+end
+
+-- is this package built?
+function _instance:is_built()
+ return not self._IS_PRECOMPILED
+end
+
-- get the given dependent package
function _instance:dep(name)
local deps = self:deps()
@@ -283,7 +307,6 @@ function _instance:sourcehash(url_alias)
local versions = self:get("versions")
local version_str = self:version_str()
if versions and version_str then
-
local sourcehash = nil
if url_alias then
sourcehash = versions[url_alias .. ":" ..version_str]
@@ -1050,8 +1073,6 @@ function _instance:script(name, generic)
end
end
end
-
- -- ok
return result
end
diff --git a/xmake/core/sandbox/modules/import/core/package/repository.lua b/xmake/core/sandbox/modules/import/core/package/repository.lua
index ceae3fc05..86f27b497 100644
--- a/xmake/core/sandbox/modules/import/core/package/repository.lua
+++ b/xmake/core/sandbox/modules/import/core/package/repository.lua
@@ -107,13 +107,36 @@ function sandbox_core_package_repository.repositories(is_global)
end
end
- -- add main global xmake repository
+ -- add global xmake repositories
if is_global then
- -- get sorted main urls
+ -- add artifacts urls
+ local artifacts_urls = localcache.cache("repository"):get("artifacts_urls")
+ if not artifacts_urls then
+ artifacts_urls = {"https://github.com/xmake-mirror/build-artifacts.git",
+ "https://gitlab.com/xmake-mirror/build-artifacts.git",
+ "https://gitee.com/xmake-mirror/build-artifacts.git"}
+ if global.get("network") ~= "private" then
+ import("net.fasturl")
+ fasturl.add(artifacts_urls)
+ artifacts_urls = fasturl.sort(artifacts_urls)
+ localcache.cache("repository"):set("artifacts_urls", artifacts_urls)
+ localcache.cache("repository"):save()
+ end
+ end
+ if #artifacts_urls > 0 then
+ local repo = repository.load("build-artifacts", artifacts_urls[1], "main", true)
+ if repo then
+ table.insert(repositories, repo)
+ end
+ end
+
+ -- add main urls
local mainurls = localcache.cache("repository"):get("mainurls")
if not mainurls then
- mainurls = {"https://github.com/xmake-io/xmake-repo.git", "https://gitlab.com/tboox/xmake-repo.git", "https://gitee.com/tboox/xmake-repo.git"}
+ mainurls = {"https://github.com/xmake-io/xmake-repo.git",
+ "https://gitlab.com/tboox/xmake-repo.git",
+ "https://gitee.com/tboox/xmake-repo.git"}
if global.get("network") ~= "private" then
import("net.fasturl")
fasturl.add(mainurls)
@@ -122,8 +145,6 @@ function sandbox_core_package_repository.repositories(is_global)
localcache.cache("repository"):save()
end
end
-
- -- add main url
if #mainurls > 0 then
local repo = repository.load("xmake-repo", mainurls[1], "master", true)
if repo then
diff --git a/xmake/modules/private/action/require/impl/actions/download_resources.lua b/xmake/modules/private/action/require/impl/actions/download_resources.lua
index ffa303cde..e603b3d9f 100644
--- a/xmake/modules/private/action/require/impl/actions/download_resources.lua
+++ b/xmake/modules/private/action/require/impl/actions/download_resources.lua
@@ -128,6 +128,11 @@ end
-- download all resources of the given package
function main(package)
+ -- we need not download it if we use the precompiled artifacts to install package
+ if not package:is_built() then
+ return
+ end
+
-- no resources?
local resources = package:resources()
if not resources then
diff --git a/xmake/modules/private/action/require/impl/actions/patch_sources.lua b/xmake/modules/private/action/require/impl/actions/patch_sources.lua
index d3ca226b1..23d46f3d3 100644
--- a/xmake/modules/private/action/require/impl/actions/patch_sources.lua
+++ b/xmake/modules/private/action/require/impl/actions/patch_sources.lua
@@ -100,6 +100,11 @@ end
-- patch the given package
function main(package)
+ -- we need not patch it if we use the precompiled artifacts to install package
+ if not package:is_built() then
+ return
+ end
+
-- no patches?
local patches = package:patches()
if not patches then
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index e3fa7e3af..d66686482 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -78,6 +78,7 @@ end
-- true: only get system package
-- false: only get remote packages
--
+-- {build = true}: always build packages, we do not use the precompiled artifacts
--
function _parse_require(require_str)
@@ -173,7 +174,8 @@ function _load_require(require_str, requires_extra, parentinfo)
optional = parentinfo.optional or require_extra.optional, -- default: false, inherit parentinfo.optional
verify = require_extra.verify, -- default: true, we can set false to ignore sha256sum and select any version
external = require_extra.external, -- default: true, we use sysincludedirs/-isystem instead of -I/xxx
- private = require_extra.private -- default: false, private package, only for installation, do not export any links/includes and environments
+ private = require_extra.private, -- default: false, private package, only for installation, do not export any links/includes and environments
+ build = require_extra.build -- default: false, always build packages, we do not use the precompiled artifacts
}
return required.packagename, required.requireinfo
end
@@ -544,8 +546,12 @@ function _load_package(packagename, requireinfo, opt)
end
-- load package from repositories
+ local from_repo = false
if not package then
package = _load_package_from_repository(packagename, requireinfo.reponame)
+ if package then
+ from_repo = true
+ end
end
-- load package from system
@@ -616,6 +622,18 @@ function _load_package(packagename, requireinfo, opt)
-- check package configurations
_check_package_configurations(package)
+ -- save artifacts info, we need add it at last before buildhash need depend on package configurations
+ if from_repo and not option.get("build") and not requireinfo.build then
+ local artifacts_manifest = repository.artifacts_manifest(packagename, version)
+ if artifacts_manifest then
+ local buildid = package:plat() .. "-" .. package:arch() .. "-" .. package:buildhash()
+ local artifacts_info = artifacts_manifest[buildid]
+ if artifacts_info then
+ package:artifacts_set(artifacts_info)
+ end
+ end
+ end
+
-- do load
local on_load = package:script("load")
if on_load then
diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua
index f997ee703..4dbf44e52 100644
--- a/xmake/modules/private/action/require/impl/repository.lua
+++ b/xmake/modules/private/action/require/impl/repository.lua
@@ -51,6 +51,7 @@ end
function packagedir(packagename, reponame)
-- strip trailng ~tag, e.g. zlib~debug
+ packagename = packagename:lower()
if packagename:find('~', 1, true) then
packagename = packagename:gsub("~.+$", "")
end
@@ -64,8 +65,8 @@ function packagedir(packagename, reponame)
-- find the package directory from repositories
for _, repo in ipairs(repositories()) do
- local dir = path.join(repo:directory(), "packages", packagename:sub(1, 1):lower(), packagename)
- if os.isdir(dir) and (not reponame or reponame == repo:name()) then
+ local dir = path.join(repo:directory(), "packages", packagename:sub(1, 1), packagename)
+ if os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")) and (not reponame or reponame == repo:name()) then
foundir = {dir, repo}
break
end
@@ -77,6 +78,17 @@ function packagedir(packagename, reponame)
end
end
+-- get artifacts manifest from repositories
+function artifacts_manifest(packagename, version)
+ packagename = packagename:lower()
+ for _, repo in ipairs(repositories()) do
+ local manifestfile = path.join(repo:directory(), "packages", packagename:sub(1, 1), packagename, version, "manifest.txt")
+ if os.isfile(manifestfile) then
+ return io.load(manifestfile)
+ end
+ end
+end
+
-- search package directories from repositories
function searchdirs(name)