summaryrefslogtreecommitdiff
path: root/xmake/core/package/package.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-28 22:36:41 +0800
committerruki <[email protected]>2024-05-28 22:36:41 +0800
commita4600c92868523942d60068076d8cf51e5503f16 (patch)
tree75b721b2489cbd1e4671014035ef7da13ba49527 /xmake/core/package/package.lua
parentc9cf85fc880d6c2937d3dea66fa78fabf4bbf97b (diff)
improve load source
Diffstat (limited to 'xmake/core/package/package.lua')
-rw-r--r--xmake/core/package/package.lua40
1 files changed, 34 insertions, 6 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 101c8f23e..27b263f2c 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -109,11 +109,21 @@ end
-- set the value to the package info
function _instance:set(name, ...)
+ if self._SOURCE_INITED then
+ if self:_sourceset():has(name) then
+ os.raise("package:set(\"%s\", ...) can only be called in on_source().", name)
+ end
+ end
self._INFO:apival_set(name, ...)
end
-- add the value to the package info
function _instance:add(name, ...)
+ if self._SOURCE_INITED then
+ if self:_sourceset():has(name) then
+ os.raise("package:add(\"%s\", ...) can only be called in on_source().", name)
+ end
+ end
self._INFO:apival_add(name, ...)
end
@@ -975,19 +985,37 @@ function _instance:manifest_save()
end
end
+-- get the source configuration set
+function _instance:_sourceset()
+ local sourceset = self._SOURCESET
+ if sourceset == nil then
+ sourceset = hashset.of("urls", "versions", "versionfiles", "configs")
+ self._SOURCESET = sourceset
+ end
+ return sourceset
+end
+
-- init package source
function _instance:_init_source()
- local on_source = self:script("source")
- if on_source then
- on_source(self)
+ local inited = self._SOURCE_INITED
+ if not inited then
+ local on_source = self:script("source")
+ if on_source then
+ on_source(self)
+ end
end
end
-- load package
function _instance:_load()
- local on_load = self:script("load")
- if on_load then
- on_load(self)
+ self._SOURCE_INITED = true
+ local loaded = self._LOADED
+ if not loaded then
+ local on_load = self:script("load")
+ if on_load then
+ on_load(self)
+ end
+ self._LOADED = true
end
end