github.com/please-build/puku@v1.7.3-0.20240516143641-f7d7f4941f57/kinds/kinds.go (about)

     1  package kinds
     2  
     3  type Type int
     4  
     5  const (
     6  	Lib Type = iota
     7  	Test
     8  	Bin
     9  	ThirdParty
    10  )
    11  
    12  // Kind is a kind of build target, e.g. go_library. These can either be library, test or binaries. They can also provide
    13  // dependencies e.g. you could wrap go_test to add a common testing library, in which case, we should not add it as a
    14  // dep.
    15  type Kind struct {
    16  	Name              string
    17  	Type              Type
    18  	ProvidedDeps      []string
    19  	DefaultVisibility []string
    20  	SrcsAttr          string
    21  	// NonGoSources indicates the puku that the sources to this rule are not go so we shouldn't try to parse them to
    22  	// infer their deps, for example, proto_library.
    23  	NonGoSources bool
    24  }
    25  
    26  // IsProvided returns whether the dependency is already provided by the kind, and therefore can be omitted from the deps
    27  // list.
    28  func (k *Kind) IsProvided(i string) bool {
    29  	for _, dep := range k.ProvidedDeps {
    30  		if i == dep {
    31  			return true
    32  		}
    33  	}
    34  	return false
    35  }
    36  
    37  // DefaultKinds are the base kinds that puku supports out of the box
    38  var DefaultKinds = map[string]*Kind{
    39  	"go_library": {
    40  		Name:     "go_library",
    41  		Type:     Lib,
    42  		SrcsAttr: "srcs",
    43  	},
    44  	"go_binary": {
    45  		Name:     "go_binary",
    46  		Type:     Bin,
    47  		SrcsAttr: "srcs",
    48  	},
    49  	"go_test": {
    50  		Name:     "go_test",
    51  		Type:     Test,
    52  		SrcsAttr: "srcs",
    53  	},
    54  	"go_benchmark": {
    55  		Name:     "go_benchmark",
    56  		Type:     Test,
    57  		SrcsAttr: "srcs",
    58  	},
    59  	"proto_library": {
    60  		Name:         "proto_library",
    61  		Type:         Lib,
    62  		NonGoSources: true,
    63  	},
    64  	"grpc_library": {
    65  		Name:         "proto_library",
    66  		Type:         Lib,
    67  		NonGoSources: true,
    68  	},
    69  	"go_repo": {
    70  		Name:              "go_repo",
    71  		Type:              ThirdParty,
    72  		DefaultVisibility: []string{"PUBLIC"},
    73  	},
    74  	"go_module": {
    75  		Name: "go_repo",
    76  		Type: ThirdParty,
    77  	},
    78  }