diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/gazelle/BUILD.bazel b/cmd/gazelle/BUILD.bazel index 038ba6469..4e650705d 100644 --- a/cmd/gazelle/BUILD.bazel +++ b/cmd/gazelle/BUILD.bazel @@ -29,6 +29,7 @@ go_library( "//cmd/gazelle/internal/wspace", "//language/proto_go_modules", "//language/protobuf", + "//language/starlarkmodules", "@bazel_gazelle//config:go_default_library", "@bazel_gazelle//flag:go_default_library", "@bazel_gazelle//label:go_default_library", diff --git a/cmd/gazelle/langs.go b/cmd/gazelle/langs.go index 021652958..26fab01c0 100644 --- a/cmd/gazelle/langs.go +++ b/cmd/gazelle/langs.go @@ -21,6 +21,7 @@ import ( "github.com/bazelbuild/bazel-gazelle/language/proto" "github.com/stackb/rules_proto/language/proto_go_modules" "github.com/stackb/rules_proto/language/protobuf" + "github.com/stackb/rules_proto/language/starlarkrepository" ) var languages = []language.Language{ @@ -28,4 +29,5 @@ var languages = []language.Language{ protobuf.NewLanguage(), golang.NewLanguage(), proto_go_modules.NewLanguage(), + starlarkrepository.NewLanguage(), } diff --git a/extensions/starlark_repository.bzl b/extensions/starlark_repository.bzl new file mode 100644 index 000000000..277ab42cb --- /dev/null +++ b/extensions/starlark_repository.bzl @@ -0,0 +1,90 @@ +"""proto_repostitory.bzl provides the starlark_repository rule.""" + +# Copyright 2014 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@bazel_features//:features.bzl", "bazel_features") +load("@build_stack_rules_proto//rules/proto:starlark_repository.bzl", "starlark_repository_attrs", starlark_repository_repo_rule = "starlark_repository") + +def _extension_metadata( + module_ctx, + *, + root_module_direct_deps = None, + root_module_direct_dev_deps = None, + reproducible = False): + """returns the module_ctx.extension_metadata in a bazel-version-aware way + + This function was copied from the bazel-gazelle repository. + """ + + if not hasattr(module_ctx, "extension_metadata"): + return None + metadata_kwargs = {} + if bazel_features.external_deps.extension_metadata_has_reproducible: + metadata_kwargs["reproducible"] = reproducible + return module_ctx.extension_metadata( + root_module_direct_deps = root_module_direct_deps, + root_module_direct_dev_deps = root_module_direct_dev_deps, + **metadata_kwargs + ) + +def _starlark_repository_impl(module_ctx): + # named_repos is a dict where V is the kwargs for the actual + # "starlark_repository" repo rule and K is the tag.name (the name given by the + # MODULE.bazel author) + named_archives = {} + + # iterate all the module tags and gather a list of named_archives. + # + # TODO(pcj): what is the best practice for version selection here? Do I need + # to check if module.is_root and handle that differently? + # + for module in module_ctx.modules: + for tag in module.tags.archive: + kwargs = { + attr: getattr(tag, attr) + for attr in _starlark_repository_archive_attrs.keys() + if hasattr(tag, attr) + } + named_archives[tag.name] = kwargs + + # declare a repository rule foreach one + for apparent_name, kwargs in named_archives.items(): + starlark_repository_repo_rule( + apparent_name = apparent_name, + **kwargs + ) + + return _extension_metadata( + module_ctx, + reproducible = True, + ) + +_starlark_repository_archive_attrs = starlark_repository_attrs | { + "name": attr.string( + doc = "The repo name.", + mandatory = True, + ), +} +_starlark_repository_archive_attrs.pop("apparent_name") + +starlark_repository = module_extension( + implementation = _starlark_repository_impl, + tag_classes = dict( + archive = tag_class( + doc = "declare an http_archive repository that is post-processed by a custom version of gazelle that includes the 'protobuf' language", + attrs = _starlark_repository_archive_attrs, + ), + ), +) diff --git a/language/starlarkrepository/BUILD.bazel b/language/starlarkrepository/BUILD.bazel new file mode 100644 index 000000000..6ba3ede0c --- /dev/null +++ b/language/starlarkrepository/BUILD.bazel @@ -0,0 +1,18 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "starlarkrepository", + srcs = ["language.go"], + importpath = "github.com/stackb/rules_proto/language/starlarkrepository", + visibility = ["//visibility:public"], + deps = [ + "@bazel_gazelle//config:go_default_library", + "@bazel_gazelle//label:go_default_library", + "@bazel_gazelle//language:go_default_library", + "@bazel_gazelle//pathtools:go_default_library", + "@bazel_gazelle//repo:go_default_library", + "@bazel_gazelle//resolve:go_default_library", + "@bazel_gazelle//rule:go_default_library", + "@com_github_bazelbuild_buildtools//build:go_default_library", + ], +) diff --git a/language/starlarkrepository/language.go b/language/starlarkrepository/language.go new file mode 100644 index 000000000..841f4931c --- /dev/null +++ b/language/starlarkrepository/language.go @@ -0,0 +1,572 @@ +/* Copyright 2020 The Bazel Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package symbol generates a `starlark_library` target for every `.bzl` file in +// each package. At the root of the module, a single starlark_library is +// populated with deps that include all other starlark_libraries. +// +// The original code for this gazelle extension started from +// https://github.com/bazelbuild/bazel-skylib/blob/main/gazelle/bzl/gazelle.go. +package starlarkrepository + +import ( + "bufio" + "context" + "flag" + "fmt" + "io" + "log" + "maps" + "os" + "path/filepath" + "slices" + "sort" + "strings" + + "github.com/bazelbuild/bazel-gazelle/config" + "github.com/bazelbuild/bazel-gazelle/label" + "github.com/bazelbuild/bazel-gazelle/language" + "github.com/bazelbuild/bazel-gazelle/repo" + "github.com/bazelbuild/bazel-gazelle/resolve" + "github.com/bazelbuild/bazel-gazelle/rule" + "github.com/bazelbuild/buildtools/build" +) + +const ( + languageName = "starlarkrepository" + repoNameDirectiveName = languageName + "_repo_name" + rootDirectiveName = languageName + "_root" + excludeDirectiveName = languageName + "_exclude" + logFileDirectiveName = languageName + "_log_file" + starlarkModuleKind = "starlark_module" + starlarkModuleLibraryKind = "starlark_module_library" + starlarkModuleLibraryName = "modules" + fileType = ".bzl" + visibilityPublic = "//visibility:public" +) + +var ( + ignoreSuffix = suffixes{ + "_tests.bzl", + "_test.bzl", + } + starlarkModuleLibraryKindInfo = map[string]rule.KindInfo{ + starlarkModuleLibraryKind: { + NonEmptyAttrs: map[string]bool{"modules": true}, + ResolveAttrs: map[string]bool{"modules": true}, + }, + } + starlarkModuleKindInfo = map[string]rule.KindInfo{ + starlarkModuleKind: { + NonEmptyAttrs: map[string]bool{"src": true}, + }, + } + starlarkModuleLibraryLoadInfo = rule.LoadInfo{ + Name: "@build_stack_rules_proto//rules:starlark_module_library.bzl", + Symbols: []string{starlarkModuleLibraryKind}, + } + starlarkModuleLoadInfo = rule.LoadInfo{ + Name: "@build_stack_rules_proto//rules:starlark_module.bzl", + Symbols: []string{starlarkModuleKind}, + } +) + +type starlarkRepositoryLang struct { + roots []string + repoName string + excludeDirs []string + bazelVersion string + bazelIgnore []string + logFile string + logWriter *os.File + logger *log.Logger +} + +// NewLanguage is called by Gazelle to install this language extension in a +// binary. +func NewLanguage() language.Language { + return &starlarkRepositoryLang{ + excludeDirs: []string{ + "docs", + "javatests", + "testdata", + "tests", + }, + } +} + +// Name returns the name of the language. This should be a prefix of the kinds +// of rules generated by the language, e.g., "go" for the Go extension since it +// generates "go_library" rules. +func (*starlarkRepositoryLang) Name() string { + return languageName +} + +// The following methods are implemented to satisfy the +// https://pkg.go.dev/github.com/bazelbuild/bazel-gazelle/resolve?tab=doc#Resolver +// interface, but are otherwise unused. +func (ext *starlarkRepositoryLang) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) { + fs.StringVar(&ext.logFile, logFileDirectiveName, "", "path to log file for this extension") +} + +func (ext *starlarkRepositoryLang) CheckFlags(fs *flag.FlagSet, c *config.Config) error { + if ext.logFile != "" { + ext.createLogger(ext.logFile) + ext.logf("CheckFlags: log file initialized from flag: %s", ext.logFile) + } + if ext.logger == nil { + ext.logger = log.New(io.Discard, "", 0) + } + + // REPO.bazel causes visibility issues if the root BUILD file has been + // deleted but still referencing non-existent rules. This should be moved + // to the part where gazelle cleans up build files. + repoBazelFilename := filepath.Join(c.RepoRoot, "REPO.bazel") + deleteFile(repoBazelFilename, ext.logf) + + bazelVersionFilename := filepath.Join(c.RepoRoot, ".bazelversion") + if lines, err := readFileLines(bazelVersionFilename, ext.logf); err == nil { + ext.bazelVersion = strings.Join(lines, ":") + deleteFile(bazelVersionFilename, ext.logf) + } + + bazelIgnoreFilename := filepath.Join(c.RepoRoot, ".bazelignore") + if lines, err := readFileLines(bazelIgnoreFilename, ext.logf); err == nil { + ext.bazelIgnore = lines + deleteFile(bazelIgnoreFilename, ext.logf) + } + + return nil +} + +func (*starlarkRepositoryLang) KnownDirectives() []string { + return []string{ + rootDirectiveName, + excludeDirectiveName, + logFileDirectiveName, + } +} + +func (ext *starlarkRepositoryLang) Configure(c *config.Config, rel string, f *rule.File) { + if f != nil { + ext.logf("Configure: processing %d directives in %s", len(f.Directives), rel) + for _, d := range f.Directives { + switch d.Key { + case rootDirectiveName: + ext.roots = append(ext.roots, d.Value) + case repoNameDirectiveName: + ext.repoName = d.Value + case excludeDirectiveName: + ext.excludeDirs = append(ext.excludeDirs, d.Value) + case logFileDirectiveName: + ext.createLogger(d.Value) + } + } + } +} + +func (ext *starlarkRepositoryLang) createLogger(logFile string) { + if logFile != "" { + f, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) + if err == nil { + ext.logWriter = f + ext.logger = log.New(f, "", log.LstdFlags) + } else { + log.Fatalf("attempting to open log file: %v", err) + } + } + if false && ext.logger == nil { + ext.logger = log.New(io.Discard, "", 0) + } + + ext.logf("Log initialized") +} + +// Kinds returns a map of maps rule names (kinds) and information on how to +// match and merge attributes that may be found in rules of those kinds. All +// kinds of rules generated for this language may be found here. +func (*starlarkRepositoryLang) Kinds() map[string]rule.KindInfo { + kinds := map[string]rule.KindInfo{} + maps.Copy(kinds, starlarkModuleLibraryKindInfo) + maps.Copy(kinds, starlarkModuleKindInfo) + return kinds +} + +// Loads returns .bzl files and symbols they define. Every rule generated by +// GenerateRules, now or in the past, should be loadable from one of these +// files. +func (*starlarkRepositoryLang) Loads() []rule.LoadInfo { + return []rule.LoadInfo{ + starlarkModuleLibraryLoadInfo, + starlarkModuleLoadInfo, + } +} + +// Fix repairs deprecated usage of language-specific rules in f. This is called +// before the file is indexed. Unless c.ShouldFix is true, fixes that delete or +// rename rules should not be performed. +func (*starlarkRepositoryLang) Fix(c *config.Config, f *rule.File) { +} + +// Imports returns a list of ImportSpecs that can be used to import the rule r. +// This is used to populate RuleIndex. +// +// If nil is returned, the rule will not be indexed. If any non-nil slice is +// returned, including an empty slice, the rule will be indexed. +func (ext *starlarkRepositoryLang) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec { + switch r.Kind() { + case starlarkModuleKind: + return ext.starlarkModuleImports(c, r, f) + default: + return nil + } +} + +func (ext *starlarkRepositoryLang) starlarkModuleImports(_ *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec { + // return one for file level dep resolution, one for the rule kind itself + return []resolve.ImportSpec{ + {Lang: languageName, Imp: fmt.Sprintf("//%s:%s", f.Pkg, r.AttrString("src"))}, + {Lang: languageName, Imp: starlarkModuleKind}, + } +} + +// Embeds returns a list of labels of rules that the given rule embeds. If a +// rule is embedded by another importable rule of the same language, only the +// embedding rule will be indexed. The embedding rule will inherit the imports +// of the embedded rule. Since SkyLark doesn't support embedding this should +// always return nil. +func (*starlarkRepositoryLang) Embeds(r *rule.Rule, from label.Label) []label.Label { + return nil +} + +// Resolve translates imported libraries for a given rule into Bazel +// dependencies. Information about imported libraries is returned for each rule +// generated by language.GenerateRules in language.GenerateResult.Imports. +// Resolve generates a "deps" attribute (or the appropriate language-specific +// equivalent) for each import according to language-specific rules and +// heuristics. +func (ext *starlarkRepositoryLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, r *rule.Rule, importsRaw interface{}, from label.Label) { + switch r.Kind() { + case starlarkModuleLibraryKind: + ext.starlarkModuleLibraryResolve(c, ix, rc, r, importsRaw, from) + } +} + +// GenerateRules extracts build metadata from source files in a directory. +// GenerateRules is called in each directory where an update is requested in +// depth-first post-order. +// +// args contains the arguments for GenerateRules. This is passed as a struct to +// avoid breaking implementations in the future when new fields are added. +// +// A GenerateResult struct is returned. Optional fields may be added to this +// type in the future. +// +// Any non-fatal errors this function encounters should be logged using +// log.Print. +func (ext *starlarkRepositoryLang) GenerateRules(args language.GenerateArgs) (result language.GenerateResult) { + // extension is effectively disabled without specifying at least one root + if len(ext.roots) == 0 { + return + } + // skip excluded dirs + for _, dir := range ext.excludeDirs { + if strings.HasPrefix(args.Rel, dir) { + return + } + } + + ext.logf("GenerateRules %v: visiting %s: %v", ext.roots, args.Rel, args.RegularFiles) + mustListFiles(ext.logf, filepath.Join(args.Config.WorkDir, args.Rel)) + for _, f := range args.RegularFiles { + if !isBzlSourceFile(f) { + continue + } + relPath := filepath.Join(args.Rel, f) + fullPath := filepath.Join(args.Config.WorkDir, relPath) + + _, loadStmts, err := getBzlFileLoadsStmts(fullPath, args.Rel, ext.logf) + if err != nil { + ext.logf("%s: contains syntax errors: %v", fullPath, err) + continue + } + + r, imports := ext.starlarkModuleRule(args, f, loadStmts) + result.Gen = append(result.Gen, r) + result.Imports = append(result.Imports, imports) + log.Printf("generated %s %s/%s", r.Kind(), args.Rel, r.Name()) + } + + if _, ok := getMatchingRoot(args.Rel, ext.roots); ok { + r, imports := ext.starlarkModuleLibraryRule(args) + result.Gen = append(result.Gen, r) + result.Imports = append(result.Imports, imports) + } + + return +} + +// mustListFiles - convenience debugging function to log the files under a given +// dir, excluding proto files and the extra binaries here. +func mustListFiles(logf LogFunc, dir string) []string { + files := make([]string, 0) + + if err := filepath.Walk(dir, func(relname string, info os.FileInfo, err error) error { + if err != nil { + log.Fatal(err) + } + if info.IsDir() { + return nil + } + if filepath.Ext(relname) == ".proto" { + return nil + } + files = append(files, relname) + logf("file: %s", relname) + return nil + }); err != nil { + logf("walk error: %v", err) + } + + return files +} +func (ext *starlarkRepositoryLang) starlarkModuleRule(args language.GenerateArgs, src string, loadStmts []*build.LoadStmt) (*rule.Rule, []any) { + + name := strings.TrimSuffix(src, fileType) + ext.logf("generating %s rule for %s //%s:%s", starlarkModuleKind, src, args.Rel, name) + + loads := make([]string, 0, len(loadStmts)) + for _, stmt := range loadStmts { + loads = append(loads, stmt.Module.Value) + } + sort.Strings(loads) + + r := rule.NewRule(starlarkModuleKind, name) + r.SetAttr("src", src) + r.SetAttr("loads", loads) + r.SetAttr("visibility", []string{visibilityPublic}) + + return r, []any{} +} + +func (ext *starlarkRepositoryLang) starlarkModuleLibraryRule(_ language.GenerateArgs) (*rule.Rule, []any) { + r := rule.NewRule(starlarkModuleLibraryKind, starlarkModuleLibraryName) + if ext.repoName != "" { + r.SetAttr("repo_name", ext.repoName) + } + if ext.bazelVersion != "" { + r.SetAttr("bazelversion", ext.bazelVersion) + } + if len(ext.bazelIgnore) > 0 { + r.SetAttr("bazelignore", ext.bazelIgnore) + } + r.SetAttr("visibility", []string{visibilityPublic}) + return r, []any{} +} + +func (ext *starlarkRepositoryLang) starlarkModuleLibraryResolve(c *config.Config, ix *resolve.RuleIndex, _ *repo.RemoteCache, r *rule.Rule, _ interface{}, from label.Label) { + // only perform resolve if this is one of the roots + root, isRoot := getMatchingRoot(from.Pkg, ext.roots) + if !isRoot { + ext.logf("skipping modules resolution for %v (not a root: %v)", from, ext.roots) + return + } + + var modules []string + + // fetch all starlark_module rules, then filter by the ones below our root + matches := ix.FindRulesByImportWithConfig(c, resolve.ImportSpec{ + Lang: languageName, + Imp: starlarkModuleKind, + }, languageName) + for _, m := range matches { + depLabel := m.Label.Rel(from.Repo, from.Pkg) + if strings.HasPrefix(depLabel.Pkg, root) { + modules = append(modules, depLabel.String()) + } + } + + if len(modules) > 0 { + sort.Strings(modules) + r.SetAttr("modules", modules) + } +} + +// Before implements part of the language.LifecycleManager interface. +func (ext *starlarkRepositoryLang) Before(context.Context) { + ext.logf("Lifecycle: Before() called") + ext.logf("roots: %v", ext.roots) +} + +// DoneGeneratingRules implements part of the language.FinishableLanguage interface. +func (ext *starlarkRepositoryLang) DoneGeneratingRules() { + ext.logf("Lifecycle: DoneGeneratingRules() called") +} + +// AfterResolvingDeps implements part of the language.LifecycleManager interface. +// This is where we flush and close the log file. +func (ext *starlarkRepositoryLang) AfterResolvingDeps(context.Context) { + ext.logf("Lifecycle: AfterResolvingDeps() called - flushing and closing log file") + if ext.logWriter != nil { + // Sync flushes any buffered data to disk + _ = ext.logWriter.Sync() + // Close the file + _ = ext.logWriter.Close() + ext.logWriter = nil + } +} + +// logf logs a message using the extension's logger if configured +func (ext *starlarkRepositoryLang) logf(format string, args ...any) { + if ext.logger != nil { + ext.logger.Printf(format, args...) + } +} + +func getMatchingRoot(rel string, roots []string) (string, bool) { + for _, root := range roots { + if root == rel { + return root, true + } + } + return "", false +} + +type suffixes []string + +func (s suffixes) Matches(test string) bool { + for _, v := range s { + if strings.HasSuffix(test, v) { + return true + } + } + return false +} + +// LogFunc is a function type for logging messages +type LogFunc func(format string, args ...any) + +// deleteFile removes a file and logs any errors +func deleteFile(filename string, logf LogFunc) { + if err := os.Remove(filename); err != nil { + logf("ERROR: failed to remove %s: %v", filename, err) + } +} + +// readFileLines reads a file and returns a slice of trimmed non-empty lines, +// excluding comments (lines starting with #). +func readFileLines(filePath string, logf LogFunc) ([]string, error) { + logf("Reading lines from file: %s", filePath) + + // Open the file + file, err := os.Open(filePath) + if err != nil { + if os.IsNotExist(err) { + logf(" File does not exist") + return nil, err + } + return nil, fmt.Errorf("failed to open file: %w", err) + } + defer file.Close() + + // Scan lines using bufio.Scanner + scanner := bufio.NewScanner(file) + var lines []string + + for scanner.Scan() { + line := scanner.Text() + trimmed := strings.TrimSpace(line) + + // Skip empty lines + if trimmed == "" { + continue + } + + // Skip comments + if strings.HasPrefix(trimmed, "#") { + continue + } + + lines = append(lines, trimmed) + } + + if err := scanner.Err(); err != nil { + return nil, fmt.Errorf("failed to scan file: %w", err) + } + + logf(" Read %d non-empty lines", len(lines)) + return lines, nil +} + +func isBzlSourceFile(f string) bool { + return strings.HasSuffix(f, fileType) && !ignoreSuffix.Matches(f) +} + +func getBzlFileLoadsStmts(path, rel string, logf LogFunc) (*build.File, []*build.LoadStmt, error) { + f, err := os.ReadFile(path) + if err != nil { + return nil, nil, fmt.Errorf("os.ReadFile(%q) error: %v", path, err) + } + ast, err := build.ParseBzl(path, f) + if err != nil { + return nil, nil, fmt.Errorf("build.Parse(%q) error: %v", f, err) + } + + var loads []*build.LoadStmt + build.WalkOnce(ast, func(expr *build.Expr) { + n := *expr + if l, ok := n.(*build.LoadStmt); ok { + if lbl, err := label.Parse(l.Module.Value); err == nil { + l.Module.Value = lbl.Abs("", rel).String() + } else { + logf("rel=%q: load parse error: %s %v", rel, l.Module.Value, err) + } + loads = append(loads, l) + } + }) + + return ast, loads, nil +} + +// stringListDict creates a Dict expression with string keys and List values +// containing StringExpr elements. Used for representing load statements by file. +func stringListDict(data map[string][]string) *build.DictExpr { + if len(data) == 0 { + return &build.DictExpr{} + } + + // Sort keys for deterministic output + keys := slices.Sorted(maps.Keys(data)) + + var keyValues []*build.KeyValueExpr + for _, key := range keys { + values := data[key] + + // Create list of string expressions for the values + var listExprs []build.Expr + for _, value := range values { + listExprs = append(listExprs, &build.StringExpr{Value: value}) + } + + keyValues = append(keyValues, &build.KeyValueExpr{ + Key: &build.StringExpr{Value: key}, + Value: &build.ListExpr{List: listExprs}, + }) + } + + return &build.DictExpr{ + List: keyValues, + } +} diff --git a/language/starlarkrepository/language_test.go b/language/starlarkrepository/language_test.go new file mode 100644 index 000000000..3c0c61235 --- /dev/null +++ b/language/starlarkrepository/language_test.go @@ -0,0 +1,237 @@ +package starlarkrepository + +import ( + "os" + "path/filepath" + "testing" + + "github.com/bazelbuild/buildtools/build" +) + +// readFileLines tests + +func TestReadLines(t *testing.T) { + tests := []struct { + name string + input string + expected []string + }{ + { + name: "filters empty lines and comments", + input: `.build/ +# This is a comment +.swiftpm/ +.vscode/ + +`, + expected: []string{".build/", ".swiftpm/", ".vscode/"}, + }, + { + name: "handles only comments", + input: `# Comment 1 +# Comment 2 +# Comment 3 +`, + expected: []string{}, + }, + { + name: "handles mixed content", + input: ` .build/ +# Comment + +.swiftpm/ + # Another comment +.vscode/ +`, + expected: []string{".build/", ".swiftpm/", ".vscode/"}, + }, + { + name: "empty file", + input: "", + expected: []string{}, + }, + { + name: "only whitespace", + input: ` + + +`, + expected: []string{}, + }, + { + name: "trims whitespace", + input: ` .build/ + .swiftpm/ + .vscode/ +`, + expected: []string{".build/", ".swiftpm/", ".vscode/"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Create temp directory + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "test.txt") + + // Write input content + if err := os.WriteFile(testFile, []byte(tt.input), 0644); err != nil { + t.Fatalf("failed to write test file: %v", err) + } + + // Create a no-op log function for tests + noop := func(format string, args ...any) {} + + // Run the function + lines, err := readFileLines(testFile, noop) + if err != nil { + t.Fatalf("readLines failed: %v", err) + } + + // Handle nil vs empty slice + if tt.expected == nil || len(tt.expected) == 0 { + if len(lines) != 0 { + t.Errorf("Expected empty result, got %d lines: %v", len(lines), lines) + } + return + } + + // Compare results + if len(lines) != len(tt.expected) { + t.Errorf("Length mismatch: got %d lines, want %d lines", len(lines), len(tt.expected)) + t.Errorf("got: %v", lines) + t.Errorf("want: %v", tt.expected) + return + } + + for i, line := range lines { + if line != tt.expected[i] { + t.Errorf("Line %d mismatch:\ngot: %q\nwant: %q", i, line, tt.expected[i]) + } + } + }) + } +} + +func TestReadLines_NonExistent(t *testing.T) { + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "nonexistent.txt") + + noop := func(format string, args ...any) {} + + // Should return error for non-existent file + lines, err := readFileLines(testFile, noop) + if err == nil { + t.Errorf("expected error for non-existent file, got nil") + } + if lines != nil { + t.Errorf("expected nil slice for non-existent file, got: %v", lines) + } +} + +// stringListDict tests + +func TestStringListDict(t *testing.T) { + tests := []struct { + name string + input map[string][]string + }{ + { + name: "empty map", + input: map[string][]string{}, + }, + { + name: "single key with single value", + input: map[string][]string{ + "foo.bzl": {"@repo//pkg:file.bzl"}, + }, + }, + { + name: "single key with multiple values", + input: map[string][]string{ + "foo.bzl": { + "@repo1//pkg:file1.bzl", + "@repo2//pkg:file2.bzl", + }, + }, + }, + { + name: "multiple keys sorted alphabetically", + input: map[string][]string{ + "zebra.bzl": {"@repo//z:z.bzl"}, + "alpha.bzl": {"@repo//a:a.bzl"}, + "beta.bzl": {"@repo//b:b.bzl"}, + }, + }, + { + name: "multiple keys with multiple values", + input: map[string][]string{ + "rules.bzl": { + "@rules_proto//proto:defs.bzl", + "@bazel_skylib//lib:paths.bzl", + }, + "providers.bzl": { + "@rules_proto//proto:providers.bzl", + }, + }, + }, + { + name: "empty values list", + input: map[string][]string{ + "empty.bzl": {}, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := stringListDict(tt.input) + + // Verify the structure + if result == nil { + t.Fatal("result should not be nil") + } + + if len(tt.input) == 0 && len(result.List) != 0 { + t.Errorf("empty input should produce empty dict, got %d entries", len(result.List)) + } + + if len(tt.input) != 0 && len(result.List) != len(tt.input) { + t.Errorf("expected %d dict entries, got %d", len(tt.input), len(result.List)) + } + + // Verify each key-value pair + for _, kv := range result.List { + keyExpr, ok := kv.Key.(*build.StringExpr) + if !ok { + t.Errorf("key should be StringExpr, got %T", kv.Key) + continue + } + + listExpr, ok := kv.Value.(*build.ListExpr) + if !ok { + t.Errorf("value should be ListExpr, got %T", kv.Value) + continue + } + + // Verify all list elements are StringExpr + for i, elem := range listExpr.List { + if _, ok := elem.(*build.StringExpr); !ok { + t.Errorf("list element %d should be StringExpr, got %T", i, elem) + } + } + + // Verify the values match + expectedValues, exists := tt.input[keyExpr.Value] + if !exists { + t.Errorf("unexpected key %q in result", keyExpr.Value) + continue + } + + if len(listExpr.List) != len(expectedValues) { + t.Errorf("key %q: expected %d values, got %d", keyExpr.Value, len(expectedValues), len(listExpr.List)) + } + } + }) + } +} diff --git a/rules/private/proto_repository_tools_srcs.bzl b/rules/private/proto_repository_tools_srcs.bzl index 9810725aa..d3471cd4e 100644 --- a/rules/private/proto_repository_tools_srcs.bzl +++ b/rules/private/proto_repository_tools_srcs.bzl @@ -43,6 +43,8 @@ PROTO_REPOSITORY_TOOLS_SRCS = [ "@build_stack_rules_proto//language/proto_go_modules:rule.go", "@build_stack_rules_proto//language/protobuf:BUILD.bazel", "@build_stack_rules_proto//language/protobuf:protobuf.go", + "@build_stack_rules_proto//language/starlarkrepository:BUILD.bazel", + "@build_stack_rules_proto//language/starlarkrepository:language.go", "@build_stack_rules_proto//pkg:BUILD.bazel", "@build_stack_rules_proto//pkg/goldentest:BUILD.bazel", "@build_stack_rules_proto//pkg/goldentest:cases.go", @@ -190,14 +192,22 @@ PROTO_REPOSITORY_TOOLS_SRCS = [ "@build_stack_rules_proto//toolchain:BUILD.bazel", "@build_stack_rules_proto//toolchain/scala:BUILD.bazel", "@build_stack_rules_proto//tools:BUILD.bazel", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/config:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/config:config.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/config:constants.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/flag:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/flag:flag.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/internal/module:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/internal/module:module.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/internal/version:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/internal/version:version.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/internal/wspace:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/internal/wspace:finder.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/label:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/label:label.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language:base.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/go:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/go:build_constraints.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/go:config.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/go:constants.go", @@ -218,6 +228,7 @@ PROTO_REPOSITORY_TOOLS_SRCS = [ "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/go:work.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language:lang.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language:lifecycle.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/proto:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/proto:config.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/proto:constants.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/proto:fileinfo.go", @@ -231,13 +242,18 @@ PROTO_REPOSITORY_TOOLS_SRCS = [ "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/proto:package.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language/proto:resolve.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/language:update.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/merger:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/merger:fix.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/merger:merger.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/pathtools:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/pathtools:path.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/repo:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/repo:remote.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/repo:repo.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/resolve:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/resolve:config.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/resolve:index.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/rule:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/rule:directives.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/rule:expr.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/rule:merge.go", @@ -247,12 +263,15 @@ PROTO_REPOSITORY_TOOLS_SRCS = [ "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/rule:sort_labels.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/rule:types.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/rule:value.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/testtools:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/testtools:config.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/testtools:files.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/walk:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/walk:cache.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/walk:config.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/walk:dirinfo.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/walk:walk.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/build:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/build:lex.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/build:parse.y.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/build:print.go", @@ -262,14 +281,18 @@ PROTO_REPOSITORY_TOOLS_SRCS = [ "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/build:syntax.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/build:utils.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/build:walk.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/labels:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/labels:labels.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/tables:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/tables:jsonparser.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/buildtools/tables:tables.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/runfiles:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/runfiles:directory.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/runfiles:fs.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/runfiles:global.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/runfiles:manifest.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/runfiles:runfiles.go", + "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/tools/bazel:BUILD.bazel", "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/tools/bazel:bazel.go", "@build_stack_rules_proto//vendor/github.com/bazelbuild/rules_go/go/tools/bazel:runfiles.go", "@build_stack_rules_proto//vendor/github.com/bmatcuk/doublestar:doublestar.go", diff --git a/rules/proto/starlark_repository.bzl b/rules/proto/starlark_repository.bzl new file mode 100644 index 000000000..604b80e6c --- /dev/null +++ b/rules/proto/starlark_repository.bzl @@ -0,0 +1,31 @@ +"""proto_repository.bzl provides the proto_repository rule.""" + +# Copyright 2014 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@build_stack_rules_proto//rules/proto:proto_repository.bzl", "protobuf_go_repository", _proto_repository_attrs = "proto_repository_attrs") + +# TODO: narrow the set of available attrs +starlark_repository_attrs = _proto_repository_attrs + +def starlark_repository(**kwargs): + """starlark_repository wraps proto_repository and sets the language to starlark_bundle + + Args: + **kwargs: the kwargs dict passed to protobuf_go_repository + """ + name = kwargs.get("name") + kwargs.setdefault("apparent_name", name) + + protobuf_go_repository(**kwargs) diff --git a/rules/starlark_module.bzl b/rules/starlark_module.bzl new file mode 100644 index 000000000..60c857687 --- /dev/null +++ b/rules/starlark_module.bzl @@ -0,0 +1,39 @@ +"""starlark_module.bzl is similar to bzl_library but also provides load statement foreach file.""" + +load("@bazel_skylib//:bzl_library.bzl", "StarlarkLibraryInfo") + +StarlarkModuleInfo = provider( + "Information about a single .bzl file.", + fields = { + "label": "Label: The label of the target rule", + "loads": "List[str]: load statements for this file", + "src": "File: The .bzl file", + }, +) + +def _starlark_module_impl(ctx): + return [ + StarlarkLibraryInfo( + srcs = [ctx.file.src], + transitive_srcs = depset([ctx.file.src]), + ), + StarlarkModuleInfo( + label = ctx.label, + loads = ctx.attr.loads, + src = ctx.file.src, + ), + ] + +starlark_module = rule( + implementation = _starlark_module_impl, + attrs = { + "loads": attr.string_list( + doc = "the load statements in this file", + ), + "src": attr.label( + doc = "the .bzl source file", + allow_single_file = True, + ), + }, + provides = [StarlarkLibraryInfo, StarlarkModuleInfo], +) diff --git a/rules/starlark_module_library.bzl b/rules/starlark_module_library.bzl new file mode 100644 index 000000000..2dfa53e34 --- /dev/null +++ b/rules/starlark_module_library.bzl @@ -0,0 +1,43 @@ +"""starlark_module_library.bzl is similar to bzl_library but also provides load statement foreach file.""" + +load("//rules:starlark_module.bzl", "StarlarkModuleInfo") + +StarlarkModuleLibraryInfo = provider( + "Information on a set of starlark modules. This is a flat list, non-transitive.", + fields = { + "label": "The label of the target rule", + "modules": "List[StarlarkModuleInfo]: modules deps of this rule", + "srcs": "List[File]: source files for the modules, for convenience", + "bazelignore": "List[str] value of ctx.attr.bazelignore", + "bazelversion": "str: the value of ctx.attr.bazelversion", + }, +) + +def _starlark_module_library_impl(ctx): + modules = [m[StarlarkModuleInfo] for m in ctx.attr.modules] + return [ + StarlarkModuleLibraryInfo( + label = ctx.label, + bazelignore = ctx.attr.bazelignore, + bazelversion = ctx.attr.bazelversion, + modules = modules, + srcs = [m.src for m in modules], + ), + ] + +starlark_module_library = rule( + implementation = _starlark_module_library_impl, + attrs = { + "bazelignore": attr.string_list( + doc = "contents of the .bazelignore file, if present", + ), + "bazelversion": attr.string( + doc = "contents of the .bazelversion file, if present", + ), + "modules": attr.label_list( + doc = "list of starlark_module rule dependencies.", + providers = [StarlarkModuleInfo], + ), + }, + provides = [StarlarkModuleLibraryInfo], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/config/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/config/BUILD.bazel new file mode 100644 index 000000000..2d5718174 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/config/BUILD.bazel @@ -0,0 +1,41 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "config", + srcs = [ + "config.go", + "constants.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/config", + visibility = ["//visibility:public"], + deps = [ + "//internal/module", + "//internal/wspace", + "//rule", + ], +) + +go_test( + name = "config_test", + srcs = ["config_test.go"], + embed = [":config"], + deps = ["//rule"], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "config.go", + "config_test.go", + "constants.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":config", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/flag/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/flag/BUILD.bazel new file mode 100644 index 000000000..6820783c6 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/flag/BUILD.bazel @@ -0,0 +1,24 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "flag", + srcs = ["flag.go"], + importpath = "github.com/bazelbuild/bazel-gazelle/flag", + visibility = ["//visibility:public"], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "flag.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":flag", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/internal/module/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/internal/module/BUILD.bazel new file mode 100644 index 000000000..2446f86c7 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/internal/module/BUILD.bazel @@ -0,0 +1,43 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "module", + srcs = ["module.go"], + importpath = "github.com/bazelbuild/bazel-gazelle/internal/module", + visibility = ["//:__subpackages__"], + deps = [ + "//label", + "@com_github_bazelbuild_buildtools//build", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "module.go", + "module_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":module", + visibility = ["//:__subpackages__"], +) + +go_test( + name = "module_test", + srcs = ["module_test.go"], + data = glob( + ["testdata/**"], + allow_empty = True, + ), + embed = [":module"], + deps = [ + "@com_github_google_go_cmp//cmp", + "@io_bazel_rules_go//go/runfiles", + ], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/internal/version/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/internal/version/BUILD.bazel new file mode 100644 index 000000000..2d358d8d7 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/internal/version/BUILD.bazel @@ -0,0 +1,31 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "version", + srcs = ["version.go"], + importpath = "github.com/bazelbuild/bazel-gazelle/internal/version", + visibility = ["//:__subpackages__"], +) + +go_test( + name = "version_test", + srcs = ["version_test.go"], + embed = [":version"], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "version.go", + "version_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":version", + visibility = ["//:__subpackages__"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/internal/wspace/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/internal/wspace/BUILD.bazel new file mode 100644 index 000000000..7cd120185 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/internal/wspace/BUILD.bazel @@ -0,0 +1,32 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "wspace", + srcs = ["finder.go"], + importpath = "github.com/bazelbuild/bazel-gazelle/internal/wspace", + visibility = ["//visibility:public"], +) + +go_test( + name = "wspace_test", + size = "small", + srcs = ["finder_test.go"], + embed = [":wspace"], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "finder.go", + "finder_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":wspace", + visibility = ["//:__subpackages__"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/label/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/label/BUILD.bazel new file mode 100644 index 000000000..94aaa100d --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/label/BUILD.bazel @@ -0,0 +1,35 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "label", + srcs = ["label.go"], + importpath = "github.com/bazelbuild/bazel-gazelle/label", + visibility = ["//visibility:public"], + deps = [ + "//pathtools", + "@com_github_bazelbuild_buildtools//build", + ], +) + +go_test( + name = "label_test", + srcs = ["label_test.go"], + embed = [":label"], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "label.go", + "label_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":label", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/language/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/language/BUILD.bazel new file mode 100644 index 000000000..77e295069 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/language/BUILD.bazel @@ -0,0 +1,42 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "language", + srcs = [ + "base.go", + "lang.go", + "lifecycle.go", + "update.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/language", + visibility = ["//visibility:public"], + deps = [ + "//config", + "//label", + "//repo", + "//resolve", + "//rule", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "base.go", + "lang.go", + "lifecycle.go", + "update.go", + "//language/bazel:all_files", + "//language/go:all_files", + "//language/proto:all_files", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":language", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/language/go/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/language/go/BUILD.bazel new file mode 100644 index 000000000..bdcc9ad64 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/language/go/BUILD.bazel @@ -0,0 +1,162 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@bazel_skylib//rules:diff_test.bzl", "diff_test") +load("@bazel_skylib//rules:run_binary.bzl", "run_binary") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load(":def.bzl", "std_package_list") + +# gazelle:exclude testdata + +# TODO(jayconrod): test that the checked-in static file matches the generated +# file. The generated code is checked in so that Gazelle can still be built +# with "go get". +std_package_list( + name = "std_package_list", + out = "std_package_list.go", +) + +# gazelle:exclude gen_platform_info.go +run_binary( + name = "gen_platform_info", + outs = ["gen_platform_info.go"], + args = ["$(location :gen_platform_info.go)"], + tool = "//language/go/platform_info_generator", +) + +diff_test( + name = "platform_info_diff_test", + file1 = ":gen_platform_info.go", + file2 = "platform_info.go", +) + +go_library( + name = "go", + srcs = [ + "build_constraints.go", + "config.go", + "constants.go", + "embed.go", + "fileinfo.go", + "fix.go", + "generate.go", + "kinds.go", + "lang.go", + "modules.go", + "package.go", + "platform_info.go", + "resolve.go", + "std_package_list.go", + "stdlib_links.go", + "update.go", + "utils.go", + "work.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/language/go", + visibility = ["//visibility:public"], + deps = [ + "//config", + "//flag", + "//internal/module", + "//internal/version", + "//label", + "//language", + "//language/proto", + "//pathtools", + "//repo", + "//resolve", + "//rule", + "@com_github_bazelbuild_buildtools//build", + "@org_golang_x_mod//modfile", + "@org_golang_x_mod//module", + "@org_golang_x_sync//errgroup", + ], +) + +go_test( + name = "go_test", + srcs = [ + "build_constraints_test.go", + "config_test.go", + "fileinfo_go_test.go", + "fileinfo_test.go", + "fix_test.go", + "generate_test.go", + "resolve_test.go", + "stubs_test.go", + "update_import_test.go", + ], + data = glob( + ["testdata/**"], + # Empty when distributed. + allow_empty = True, + ), + embed = [":go"], + deps = [ + "//config", + "//label", + "//language", + "//language/proto", + "//merger", + "//pathtools", + "//repo", + "//resolve", + "//rule", + "//testtools", + "//walk", + "@com_github_bazelbuild_buildtools//build", + "@com_github_google_go_cmp//cmp", + "@io_bazel_rules_go//go/tools/bazel", + "@org_golang_x_tools_go_vcs//:vcs", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "build_constraints.go", + "build_constraints_test.go", + "config.go", + "config_test.go", + "constants.go", + "def.bzl", + "embed.go", + "fileinfo.go", + "fileinfo_go_test.go", + "fileinfo_test.go", + "fix.go", + "fix_test.go", + "generate.go", + "generate_test.go", + "kinds.go", + "lang.go", + "modules.go", + "package.go", + "platform_info.go", + "resolve.go", + "resolve_test.go", + "std_package_list.go", + "stdlib_links.go", + "stubs_test.go", + "update.go", + "update_import_test.go", + "utils.go", + "work.go", + "//language/go/gen_std_package_list:all_files", + "//language/go/platform_info_generator:all_files", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":go", + visibility = ["//visibility:public"], +) + +bzl_library( + name = "def", + srcs = ["def.bzl"], + visibility = ["//visibility:public"], + deps = ["@io_bazel_rules_go//go:def"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/language/proto/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/language/proto/BUILD.bazel new file mode 100644 index 000000000..d274b97e1 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/language/proto/BUILD.bazel @@ -0,0 +1,127 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("//language/proto/gen:def.bzl", "known_imports") + +# gazelle:exclude testdata + +known_imports( + name = "known_imports", + src = "proto.csv", + out = "known_imports.go", + key = 0, + package = "proto", + value = 1, + var = "knownImports", +) + +known_imports( + name = "known_proto_imports", + src = "proto.csv", + out = "known_proto_imports.go", + key = 0, + package = "proto", + value = 3, + var = "knownProtoImports", +) + +known_imports( + name = "known_go_imports", + src = "proto.csv", + out = "known_go_imports.go", + key = 2, + package = "proto", + value = 3, + var = "knownGoProtoImports", +) + +go_library( + name = "proto", + srcs = [ + "config.go", + "constants.go", + "fileinfo.go", + "fix.go", + "generate.go", + "kinds.go", + "known_go_imports.go", + "known_imports.go", + "known_proto_imports.go", + "lang.go", + "package.go", + "resolve.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/language/proto", + visibility = ["//visibility:public"], + deps = [ + "//config", + "//label", + "//language", + "//merger", + "//pathtools", + "//repo", + "//resolve", + "//rule", + ], +) + +go_test( + name = "proto_test", + srcs = [ + "config_test.go", + "fileinfo_test.go", + "generate_test.go", + "resolve_test.go", + ], + data = glob( + ["testdata/**"], + # Empty when distributed. + allow_empty = True, + ), + embed = [":proto"], + deps = [ + "//config", + "//label", + "//language", + "//merger", + "//repo", + "//resolve", + "//rule", + "//testtools", + "//walk", + "@com_github_bazelbuild_buildtools//build", + ], +) + +exports_files(["proto.csv"]) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "config.go", + "config_test.go", + "constants.go", + "fileinfo.go", + "fileinfo_test.go", + "fix.go", + "generate.go", + "generate_test.go", + "kinds.go", + "known_go_imports.go", + "known_imports.go", + "known_proto_imports.go", + "lang.go", + "package.go", + "proto.csv", + "resolve.go", + "resolve_test.go", + "//language/proto/gen:all_files", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":proto", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/merger/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/merger/BUILD.bazel new file mode 100644 index 000000000..505838990 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/merger/BUILD.bazel @@ -0,0 +1,52 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "merger", + srcs = [ + "fix.go", + "merger.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/merger", + visibility = ["//visibility:public"], + deps = [ + "//rule", + "@com_github_bazelbuild_buildtools//build", + ], +) + +go_test( + name = "merger_test", + size = "small", + srcs = [ + "fix_test.go", + "merger_test.go", + ], + deps = [ + ":merger", + "//language", + "//language/go", + "//language/proto", + "//rule", + "@com_github_bazelbuild_buildtools//build", + "@com_github_google_go_cmp//cmp", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "fix.go", + "fix_test.go", + "merger.go", + "merger_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":merger", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/pathtools/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/pathtools/BUILD.bazel new file mode 100644 index 000000000..a429f877b --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/pathtools/BUILD.bazel @@ -0,0 +1,32 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "pathtools", + srcs = ["path.go"], + importpath = "github.com/bazelbuild/bazel-gazelle/pathtools", + visibility = ["//visibility:public"], +) + +go_test( + name = "pathtools_test", + srcs = ["path_test.go"], + embed = [":pathtools"], + deps = ["@com_github_google_go_cmp//cmp"], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "path.go", + "path_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":pathtools", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/repo/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/repo/BUILD.bazel new file mode 100644 index 000000000..71396b236 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/repo/BUILD.bazel @@ -0,0 +1,54 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "repo", + srcs = [ + "remote.go", + "repo.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/repo", + visibility = ["//visibility:public"], + deps = [ + "//label", + "//pathtools", + "//rule", + "@org_golang_x_mod//modfile", + "@org_golang_x_tools_go_vcs//:vcs", + ], +) + +go_test( + name = "repo_test", + srcs = [ + "remote_test.go", + "repo_test.go", + "stubs_test.go", + ], + embed = [":repo"], + deps = [ + "//pathtools", + "//rule", + "//testtools", + "@org_golang_x_tools_go_vcs//:vcs", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "remote.go", + "remote_test.go", + "repo.go", + "repo_test.go", + "stubs_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":repo", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/resolve/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/resolve/BUILD.bazel new file mode 100644 index 000000000..0acd29e3c --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/resolve/BUILD.bazel @@ -0,0 +1,47 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "resolve", + srcs = [ + "config.go", + "index.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/resolve", + visibility = ["//visibility:public"], + deps = [ + "//config", + "//label", + "//repo", + "//rule", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "config.go", + "index.go", + "resolve_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":resolve", + visibility = ["//visibility:public"], +) + +go_test( + name = "resolve_test", + srcs = ["resolve_test.go"], + embed = [":resolve"], + deps = [ + "//config", + "//label", + "//rule", + "@com_github_google_go_cmp//cmp", + ], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/rule/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/rule/BUILD.bazel new file mode 100644 index 000000000..7884d50ef --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/rule/BUILD.bazel @@ -0,0 +1,67 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "rule", + srcs = [ + "directives.go", + "expr.go", + "merge.go", + "platform.go", + "platform_strings.go", + "rule.go", + "sort_labels.go", + "types.go", + "value.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/rule", + visibility = ["//visibility:public"], + deps = [ + "//label", + "@com_github_bazelbuild_buildtools//build", + "@com_github_bazelbuild_buildtools//tables", + ], +) + +go_test( + name = "rule_test", + srcs = [ + "directives_test.go", + "merge_test.go", + "rule_test.go", + "value_test.go", + ], + embed = [":rule"], + deps = [ + "//label", + "@com_github_bazelbuild_buildtools//build", + "@com_github_google_go_cmp//cmp", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "directives.go", + "directives_test.go", + "expr.go", + "merge.go", + "merge_test.go", + "platform.go", + "platform_strings.go", + "rule.go", + "rule_test.go", + "sort_labels.go", + "types.go", + "value.go", + "value_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":rule", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/testtools/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/testtools/BUILD.bazel new file mode 100644 index 000000000..bc3495030 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/testtools/BUILD.bazel @@ -0,0 +1,34 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "testtools", + testonly = True, + srcs = [ + "config.go", + "files.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/testtools", + visibility = ["//visibility:public"], + deps = [ + "//config", + "//language", + "@com_github_google_go_cmp//cmp", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "config.go", + "files.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":testtools", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/bazel-gazelle/walk/BUILD.bazel b/vendor/github.com/bazelbuild/bazel-gazelle/walk/BUILD.bazel new file mode 100644 index 000000000..c1f181932 --- /dev/null +++ b/vendor/github.com/bazelbuild/bazel-gazelle/walk/BUILD.bazel @@ -0,0 +1,58 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "walk", + srcs = [ + "cache.go", + "config.go", + "dirinfo.go", + "walk.go", + ], + importpath = "github.com/bazelbuild/bazel-gazelle/walk", + visibility = ["//visibility:public"], + deps = [ + "//config", + "//flag", + "//pathtools", + "//rule", + "@com_github_bazelbuild_buildtools//build", + "@com_github_bmatcuk_doublestar_v4//:doublestar", + ], +) + +go_test( + name = "walk_test", + srcs = [ + "config_test.go", + "walk_test.go", + ], + embed = [":walk"], + deps = [ + "//config", + "//rule", + "//testtools", + "@com_github_bmatcuk_doublestar_v4//:doublestar", + "@com_github_google_go_cmp//cmp", + ], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = [ + "BUILD.bazel", + "cache.go", + "config.go", + "config_test.go", + "dirinfo.go", + "walk.go", + "walk_test.go", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":walk", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/buildtools/build/BUILD.bazel b/vendor/github.com/bazelbuild/buildtools/build/BUILD.bazel new file mode 100644 index 000000000..2b7fcf0dc --- /dev/null +++ b/vendor/github.com/bazelbuild/buildtools/build/BUILD.bazel @@ -0,0 +1,64 @@ +# gazelle:exclude parse.y.go +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load(":build_defs.bzl", "go_yacc") + +go_yacc( + src = "parse.y", + out = "parse.y.baz.go", +) + +go_library( + name = "build", + srcs = [ + "lex.go", + "parse.y.baz.go", # keep + "print.go", + "quote.go", + "rewrite.go", + "rule.go", + "syntax.go", + "utils.go", + "walk.go", + ], + importpath = "github.com/bazelbuild/buildtools/build", + visibility = ["//visibility:public"], + deps = [ + "//labels", + "//tables", + ], +) + +go_test( + name = "build_test", + size = "small", + srcs = [ + "checkfile_test.go", + "lex_test.go", + "parse_test.go", + "print_test.go", + "quote_test.go", + "rewrite_test.go", + "rule_test.go", + "walk_test.go", + ], + data = glob(["testdata/*"]) + [ + # parse.y.go is checked in to satisfy the Go community + # https://github.com/bazelbuild/buildtools/issues/14 + # this test ensures it doesn't get stale. + "parse.y.baz.go", + "parse.y.go", + "rewrite_test_files/original_formatted.star", + "rewrite_test_files/original.star", + ], + embed = [":build"], + deps = [ + "//tables", + "//testutils", + ], +) + +alias( + name = "go_default_library", + actual = ":build", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/buildtools/labels/BUILD.bazel b/vendor/github.com/bazelbuild/buildtools/labels/BUILD.bazel new file mode 100644 index 000000000..d6ed5b2c0 --- /dev/null +++ b/vendor/github.com/bazelbuild/buildtools/labels/BUILD.bazel @@ -0,0 +1,20 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "labels", + srcs = ["labels.go"], + importpath = "github.com/bazelbuild/buildtools/labels", + visibility = ["//visibility:public"], +) + +go_test( + name = "labels_test", + srcs = ["labels_test.go"], + embed = [":labels"], +) + +alias( + name = "go_default_library", + actual = ":labels", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/buildtools/tables/BUILD.bazel b/vendor/github.com/bazelbuild/buildtools/tables/BUILD.bazel new file mode 100644 index 000000000..5fa695cf4 --- /dev/null +++ b/vendor/github.com/bazelbuild/buildtools/tables/BUILD.bazel @@ -0,0 +1,25 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "tables", + srcs = [ + "jsonparser.go", + "tables.go", + ], + importpath = "github.com/bazelbuild/buildtools/tables", + visibility = ["//visibility:public"], +) + +go_test( + name = "tables_test", + size = "small", + srcs = ["jsonparser_test.go"], + data = glob(["testdata/*"]), + embed = [":tables"], +) + +alias( + name = "go_default_library", + actual = ":tables", + visibility = ["//visibility:public"], +) diff --git a/vendor/github.com/bazelbuild/rules_go/go/runfiles/BUILD.bazel b/vendor/github.com/bazelbuild/rules_go/go/runfiles/BUILD.bazel new file mode 100644 index 000000000..58e3b9bf6 --- /dev/null +++ b/vendor/github.com/bazelbuild/rules_go/go/runfiles/BUILD.bazel @@ -0,0 +1,61 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "runfiles", + srcs = [ + "directory.go", + "fs.go", + "global.go", + "manifest.go", + "runfiles.go", + ], + importpath = "github.com/bazelbuild/rules_go/go/runfiles", + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":runfiles", + visibility = ["//visibility:public"], +) + +go_test( + name = "example_test", + srcs = [ + "caller_repository_example_test.go", + "example_test.go", + "rlocationpath_xdefs_example_test.go", + ], + deps = [":runfiles"], +) + +filegroup( + name = "all_files", + testonly = True, + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +go_test( + name = "runfiles_test", + srcs = [ + "caller_repository_example_test.go", + "example_test.go", + "rlocationpath_xdefs_example_test.go", + ], + deps = [":runfiles"], +) diff --git a/vendor/github.com/bazelbuild/rules_go/go/tools/bazel/BUILD.bazel b/vendor/github.com/bazelbuild/rules_go/go/tools/bazel/BUILD.bazel new file mode 100644 index 000000000..674da86f8 --- /dev/null +++ b/vendor/github.com/bazelbuild/rules_go/go/tools/bazel/BUILD.bazel @@ -0,0 +1,34 @@ +load("//go:def.bzl", "go_library", "go_test") + +go_library( + name = "bazel", + srcs = [ + "bazel.go", + "runfiles.go", + ], + importpath = "github.com/bazelbuild/rules_go/go/tools/bazel", + visibility = ["//visibility:public"], +) + +go_test( + name = "bazel_test", + size = "small", + srcs = ["bazel_test.go"], + data = ["empty.txt"], + embed = [":bazel"], +) + +# Runfiles functionality in this package is tested by //tests/core/runfiles. + +filegroup( + name = "all_files", + testonly = True, + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":bazel", + visibility = ["//visibility:public"], +)