diff options
| author | ruki <[email protected]> | 2019-02-03 14:22:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-02-03 14:22:06 +0800 |
| commit | a2e6e7ce0729ec8108c0eb2d86fbe68cdf832b53 (patch) | |
| tree | a5bf8c2bb9bf5f916abb31b1a2d6475662c6537b | |
| parent | 2c7a2ff446fd7ad85922a2990d6452627133c8c3 (diff) | |
improve set_version and add builtin variables
| -rw-r--r-- | tests/apis/add_configfiles/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/actions/config/configfiles.lua | 59 | ||||
| -rw-r--r-- | xmake/actions/config/configheader.lua | 6 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 27 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/platform/platform.lua | 13 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 24 | ||||
| -rw-r--r-- | xmake/plugins/doxygen/main.lua | 10 |
8 files changed, 103 insertions, 40 deletions
diff --git a/tests/apis/add_configfiles/xmake.lua b/tests/apis/add_configfiles/xmake.lua index 6c4fcc588..b941a0366 100644 --- a/tests/apis/add_configfiles/xmake.lua +++ b/tests/apis/add_configfiles/xmake.lua @@ -1,7 +1,4 @@ -set_configvar("ARCH", get_config("arch")) -set_configvar("PLAT", get_config("plat")) - option("foo") set_default("foo") set_description("The Foo Info") diff --git a/xmake/actions/config/configfiles.lua b/xmake/actions/config/configfiles.lua index 2020670e3..b4cbd11b7 100644 --- a/xmake/actions/config/configfiles.lua +++ b/xmake/actions/config/configfiles.lua @@ -24,8 +24,10 @@ -- imports import("core.base.option") +import("core.base.semver") import("core.project.config") import("core.project.project") +import("core.platform.platform") -- get all configuration files function _get_configfiles() @@ -65,6 +67,50 @@ function _get_configfiles() return configfiles end +-- get the builtin variables +function _get_builtinvars_target(target) + + -- get version variables + local builtinvars = {} + local version, version_build = target:version() + if version then + builtinvars.VERSION = version + try {function () + local v = semver.new(version) + if v then + builtinvars.VERSION_MAJOR = v:major() + builtinvars.VERSION_MINOR = v:minor() + builtinvars.VERSION_ALTER = v:patch() + end + end} + if version_build then + builtinvars.VERSION_BUILD = version_build + end + end + return builtinvars +end + +-- get the global builtin variables +function _get_builtinvars_global() + local builtinvars = _g.builtinvars_global + if builtinvars == nil then + builtinvars = + { + arch = config.get("arch") or os.arch() + , plat = config.get("plat") or os.host() + , host = os.host() + , mode = config.get("mode") or "release" + , debug = is_mode("debug") and 1 or 0 + , os = platform.os() + } + for name, value in pairs(builtinvars) do + builtinvars[name:upper()] = type(value) == "string" and value:upper() or value + end + _g.builtinvars_global = builtinvars + end + return builtinvars +end + -- generate the configuration file function _generate_configfile(srcfile, dstfile, fileinfo, targets) @@ -114,6 +160,19 @@ function _generate_configfile(srcfile, dstfile, fileinfo, targets) end end end + + -- get the builtin variables from the target + for name, value in pairs(_get_builtinvars_target(target)) do + if variables[name] == nil then + variables[name] = value + end + end + end + -- get the global builtin variables + for name, value in pairs(_get_builtinvars_global()) do + if variables[name] == nil then + variables[name] = value + end end -- replace all variables diff --git a/xmake/actions/config/configheader.lua b/xmake/actions/config/configheader.lua index 307a9bf83..74ed7b088 100644 --- a/xmake/actions/config/configheader.lua +++ b/xmake/actions/config/configheader.lua @@ -49,12 +49,12 @@ function _make_for_target(target) -- make version local version, version_build = target:configversion() if not version or not version_build then - local project_version, project_version_build = project.version() + local target_version, target_version_build = target:version() if not version then - version = project_version + version = target_version end if not version_build then - version_build = project_version_build + version_build = target_version_build end end if version then diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 0d7289a90..88da7811c 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -209,7 +209,6 @@ function project.interpreter() { -- set_xxx "set_project" - , "set_version" , "set_modes" -- add_xxx , "add_requires" diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index f1762177f..c71baf45d 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -55,6 +55,7 @@ function target.apis() "target.set_kind" , "target.set_strip" , "target.set_rules" + , "target.set_version" , "target.set_enabled" , "target.set_default" , "target.set_options" @@ -491,6 +492,30 @@ function target:name() return self._NAME end +-- get the target version +function target:version() + + -- get version and build version + local version = self:get("version") + local version_build = nil + if version then + local version_extra = self:get("__extra_version") + if version_extra then + version_build = self._VERSION_BUILD + if not version_build then + version_build = table.wrap(version_extra[version]).build + if type(version_build) == "string" then + version_build = os.date(version_build, os.time()) + self._VERSION_BUILD = version_build + end + end + end + end + + -- ok? + return version, version_build +end + -- get the base name of target file function target:basename() local filename = self:get("filename") @@ -1477,7 +1502,7 @@ function target:script(name, generic) return result end --- get the config header version +-- TODO get the config header version (deprecated) function target:configversion() -- get the config version and build version diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index 31f530d9e..c2f4db2c2 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -39,15 +39,14 @@ function sandbox_core_platform.load(plat) end end +-- get the platform os +function sandbox_core_platform.os() + return assert(platform.os()) +end + -- get the all platforms function sandbox_core_platform.plats() - - -- get it - local plats = platform.plats() - assert(plats) - - -- ok - return plats + return assert(platform.plats()) end -- get the all architectures for the given platform diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index ae8376a3d..a5b3d829d 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -157,30 +157,6 @@ function sandbox_core_project.mtimes() return project.mtimes() end --- get the project version -function sandbox_core_project.version() - - -- get version and build version - local version = project.get("version") - local version_build = nil - if version then - local version_extra = project.get("__extra_version") - if version_extra then - version_build = sandbox_core_project._VERSION_BUILD - if not version_build then - version_build = table.wrap(version_extra[version]).build - if type(version_build) == "string" then - version_build = os.date(version_build, os.time()) - sandbox_core_project._VERSION_BUILD = version_build - end - end - end - end - - -- ok? - return version, version_build -end - -- get the project info from the given name function sandbox_core_project.get(name) return project.get(name) diff --git a/xmake/plugins/doxygen/main.lua b/xmake/plugins/doxygen/main.lua index 83377d251..8f31a79e8 100644 --- a/xmake/plugins/doxygen/main.lua +++ b/xmake/plugins/doxygen/main.lua @@ -77,7 +77,15 @@ function main() -- -- PROJECT_NUMBER = -- - local version = project.version() + local version = nil + for _, target in ipairs(project.targets()) do + if target:get("enabled") ~= false then + version = target:version() + if version then + break + end + end + end if version then io.gsub(doxyfile, "PROJECT_NUMBER%s-=.-\n", format("PROJECT_NUMBER = %s\n", version)) end |
