1 /* 2 Copyright 2014 The Perkeep Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package buildinfo provides information about the current build. 18 package buildinfo // import "perkeep.org/pkg/buildinfo" 19 20 import "flag" 21 22 // GitInfo is either the empty string (the default) 23 // or is set to the git hash of the most recent commit 24 // using the -X linker flag. For example, it's set like: 25 // $ go install --ldflags="-X perkeep.org/pkg/buildinfo.GitInfo "`./misc/gitversion` perkeep.org/server/perkeepd 26 var GitInfo string 27 28 // Version is a string like "0.10" or "1.0", if applicable. 29 var Version string 30 31 // Summary returns the version and/or git version of this binary. 32 // If the linker flags were not provided, the return value is "unknown". 33 func Summary() string { 34 if Version != "" && GitInfo != "" { 35 return Version + ", " + GitInfo 36 } 37 if GitInfo != "" { 38 return GitInfo 39 } 40 if Version != "" { 41 return Version 42 } 43 return "unknown" 44 } 45 46 // TestingLinked reports whether the "testing" package is linked into the binary. 47 func TestingLinked() bool { 48 return flag.CommandLine.Lookup("test.v") != nil 49 } 50 51 // djpegFunc implements DjpegStatus. nil means the images/fastjpeg package 52 // isn't linked in. 53 var djpegFunc func() string 54 55 func RegisterDjpegStatusFunc(fn func() string) { 56 djpegFunc = fn 57 } 58 59 // DjpegStatus returns a plaintext (non-HTML) string describing the 60 // state of djpeg on the system. 61 func DjpegStatus() string { 62 if djpegFunc != nil { 63 return djpegFunc() 64 } 65 return "unknown" 66 }