Skip to content

Commit

Permalink
update runfiles style
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebarrau committed Dec 12, 2023
1 parent 711b68c commit 69c3362
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion java/gazelle/private/servermanager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_library(
visibility = ["//java/gazelle:__subpackages__"],
deps = [
"//java/gazelle/private/javaparser/proto/gazelle/java/javaparser/v0:javaparser",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
"@io_bazel_rules_go//go/runfiles:go_default_library",
"@org_golang_google_grpc//:go_default_library",
],
)
28 changes: 8 additions & 20 deletions java/gazelle/private/servermanager/servermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import (
"os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

pb "github.com/bazel-contrib/rules_jvm/java/gazelle/private/javaparser/proto/gazelle/java/javaparser/v0"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/bazelbuild/rules_go/go/runfiles"
"google.golang.org/grpc"
)

const javaparser = "java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators/Main"

type ServerManager struct {
workspace string
javaLogLevel string
Expand Down Expand Up @@ -89,27 +86,18 @@ func (m *ServerManager) Connect() (*grpc.ClientConn, error) {
}

func locateJavaparser() (string, error) {
runfiles, err := bazel.ListRunfiles()
rf, err := runfiles.New()
if err != nil {
return "", fmt.Errorf("failed to find javaparser in runfiles: %w", err)
}

possiblePaths := make(map[string]bool)
for _, rf := range runfiles {
if strings.HasSuffix(rf.ShortPath, javaparser) {
possiblePaths[rf.Path] = true
}
return "", fmt.Errorf("failed to init new style runfiles: %w", err)
}

if len(possiblePaths) == 0 {
return "", fmt.Errorf("failed to find javaparser in runfiles")
// We want //java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators:Main
loc, err := rf.Rlocation("contrib_rules_jvm/java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators/Main")
if err != nil {
return "", fmt.Errorf("failed to call RLocation: %w", err)
}

// The set may contain multiple element indirectly pointing to the same thing.
for path := range possiblePaths {
return path, nil
}
panic("unreachable code")
return loc, nil
}

func readPort(path string) (int32, error) {
Expand Down

0 comments on commit 69c3362

Please sign in to comment.