id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c178500
y[i] if cmp != 0 { return cmp } } return len(x) - len(y) }
c178501
return nil, fmt.Errorf("could not parse version string: %q is not an integer", cstr) } if cn < 0 { return nil, fmt.Errorf("could not parse version string: %q is negative", cstr) } v[i] = cn } return v, nil }
c178502
path, Type: bzl.TypeBuild}, Path: path, Pkg: pkg, } }
c178503
return nil, err } return LoadWorkspaceData(path, pkg, data) }
c178504
return nil, err } return LoadMacroData(path, pkg, defName, data) }
c178505
return nil, err } return LoadMacroData(path, pkg, defName, nil) }
c178506
return nil, err } return ScanAST(pkg, ast), nil }
c178507
{ return nil, err } return ScanAST(pkg, ast), nil }
c178508
{ return nil, err } return ScanASTBody(pkg, defName, ast), nil }
c178509
ScanASTBody(pkg, "", bzlFile) }
c178510
:= defStmt.Body[0].(*bzl.BranchStmt); ok && v.Token == "pass" { f.function.hasPass = true } } } else if defName != "" { f.function = &function{ stmt: &bzl.DefStmt{Name: defName}, inserted: false, } } f.Directives = ParseDirectives(bzlFile) return f }
c178511
name && !fi.IsDir() { return filepath.Join(dir, name) } } } return "" }
c178512
*toFunc = fromFunc } else { f.File.Stmt = append(f.File.Stmt, &fromFunc) } }
c178513
nil && f.function.stmt != nil { return f.function.stmt.Name } return "" }
c178514
stmts) } else { updateStmt(&f.File.Stmt, loadInserts, loadDeletes, loadStmts) if f.function.hasPass && len(ruleInserts) > 0 { f.function.stmt.Body = []bzl.Expr{} f.function.hasPass = false } updateStmt(&f.function.stmt.Body, ruleInserts, ruleDeletes, ruleStmts) if len(f.function.stmt.Body) == 0 { f.function.stmt.Body = append(f.function.stmt.Body, &bzl.BranchStmt{Token: "pass"}) f.function.hasPass = true } if !f.function.inserted { f.File.Stmt = append(f.File.Stmt, f.function.stmt) f.function.inserted = true } } }
c178515
return bzl.Format(f.File) }
c178516
return ioutil.WriteFile(path, data, 0666) }
c178517
{ if r.Kind() == "package" && r.Attr("default_visibility") != nil { return true } } return false }
c178518
&bzl.StringExpr{Value: name}, ForceCompact: true, }, }, name: name, symbols: make(map[string]identPair), } }
c178519
syms = append(syms, sym) } sort.Strings(syms) return syms }
c178520
ok := l.symbols[sym] return ok }
c178521
= identPair{to: i, from: i} l.updated = true } }
c178522
delete(l.symbols, sym) l.updated = true } }
c178523
l.inserted = true f.Loads = append(f.Loads, l) }
c178524
stmt: stmt{ expr: &bzl.CallExpr{ X: &bzl.Ident{Name: kind}, List: []bzl.Expr{nameAttr}, }, }, kind: kind, attrs: map[string]*bzl.AssignExpr{"name": nameAttr}, private: map[string]interface{}{}, } return r }
c178525
kind r.updated = true }
c178526
} sort.SliceStable(keys, func(i, j int) bool { if cmp := bt.NamePriority[keys[i]] - bt.NamePriority[keys[j]]; cmp != 0 { return cmp < 0 } return keys[i] < keys[j] }) return keys }
c178527
ok := r.attrs[key] if !ok { return nil } return attr.RHS }
c178528
} str, ok := attr.RHS.(*bzl.StringExpr) if !ok { return "" } return str.Value }
c178529
_, e := range list.List { if str, ok := e.(*bzl.StringExpr); ok { strs = append(strs, str.Value) } } return strs }
c178530
{ delete(r.attrs, key) r.updated = true }
c178531
LHS: &bzl.Ident{Name: key}, RHS: rhs, Op: "=", } } r.updated = true }
c178532
keys = append(keys, k) } sort.Strings(keys) return keys }
c178533
{ r.private[key] = value }
c178534
else { stmt = f.function.stmt.Body } r.index = len(stmt) r.inserted = true f.Rules = append(f.Rules, r) }
c178535
{ if _, ok := r.attrs[k]; ok { return false } } return true }
c178536
else if strings.HasPrefix(rel, "internal/") { visibility = "//:__subpackages__" } return visibility }
c178537
repo, Pkg: pkg, Name: name} }
c178538
return l } if l.Pkg == pkg { return Label{Name: l.Name, Relative: true} } return Label{Pkg: l.Pkg, Name: l.Name} }
c178539
l.Name == other.Name && l.Relative == other.Relative }
c178540
other.Relative { log.Panicf("other must not be relative: %s", other) } result := l.Repo == other.Repo && pathtools.HasPrefix(other.Pkg, l.Pkg) return result }
c178541
// Special case: these protos need to be built together with protos in // google/api. They have the same 'option go_package'. The proto_library // rule requires them to be in the same Bazel package, so we don't // create a build file in experimental. packagePath := "google.golang.org/genproto/googleapis/api" protoLabel, goLabel := protoLabels("google/api/x", "api") fmt.Fprintf(w, "%s,%s,%s,%s\n", relPath, protoLabel, packagePath, goLabel) return nil } packagePath, packageName, err := loadGoPackage(path) if err != nil { log.Print(err) return nil } protoLabel, goLabel := protoLabels(relPath, packageName) fmt.Fprintf(w, "%s,%s,%s,%s\n", relPath, protoLabel, packagePath, goLabel) return nil }) }
c178542
mode != UpdateDirsMode || updateRels[rel] }
c178543
map[string]bool) bool { return mode == VisitAllUpdateSubdirsMode && updateParent || updateRels[rel] }
c178544
return true } _, ok := updateRels[rel] return ok }
c178545
dst.SetAttr(key, squashedValue) } } } dst.expr.Comment().Before = append(dst.expr.Comment().Before, src.expr.Comment().Before...) dst.expr.Comment().Suffix = append(dst.expr.Comment().Suffix, src.expr.Comment().Suffix...) dst.expr.Comment().After = append(dst.expr.Comment().After, src.expr.Comment().After...) return nil }
c178546
} if err != nil { return fmt.Errorf("failed to connect to server: %v", err) } } defer conn.Close() if _, err := io.Copy(os.Stderr, conn); err != nil { log.Print(err) } elapsedTime := time.Since(startTime) log.Printf("ran gazelle in %.3f s", elapsedTime.Seconds()) return nil }
c178547
Repo{ Name: name, GoPrefix: root, Commit: commit, Tag: tag, Remote: remote, VCS: vcs, } return repo, nil }
c178548
if repo.Remote != "" { r.remote.cache[repo.GoPrefix] = &remoteCacheEntry{ value: remoteValue{ remote: repo.Remote, vcs: repo.VCS, }, } } r.mod.cache[repo.GoPrefix] = &remoteCacheEntry{ value: modValue{ path: repo.GoPrefix, name: repo.Name, known: true, }, } } return r, r.cleanup }
c178549
return remoteValue{remote: repo.Repo, vcs: repo.VCS.Cmd}, nil }) if err != nil { return "", "", err } value := v.(remoteValue) return value.remote, value.vcs, nil }
c178550
e, ok := m.cache[key] m.mu.Unlock() if !ok { return nil, ok, nil } if e.ready != nil { <-e.ready } return e.value, ok, e.err }
c178551
= load() close(e.ready) } else { m.mu.Unlock() if e.ready != nil { <-e.ready } } return e.value, e.err }
c178552
base = filepath.Base(root) } if base == "." || base == "/" { base = "root" } return base }
c178553
} cc.KindMap = make(map[string]MappedKind) for k, v := range c.KindMap { cc.KindMap[k] = v } return &cc }
c178554
name == n { return true } } return false }
c178555
if g.check(c, os, arch) { return true } } return false }
c178556
is intended to match the logic // in goodOSArchFile in go/build. var isTest bool var goos, goarch string l := strings.Split(name[:len(name)-len(path.Ext(name))], "_") if len(l) >= 2 && l[len(l)-1] == "test" { isTest = ext == goExt l = l[:len(l)-1] } switch { case len(l) >= 3 && rule.KnownOSSet[l[len(l)-2]] && rule.KnownArchSet[l[len(l)-1]]: goos = l[len(l)-2] goarch = l[len(l)-1] case len(l) >= 2 && rule.KnownOSSet[l[len(l)-1]]: goos = l[len(l)-1] case len(l) >= 2 && rule.KnownArchSet[l[len(l)-1]]: goarch = l[len(l)-1] } return fileInfo{ path: path_, name: name, ext: ext, isTest: isTest, goos: goos, goarch: goarch, } }
c178557
reading file: %v", info.path, err) return info } info.tags = tags return info }
c178558
} else { if i := strings.LastIndexByte(opt.Value, ';'); i != -1 { info.importPath = opt.Value[:i] info.packageName = opt.Value[i+1:] } else { info.importPath = opt.Value info.packageName = path.Base(opt.Value) } } } // Set the Go package name from the proto package name if there was no // option go_package. if info.packageName == "" && protoInfo.PackageName != "" { info.packageName = strings.Replace(protoInfo.PackageName, ".", "_", -1) } info.imports = protoInfo.Imports info.hasServices = protoInfo.HasServices return info }
c178559
label.New(c.RepoName, f.Pkg, r.Name()), file: f, importedAs: imps, } if _, ok := ix.labelMap[record.label]; ok { log.Printf("multiple rules found with label %s", record.label) return } ix.rules = append(ix.rules, record) ix.labelMap[record.label] = record }
c178560
ix.collectEmbeds(r) } ix.buildImportIndex() }
c178561
{ if indexed[imp] { continue } indexed[imp] = true ix.importMap[imp] = append(ix.importMap[imp], r) } } }
c178562
return true } for _, e := range r.Embeds { if from.Equal(e) { return true } } return false }
c178563
existing ones with merged ones. mappedLoads := make([]rule.LoadInfo, len(loads)) copy(mappedLoads, loads) for _, mappedKind := range mappedKinds { mappedLoads = appendOrMergeKindMapping(mappedLoads, mappedKind) } return mappedLoads }
c178564
return mappedLoads } } // Add a new LoadInfo. return append(mappedLoads, rule.LoadInfo{ Name: mappedKind.KindLoad, Symbols: []string{mappedKind.KindName}, }) }
c178565
if i := strings.LastIndexFunc(name, notIdent); i >= 0 { name = name[i+1:] } if name != "" { base = name break } } return base + "_proto" }
c178566
err != nil { log.Print(err) } if pkg == nil { return nil // empty rule created in generateEmpty } for _, name := range genFiles { pkg.addGenFile(dir, name) } return []*Package{pkg} case PackageMode: pkgs := make([]*Package, 0, len(packageMap)) for _, pkg := range packageMap { pkgs = append(pkgs, pkg) } return pkgs default: return nil } }
c178567
goPackageName(pkg); pkgName != "" && pkgName == defaultPackageName { return pkg, nil } } return nil, fmt.Errorf("%s: directory contains multiple proto packages. Gazelle can only generate a proto_library for one package.", dir) }
c178568
used outside this extension. It's still // convenient for testing though. r.SetPrivateAttr(config.GazelleImportsKey, imports) for k, v := range pkg.Options { r.SetPrivateAttr(k, v) } if shouldSetVisibility { vis := rule.CheckInternalVisibility(rel, "//visibility:public") r.SetAttr("visibility", []string{vis}) } if pc.stripImportPrefix != "" { r.SetAttr("strip_import_prefix", pc.stripImportPrefix) } if pc.importPrefix != "" { r.SetAttr("import_prefix", pc.importPrefix) } return r }
c178569
!= nil { // srcs is not a string list; leave it alone continue } for _, src := range r.AttrStrings("srcs") { if knownFiles[src] { continue outer } } empty = append(empty, rule.NewRule("proto_library", r.Name())) } return empty }
c178570
!= nil { return nil, fmt.Errorf("error parsing %q: %v", filename, err) } sort.Stable(byName(repos)) rules := make([]*rule.Rule, 0, len(repos)) for _, repo := range repos { rules = append(rules, GenerateRule(repo)) } return rules, nil }
c178571
} } rulesByFile := make(map[*rule.File][]*rule.Rule) for _, rule := range genRules { dest := destFile if file, ok := repoMap[rule.Name()]; ok { dest = file } rulesByFile[dest] = append(rulesByFile[dest], rule) } updatedFiles := make(map[string]*rule.File) for f, rules := range rulesByFile { merger.MergeFile(f, nil, rules, merger.PreResolve, kinds) f.Sync() if uf, ok := updatedFiles[f.Path]; ok { uf.SyncMacroFile(f) } else { updatedFiles[f.Path] = f } } files := make([]*rule.File, 0, len(updatedFiles)) for _, f := range updatedFiles { files = append(files, f) } return files }
c178572
if repo.Remote != "" { r.SetAttr("remote", repo.Remote) } if repo.VCS != "" { r.SetAttr("vcs", repo.VCS) } if repo.Version != "" { r.SetAttr("version", repo.Version) } if repo.Sum != "" { r.SetAttr("sum", repo.Sum) } if repo.Replace != "" { r.SetAttr("replace", repo.Replace) } return r }
c178573
"external", name}, string(os.PathSeparator)) cleanPath, err := filepath.EvalSymlinks(externalPath) if err != nil { return "", err } st, err := os.Stat(cleanPath) if err != nil { return "", err } if !st.IsDir() { return "", fmt.Errorf("%s: not a directory", externalPath) } return cleanPath, nil }
c178574
macroFile, err := rule.LoadMacroFile(f, "", defName) if err != nil { return nil, nil, err } currRepos, names := getRepos(macroFile.Rules) repoNamesByFile[macroFile] = names repos = append(repos, currRepos...) } } return repos, repoNamesByFile, nil }
c178575
continue } r.DelAttr("library") r.SetAttr("embed", &bzl.ListExpr{List: []bzl.Expr{libExpr}}) } }
c178576
r.ShouldKeep() || r.Attr("compilers") != nil { continue } r.SetKind("go_proto_library") r.SetAttr("compilers", []string{grpcCompilerLabel}) } }
c178577
Run 'gazelle fix' to squash with go_library.", f.Path) return } if goLibrary == nil { cgoLibrary.SetKind("go_library") cgoLibrary.SetName(defaultLibName) cgoLibrary.SetAttr("cgo", true) return } if err := rule.SquashRules(cgoLibrary, goLibrary, f.Path); err != nil { log.Print(err) return } goLibrary.DelAttr("embed") goLibrary.SetAttr("cgo", true) cgoLibrary.Delete() }
c178578
if r.Kind() == "filegroup" && r.Name() == legacyProtoFilegroupName { protoFilegroups = append(protoFilegroups, r) } if r.Kind() == "go_proto_library" { protoRules = append(protoRules, r) } } if len(protoLoads)+len(protoFilegroups) == 0 { return } if !c.ShouldFix { log.Printf("%s: go_proto_library.bzl is deprecated. Run 'gazelle fix' to replace old rules.", f.Path) return } // Delete legacy proto loads and filegroups. Only delete go_proto_library // rules if we deleted a load. for _, l := range protoLoads { l.Delete() } for _, r := range protoFilegroups { r.Delete() } if len(protoLoads) > 0 { for _, r := range protoRules { r.Delete() } } }
c178579
l.Name() == "@io_bazel_rules_go//go:def.bzl" && l.Has("gazelle") { l.Remove("gazelle") if l.IsEmpty() { l.Delete() } } } }
c178580
for name, pkg := range buildablePackages { // Add the first file for each package for the error message. // Error() method expects these lists to be the same length. File // lists must be non-empty. These lists are only created by // buildPackage for packages with .go files present. err.Packages = append(err.Packages, name) err.Files = append(err.Files, pkg.firstGoFile()) } return nil, err }
c178581
mr.builtins[kindName] = resolver }
c178582
mr.mappedKinds[pkgRel] = append(mr.mappedKinds[pkgRel], kind) }
c178583
{ return mr.builtins[mappedKind.FromKind] } } return mr.builtins[r.Kind()] }
c178584
if !ok { return // don't sort lists unless all elements are strings } keys[i] = makeSortKey(i, s) } before := keys[0].x.Comment().Before keys[0].x.Comment().Before = nil sort.Sort(byStringExpr(keys)) keys[0].x.Comment().Before = append(before, keys[0].x.Comment().Before...) for i, k := range keys { list.List[i] = k.x } }
c178585
vstr := string(match[1]) v, err := version.ParseVersion(vstr) if err != nil { log.Printf("RULES_GO_VERSION %q could not be parsed in @%s//go:def.bzl.\n%s", vstr, config.RulesGoRepoName, message) } if v.Compare(minimumRulesGoVersion) < 0 { log.Printf("Found RULES_GO_VERSION %s. Minimum compatible version is %s.\n%s", v, minimumRulesGoVersion, message) } }
c178586
== nil { gc.genericTags = make(map[string]bool) } gc.genericTags["gc"] = true }
c178587
return fmt.Errorf("build tags can't be negated: %s", t) } gc.genericTags[t] = true } return nil }
c178588
parts { values = append(values, strings.TrimSpace(part)) } return values }
c178589
cerr := goModCopy.Close(); err == nil && cerr != nil { err = cerr } }() _, err = io.Copy(goModCopy, goModOrig) if err != nil { os.RemoveAll(tempDir) return "", err } return tempDir, err }
c178590
} if runtime.GOOS == "windows" { path += ".exe" } return path }
c178591
pkg.firstGoFile() != "" || !pkg.proto.sources.isEmpty() }
c178592
cmd := exec.Command(exe, args...) log.Printf("starting server: %s", strings.Join(cmd.Args, " ")) if err := cmd.Start(); err != nil { return err } if err := cmd.Process.Release(); err != nil { return err } return nil }
c178593
for _, err := range errs { log.Print(err) } for _, dir := range dirs { if err := w.Add(dir); err != nil { log.Print(err) } recordWrite(dir) } } } else { recordWrite(filepath.Dir(ev.Name)) } case err := <-w.Errors: log.Print(err) case <-done: if err := w.Close(); err != nil { log.Print(err) } return } } }() return func() { close(done) }, nil }
c178594
error { if err != nil { errs = append(errs, err) return nil } if info.IsDir() { dirs = append(dirs, path) } return nil }) if err != nil { errs = append(errs, err) } return dirs, errs }
c178595
base := path.Base(p) return strings.HasPrefix(p, "tools/") || base == ".git" || base == "BUILD" || base == "BUILD.bazel" }
c178596
dirSetMutex.Unlock() dirSet[path] = true }
c178597
dirSet { dirs = append(dirs, d) } dirSet = make(map[string]bool) return dirs }
c178598
func(w http.ResponseWriter, req *http.Request) { for _, handler := range handlers { handler(w, req) } } }
c178599
Expect(req.Header.Get("Content-Type")).Should(Equal(contentType)) } }