diff options
| author | ruki <[email protected]> | 2023-11-12 00:05:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-11-12 00:05:21 +0800 |
| commit | fb648845e465bf0c376f6d0d4197c8243abdaecd (patch) | |
| tree | a177a51f56b57a3977f036b45c524943353a0315 /xmake/plugins/pack/xpack.lua | |
| parent | f23af7855d5d5d2b2126dd67db0de04e05836c12 (diff) | |
improve specvars
Diffstat (limited to 'xmake/plugins/pack/xpack.lua')
| -rw-r--r-- | xmake/plugins/pack/xpack.lua | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua index cbc2b9045..8c4537f2b 100644 --- a/xmake/plugins/pack/xpack.lua +++ b/xmake/plugins/pack/xpack.lua @@ -24,6 +24,7 @@ import("core.base.option") import("core.base.hashset") import("core.project.config") import("core.project.project") +import("lib.detect.find_tool") -- define module local xpack = xpack or object {_init = {"_name", "_info"}} @@ -209,6 +210,70 @@ function xpack:basename() return self:get("basename") or self:name() end +-- get the spec variables +function xpack:specvars() + local specvars = self._specvars + if specvars == nil then + specvars = { + ARCH = self:arch() + , PLAT = self:plat() + , HOST = os.host() + , MODE = config.get("mode") or "release" + } + + -- get version + local version, version_build = self:version() + if version then + specvars.VERSION = version + try {function () + local v = semver.new(version) + if v then + specvars.VERSION_MAJOR = v:major() + specvars.VERSION_MINOR = v:minor() + specvars.VERSION_ALTER = v:patch() + end + end} + if version_build then + specvars.VERSION_BUILD = version_build + end + end + + -- get git information + local cmds = + { + GIT_TAG = {"describe", "--tags"}, + GIT_TAG_LONG = {"describe", "--tags", "--long"}, + GIT_BRANCH = {"rev-parse", "--abbrev-ref", "HEAD"}, + GIT_COMMIT = {"rev-parse", "--short", "HEAD"}, + GIT_COMMIT_LONG = {"rev-parse", "HEAD"}, + GIT_COMMIT_DATE = {"log", "-1", "--date=format:%Y%m%d%H%M%S", "--format=%ad"} + } + for name, argv in pairs(cmds) do + specvars[name] = function () + local result + local git = find_tool("git") + if git then + result = try {function () + return os.iorunv(git.program, argv) + end} + end + if not result then + result = "none" + end + return result:trim() + end + end + + -- get user variables + local vars = self:get("specvar") + if vars then + table.join2(specvars, vars) + end + self._specvars = specvars + end + return specvars +end + -- get the specfile path function xpack:specfile() local extensions = { |
