Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use upstream definitions, fix gopackagesdriver #4185

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,22 @@ go_repository(
go_repository(
name = "org_golang_x_mod",
importpath = "golang.org/x/mod",
sum = "h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=",
version = "v0.9.0",
sum = "h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=",
version = "v0.22.0",
)

go_repository(
name = "org_golang_x_net",
importpath = "golang.org/x/net",
sum = "h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=",
version = "v0.31.0",
)

go_repository(
name = "org_golang_x_sync",
importpath = "golang.org/x/sync",
sum = "h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=",
version = "v0.1.0",
sum = "h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=",
version = "v0.9.0",
)

go_repository(
Expand All @@ -183,6 +190,13 @@ go_repository(
version = "v0.6.0",
)

go_repository(
name = "org_golang_x_tools",
importpath = "golang.org/x/tools",
sum = "h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=",
version = "v0.27.0",
)

http_archive(
name = "googleapis",
sha256 = "9d1a930e767c93c825398b8f8692eca3fe353b9aaadedfbcf1fca2282c85df88",
Expand Down
21 changes: 12 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
module github.com/bazelbuild/rules_go

go 1.21.1
go 1.22.0

toolchain go1.22.2

require (
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.7.0-rc.1
github.com/golang/protobuf v1.5.3
golang.org/x/net v0.26.0
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.40.1
golang.org/x/net v0.31.0
golang.org/x/tools v0.27.0
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.56.3
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.33.0
)

require (
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
)
128 changes: 18 additions & 110 deletions go.sum

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions go/runfiles/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ alias(
visibility = ["//visibility:public"],
)

filegroup(
name = "all_files",
testonly = True,
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)

go_test(
name = "example_test",
name = "runfiles_test",
srcs = [
"caller_repository_example_test.go",
ellie-idb marked this conversation as resolved.
Show resolved Hide resolved
"example_test.go",
"rlocationpath_xdefs_example_test.go",
],
deps = [":runfiles"],
)

filegroup(
name = "all_files",
testonly = True,
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
5 changes: 1 addition & 4 deletions go/tools/builders/stdliblist.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ func stdliblist(args []string) error {
listArgs = append(listArgs, "-tags", strings.Join(build.Default.BuildTags, ","))
}

if cgoEnabled {
listArgs = append(listArgs, "-compiled=true")
}

listArgs = append(listArgs, "-compiled=true")
listArgs = append(listArgs, "-json", "builtin", "std", "runtime/cgo")

jsonFile, err := os.Create(*out)
Expand Down
6 changes: 6 additions & 0 deletions go/tools/bzltestutil/chdir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ filegroup(
),
visibility = ["//visibility:public"],
)

alias(
name = "go_default_library",
actual = ":chdir",
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions go/tools/gopackagesdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_library(
visibility = [
"//tests/integration/gopackagesdriver:__pkg__",
],
deps = ["@org_golang_x_tools//go/packages"],
)

go_binary(
Expand Down
10 changes: 6 additions & 4 deletions go/tools/gopackagesdriver/bazel_json_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"regexp"
"runtime"
"strings"

"golang.org/x/tools/go/packages"
)

type BazelJSONBuilder struct {
Expand Down Expand Up @@ -136,7 +138,7 @@ func (b *BazelJSONBuilder) queryFromRequests(requests ...string) string {
} else if isLocalPattern(request) {
result = b.localQuery(request)
} else if request == "builtin" || request == "std" {
result = fmt.Sprintf(RulesGoStdlibLabel)
result = fmt.Sprintf("%s", RulesGoStdlibLabel)
}

if result != "" {
Expand All @@ -156,9 +158,9 @@ func NewBazelJSONBuilder(bazel *Bazel, includeTests bool) (*BazelJSONBuilder, er
}, nil
}

func (b *BazelJSONBuilder) outputGroupsForMode(mode LoadMode) string {
func (b *BazelJSONBuilder) outputGroupsForMode(mode packages.LoadMode) string {
og := "go_pkg_driver_json_file,go_pkg_driver_stdlib_json_file,go_pkg_driver_srcs"
if mode&NeedExportsFile != 0 {
if mode&packages.NeedExportsFile != 0 {
og += ",go_pkg_driver_export_file"
}
return og
Expand Down Expand Up @@ -200,7 +202,7 @@ func (b *BazelJSONBuilder) Labels(ctx context.Context, requests []string) ([]str
return labels, nil
}

func (b *BazelJSONBuilder) Build(ctx context.Context, labels []string, mode LoadMode) ([]string, error) {
func (b *BazelJSONBuilder) Build(ctx context.Context, labels []string, mode packages.LoadMode) ([]string, error) {
aspects := append(additionalAspects, goDefaultAspect)

buildArgs := concatStringsArrays([]string{
Expand Down
66 changes: 3 additions & 63 deletions go/tools/gopackagesdriver/driver_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,72 +18,12 @@ import (
"encoding/json"
"fmt"
"io"
)

// From https://pkg.go.dev/golang.org/x/tools/go/packages#LoadMode
type LoadMode int

// Only NeedExportsFile is needed in our case
const (
// NeedName adds Name and PkgPath.
NeedName LoadMode = 1 << iota

// NeedFiles adds GoFiles and OtherFiles.
NeedFiles

// NeedCompiledGoFiles adds CompiledGoFiles.
NeedCompiledGoFiles

// NeedImports adds Imports. If NeedDeps is not set, the Imports field will contain
// "placeholder" Packages with only the ID set.
NeedImports

// NeedDeps adds the fields requested by the LoadMode in the packages in Imports.
NeedDeps

// NeedExportsFile adds ExportFile.
NeedExportFile

// NeedTypes adds Types, Fset, and IllTyped.
NeedTypes

// NeedSyntax adds Syntax.
NeedSyntax

// NeedTypesInfo adds TypesInfo.
NeedTypesInfo

// NeedTypesSizes adds TypesSizes.
NeedTypesSizes

// typecheckCgo enables full support for type checking cgo. Requires Go 1.15+.
// Modifies CompiledGoFiles and Types, and has no effect on its own.
typecheckCgo

// NeedModule adds Module.
NeedModule
"golang.org/x/tools/go/packages"
)

// Deprecated: NeedExportsFile is a historical misspelling of NeedExportFile.
const NeedExportsFile = NeedExportFile

// From https://github.com/golang/tools/blob/v0.1.0/go/packages/external.go#L32
// Most fields are disabled since there is no need for them
type DriverRequest struct {
Mode LoadMode `json:"mode"`
// Env specifies the environment the underlying build system should be run in.
// Env []string `json:"env"`
// BuildFlags are flags that should be passed to the underlying build system.
// BuildFlags []string `json:"build_flags"`
// Tests specifies whether the patterns should also return test packages.
Tests bool `json:"tests"`
// Overlay maps file paths (relative to the driver's working directory) to the byte contents
// of overlay files.
Overlay map[string][]byte `json:"overlay"`
}

func ReadDriverRequest(r io.Reader) (*DriverRequest, error) {
req := &DriverRequest{}
func ReadDriverRequest(r io.Reader) (*packages.DriverRequest, error) {
req := &packages.DriverRequest{}
if err := json.NewDecoder(r).Decode(&req); err != nil {
return nil, fmt.Errorf("unable to decode driver request: %w", err)
}
Expand Down
Loading