diff options
| author | ruki <[email protected]> | 2018-11-23 22:53:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-23 11:19:48 +0800 |
| commit | 97953a03922981aeb3614e9a0cb40d1ef7cb70f7 (patch) | |
| tree | 5de0c5444f536188fec621e7bbfc4c47da7acc68 | |
| parent | be2ea01017a8a876a786167dd697cd79343b6d4a (diff) | |
add on_load in require info
| -rw-r--r-- | xmake/actions/config/configheader.lua | 12 | ||||
| -rw-r--r-- | xmake/actions/require/install.lua | 3 | ||||
| -rw-r--r-- | xmake/core/project/requireinfo.lua | 51 |
3 files changed, 55 insertions, 11 deletions
diff --git a/xmake/actions/config/configheader.lua b/xmake/actions/config/configheader.lua index 09f75286d..63e496862 100644 --- a/xmake/actions/config/configheader.lua +++ b/xmake/actions/config/configheader.lua @@ -73,18 +73,20 @@ function _make_for_target(target) -- make the undefines local undefines = table.copy(target:get("undefines_h")) - -- make the options + -- make the defines for options for _, opt in ipairs(target:options()) do - - -- get the option defines table.join2(defines, opt:get("defines_h")) table.join2(defines, opt:get("defines_h_if_ok")) -- deprecated - - -- get the option undefines table.join2(undefines, opt:get("undefines_h")) table.join2(undefines, opt:get("undefines_h_if_ok")) -- deprecated end + -- make the defines for packages + for _, pkg in ipairs(target:packages()) do + table.join2(defines, pkg:get("defines_h")) + table.join2(undefines, pkg:get("undefines_h")) + end + -- make the defines if #defines ~= 0 then file:print("// defines") diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua index b0ffb4f0b..941a43fc2 100644 --- a/xmake/actions/require/install.lua +++ b/xmake/actions/require/install.lua @@ -53,6 +53,9 @@ function _register_required_package(instance, requireinfo) end end + -- save this package version + requireinfo:set("version", instance:version_str()) + -- enable this require info requireinfo:enable(true) end diff --git a/xmake/core/project/requireinfo.lua b/xmake/core/project/requireinfo.lua index 257de6ffe..ac5b397ce 100644 --- a/xmake/core/project/requireinfo.lua +++ b/xmake/core/project/requireinfo.lua @@ -26,12 +26,14 @@ local requireinfo = requireinfo or {} -- load modules -local io = require("base/io") -local os = require("base/os") -local path = require("base/path") -local table = require("base/table") -local utils = require("base/utils") -local cache = require("project/cache") +local io = require("base/io") +local os = require("base/os") +local path = require("base/path") +local table = require("base/table") +local utils = require("base/utils") +local cache = require("project/cache") +local semver = require("base/semver") +local sandbox = require("sandbox/sandbox") -- get cache function requireinfo._cache() @@ -50,6 +52,21 @@ end -- save the requires info to the cache function requireinfo:save() + + -- To ensure that the full information (version, ..) is obtained, delay loading it + if not self._LOADED then + local extrainfo = self:extrainfo() + if extrainfo and extrainfo.on_load then + local ok, errors = sandbox.load(extrainfo.on_load, self) + if not ok then + os.raise(errors) + end + extrainfo.on_load = nil + end + self._LOADED = true + end + + -- save it requireinfo._cache():set(self:name(), self._INFO) requireinfo._cache():flush() end @@ -74,6 +91,28 @@ function requireinfo:name() return self._NAME end +-- get the package version +function requireinfo:version() + + -- get it from cache first + if self._VERSION ~= nil then + return self._VERSION + end + + -- get version + local version = nil + local verstr = self:get("version") + if verstr then + version = semver.new(verstr) + end + + -- save to cache + self._VERSION = version or false + + -- done + return version +end + -- get the require string function requireinfo:requirestr() return self:get("requirestr") |
