Skip to content

Commit 9765cfd

Browse files
authored
Merge pull request #400 from tayloraswift/unidoc-version
enable printing the tool version with `unidoc --version`
2 parents e9d6160 + eaa3f9c commit 9765cfd

File tree

6 files changed

+74
-8
lines changed

6 files changed

+74
-8
lines changed

Package.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ let package:Package = .init(
148148
.product(name: "OrderedCollections", package: "swift-collections"),
149149
]),
150150

151+
.target(name: "_GitVersion",
152+
cSettings: [
153+
.define("SWIFTPM_GIT_VERSION", to: "\"\(version)\"")
154+
]),
155+
151156
.target(name: "AvailabilityDomain"),
152157

153158
.target(name: "Availability",
@@ -476,6 +481,7 @@ let package:Package = .init(
476481

477482
.target(name: "UnidocCLI",
478483
dependencies: [
484+
.target(name: "_GitVersion"),
479485
.target(name: "System_ArgumentParser"),
480486
.target(name: "UnidocServer"),
481487
.product(name: "ArgumentParser", package: "swift-argument-parser"),
@@ -771,3 +777,16 @@ for target:PackageDescription.Target in package.targets
771777
$0 = settings
772778
} (&target.swiftSettings)
773779
}
780+
781+
var version:String
782+
{
783+
if let git:GitInformation = Context.gitInformation
784+
{
785+
let base:String = git.currentTag ?? git.currentCommit
786+
return git.hasUncommittedChanges ? "\(base) (modified)" : base
787+
}
788+
else
789+
{
790+
return "(untracked)"
791+
}
792+
}

Sources/UnidocCLI/Unidoc (ext).swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import _GitVersion
2+
3+
extension Unidoc
4+
{
5+
public
6+
static var version:String
7+
{
8+
.init(cString: _GitVersion.swiftpm_git_version())
9+
}
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#if !defined(SWIFTPM_GIT_VERSION_H)
2+
#define SWIFTPM_GIT_VERSION_H
3+
4+
extern const char * swiftpm_git_version(void);
5+
6+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "swiftpm_git_version.h"
2+
3+
const char * swiftpm_git_version(void)
4+
{
5+
return SWIFTPM_GIT_VERSION;
6+
}

Sources/unidoc-linkerd/Main.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ struct Main
3232
name: [.customLong("assume-encrypted")],
3333
help: "Assume that the connection is encrypted")
3434
var assumeEncrypted:Bool = false
35+
36+
@Flag(name: [.customLong("version")], help: "Print version information and exit")
37+
var version:Bool = false
3538
}
3639

3740
@main
3841
extension Main:AsyncParsableCommand
3942
{
4043
func run() async throws
4144
{
45+
if self.version
46+
{
47+
print(Unidoc.version)
48+
return
49+
}
50+
4251
NIOSingletons.groupLoopCountSuggestion = 2
4352

4453
let clientIdentity:NIOSSLContext = try .clientDefault

Sources/unidoc-tools/Main.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@ import ArgumentParser
22
import SymbolGraphCompiler
33

44
@main
5-
struct Main:AsyncParsableCommand
5+
struct Main
66
{
7-
static let configuration:CommandConfiguration = .init(subcommands: [
8-
SSGC.CompileCommand.self,
9-
Unidoc.InitCommand.self,
10-
Unidoc.LocalCommand.self,
11-
Unidoc.PreviewCommand.self,
12-
Unidoc.ListAssetsCommand.self,
13-
])
7+
@Flag(name: [.customLong("version")], help: "Print version information and exit")
8+
var version:Bool = false
9+
}
10+
extension Main:AsyncParsableCommand
11+
{
12+
static var configuration:CommandConfiguration
13+
{
14+
.init(subcommands: [
15+
SSGC.CompileCommand.self,
16+
Unidoc.InitCommand.self,
17+
Unidoc.LocalCommand.self,
18+
Unidoc.PreviewCommand.self,
19+
Unidoc.ListAssetsCommand.self,
20+
])
21+
}
22+
23+
func run() async throws
24+
{
25+
if self.version
26+
{
27+
print(Unidoc.version)
28+
}
29+
}
1430
}

0 commit comments

Comments
 (0)