File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,10 +21,6 @@ import CompilerPluginSupport
2121import Foundation
2222import PackageDescription
2323
24- let gitCommit = ProcessInfo . processInfo. environment [ " GIT_COMMIT " ] ?? " unspecified "
25- let gitTag = ProcessInfo . processInfo. environment [ " GIT_TAG " ] ?? " "
26- let buildTime = ProcessInfo . processInfo. environment [ " BUILD_TIME " ] ?? " unspecified "
27-
2824let package = Package (
2925 name: " containerization " ,
3026 platforms: [ . macOS( " 15.0 " ) ] ,
@@ -264,15 +260,6 @@ let package = Package(
264260 . target(
265261 name: " CShim "
266262 ) ,
267- . target(
268- name: " CVersion " ,
269- path: " vminitd/Sources/CVersion " ,
270- cSettings: [
271- . define( " GIT_COMMIT " , to: " \" \( gitCommit) \" " ) ,
272- . define( " GIT_TAG " , to: " \" \( gitTag) \" " ) ,
273- . define( " BUILD_TIME " , to: " \" \( buildTime) \" " ) ,
274- ]
275- ) ,
276263 . target(
277264 name: " LCShim " ,
278265 path: " vminitd/Sources/LCShim "
@@ -303,7 +290,6 @@ let package = Package(
303290 . product( name: " GRPCNIOTransportHTTP2 " , package : " grpc-swift-nio-transport " ) ,
304291 . product( name: " GRPCProtobuf " , package : " grpc-swift-protobuf " ) ,
305292 " LCShim " ,
306- " CVersion " ,
307293 " Cgroup " ,
308294 ] ,
309295 path: " vminitd/Sources/VminitdCore "
Original file line number Diff line number Diff line change 1717
1818// The swift-tools-version declares the minimum version of Swift required to build this package.
1919
20+ import Foundation
2021import PackageDescription
2122
23+ let gitCommit = ProcessInfo . processInfo. environment [ " GIT_COMMIT " ] ?? " unspecified "
24+ let gitTag = ProcessInfo . processInfo. environment [ " GIT_TAG " ] ?? " "
25+ let buildTime = ProcessInfo . processInfo. environment [ " BUILD_TIME " ] ?? " unspecified "
26+
2227let package = Package (
2328 name: " swift-vminitd " ,
2429 platforms: [ . macOS( " 15 " ) ] ,
@@ -33,13 +38,22 @@ let package = Package(
3338 . package ( name: " containerization " , path: " ../ " ) ,
3439 ] ,
3540 targets: [
41+ . target(
42+ name: " CVersion " ,
43+ cSettings: [
44+ . define( " GIT_COMMIT " , to: " \" \( gitCommit) \" " ) ,
45+ . define( " GIT_TAG " , to: " \" \( gitTag) \" " ) ,
46+ . define( " BUILD_TIME " , to: " \" \( buildTime) \" " ) ,
47+ ]
48+ ) ,
3649 . executableTarget(
3750 name: " vminitd " ,
3851 dependencies: [
3952 . product( name: " ArgumentParser " , package : " swift-argument-parser " ) ,
4053 . product( name: " ContainerizationOS " , package : " containerization " ) ,
4154 . product( name: " Logging " , package : " swift-log " ) ,
4255 . product( name: " VminitdCore " , package : " containerization " ) ,
56+ " CVersion " ,
4357 ]
4458 ) ,
4559 . executableTarget(
Original file line number Diff line number Diff line change 1717#if os(Linux)
1818
1919import ArgumentParser
20- import CVersion
2120import Cgroup
2221import Containerization
2322import ContainerizationError
@@ -79,14 +78,7 @@ public struct AgentCommand: AsyncParsableCommand {
7978
8079 signal ( SIGPIPE, SIG_IGN)
8180
82- let gitCommit = String ( cString: CZ_get_git_commit ( ) )
83- let gitTag = String ( cString: CZ_get_git_tag ( ) )
84- let buildTime = String ( cString: CZ_get_build_time ( ) )
85- var metadata : Logger . Metadata = [ " commit " : " \( gitCommit) " , " built " : " \( buildTime) " ]
86- if !gitTag. isEmpty {
87- metadata [ " tag " ] = " \( gitTag) "
88- }
89- log. info ( " vminitd booting " , metadata: metadata)
81+ log. info ( " vminitd booting " , metadata: versionMetadata ( ) )
9082
9183 // Set of mounts necessary to be mounted prior to taking any RPCs.
9284 // 1. /proc as the sysctl rpc wouldn't make sense if it wasn't there (NOTE: This is done before this method
Original file line number Diff line number Diff line change @@ -50,6 +50,16 @@ public struct LogLevelOption: ParsableArguments {
5050}
5151
5252private let _loggingBootstrapped = Mutex ( false )
53+ private let _versionMetadata = Mutex < Logger . Metadata > ( [ : ] )
54+
55+ /// Set the version metadata logged on boot.
56+ public func setVersionMetadata( _ metadata: Logger . Metadata ) {
57+ _versionMetadata. withLock { $0 = metadata }
58+ }
59+
60+ func versionMetadata( ) -> Logger . Metadata {
61+ _versionMetadata. withLock { $0 }
62+ }
5363
5464func makeLogger( label: String , level: Logger . Level ) -> Logger {
5565 _loggingBootstrapped. withLock { bootstrapped in
Original file line number Diff line number Diff line change 1515//===----------------------------------------------------------------------===//
1616
1717import ArgumentParser
18+ import CVersion
1819import ContainerizationOS
1920import Foundation
2021import Logging
@@ -35,6 +36,8 @@ struct Application: AsyncParsableCommand {
3536 )
3637
3738 static func main( ) async throws {
39+ setVersionMetadata ( Self . versionMetadata ( ) )
40+
3841 // Busybox-style: if invoked as .cz-init, run init mode directly.
3942 let invoked = CommandLine . arguments. first? . split ( separator: " / " ) . last. map ( String . init) ?? " "
4043 if invoked == " .cz-init " {
@@ -57,6 +60,17 @@ struct Application: AsyncParsableCommand {
5760 }
5861 }
5962
63+ private static func versionMetadata( ) -> Logger . Metadata {
64+ let gitCommit = String ( cString: CZ_get_git_commit ( ) )
65+ let gitTag = String ( cString: CZ_get_git_tag ( ) )
66+ let buildTime = String ( cString: CZ_get_build_time ( ) )
67+ var metadata : Logger . Metadata = [ " commit " : " \( gitCommit) " , " built " : " \( buildTime) " ]
68+ if !gitTag. isEmpty {
69+ metadata [ " tag " ] = " \( gitTag) "
70+ }
71+ return metadata
72+ }
73+
6074 private static func mountProc( ) throws {
6175 if isProcMounted ( ) {
6276 return
You can’t perform that action at this time.
0 commit comments