summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-29 22:41:19 +0800
committerruki <[email protected]>2021-09-29 22:41:19 +0800
commit9b11147b98d5b51bc5064757c7f3629e5ad37cbb (patch)
tree7b11541cefddf6b96b398b5c962619911b4514dd
parent9b6ed10af9394ac3db541f848ab3405b7d0daf3d (diff)
add local package dir
-rw-r--r--tests/projects/c/library_with_cmakelists/xmake.lua4
-rw-r--r--xmake/core/package/package.lua18
2 files changed, 16 insertions, 6 deletions
diff --git a/tests/projects/c/library_with_cmakelists/xmake.lua b/tests/projects/c/library_with_cmakelists/xmake.lua
index e27fcbafa..4bf632e08 100644
--- a/tests/projects/c/library_with_cmakelists/xmake.lua
+++ b/tests/projects/c/library_with_cmakelists/xmake.lua
@@ -1,12 +1,8 @@
add_rules("mode.debug", "mode.release")
-local cachedir = path.join(os.scriptdir(), "build", "cache")
-local packagesdir = path.join(os.scriptdir(), "build", "packages")
package("foo")
add_deps("cmake")
set_sourcedir("foo")
- set_cachedir(cachedir)
- set_installdir(packagesdir)
on_install(function (package)
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 5c7a04d34..e6a8335ee 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -461,6 +461,18 @@ function _instance:is_parallelize()
return self:get("parallelize") ~= false
end
+-- is local embed package?
+-- we install directly from the local source code instead of downloading it remotely
+function _instance:is_embed()
+ return self:get("sourcedir") and #self:urls() == 0 and self:script("install")
+end
+
+-- is local package?
+-- we will use local installdir and cachedir in current project
+function _instance:is_local()
+ return self:is_embed()
+end
+
-- is debug package? (deprecated)
function _instance:debug()
return self:is_debug()
@@ -526,7 +538,8 @@ function _instance:cachedir()
cachedir = self:get("cachedir")
if not cachedir then
local name = self:name():lower():gsub("::", "_")
- cachedir = path.join(package.cachedir(), name:sub(1, 1):lower(), name, self:version_str())
+ local rootdir = self:is_local() and path.join(config.directory(), "cache", "packages") or package.cachedir()
+ cachedir = path.join(rootdir, name:sub(1, 1):lower(), name, self:version_str())
end
self._CACHEDIR = cachedir
end
@@ -540,7 +553,8 @@ function _instance:installdir(...)
installdir = self:get("installdir")
if not installdir then
local name = self:name():lower():gsub("::", "_")
- installdir = path.join(package.installdir(), name:sub(1, 1):lower(), name)
+ local rootdir = self:is_local() and path.join(config.directory(), "packages") or package.installdir()
+ installdir = path.join(rootdir, name:sub(1, 1):lower(), name)
if self:version_str() then
installdir = path.join(installdir, self:version_str())
end