github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/pkg/rule/rules_python/proto_py_library.go (about)

     1  package rules_python
     2  
     3  import (
     4  	"github.com/bazelbuild/bazel-gazelle/rule"
     5  
     6  	"github.com/stackb/rules_proto/pkg/protoc"
     7  )
     8  
     9  const (
    10  	ProtoPyLibraryRuleName   = "proto_py_library"
    11  	ProtoPyLibraryRuleSuffix = "_py_library"
    12  )
    13  
    14  func init() {
    15  	protoc.Rules().MustRegisterRule("stackb:rules_proto:proto_py_library", &protoPyLibrary{})
    16  }
    17  
    18  // protoPyLibrary implements LanguageRule for the 'proto_py_library' rule from
    19  // @rules_proto.
    20  type protoPyLibrary struct{}
    21  
    22  // Name implements part of the LanguageRule interface.
    23  func (s *protoPyLibrary) Name() string {
    24  	return ProtoPyLibraryRuleName
    25  }
    26  
    27  // KindInfo implements part of the LanguageRule interface.
    28  func (s *protoPyLibrary) KindInfo() rule.KindInfo {
    29  	return pyLibraryKindInfo
    30  }
    31  
    32  // LoadInfo implements part of the LanguageRule interface.
    33  func (s *protoPyLibrary) LoadInfo() rule.LoadInfo {
    34  	return rule.LoadInfo{
    35  		Name:    "@build_stack_rules_proto//rules/py:proto_py_library.bzl",
    36  		Symbols: []string{ProtoPyLibraryRuleName},
    37  	}
    38  }
    39  
    40  // ProvideRule implements part of the LanguageRule interface.
    41  func (s *protoPyLibrary) ProvideRule(cfg *protoc.LanguageRuleConfig, pc *protoc.ProtocConfiguration) protoc.RuleProvider {
    42  	outputs := pc.GetPluginOutputs("builtin:python")
    43  	if len(outputs) == 0 {
    44  		return nil
    45  	}
    46  	return &PyLibrary{
    47  		KindName:       ProtoPyLibraryRuleName,
    48  		RuleNameSuffix: ProtoPyLibraryRuleSuffix,
    49  		Outputs:        outputs,
    50  		RuleConfig:     cfg,
    51  		Config:         pc,
    52  		Resolver:       protoc.ResolveDepsAttr("deps", false),
    53  	}
    54  }