github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/pkg/language/noop/noop.go (about)

     1  package noop
     2  
     3  import (
     4  	"flag"
     5  
     6  	"github.com/bazelbuild/bazel-gazelle/config"
     7  	"github.com/bazelbuild/bazel-gazelle/label"
     8  	"github.com/bazelbuild/bazel-gazelle/language"
     9  	"github.com/bazelbuild/bazel-gazelle/repo"
    10  	"github.com/bazelbuild/bazel-gazelle/resolve"
    11  	"github.com/bazelbuild/bazel-gazelle/rule"
    12  )
    13  
    14  // NewNoOpLanguage create a new NoOpLanguage Gazelle extension implementation.
    15  func NewNoOpLanguage(name string) *NoOpLanguage {
    16  	return &NoOpLanguage{
    17  		name: name,
    18  	}
    19  }
    20  
    21  // NoOpLanguage implements language.Language.
    22  type NoOpLanguage struct {
    23  	name string
    24  }
    25  
    26  // Name returns the name of the language. This should be a prefix of the kinds
    27  // of rules generated by the language, e.g., "go" for the Go extension since it
    28  // generates "go_library" rules.
    29  func (pl *NoOpLanguage) Name() string { return pl.name }
    30  
    31  // The following methods are implemented to satisfy the
    32  // https://pkg.go.dev/github.com/bazelbuild/bazel-gazelle/resolve?tab=doc#Resolver
    33  // interface, but are otherwise unused.
    34  func (*NoOpLanguage) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) {}
    35  
    36  func (*NoOpLanguage) CheckFlags(fs *flag.FlagSet, c *config.Config) error { return nil }
    37  
    38  func (*NoOpLanguage) KnownDirectives() []string { return nil }
    39  
    40  // Configure implements config.Configurer
    41  func (pl *NoOpLanguage) Configure(c *config.Config, rel string, f *rule.File) {}
    42  
    43  // Kinds returns a map of maps rule names (kinds) and information on how to
    44  // match and merge attributes that may be found in rules of those kinds. All
    45  // kinds of rules generated for this language may be found here.
    46  func (*NoOpLanguage) Kinds() map[string]rule.KindInfo {
    47  	return nil
    48  }
    49  
    50  // Loads returns .bzl files and symbols they define. Every rule generated by
    51  // GenerateRules, now or in the past, should be loadable from one of these
    52  // files.
    53  func (pl *NoOpLanguage) Loads() []rule.LoadInfo { return nil }
    54  
    55  // Fix repairs deprecated usage of language-specific rules in f. This is called
    56  // before the file is indexed. Unless c.ShouldFix is true, fixes that delete or
    57  // rename rules should not be performed.
    58  func (*NoOpLanguage) Fix(c *config.Config, f *rule.File) {}
    59  
    60  // Imports returns a list of ImportSpecs that can be used to import the rule r.
    61  // This is used to populate RuleIndex.
    62  //
    63  // If nil is returned, the rule will not be indexed. If any non-nil slice is
    64  // returned, including an empty slice, the rule will be indexed.
    65  func (pl *NoOpLanguage) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec {
    66  	return nil
    67  }
    68  
    69  // Embeds returns a list of labels of rules that the given rule embeds. If a
    70  // rule is embedded by another importable rule of the same language, only the
    71  // embedding rule will be indexed. The embedding rule will inherit the imports
    72  // of the embedded rule. Since SkyLark doesn't support embedding this should
    73  // always return nil.
    74  func (*NoOpLanguage) Embeds(r *rule.Rule, from label.Label) []label.Label { return nil }
    75  
    76  // Resolve translates imported libraries for a given rule into Bazel
    77  // dependencies. Information about imported libraries is returned for each rule
    78  // generated by language.GenerateRules in language.GenerateResult.Imports.
    79  // Resolve generates a "deps" attribute (or the appropriate language-specific
    80  // equivalent) for each import according to language-specific rules and
    81  // heuristics.
    82  func (pl *NoOpLanguage) Resolve(
    83  	c *config.Config,
    84  	ix *resolve.RuleIndex,
    85  	rc *repo.RemoteCache,
    86  	r *rule.Rule,
    87  	importsRaw interface{},
    88  	from label.Label,
    89  ) {
    90  }
    91  
    92  // GenerateRules extracts build metadata from source files in a directory.
    93  // GenerateRules is called in each directory where an update is requested in
    94  // depth-first post-order.
    95  //
    96  // args contains the arguments for GenerateRules. This is passed as a struct to
    97  // avoid breaking implementations in the future when new fields are added.
    98  //
    99  // A GenerateResult struct is returned. Optional fields may be added to this
   100  // type in the future.
   101  //
   102  // Any non-fatal errors this function encounters should be logged using
   103  // log.Print.
   104  func (pl *NoOpLanguage) GenerateRules(args language.GenerateArgs) language.GenerateResult {
   105  	return language.GenerateResult{}
   106  }