github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/engine/autoconf/probe/git_describe.go (about)

     1  package probe
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/metux/go-metabuild/spec/buildconf"
     7  	"github.com/metux/go-metabuild/util/git"
     8  )
     9  
    10  type GitDescribe struct {
    11  	ProbeBase
    12  }
    13  
    14  func (p GitDescribe) Probe() error {
    15  	if ver, err := git.PkgVersion(
    16  		p.EntryBoolDef("tags", false),
    17  		p.EntryBoolDef("all", false),
    18  		p.EntryStrList("exclude"),
    19  		p.EntryStrList("match")); err == nil {
    20  		p.Logf("detected version from git: \"%s\"\n", ver)
    21  		p.BuildConf.EntryPutStr(buildconf.KeyVersion, ver)
    22  	} else {
    23  		return err
    24  	}
    25  
    26  	if authors, err := git.Authors(); err == nil {
    27  		p.BuildConf.EntryPutStr(buildconf.KeyAuthors, strings.Join(authors, "\n"))
    28  	} else {
    29  		return err
    30  	}
    31  
    32  	return nil
    33  }
    34  
    35  func MakeGitDescribe(chk Check) ProbeInterface {
    36  	return GitDescribe{MakeProbeBase(chk)}
    37  }