Skip to content

Commit

Permalink
Use an OS-agnostic path separator for the srcs attribute (#270)
Browse files Browse the repository at this point in the history
This pull request updates the srcs attribute with "/" regardless of the
OS not to update the BUILD file when Gazelle is run on a different OS
and to correctly trim the parent path (#269).
  • Loading branch information
bartoszpop authored May 7, 2024
1 parent 649e64a commit dac29ee
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions java/gazelle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
srcs := make([]string, 0, allTestRelatedSrcs.Len())
for _, src := range allTestRelatedSrcs.SortedSlice() {
if _, ok := separateTestJavaFiles[src]; !ok {
srcs = append(srcs, strings.TrimPrefix(src.pathRelativeToBazelWorkspaceRoot, args.Rel+"/"))
srcs = append(srcs, strings.TrimPrefix(filepath.ToSlash(src.pathRelativeToBazelWorkspaceRoot), args.Rel+"/"))
}
}
if len(srcs) > 0 {
Expand Down Expand Up @@ -459,7 +459,7 @@ func (l javaLang) generateJavaLibrary(file *rule.File, pathToPackageRelativeToBa

srcs := make([]string, 0, len(srcsRelativeToBazelWorkspace))
for _, src := range srcsRelativeToBazelWorkspace {
srcs = append(srcs, strings.TrimPrefix(src, pathToPackageRelativeToBazelWorkspace+"/"))
srcs = append(srcs, strings.TrimPrefix(filepath.ToSlash(src), filepath.ToSlash(pathToPackageRelativeToBazelWorkspace+"/")))
}
sort.Strings(srcs)

Expand Down Expand Up @@ -547,7 +547,7 @@ func (l javaLang) generateJavaTest(file *rule.File, pathToPackageRelativeToBazel
r.AddArg(&bzl.Ident{Name: javaRuleKind})
}

path := strings.TrimPrefix(f.pathRelativeToBazelWorkspaceRoot, pathToPackageRelativeToBazelWorkspace+"/")
path := strings.TrimPrefix(filepath.ToSlash(f.pathRelativeToBazelWorkspaceRoot), filepath.ToSlash(pathToPackageRelativeToBazelWorkspace+"/"))
r.SetAttr("srcs", []string{path})
r.SetAttr("test_class", fullyQualifiedTestClass)
r.SetPrivateAttr(packagesKey, []types.ResolvableJavaPackage{*types.NewResolvableJavaPackage(f.pkg, true, false)})
Expand Down

0 comments on commit dac29ee

Please sign in to comment.