kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/util/build/build.go (about)

     1  /*
     2   * Copyright 2016 The Kythe Authors. All rights reserved.
     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 build provides information about how a given binary was built and in
    18  // what context.
    19  package build // import "kythe.io/kythe/go/util/build"
    20  
    21  import "fmt"
    22  
    23  var (
    24  	_BUILD_SCM_REVISION    string
    25  	_BUILD_SCM_STATUS      string
    26  	_KYTHE_RELEASE_VERSION string
    27  )
    28  
    29  // VersionLine returns the following formatted string
    30  // fmt.Sprintf("Version: %s [%s %s]", ReleaseVersion(), Status(), Revision()).
    31  func VersionLine() string {
    32  	return fmt.Sprintf("Version: %s [%s %s]", ReleaseVersion(), Status(), Revision())
    33  }
    34  
    35  // ReleaseVersion returns the Kythe release version for the current build.
    36  func ReleaseVersion() string {
    37  	if _KYTHE_RELEASE_VERSION != "" {
    38  		return _KYTHE_RELEASE_VERSION
    39  	}
    40  	return Revision()
    41  }
    42  
    43  // Revision returns the source control revision for the current build.
    44  func Revision() string {
    45  	if _BUILD_SCM_REVISION != "" {
    46  		return _BUILD_SCM_REVISION
    47  	}
    48  	return "HEAD"
    49  }
    50  
    51  // Status returns the source control status for the current build.
    52  func Status() string {
    53  	if _BUILD_SCM_STATUS != "" {
    54  		return _BUILD_SCM_STATUS
    55  	}
    56  	return "Unknown"
    57  }