summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-05-27 00:37:12 +0800
committerruki <[email protected]>2021-05-27 00:37:12 +0800
commitcabfdf44c5b08ad2dfeb425eb5e372cbff6c37fe (patch)
tree03bd24507f64fa722eeb66d6ba0072db3c5ae08d
parent02d3e2cd9743435dc37a7b51ace4a638e7661a75 (diff)
improve to import packages again
-rw-r--r--xmake/core/sandbox/modules/import/core/package/repository.lua14
-rw-r--r--xmake/modules/private/action/require/impl/import_packages.lua2
-rw-r--r--xmake/modules/private/action/require/impl/repository.lua20
-rw-r--r--xmake/modules/private/action/require/import.lua14
4 files changed, 31 insertions, 19 deletions
diff --git a/xmake/core/sandbox/modules/import/core/package/repository.lua b/xmake/core/sandbox/modules/import/core/package/repository.lua
index e05a98aaf..ceae3fc05 100644
--- a/xmake/core/sandbox/modules/import/core/package/repository.lua
+++ b/xmake/core/sandbox/modules/import/core/package/repository.lua
@@ -108,17 +108,19 @@ function sandbox_core_package_repository.repositories(is_global)
end
-- add main global xmake repository
- if is_global and global.get("network") ~= "private" then
+ if is_global then
-- get sorted main urls
local mainurls = localcache.cache("repository"):get("mainurls")
if not mainurls then
- import("net.fasturl")
mainurls = {"https://github.com/xmake-io/xmake-repo.git", "https://gitlab.com/tboox/xmake-repo.git", "https://gitee.com/tboox/xmake-repo.git"}
- fasturl.add(mainurls)
- mainurls = fasturl.sort(mainurls)
- localcache.cache("repository"):set("mainurls", mainurls)
- localcache.cache("repository"):save()
+ if global.get("network") ~= "private" then
+ import("net.fasturl")
+ fasturl.add(mainurls)
+ mainurls = fasturl.sort(mainurls)
+ localcache.cache("repository"):set("mainurls", mainurls)
+ localcache.cache("repository"):save()
+ end
end
-- add main url
diff --git a/xmake/modules/private/action/require/impl/import_packages.lua b/xmake/modules/private/action/require/impl/import_packages.lua
index 1b875314e..d01660aa1 100644
--- a/xmake/modules/private/action/require/impl/import_packages.lua
+++ b/xmake/modules/private/action/require/impl/import_packages.lua
@@ -35,7 +35,7 @@ function main(requires, opt)
local importpath, count = installdir:replace(rootdir, packagedir, {plain = true})
-- import this package
- if importpath and count == 1 and not instance:fetch({force = true}) then
+ if importpath and count == 1 then
print("importing %s-%s %s", instance:displayname(), instance:version_str(), package.get_configs_str(instance))
cprint(" ${yellow}<-${clear} %s", importpath)
os.tryrm(installdir)
diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua
index 6fc72d49c..6a0471f8b 100644
--- a/xmake/modules/private/action/require/impl/repository.lua
+++ b/xmake/modules/private/action/require/impl/repository.lua
@@ -19,33 +19,29 @@
--
-- imports
+import("core.base.global")
import("core.package.repository")
-- get all repositories
function repositories()
-
- -- get it from cache it
if _g._REPOSITORIES then
return _g._REPOSITORIES
end
-
-- get all repositories (local first)
local repos = table.join(repository.repositories(false), repository.repositories(true))
-
- -- save repositories
_g._REPOSITORIES = repos
-
- -- ok
return repos
end
-- the remote repositories have been pulled?
function pulled()
- for _, repo in ipairs(repositories()) do
- -- repository not found? or xmake has been re-installed
- local updatefile = path.join(repo:directory(), "updated")
- if not os.isdir(repo:directory()) or (os.isfile(updatefile) and os.mtime(os.programfile()) > os.mtime(updatefile)) then
- return false
+ if global.get("network") ~= "private" then
+ for _, repo in ipairs(repositories()) do
+ -- repository not found? or xmake has been re-installed
+ local updatefile = path.join(repo:directory(), "updated")
+ if not os.isdir(repo:directory()) or (os.isfile(updatefile) and os.mtime(os.programfile()) > os.mtime(updatefile)) then
+ return false
+ end
end
end
return true
diff --git a/xmake/modules/private/action/require/import.lua b/xmake/modules/private/action/require/import.lua
index 43ac9a13a..cf6cb85c7 100644
--- a/xmake/modules/private/action/require/import.lua
+++ b/xmake/modules/private/action/require/import.lua
@@ -19,13 +19,24 @@
--
-- imports
+import("core.base.task")
import("core.base.option")
+import("private.action.require.impl.repository")
+import("private.action.require.impl.environment")
import("private.action.require.impl.import_packages")
import("private.action.require.impl.utils.get_requires")
-- import the given packages
function main(requires_raw)
+ -- enter environment
+ environment.enter()
+
+ -- pull all repositories first if not exists
+ if not repository.pulled() then
+ task.run("repo", {update = true})
+ end
+
-- get requires and extra config
local requires_extra = nil
local requires, requires_extra = get_requires(requires_raw)
@@ -50,5 +61,8 @@ function main(requires_raw)
end
end
end
+
+ -- leave environment
+ environment.leave()
end