Support xtool --version

This commit is contained in:
Kabir Oberai
2025-05-17 19:01:42 +05:30
Unverified
parent d5fdbbc10a
commit d4dcd7b23b
4 changed files with 39 additions and 0 deletions
+5
View File
@@ -2,8 +2,13 @@
import PackageDescription
let gitCommit: String? = Context.gitInformation?.currentCommit
let gitTag: String? = Context.gitInformation?.currentTag
let cSettings: [CSetting] = [
.define("_GNU_SOURCE", .when(platforms: [.linux])),
.define("XTL_GIT_COMMIT", to: gitCommit.map { "\"\($0)\"" } ?? "NULL"),
.define("XTL_GIT_TAG", to: gitTag.map { "\"\($0)\"" } ?? "NULL"),
]
let package = Package(
+7
View File
@@ -0,0 +1,7 @@
inline static const char * _Nullable xtl_git_commit() {
return XTL_GIT_COMMIT;
}
inline static const char * _Nullable xtl_git_tag() {
return XTL_GIT_TAG;
}
+1
View File
@@ -12,6 +12,7 @@ struct XToolCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "xtool",
abstract: "Cross-platform Xcode replacement",
version: XTool.version?.description ?? "unknown",
groupedSubcommands: [
CommandGroup(
name: "Configuration",
+26
View File
@@ -0,0 +1,26 @@
import CXKit
extension XTool {
public struct Version: Sendable, Hashable {
public var commit: String
public var tag: String?
}
public static let version: Version? = {
guard let commit = xtl_git_commit() else { return nil }
return Version(
commit: String(cString: commit),
tag: xtl_git_tag().map { String(cString: $0) }
)
}()
}
extension XTool.Version: CustomStringConvertible {
public var description: String {
if let tag {
"xtool version \(tag)"
} else {
"xtool commit \(commit)"
}
}
}