mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-16 20:41:53 +03:00
Support xtool --version
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user