@ -77,7 +77,7 @@ func Long() string {
if ! bi . valid {
return strings . TrimSpace ( tailscaleroot . VersionDotTxt ) + "-ERR-BuildInfo"
}
return fmt . Sprintf ( "%s-dev%s-t%s%s" , strings . TrimSpace ( tailscaleroot . VersionDotTxt ) , bi . C ommitDate, bi . commitAbbrev ( ) , dirtyString ( ) )
return fmt . Sprintf ( "%s-dev%s-t%s%s" , strings . TrimSpace ( tailscaleroot . VersionDotTxt ) , bi . c ommitDate, bi . commitAbbrev ( ) , dirtyString ( ) )
} )
}
@ -97,58 +97,47 @@ func Short() string {
if ! bi . valid {
return strings . TrimSpace ( tailscaleroot . VersionDotTxt ) + "-ERR-BuildInfo"
}
return strings . TrimSpace ( tailscaleroot . VersionDotTxt ) + "-dev" + bi . C ommitDate
return strings . TrimSpace ( tailscaleroot . VersionDotTxt ) + "-dev" + bi . c ommitDate
} )
}
// Info returns information about the version embedded in the binary.
// If the version information is not present, the second return value is false.
func Info ( ) ( EmbeddedInfo , bool ) {
ei := getEmbeddedInfo ( )
if ! ei . valid {
return EmbeddedInfo { } , false
}
return ei , true
}
// EmbeddedInfo contains information about the version embedded in the binary.
type EmbeddedInfo struct {
type embeddedInfo struct {
valid bool
C ommit string
C ommitDate string
D irty bool
commit string
commitDate string
dirty bool
}
func ( i E mbeddedInfo) commitAbbrev ( ) string {
if len ( i . C ommit) >= 9 {
return i . C ommit[ : 9 ]
func ( i embeddedInfo ) commitAbbrev ( ) string {
if len ( i . commit ) >= 9 {
return i . commit [ : 9 ]
}
return i . C ommit
return i . commit
}
var getEmbeddedInfo = lazy . SyncFunc ( func ( ) E mbeddedInfo {
var getEmbeddedInfo = lazy . SyncFunc ( func ( ) e mbeddedInfo {
bi , ok := debug . ReadBuildInfo ( )
if ! ok {
return E mbeddedInfo{ }
return e mbeddedInfo{ }
}
ret := E mbeddedInfo{ valid : true }
ret := e mbeddedInfo{ valid : true }
for _ , s := range bi . Settings {
switch s . Key {
case "vcs.revision" :
ret . C ommit = s . Value
ret . c ommit = s . Value
case "vcs.time" :
if len ( s . Value ) >= len ( "yyyy-mm-dd" ) {
ret . C ommitDate = s . Value [ : len ( "yyyy-mm-dd" ) ]
ret . CommitDate = strings . ReplaceAll ( ret . C ommitDate, "-" , "" )
ret . c ommitDate = s . Value [ : len ( "yyyy-mm-dd" ) ]
ret . commitDate = strings . ReplaceAll ( ret . c ommitDate, "-" , "" )
}
case "vcs.modified" :
ret . D irty = s . Value == "true"
ret . d irty = s . Value == "true"
}
}
if ret . Commit == "" || ret . C ommitDate == "" {
if ret . commit == "" || ret . c ommitDate == "" {
// Build info is present in the binary, but has no useful data. Act as
// if it's missing.
return E mbeddedInfo{ }
return e mbeddedInfo{ }
}
return ret
} )
@ -157,14 +146,14 @@ func gitCommit() string {
if gitCommitStamp != "" {
return gitCommitStamp
}
return getEmbeddedInfo ( ) . C ommit
return getEmbeddedInfo ( ) . c ommit
}
func gitDirty ( ) bool {
if gitDirtyStamp {
return true
}
return getEmbeddedInfo ( ) . D irty
return getEmbeddedInfo ( ) . d irty
}
func dirtyString ( ) string {