summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-04-14 00:37:13 +0800
committerruki <[email protected]>2022-04-14 00:37:13 +0800
commit12652bfd524697241b893d4a4e1672ecc3608f2c (patch)
tree6b0aa0ba694723e1bb99b39830a7c8969c71f2a1
parenta39818c953e11781d2305e2ad3afe5b551c15eec (diff)
support git commit as require version
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/core/package/package.lua16
-rw-r--r--xmake/modules/private/action/require/impl/actions/download.lua2
-rw-r--r--xmake/modules/private/action/require/impl/package.lua6
4 files changed, 22 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eea64f5af..32c551f74 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
* [#2138](https://github.com/xmake-io/xmake/issues/2138): Support template package
* [#2185](https://github.com/xmake-io/xmake/issues/2185): Add `--appledev=simulator` to improve apple simulator support
* [#2227](https://github.com/xmake-io/xmake/issues/2227): Improve cargo package with Cargo.toml file
+* Improve `add_requires` to support git commit as version
### Changes
@@ -1244,6 +1245,7 @@
* [#2138](https://github.com/xmake-io/xmake/issues/2138): 支持模板包
* [#2185](https://github.com/xmake-io/xmake/issues/2185): 添加 `--appledev=simulator` 去改进 Apple 模拟器目标编译支持
* [#2227](https://github.com/xmake-io/xmake/issues/2227): 改进 cargo 包,支持指定 Cargo.toml 文件
+* 改进 `add_requires` 支持 git command 作为版本
### 改进
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index c7ae4901b..43d4e1307 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1016,10 +1016,17 @@ function _instance:version_set(version, source)
self._BRANCH = version
elseif source == "tag" then
self._TAG = version
+ elseif source == "commit" then
+ self._COMMIT = version
end
-- save version string
- self._VERSION_STR = version
+ if source == "commit" then
+ -- we strip it to avoid long paths
+ self._VERSION_STR = version:sub(1, 8)
+ else
+ self._VERSION_STR = version
+ end
end
-- get branch version
@@ -1032,9 +1039,14 @@ function _instance:tag()
return self._TAG
end
+-- get commit version
+function _instance:commit()
+ return self._COMMIT
+end
+
-- is git ref?
function _instance:gitref()
- return self:branch() or self:tag()
+ return self:branch() or self:tag() or self:commit()
end
-- get the require info
diff --git a/xmake/modules/private/action/require/impl/actions/download.lua b/xmake/modules/private/action/require/impl/actions/download.lua
index ad0e7bc37..2275c96f7 100644
--- a/xmake/modules/private/action/require/impl/actions/download.lua
+++ b/xmake/modules/private/action/require/impl/actions/download.lua
@@ -79,7 +79,7 @@ function _checkout(package, url, sourcedir, url_alias)
git.clone(url, {longpaths = longpaths, outputdir = packagedir})
-- attempt to checkout the given version
- local revision = package:revision(url_alias) or package:tag() or package:version_str()
+ local revision = package:revision(url_alias) or package:tag() or package:commit() or package:version_str()
git.checkout(revision, {repodir = packagedir})
-- update all submodules
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index b0fe3399c..848ad4b8f 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -361,7 +361,11 @@ function _select_package_version(package, requireinfo, locked_requireinfo)
version, source = try { function () return semver.select(require_version, package:versions()) end }
end
if not version and has_giturl and not semver.is_valid(require_version) then -- select branch?
- version, source = require_version ~= "latest" and require_version or "master", "branch"
+ if require_version and #require_version == 40 and require_version:match("%w+") then
+ version, source = require_version, "commit"
+ else
+ version, source = require_version ~= "latest" and require_version or "master", "branch"
+ end
end
-- local source package? we use a phony version
if not version and require_version == "latest" and #package:urls() == 0 then