123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package main
- import (
- "fmt"
- "io/ioutil"
- "path/filepath"
- bzl "github.com/bazelbuild/buildtools/build"
- )
- const (
- pkgSrcsTarget = "package-srcs"
- allSrcsTarget = "all-srcs"
- )
- func (v *Vendorer) walkSource(pkgPath string) ([]string, error) {
-
- pkgPath = filepath.Clean(pkgPath)
- for _, r := range v.skippedPaths {
- if r.MatchString(pkgPath) {
- return nil, nil
- }
- }
- files, err := ioutil.ReadDir(pkgPath)
- if err != nil {
- return nil, err
- }
-
- var children []string
- for _, f := range files {
- if f.IsDir() {
- c, err := v.walkSource(filepath.Join(pkgPath, f.Name()))
- if err != nil {
- return nil, err
- }
- children = append(children, c...)
- }
- }
-
- _, hasRules := v.newRules[pkgPath]
- isPkg := hasRules
- if !isPkg {
- isPkg, _ = findBuildFile(pkgPath)
- }
- if !isPkg {
-
-
-
- return children, nil
- }
-
- if !hasRules {
- v.addRules(pkgPath, nil)
- }
- if !v.cfg.AddSourcesRules {
- return nil, nil
- }
- pkgSrcsExpr := &bzl.LiteralExpr{Token: `glob(["**"])`}
- if pkgPath == "." {
- pkgSrcsExpr = &bzl.LiteralExpr{Token: `glob(["**"], exclude=["bazel-*/**", ".git/**", ".idea/**"])`}
- }
- v.addRules(pkgPath, []*bzl.Rule{
- newRule(RuleTypeFileGroup,
- func(_ ruleType) string { return pkgSrcsTarget },
- map[string]bzl.Expr{
- "srcs": pkgSrcsExpr,
- "visibility": asExpr([]string{"//visibility:private"}),
- }),
- newRule(RuleTypeFileGroup,
- func(_ ruleType) string { return allSrcsTarget },
- map[string]bzl.Expr{
- "srcs": asExpr(append(children, fmt.Sprintf(":%s", pkgSrcsTarget))),
-
- "visibility": asExpr([]string{"//visibility:public"}),
- }),
- })
- return []string{fmt.Sprintf("//%s:%s", pkgPath, allSrcsTarget)}, nil
- }
|