_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q178500 | Compare | test | func (x Version) Compare(y Version) int {
n := len(x)
if len(y) < n {
n = len(y)
}
for i := 0; i < n; i++ {
cmp := x[i] - y[i]
if cmp != 0 {
return cmp
}
}
return len(x) - len(y)
} | go | {
"resource": ""
} |
q178501 | ParseVersion | test | func ParseVersion(vs string) (Version, error) {
i := strings.IndexByte(vs, '-')
if i >= 0 {
vs = vs[:i]
}
cstrs := strings.Split(vs, ".")
v := make(Version, len(cstrs))
for i, cstr := range cstrs {
cn, err := strconv.Atoi(cstr)
if err != nil {
return nil, fmt.Errorf("could not parse version string: %q is... | go | {
"resource": ""
} |
q178502 | EmptyFile | test | func EmptyFile(path, pkg string) *File {
return &File{
File: &bzl.File{Path: path, Type: bzl.TypeBuild},
Path: path,
Pkg: pkg,
}
} | go | {
"resource": ""
} |
q178503 | LoadWorkspaceFile | test | func LoadWorkspaceFile(path, pkg string) (*File, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return LoadWorkspaceData(path, pkg, data)
} | go | {
"resource": ""
} |
q178504 | LoadMacroFile | test | func LoadMacroFile(path, pkg, defName string) (*File, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return LoadMacroData(path, pkg, defName, data)
} | go | {
"resource": ""
} |
q178505 | EmptyMacroFile | test | func EmptyMacroFile(path, pkg, defName string) (*File, error) {
_, err := os.Create(path)
if err != nil {
return nil, err
}
return LoadMacroData(path, pkg, defName, nil)
} | go | {
"resource": ""
} |
q178506 | LoadData | test | func LoadData(path, pkg string, data []byte) (*File, error) {
ast, err := bzl.ParseBuild(path, data)
if err != nil {
return nil, err
}
return ScanAST(pkg, ast), nil
} | go | {
"resource": ""
} |
q178507 | LoadWorkspaceData | test | func LoadWorkspaceData(path, pkg string, data []byte) (*File, error) {
ast, err := bzl.ParseWorkspace(path, data)
if err != nil {
return nil, err
}
return ScanAST(pkg, ast), nil
} | go | {
"resource": ""
} |
q178508 | LoadMacroData | test | func LoadMacroData(path, pkg, defName string, data []byte) (*File, error) {
ast, err := bzl.ParseBzl(path, data)
if err != nil {
return nil, err
}
return ScanASTBody(pkg, defName, ast), nil
} | go | {
"resource": ""
} |
q178509 | ScanAST | test | func ScanAST(pkg string, bzlFile *bzl.File) *File {
return ScanASTBody(pkg, "", bzlFile)
} | go | {
"resource": ""
} |
q178510 | ScanASTBody | test | func ScanASTBody(pkg, defName string, bzlFile *bzl.File) *File {
f := &File{
File: bzlFile,
Pkg: pkg,
Path: bzlFile.Path,
}
var defStmt *bzl.DefStmt
f.Rules, f.Loads, defStmt = scanExprs(defName, bzlFile.Stmt)
if defStmt != nil {
f.Rules, _, _ = scanExprs("", defStmt.Body)
f.function = &function{
stm... | go | {
"resource": ""
} |
q178511 | MatchBuildFileName | test | func MatchBuildFileName(dir string, names []string, files []os.FileInfo) string {
for _, name := range names {
for _, fi := range files {
if fi.Name() == name && !fi.IsDir() {
return filepath.Join(dir, name)
}
}
}
return ""
} | go | {
"resource": ""
} |
q178512 | SyncMacroFile | test | func (f *File) SyncMacroFile(from *File) {
fromFunc := *from.function.stmt
_, _, toFunc := scanExprs(from.function.stmt.Name, f.File.Stmt)
if toFunc != nil {
*toFunc = fromFunc
} else {
f.File.Stmt = append(f.File.Stmt, &fromFunc)
}
} | go | {
"resource": ""
} |
q178513 | MacroName | test | func (f *File) MacroName() string {
if f.function != nil && f.function.stmt != nil {
return f.function.stmt.Name
}
return ""
} | go | {
"resource": ""
} |
q178514 | Sync | test | func (f *File) Sync() {
var loadInserts, loadDeletes, loadStmts []*stmt
var r, w int
for r, w = 0, 0; r < len(f.Loads); r++ {
s := f.Loads[r]
s.sync()
if s.deleted {
loadDeletes = append(loadDeletes, &s.stmt)
continue
}
if s.inserted {
loadInserts = append(loadInserts, &s.stmt)
s.inserted = fal... | go | {
"resource": ""
} |
q178515 | Format | test | func (f *File) Format() []byte {
f.Sync()
return bzl.Format(f.File)
} | go | {
"resource": ""
} |
q178516 | Save | test | func (f *File) Save(path string) error {
f.Sync()
data := bzl.Format(f.File)
return ioutil.WriteFile(path, data, 0666)
} | go | {
"resource": ""
} |
q178517 | HasDefaultVisibility | test | func (f *File) HasDefaultVisibility() bool {
for _, r := range f.Rules {
if r.Kind() == "package" && r.Attr("default_visibility") != nil {
return true
}
}
return false
} | go | {
"resource": ""
} |
q178518 | NewLoad | test | func NewLoad(name string) *Load {
return &Load{
stmt: stmt{
expr: &bzl.LoadStmt{
Module: &bzl.StringExpr{Value: name},
ForceCompact: true,
},
},
name: name,
symbols: make(map[string]identPair),
}
} | go | {
"resource": ""
} |
q178519 | Symbols | test | func (l *Load) Symbols() []string {
syms := make([]string, 0, len(l.symbols))
for sym := range l.symbols {
syms = append(syms, sym)
}
sort.Strings(syms)
return syms
} | go | {
"resource": ""
} |
q178520 | Has | test | func (l *Load) Has(sym string) bool {
_, ok := l.symbols[sym]
return ok
} | go | {
"resource": ""
} |
q178521 | Add | test | func (l *Load) Add(sym string) {
if _, ok := l.symbols[sym]; !ok {
i := &bzl.Ident{Name: sym}
l.symbols[sym] = identPair{to: i, from: i}
l.updated = true
}
} | go | {
"resource": ""
} |
q178522 | Remove | test | func (l *Load) Remove(sym string) {
if _, ok := l.symbols[sym]; ok {
delete(l.symbols, sym)
l.updated = true
}
} | go | {
"resource": ""
} |
q178523 | Insert | test | func (l *Load) Insert(f *File, index int) {
l.index = index
l.inserted = true
f.Loads = append(f.Loads, l)
} | go | {
"resource": ""
} |
q178524 | NewRule | test | func NewRule(kind, name string) *Rule {
nameAttr := &bzl.AssignExpr{
LHS: &bzl.Ident{Name: "name"},
RHS: &bzl.StringExpr{Value: name},
Op: "=",
}
r := &Rule{
stmt: stmt{
expr: &bzl.CallExpr{
X: &bzl.Ident{Name: kind},
List: []bzl.Expr{nameAttr},
},
},
kind: kind,
attrs: map[strin... | go | {
"resource": ""
} |
q178525 | SetKind | test | func (r *Rule) SetKind(kind string) {
r.kind = kind
r.updated = true
} | go | {
"resource": ""
} |
q178526 | AttrKeys | test | func (r *Rule) AttrKeys() []string {
keys := make([]string, 0, len(r.attrs))
for k := range r.attrs {
keys = append(keys, k)
}
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
... | go | {
"resource": ""
} |
q178527 | Attr | test | func (r *Rule) Attr(key string) bzl.Expr {
attr, ok := r.attrs[key]
if !ok {
return nil
}
return attr.RHS
} | go | {
"resource": ""
} |
q178528 | AttrString | test | func (r *Rule) AttrString(key string) string {
attr, ok := r.attrs[key]
if !ok {
return ""
}
str, ok := attr.RHS.(*bzl.StringExpr)
if !ok {
return ""
}
return str.Value
} | go | {
"resource": ""
} |
q178529 | AttrStrings | test | func (r *Rule) AttrStrings(key string) []string {
attr, ok := r.attrs[key]
if !ok {
return nil
}
list, ok := attr.RHS.(*bzl.ListExpr)
if !ok {
return nil
}
strs := make([]string, 0, len(list.List))
for _, e := range list.List {
if str, ok := e.(*bzl.StringExpr); ok {
strs = append(strs, str.Value)
}
... | go | {
"resource": ""
} |
q178530 | DelAttr | test | func (r *Rule) DelAttr(key string) {
delete(r.attrs, key)
r.updated = true
} | go | {
"resource": ""
} |
q178531 | SetAttr | test | func (r *Rule) SetAttr(key string, value interface{}) {
rhs := ExprFromValue(value)
if attr, ok := r.attrs[key]; ok {
attr.RHS = rhs
} else {
r.attrs[key] = &bzl.AssignExpr{
LHS: &bzl.Ident{Name: key},
RHS: rhs,
Op: "=",
}
}
r.updated = true
} | go | {
"resource": ""
} |
q178532 | PrivateAttrKeys | test | func (r *Rule) PrivateAttrKeys() []string {
keys := make([]string, 0, len(r.private))
for k := range r.private {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
} | go | {
"resource": ""
} |
q178533 | SetPrivateAttr | test | func (r *Rule) SetPrivateAttr(key string, value interface{}) {
r.private[key] = value
} | go | {
"resource": ""
} |
q178534 | Insert | test | func (r *Rule) Insert(f *File) {
// TODO(jayconrod): should rules always be inserted at the end? Should there
// be some sort order?
var stmt []bzl.Expr
if f.function == nil {
stmt = f.File.Stmt
} else {
stmt = f.function.stmt.Body
}
r.index = len(stmt)
r.inserted = true
f.Rules = append(f.Rules, r)
} | go | {
"resource": ""
} |
q178535 | IsEmpty | test | func (r *Rule) IsEmpty(info KindInfo) bool {
if info.NonEmptyAttrs == nil {
return false
}
for k := range info.NonEmptyAttrs {
if _, ok := r.attrs[k]; ok {
return false
}
}
return true
} | go | {
"resource": ""
} |
q178536 | CheckInternalVisibility | test | func CheckInternalVisibility(rel, visibility string) string {
if i := strings.LastIndex(rel, "/internal/"); i >= 0 {
visibility = fmt.Sprintf("//%s:__subpackages__", rel[:i])
} else if strings.HasPrefix(rel, "internal/") {
visibility = "//:__subpackages__"
}
return visibility
} | go | {
"resource": ""
} |
q178537 | New | test | func New(repo, pkg, name string) Label {
return Label{Repo: repo, Pkg: pkg, Name: name}
} | go | {
"resource": ""
} |
q178538 | Rel | test | func (l Label) Rel(repo, pkg string) Label {
if l.Relative || l.Repo != repo {
return l
}
if l.Pkg == pkg {
return Label{Name: l.Name, Relative: true}
}
return Label{Pkg: l.Pkg, Name: l.Name}
} | go | {
"resource": ""
} |
q178539 | Equal | test | func (l Label) Equal(other Label) bool {
return l.Repo == other.Repo &&
l.Pkg == other.Pkg &&
l.Name == other.Name &&
l.Relative == other.Relative
} | go | {
"resource": ""
} |
q178540 | Contains | test | func (l Label) Contains(other Label) bool {
if l.Relative {
log.Panicf("l must not be relative: %s", l)
}
if other.Relative {
log.Panicf("other must not be relative: %s", other)
}
result := l.Repo == other.Repo && pathtools.HasPrefix(other.Pkg, l.Pkg)
return result
} | go | {
"resource": ""
} |
q178541 | generateFromPath | test | func generateFromPath(w io.Writer, rootPath string) error {
return filepath.Walk(rootPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !strings.HasSuffix(path, ".proto") {
return nil
}
relPath, err := filepath.Rel(rootPath, path)
if err != nil || strings.Has... | go | {
"resource": ""
} |
q178542 | shouldCall | test | func shouldCall(rel string, mode Mode, updateRels map[string]bool) bool {
return mode != UpdateDirsMode || updateRels[rel]
} | go | {
"resource": ""
} |
q178543 | shouldUpdate | test | func shouldUpdate(rel string, mode Mode, updateParent bool, updateRels map[string]bool) bool {
return mode == VisitAllUpdateSubdirsMode && updateParent || updateRels[rel]
} | go | {
"resource": ""
} |
q178544 | shouldVisit | test | func shouldVisit(rel string, mode Mode, updateRels map[string]bool) bool {
if mode != UpdateDirsMode {
return true
}
_, ok := updateRels[rel]
return ok
} | go | {
"resource": ""
} |
q178545 | SquashRules | test | func SquashRules(src, dst *Rule, filename string) error {
if dst.ShouldKeep() {
return nil
}
for key, srcAttr := range src.attrs {
srcValue := srcAttr.RHS
if dstAttr, ok := dst.attrs[key]; !ok {
dst.SetAttr(key, srcValue)
} else if !ShouldKeep(dstAttr) {
dstValue := dstAttr.RHS
if squashedValue, er... | go | {
"resource": ""
} |
q178546 | runClient | test | func runClient() error {
startTime := time.Now()
conn, err := net.Dial("unix", *socketPath)
if err != nil {
if err := startServer(); err != nil {
return fmt.Errorf("error starting server: %v", err)
}
for retry := 0; retry < 3; retry++ {
conn, err = net.Dial("unix", *socketPath)
if err == nil {
bre... | go | {
"resource": ""
} |
q178547 | UpdateRepo | test | func UpdateRepo(rc *RemoteCache, importPath string) (Repo, error) {
root, name, err := rc.Root(importPath)
if err != nil {
return Repo{}, err
}
remote, vcs, err := rc.Remote(root)
if err != nil {
return Repo{}, err
}
commit, tag, err := rc.Head(remote, vcs)
if err != nil {
return Repo{}, err
}
repo := R... | go | {
"resource": ""
} |
q178548 | NewRemoteCache | test | func NewRemoteCache(knownRepos []Repo) (r *RemoteCache, cleanup func() error) {
r = &RemoteCache{
RepoRootForImportPath: vcs.RepoRootForImportPath,
HeadCmd: defaultHeadCmd,
root: remoteCacheMap{cache: make(map[string]*remoteCacheEntry)},
remote: remoteCacheMap{cach... | go | {
"resource": ""
} |
q178549 | Remote | test | func (r *RemoteCache) Remote(root string) (remote, vcs string, err error) {
v, err := r.remote.ensure(root, func() (interface{}, error) {
repo, err := r.RepoRootForImportPath(root, false)
if err != nil {
return nil, err
}
return remoteValue{remote: repo.Repo, vcs: repo.VCS.Cmd}, nil
})
if err != nil {
r... | go | {
"resource": ""
} |
q178550 | get | test | func (m *remoteCacheMap) get(key string) (value interface{}, ok bool, err error) {
m.mu.Lock()
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
} | go | {
"resource": ""
} |
q178551 | ensure | test | func (m *remoteCacheMap) ensure(key string, load func() (interface{}, error)) (interface{}, error) {
m.mu.Lock()
e, ok := m.cache[key]
if !ok {
e = &remoteCacheEntry{ready: make(chan struct{})}
m.cache[key] = e
m.mu.Unlock()
e.value, e.err = load()
close(e.ready)
} else {
m.mu.Unlock()
if e.ready != n... | go | {
"resource": ""
} |
q178552 | RelBaseName | test | func RelBaseName(rel, prefix, root string) string {
base := path.Base(rel)
if base == "." || base == "/" {
base = path.Base(prefix)
}
if base == "." || base == "/" {
base = filepath.Base(root)
}
if base == "." || base == "/" {
base = "root"
}
return base
} | go | {
"resource": ""
} |
q178553 | Clone | test | func (c *Config) Clone() *Config {
cc := *c
cc.Exts = make(map[string]interface{})
for k, v := range c.Exts {
cc.Exts[k] = v
}
cc.KindMap = make(map[string]MappedKind)
for k, v := range c.KindMap {
cc.KindMap[k] = v
}
return &cc
} | go | {
"resource": ""
} |
q178554 | IsValidBuildFileName | test | func (c *Config) IsValidBuildFileName(name string) bool {
for _, n := range c.ValidBuildFileNames {
if name == n {
return true
}
}
return false
} | go | {
"resource": ""
} |
q178555 | check | test | func (l tagLine) check(c *config.Config, os, arch string) bool {
if len(l) == 0 {
return false
}
for _, g := range l {
if g.check(c, os, arch) {
return true
}
}
return false
} | go | {
"resource": ""
} |
q178556 | fileNameInfo | test | func fileNameInfo(path_ string) fileInfo {
name := filepath.Base(path_)
var ext ext
switch path.Ext(name) {
case ".go":
ext = goExt
case ".c", ".cc", ".cpp", ".cxx", ".m", ".mm":
ext = cExt
case ".h", ".hh", ".hpp", ".hxx":
ext = hExt
case ".s":
ext = sExt
case ".S":
ext = csExt
case ".proto":
ext ... | go | {
"resource": ""
} |
q178557 | otherFileInfo | test | func otherFileInfo(path string) fileInfo {
info := fileNameInfo(path)
if info.ext == unknownExt {
return info
}
tags, err := readTags(info.path)
if err != nil {
log.Printf("%s: error reading file: %v", info.path, err)
return info
}
info.tags = tags
return info
} | go | {
"resource": ""
} |
q178558 | protoFileInfo | test | func protoFileInfo(path_ string, protoInfo proto.FileInfo) fileInfo {
info := fileNameInfo(path_)
// Look for "option go_package". If there's no / in the package option, then
// it's just a simple package name, not a full import path.
for _, opt := range protoInfo.Options {
if opt.Key != "go_package" {
conti... | go | {
"resource": ""
} |
q178559 | AddRule | test | func (ix *RuleIndex) AddRule(c *config.Config, r *rule.Rule, f *rule.File) {
var imps []ImportSpec
if rslv := ix.mrslv(r, f.Pkg); rslv != nil {
imps = rslv.Imports(c, r, f)
}
// If imps == nil, the rule is not importable. If imps is the empty slice,
// it may still be importable if it embeds importable libraries... | go | {
"resource": ""
} |
q178560 | Finish | test | func (ix *RuleIndex) Finish() {
for _, r := range ix.rules {
ix.collectEmbeds(r)
}
ix.buildImportIndex()
} | go | {
"resource": ""
} |
q178561 | buildImportIndex | test | func (ix *RuleIndex) buildImportIndex() {
ix.importMap = make(map[ImportSpec][]*ruleRecord)
for _, r := range ix.rules {
if r.embedded {
continue
}
indexed := make(map[ImportSpec]bool)
for _, imp := range r.importedAs {
if indexed[imp] {
continue
}
indexed[imp] = true
ix.importMap[imp] = ap... | go | {
"resource": ""
} |
q178562 | IsSelfImport | test | func (r FindResult) IsSelfImport(from label.Label) bool {
if from.Equal(r.Label) {
return true
}
for _, e := range r.Embeds {
if from.Equal(e) {
return true
}
}
return false
} | go | {
"resource": ""
} |
q178563 | applyKindMappings | test | func applyKindMappings(mappedKinds []config.MappedKind, loads []rule.LoadInfo) []rule.LoadInfo {
if len(mappedKinds) == 0 {
return loads
}
// Add new RuleInfos or replace existing ones with merged ones.
mappedLoads := make([]rule.LoadInfo, len(loads))
copy(mappedLoads, loads)
for _, mappedKind := range mappedK... | go | {
"resource": ""
} |
q178564 | appendOrMergeKindMapping | test | func appendOrMergeKindMapping(mappedLoads []rule.LoadInfo, mappedKind config.MappedKind) []rule.LoadInfo {
// If mappedKind.KindLoad already exists in the list, create a merged copy.
for _, load := range mappedLoads {
if load.Name == mappedKind.KindLoad {
load.Symbols = append(load.Symbols, mappedKind.KindName)
... | go | {
"resource": ""
} |
q178565 | RuleName | test | func RuleName(names ...string) string {
base := "root"
for _, name := range names {
notIdent := func(c rune) bool {
return !('A' <= c && c <= 'Z' ||
'a' <= c && c <= 'z' ||
'0' <= c && c <= '9' ||
c == '_')
}
if i := strings.LastIndexFunc(name, notIdent); i >= 0 {
name = name[i+1:]
}
if na... | go | {
"resource": ""
} |
q178566 | buildPackages | test | func buildPackages(pc *ProtoConfig, dir, rel string, protoFiles, genFiles []string) []*Package {
packageMap := make(map[string]*Package)
for _, name := range protoFiles {
info := protoFileInfo(dir, name)
key := info.PackageName
if pc.groupOption != "" {
for _, opt := range info.Options {
if opt.Key == pc... | go | {
"resource": ""
} |
q178567 | selectPackage | test | func selectPackage(dir, rel string, packageMap map[string]*Package) (*Package, error) {
if len(packageMap) == 0 {
return nil, nil
}
if len(packageMap) == 1 {
for _, pkg := range packageMap {
return pkg, nil
}
}
defaultPackageName := strings.Replace(rel, "/", "_", -1)
for _, pkg := range packageMap {
if... | go | {
"resource": ""
} |
q178568 | generateProto | test | func generateProto(pc *ProtoConfig, rel string, pkg *Package, shouldSetVisibility bool) *rule.Rule {
var name string
if pc.Mode == DefaultMode {
name = RuleName(goPackageName(pkg), pc.GoPrefix, rel)
} else {
name = RuleName(pkg.Options[pc.groupOption], pkg.Name, rel)
}
r := rule.NewRule("proto_library", name)
... | go | {
"resource": ""
} |
q178569 | generateEmpty | test | func generateEmpty(f *rule.File, regularFiles, genFiles []string) []*rule.Rule {
if f == nil {
return nil
}
knownFiles := make(map[string]bool)
for _, f := range regularFiles {
knownFiles[f] = true
}
for _, f := range genFiles {
knownFiles[f] = true
}
var empty []*rule.Rule
outer:
for _, r := range f.Rul... | go | {
"resource": ""
} |
q178570 | ImportRepoRules | test | func ImportRepoRules(filename string, repoCache *RemoteCache) ([]*rule.Rule, error) {
format := getLockFileFormat(filename)
if format == unknownFormat {
return nil, fmt.Errorf(`%s: unrecognized lock file format. Expected "Gopkg.lock", "go.mod", or "Godeps.json"`, filename)
}
parser := lockFileParsers[format]
rep... | go | {
"resource": ""
} |
q178571 | MergeRules | test | func MergeRules(genRules []*rule.Rule, existingRules map[*rule.File][]string, destFile *rule.File, kinds map[string]rule.KindInfo) []*rule.File {
sort.Stable(byRuleName(genRules))
repoMap := make(map[string]*rule.File)
for file, repoNames := range existingRules {
if file.Path == destFile.Path && file.MacroName() ... | go | {
"resource": ""
} |
q178572 | GenerateRule | test | func GenerateRule(repo Repo) *rule.Rule {
r := rule.NewRule("go_repository", repo.Name)
if repo.Commit != "" {
r.SetAttr("commit", repo.Commit)
}
if repo.Tag != "" {
r.SetAttr("tag", repo.Tag)
}
r.SetAttr("importpath", repo.GoPrefix)
if repo.Remote != "" {
r.SetAttr("remote", repo.Remote)
}
if repo.VCS !... | go | {
"resource": ""
} |
q178573 | FindExternalRepo | test | func FindExternalRepo(repoRoot, name string) (string, error) {
// See https://docs.bazel.build/versions/master/output_directories.html
// for documentation on Bazel directory layout.
// We expect the bazel-out symlink in the workspace root directory to point to
// <output-base>/execroot/<workspace-name>/bazel-out
... | go | {
"resource": ""
} |
q178574 | ListRepositories | test | func ListRepositories(workspace *rule.File) (repos []Repo, repoNamesByFile map[*rule.File][]string, err error) {
repoNamesByFile = make(map[*rule.File][]string)
repos, repoNamesByFile[workspace] = getRepos(workspace.Rules)
for _, d := range workspace.Directives {
switch d.Key {
case "repository_macro":
f, def... | go | {
"resource": ""
} |
q178575 | migrateLibraryEmbed | test | func migrateLibraryEmbed(c *config.Config, f *rule.File) {
for _, r := range f.Rules {
if !isGoRule(r.Kind()) {
continue
}
libExpr := r.Attr("library")
if libExpr == nil || rule.ShouldKeep(libExpr) || r.Attr("embed") != nil {
continue
}
r.DelAttr("library")
r.SetAttr("embed", &bzl.ListExpr{List: []... | go | {
"resource": ""
} |
q178576 | migrateGrpcCompilers | test | func migrateGrpcCompilers(c *config.Config, f *rule.File) {
for _, r := range f.Rules {
if r.Kind() != "go_grpc_library" || r.ShouldKeep() || r.Attr("compilers") != nil {
continue
}
r.SetKind("go_proto_library")
r.SetAttr("compilers", []string{grpcCompilerLabel})
}
} | go | {
"resource": ""
} |
q178577 | squashCgoLibrary | test | func squashCgoLibrary(c *config.Config, f *rule.File) {
// Find the default cgo_library and go_library rules.
var cgoLibrary, goLibrary *rule.Rule
for _, r := range f.Rules {
if r.Kind() == "cgo_library" && r.Name() == "cgo_default_library" && !r.ShouldKeep() {
if cgoLibrary != nil {
log.Printf("%s: when fi... | go | {
"resource": ""
} |
q178578 | removeLegacyProto | test | func removeLegacyProto(c *config.Config, f *rule.File) {
// Don't fix if the proto mode was set to something other than the default.
if pcMode := getProtoMode(c); pcMode != proto.DefaultMode {
return
}
// Scan for definitions to delete.
var protoLoads []*rule.Load
for _, l := range f.Loads {
if l.Name() == "... | go | {
"resource": ""
} |
q178579 | removeLegacyGazelle | test | func removeLegacyGazelle(c *config.Config, f *rule.File) {
for _, l := range f.Loads {
if l.Name() == "@io_bazel_rules_go//go:def.bzl" && l.Has("gazelle") {
l.Remove("gazelle")
if l.IsEmpty() {
l.Delete()
}
}
}
} | go | {
"resource": ""
} |
q178580 | selectPackage | test | func selectPackage(c *config.Config, dir string, packageMap map[string]*goPackage) (*goPackage, error) {
buildablePackages := make(map[string]*goPackage)
for name, pkg := range packageMap {
if pkg.isBuildable(c) {
buildablePackages[name] = pkg
}
}
if len(buildablePackages) == 0 {
return nil, &build.NoGoEr... | go | {
"resource": ""
} |
q178581 | AddBuiltin | test | func (mr *metaResolver) AddBuiltin(kindName string, resolver resolve.Resolver) {
mr.builtins[kindName] = resolver
} | go | {
"resource": ""
} |
q178582 | MappedKind | test | func (mr *metaResolver) MappedKind(pkgRel string, kind config.MappedKind) {
mr.mappedKinds[pkgRel] = append(mr.mappedKinds[pkgRel], kind)
} | go | {
"resource": ""
} |
q178583 | Resolver | test | func (mr metaResolver) Resolver(r *rule.Rule, pkgRel string) resolve.Resolver {
for _, mappedKind := range mr.mappedKinds[pkgRel] {
if mappedKind.KindName == r.Kind() {
return mr.builtins[mappedKind.FromKind]
}
}
return mr.builtins[r.Kind()]
} | go | {
"resource": ""
} |
q178584 | sortExprLabels | test | func sortExprLabels(e bzl.Expr, _ []bzl.Expr) {
list, ok := e.(*bzl.ListExpr)
if !ok || len(list.List) == 0 {
return
}
keys := make([]stringSortKey, len(list.List))
for i, elem := range list.List {
s, ok := elem.(*bzl.StringExpr)
if !ok {
return // don't sort lists unless all elements are strings
}
k... | go | {
"resource": ""
} |
q178585 | checkRulesGoVersion | test | func checkRulesGoVersion(repoRoot string) {
const message = `Gazelle may not be compatible with this version of rules_go.
Update io_bazel_rules_go to a newer version in your WORKSPACE file.`
rulesGoPath, err := repo.FindExternalRepo(repoRoot, config.RulesGoRepoName)
if err != nil {
return
}
defBzlPath := filepa... | go | {
"resource": ""
} |
q178586 | preprocessTags | test | func (gc *goConfig) preprocessTags() {
if gc.genericTags == nil {
gc.genericTags = make(map[string]bool)
}
gc.genericTags["gc"] = true
} | go | {
"resource": ""
} |
q178587 | setBuildTags | test | func (gc *goConfig) setBuildTags(tags string) error {
if tags == "" {
return nil
}
for _, t := range strings.Split(tags, ",") {
if strings.HasPrefix(t, "!") {
return fmt.Errorf("build tags can't be negated: %s", t)
}
gc.genericTags[t] = true
}
return nil
} | go | {
"resource": ""
} |
q178588 | splitValue | test | func splitValue(value string) []string {
parts := strings.Split(value, ",")
values := make([]string, 0, len(parts))
for _, part := range parts {
values = append(values, strings.TrimSpace(part))
}
return values
} | go | {
"resource": ""
} |
q178589 | copyGoModToTemp | test | func copyGoModToTemp(filename string) (tempDir string, err error) {
goModOrig, err := os.Open(filename)
if err != nil {
return "", err
}
defer goModOrig.Close()
tempDir, err = ioutil.TempDir("", "gazelle-temp-gomod")
if err != nil {
return "", err
}
goModCopy, err := os.Create(filepath.Join(tempDir, "go.m... | go | {
"resource": ""
} |
q178590 | findGoTool | test | func findGoTool() string {
path := "go" // rely on PATH by default
if goroot, ok := os.LookupEnv("GOROOT"); ok {
path = filepath.Join(goroot, "bin", "go")
}
if runtime.GOOS == "windows" {
path += ".exe"
}
return path
} | go | {
"resource": ""
} |
q178591 | isBuildable | test | func (pkg *goPackage) isBuildable(c *config.Config) bool {
return pkg.firstGoFile() != "" || !pkg.proto.sources.isEmpty()
} | go | {
"resource": ""
} |
q178592 | startServer | test | func startServer() error {
exe, err := os.Executable()
if err != nil {
return err
}
args := []string{"-server"}
args = append(args, os.Args[1:]...)
cmd := exec.Command(exe, args...)
log.Printf("starting server: %s", strings.Join(cmd.Args, " "))
if err := cmd.Start(); err != nil {
return err
}
if err := cm... | go | {
"resource": ""
} |
q178593 | watchDir | test | func watchDir(root string, record func(string)) (cancel func(), err error) {
w, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
dirs, errs := listDirs(root)
for _, err := range errs {
log.Print(err)
}
gitDir := filepath.Join(root, ".git")
for _, dir := range dirs {
if dir == gitDir {
co... | go | {
"resource": ""
} |
q178594 | listDirs | test | func listDirs(dir string) ([]string, []error) {
var dirs []string
var errs []error
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
errs = append(errs, err)
return nil
}
if info.IsDir() {
dirs = append(dirs, path)
}
return nil
})
if err != nil {
... | go | {
"resource": ""
} |
q178595 | shouldIgnore | test | func shouldIgnore(p string) bool {
p = strings.TrimPrefix(filepath.ToSlash(p), "./")
base := path.Base(p)
return strings.HasPrefix(p, "tools/") || base == ".git" || base == "BUILD" || base == "BUILD.bazel"
} | go | {
"resource": ""
} |
q178596 | recordWrite | test | func recordWrite(path string) {
dirSetMutex.Lock()
defer dirSetMutex.Unlock()
dirSet[path] = true
} | go | {
"resource": ""
} |
q178597 | getAndClearWrittenDirs | test | func getAndClearWrittenDirs() []string {
dirSetMutex.Lock()
defer dirSetMutex.Unlock()
dirs := make([]string, 0, len(dirSet))
for d := range dirSet {
dirs = append(dirs, d)
}
dirSet = make(map[string]bool)
return dirs
} | go | {
"resource": ""
} |
q178598 | CombineHandlers | test | func CombineHandlers(handlers ...http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
for _, handler := range handlers {
handler(w, req)
}
}
} | go | {
"resource": ""
} |
q178599 | VerifyContentType | test | func VerifyContentType(contentType string) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
Expect(req.Header.Get("Content-Type")).Should(Equal(contentType))
}
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.