Skip to content

Commit

Permalink
More slash normalising
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed May 3, 2024
1 parent a3f56ff commit c844250
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions java/gazelle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (jf *javaFile) ClassName() *types.ClassName {
return &className
}

func (jf *javaFile) PathRelativeToBazelPackage(bazelPackage string) string {
return strings.TrimPrefix(jf.pathRelativeToBazelWorkspaceRoot, filepath.FromSlash(bazelPackage)+string(os.PathSeparator))
}

func javaFileLess(l, r javaFile) bool {
return l.pathRelativeToBazelWorkspaceRoot < r.pathRelativeToBazelWorkspaceRoot
}
Expand Down Expand Up @@ -258,7 +262,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, src.PathRelativeToBazelPackage(args.Rel))
}
}
if len(srcs) > 0 {
Expand Down Expand Up @@ -548,7 +552,7 @@ func (l javaLang) generateJavaTest(file *rule.File, pathToPackageRelativeToBazel
r.AddArg(&bzl.Ident{Name: javaRuleKind})
}

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

0 comments on commit c844250

Please sign in to comment.