From 7782270ecc671e464d3dddab0192d0068930457f Mon Sep 17 00:00:00 2001 From: ellie-idb Date: Thu, 28 Nov 2024 12:47:03 -0500 Subject: [PATCH] add in changes --- WORKSPACE | 22 ++- go.mod | 21 +-- go.sum | 128 +++--------------- go/tools/gopackagesdriver/BUILD.bazel | 1 + .../gopackagesdriver/bazel_json_builder.go | 10 +- go/tools/gopackagesdriver/driver_request.go | 66 +-------- go/tools/gopackagesdriver/flatpackage.go | 76 +++++------ .../gopackagesdriver/gopackagesdriver_test.go | 61 ++------- .../gopackagesdriver/json_packages_driver.go | 13 +- go/tools/gopackagesdriver/packageregistry.go | 87 ++++++++---- go/tools/gopackagesdriver/utils.go | 4 +- 11 files changed, 176 insertions(+), 313 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 862aad8419..05678791a1 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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( @@ -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", diff --git a/go.mod b/go.mod index 4a29f87973..39db387304 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 46841e9c80..cafeeb3fe9 100644 --- a/go.sum +++ b/go.sum @@ -1,164 +1,72 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.7.0-rc.1 h1:YojYx61/OLFsiv6Rw1Z96LpldJIy31o+UHmwAUMJ6/U= github.com/golang/mock v1.7.0-rc.1/go.mod h1:s42URUywIqd+OcERslBJvOjepvNymP31m3q8d/GkuRs= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o= +golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.40.1 h1:pnP7OclFFFgFi4VHQDQDaoXUVauOFyktqTsqqgzFKbc= -google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= +google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc= +google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= diff --git a/go/tools/gopackagesdriver/BUILD.bazel b/go/tools/gopackagesdriver/BUILD.bazel index 0351845f5e..5d2adc967c 100644 --- a/go/tools/gopackagesdriver/BUILD.bazel +++ b/go/tools/gopackagesdriver/BUILD.bazel @@ -19,6 +19,7 @@ go_library( visibility = [ "//tests/integration/gopackagesdriver:__pkg__", ], + deps = ["@org_golang_x_tools//go/packages"], ) go_binary( diff --git a/go/tools/gopackagesdriver/bazel_json_builder.go b/go/tools/gopackagesdriver/bazel_json_builder.go index a86c396011..763863320c 100644 --- a/go/tools/gopackagesdriver/bazel_json_builder.go +++ b/go/tools/gopackagesdriver/bazel_json_builder.go @@ -25,6 +25,8 @@ import ( "regexp" "runtime" "strings" + + "golang.org/x/tools/go/packages" ) type BazelJSONBuilder struct { @@ -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 != "" { @@ -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 @@ -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{ diff --git a/go/tools/gopackagesdriver/driver_request.go b/go/tools/gopackagesdriver/driver_request.go index 3d7dea1d98..5e1c2e18c2 100644 --- a/go/tools/gopackagesdriver/driver_request.go +++ b/go/tools/gopackagesdriver/driver_request.go @@ -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) } diff --git a/go/tools/gopackagesdriver/flatpackage.go b/go/tools/gopackagesdriver/flatpackage.go index c4170b9fab..6fada37e79 100644 --- a/go/tools/gopackagesdriver/flatpackage.go +++ b/go/tools/gopackagesdriver/flatpackage.go @@ -24,9 +24,11 @@ import ( "os" "strconv" "strings" + + "golang.org/x/tools/go/packages" ) -type ResolvePkgFunc func(importPath string) string +type ResolvePkgFunc func(importPath string) *packages.Package // Copy and pasted from golang.org/x/tools/go/packages type FlatPackagesError struct { @@ -97,22 +99,22 @@ func WalkFlatPackagesFromJSON(jsonFile string, onPkg PackageFunc) error { return nil } -func (fp *FlatPackage) ResolvePaths(prf PathResolverFunc) error { - resolvePathsInPlace(prf, fp.CompiledGoFiles) - resolvePathsInPlace(prf, fp.GoFiles) - resolvePathsInPlace(prf, fp.OtherFiles) - fp.ExportFile = prf(fp.ExportFile) +func ResolvePaths(pak *packages.Package, prf PathResolverFunc) error { + resolvePathsInPlace(prf, pak.CompiledGoFiles) + resolvePathsInPlace(prf, pak.GoFiles) + resolvePathsInPlace(prf, pak.OtherFiles) + pak.ExportFile = prf(pak.ExportFile) return nil } // FilterFilesForBuildTags filters the source files given the current build // tags. -func (fp *FlatPackage) FilterFilesForBuildTags() { - fp.GoFiles = filterSourceFilesForTags(fp.GoFiles) - fp.CompiledGoFiles = filterSourceFilesForTags(fp.CompiledGoFiles) +func FilterFilesForBuildTags(pak *packages.Package) { + pak.GoFiles = filterSourceFilesForTags(pak.GoFiles) + pak.CompiledGoFiles = filterSourceFilesForTags(pak.CompiledGoFiles) } -func (fp *FlatPackage) filterTestSuffix(files []string) (err error, testFiles []string, xTestFiles, nonTestFiles []string) { +func filterTestSuffix(pkg *packages.Package, files []string) (err error, testFiles []string, xTestFiles, nonTestFiles []string) { for _, filename := range files { if strings.HasSuffix(filename, "_test.go") { fset := token.NewFileSet() @@ -120,7 +122,7 @@ func (fp *FlatPackage) filterTestSuffix(files []string) (err error, testFiles [] if err != nil { return err, nil, nil, nil } - if f.Name.Name == fp.Name { + if f.Name.Name == pkg.Name { testFiles = append(testFiles, filename) } else { xTestFiles = append(xTestFiles, filename) @@ -132,44 +134,45 @@ func (fp *FlatPackage) filterTestSuffix(files []string) (err error, testFiles [] return } -func (fp *FlatPackage) MoveTestFiles() *FlatPackage { - err, tgf, xtgf, gf := fp.filterTestSuffix(fp.GoFiles) +func MoveTestFiles(pkg *packages.Package) *packages.Package { + err, tgf, xtgf, gf := filterTestSuffix(pkg, pkg.GoFiles) if err != nil { return nil } - fp.GoFiles = append(gf, tgf...) + pkg.GoFiles = append(gf, tgf...) - err, ctgf, cxtgf, cgf := fp.filterTestSuffix(fp.CompiledGoFiles) + err, ctgf, cxtgf, cgf := filterTestSuffix(pkg, pkg.CompiledGoFiles) if err != nil { return nil } - fp.CompiledGoFiles = append(cgf, ctgf...) + pkg.CompiledGoFiles = append(cgf, ctgf...) if len(xtgf) == 0 && len(cxtgf) == 0 { return nil } - newImports := make(map[string]string, len(fp.Imports)) - for k, v := range fp.Imports { + newImports := make(map[string]*packages.Package, len(pkg.Imports)) + for k, v := range pkg.Imports { newImports[k] = v } - newImports[fp.PkgPath] = fp.ID + newImports[pkg.PkgPath] = &packages.Package{ + ID: pkg.ID, + } // Clone package, only xtgf files - return &FlatPackage{ - ID: fp.ID + "_xtest", - Name: fp.Name + "_test", - PkgPath: fp.PkgPath + "_test", + return &packages.Package{ + ID: pkg.ID + "_xtest", + Name: pkg.Name + "_test", + PkgPath: pkg.PkgPath + "_test", Imports: newImports, - Errors: fp.Errors, + Errors: pkg.Errors, GoFiles: append([]string{}, xtgf...), CompiledGoFiles: append([]string{}, cxtgf...), - OtherFiles: fp.OtherFiles, - ExportFile: fp.ExportFile, - Standard: fp.Standard, + OtherFiles: pkg.OtherFiles, + ExportFile: pkg.ExportFile, } } @@ -179,15 +182,10 @@ func (fp *FlatPackage) IsStdlib() bool { // ResolveImports resolves imports for non-stdlib packages and integrates file overlays // to allow modification of package imports without modifying disk files. -func (fp *FlatPackage) ResolveImports(resolve ResolvePkgFunc, overlays map[string][]byte) error { - // Stdlib packages are already complete import wise - if fp.IsStdlib() { - return nil - } - +func ResolveImports(pkg *packages.Package, resolve ResolvePkgFunc, overlays map[string][]byte) error { fset := token.NewFileSet() - for _, file := range fp.CompiledGoFiles { + for _, file := range pkg.CompiledGoFiles { // Only assign overlayContent when an overlay for the file exists, since ParseFile checks by type. // If overlay is assigned directly from the map, it will have []byte as type // Empty []byte types are parsed into io.EOF @@ -200,8 +198,8 @@ func (fp *FlatPackage) ResolveImports(resolve ResolvePkgFunc, overlays map[strin return err } // If the name is not provided, fetch it from the sources - if fp.Name == "" { - fp.Name = f.Name.Name + if pkg.Name == "" { + pkg.Name = f.Name.Name } for _, rawImport := range f.Imports { @@ -213,12 +211,12 @@ func (fp *FlatPackage) ResolveImports(resolve ResolvePkgFunc, overlays map[strin if imp == "C" { continue } - if _, ok := fp.Imports[imp]; ok { + if _, ok := pkg.Imports[imp]; ok { continue } - if pkgID := resolve(imp); pkgID != "" { - fp.Imports[imp] = pkgID + if impPkg := resolve(imp); impPkg != nil { + pkg.Imports[imp] = impPkg } } } diff --git a/go/tools/gopackagesdriver/gopackagesdriver_test.go b/go/tools/gopackagesdriver/gopackagesdriver_test.go index 751470adea..613ec8707d 100644 --- a/go/tools/gopackagesdriver/gopackagesdriver_test.go +++ b/go/tools/gopackagesdriver/gopackagesdriver_test.go @@ -10,6 +10,8 @@ import ( "strings" "testing" + "golang.org/x/tools/go/packages" + "github.com/bazelbuild/rules_go/go/tools/bazel_testing" ) @@ -85,35 +87,8 @@ const ( bzlmodOsPkgID = "@@io_bazel_rules_go//stdlib:os" ) -func TestStdlib(t *testing.T) { - resp := runForTest(t, DriverRequest{}, ".", "std") - - if len(resp.Packages) == 0 { - t.Fatal("Expected stdlib packages") - } - - for _, pkg := range resp.Packages { - // net, plugin and user stdlib packages seem to have compiled files only for Linux. - if pkg.Name != "cgo" { - continue - } - - var hasCompiledFiles bool - for _, x := range pkg.CompiledGoFiles { - if filepath.Ext(x) == "" { - hasCompiledFiles = true - break - } - } - - if !hasCompiledFiles { - t.Errorf("%q stdlib package should have compiled files", pkg.Name) - } - } -} - func TestBaseFileLookup(t *testing.T) { - resp := runForTest(t, DriverRequest{}, ".", "file=hello.go") + resp := runForTest(t, packages.DriverRequest{}, ".", "file=hello.go") t.Run("roots", func(t *testing.T) { if len(resp.Roots) != 1 { @@ -141,24 +116,19 @@ func TestBaseFileLookup(t *testing.T) { return } - if pkg.Standard { - t.Errorf("Expected package to not be Standard:\n%+v", pkg) - return - } - if len(pkg.Imports) != 1 { t.Errorf("Expected one import:\n%+v", pkg) return } - if pkg.Imports["os"] != osPkgID && pkg.Imports["os"] != bzlmodOsPkgID { + if pkg.Imports["os"].ID != osPkgID && pkg.Imports["os"].ID != bzlmodOsPkgID { t.Errorf("Expected os import to map to %q or %q:\n%+v", osPkgID, bzlmodOsPkgID, pkg) return } }) t.Run("dependency", func(t *testing.T) { - var osPkg *FlatPackage + var osPkg *packages.Package for _, p := range resp.Packages { if p.ID == osPkgID || p.ID == bzlmodOsPkgID { osPkg = p @@ -169,16 +139,11 @@ func TestBaseFileLookup(t *testing.T) { t.Errorf("Expected os package to be included:\n%+v", osPkg) return } - - if !osPkg.Standard { - t.Errorf("Expected os import to be standard:\n%+v", osPkg) - return - } }) } func TestRelativeFileLookup(t *testing.T) { - resp := runForTest(t, DriverRequest{}, "subhello", "file=./subhello.go") + resp := runForTest(t, packages.DriverRequest{}, "subhello", "file=./subhello.go") t.Run("roots", func(t *testing.T) { if len(resp.Roots) != 1 { @@ -209,7 +174,7 @@ func TestRelativeFileLookup(t *testing.T) { } func TestRelativePatternWildcardLookup(t *testing.T) { - resp := runForTest(t, DriverRequest{}, "subhello", "./...") + resp := runForTest(t, packages.DriverRequest{}, "subhello", "./...") t.Run("roots", func(t *testing.T) { if len(resp.Roots) != 1 { @@ -240,7 +205,7 @@ func TestRelativePatternWildcardLookup(t *testing.T) { } func TestExternalTests(t *testing.T) { - resp := runForTest(t, DriverRequest{}, ".", "file=hello_external_test.go") + resp := runForTest(t, packages.DriverRequest{}, ".", "file=hello_external_test.go") if len(resp.Roots) != 2 { t.Errorf("Expected exactly two roots for package: %+v", resp.Roots) } @@ -278,11 +243,11 @@ func TestOverlay(t *testing.T) { subhelloPath := path.Join(wd, "subhello/subhello.go") expectedImportsPerFile := map[string][]string{ - helloPath: []string{"fmt"}, - subhelloPath: []string{"os", "encoding/json"}, + helloPath: {"fmt"}, + subhelloPath: {"os", "encoding/json"}, } - overlayDriverRequest := DriverRequest{ + overlayDriverRequest := packages.DriverRequest{ Overlay: map[string][]byte{ helloPath: []byte(` package hello @@ -324,7 +289,7 @@ func TestOverlay(t *testing.T) { expectSetEquality(t, expectedImportsPerFile[subhelloPath], subhelloPkgImportPaths, "subhello imports") } -func runForTest(t *testing.T, driverRequest DriverRequest, relativeWorkingDir string, args ...string) driverResponse { +func runForTest(t *testing.T, driverRequest packages.DriverRequest, relativeWorkingDir string, args ...string) packages.DriverResponse { t.Helper() // Remove most environment variables, other than those on an allowlist. @@ -392,7 +357,7 @@ func runForTest(t *testing.T, driverRequest DriverRequest, relativeWorkingDir st if err := run(context.Background(), in, out, args); err != nil { t.Fatalf("running gopackagesdriver: %v", err) } - var resp driverResponse + var resp packages.DriverResponse if err := json.Unmarshal(out.Bytes(), &resp); err != nil { t.Fatalf("unmarshaling response: %v", err) } diff --git a/go/tools/gopackagesdriver/json_packages_driver.go b/go/tools/gopackagesdriver/json_packages_driver.go index 3ad7360479..14589f7c2f 100644 --- a/go/tools/gopackagesdriver/json_packages_driver.go +++ b/go/tools/gopackagesdriver/json_packages_driver.go @@ -16,7 +16,8 @@ package main import ( "fmt" - "runtime" + + "golang.org/x/tools/go/packages" ) type JSONPackagesDriver struct { @@ -47,14 +48,12 @@ func NewJSONPackagesDriver(jsonFiles []string, prf PathResolverFunc, bazelVersio return jpd, nil } -func (b *JSONPackagesDriver) GetResponse(labels []string) *driverResponse { - rootPkgs, packages := b.registry.Match(labels) +func (b *JSONPackagesDriver) GetResponse(labels []string) *packages.DriverResponse { + rootPkgs, paks := b.registry.Match(labels) - return &driverResponse{ + return &packages.DriverResponse{ NotHandled: false, - Compiler: "gc", - Arch: runtime.GOARCH, Roots: rootPkgs, - Packages: packages, + Packages: paks, } } diff --git a/go/tools/gopackagesdriver/packageregistry.go b/go/tools/gopackagesdriver/packageregistry.go index ff67c9f304..c8003de2b2 100644 --- a/go/tools/gopackagesdriver/packageregistry.go +++ b/go/tools/gopackagesdriver/packageregistry.go @@ -18,18 +18,20 @@ import ( "fmt" "os" "strings" + + "golang.org/x/tools/go/packages" ) type PackageRegistry struct { - packagesByID map[string]*FlatPackage - stdlib map[string]string + packagesByID map[string]*packages.Package + stdlib map[string]*packages.Package bazelVersion bazelVersion } func NewPackageRegistry(bazelVersion bazelVersion, pkgs ...*FlatPackage) *PackageRegistry { pr := &PackageRegistry{ - packagesByID: map[string]*FlatPackage{}, - stdlib: map[string]string{}, + packagesByID: map[string]*packages.Package{}, + stdlib: map[string]*packages.Package{}, bazelVersion: bazelVersion, } pr.Add(pkgs...) @@ -37,11 +39,34 @@ func NewPackageRegistry(bazelVersion bazelVersion, pkgs ...*FlatPackage) *Packag } func (pr *PackageRegistry) Add(pkgs ...*FlatPackage) *PackageRegistry { - for _, pkg := range pkgs { + for _, flatPkg := range pkgs { + imports := make(map[string]*packages.Package) + for impKey, imp := range flatPkg.Imports { + imports[impKey] = &packages.Package{ + ID: imp, + } + } + + pkg := &packages.Package{ + ID: flatPkg.ID, + Name: flatPkg.Name, + PkgPath: flatPkg.PkgPath, + GoFiles: flatPkg.GoFiles, + CompiledGoFiles: flatPkg.CompiledGoFiles, + OtherFiles: flatPkg.OtherFiles, + ExportFile: flatPkg.ExportFile, + Imports: imports, + } + pr.packagesByID[pkg.ID] = pkg - if pkg.IsStdlib() { - pr.stdlib[pkg.PkgPath] = pkg.ID + // TODO(ellie): wtf why does this fix things + if flatPkg.IsStdlib() { + pkg.CompiledGoFiles = pkg.GoFiles + } + + if flatPkg.IsStdlib() { + pr.stdlib[pkg.PkgPath] = pkg } } return pr @@ -49,8 +74,8 @@ func (pr *PackageRegistry) Add(pkgs ...*FlatPackage) *PackageRegistry { func (pr *PackageRegistry) ResolvePaths(prf PathResolverFunc) error { for _, pkg := range pr.packagesByID { - pkg.ResolvePaths(prf) - pkg.FilterFilesForBuildTags() + ResolvePaths(pkg, prf) + FilterFilesForBuildTags(pkg) } return nil } @@ -59,28 +84,29 @@ func (pr *PackageRegistry) ResolvePaths(prf PathResolverFunc) error { // stdlib packages are not part of the JSON file exports as bazel is unaware of // them. func (pr *PackageRegistry) ResolveImports(overlays map[string][]byte) error { - resolve := func(importPath string) string { - if pkgID, ok := pr.stdlib[importPath]; ok { - return pkgID + resolve := func(importPath string) *packages.Package { + if pkg, ok := pr.stdlib[importPath]; ok { + return pkg } - return "" + return nil } for _, pkg := range pr.packagesByID { - if err := pkg.ResolveImports(resolve, overlays); err != nil { + if err := ResolveImports(pkg, resolve, overlays); err != nil { return err } - testFp := pkg.MoveTestFiles() - if testFp != nil { - pr.packagesByID[testFp.ID] = testFp + + testPkg := MoveTestFiles(pkg) + if testPkg != nil { + pr.packagesByID[testPkg.ID] = testPkg } } return nil } -func (pr *PackageRegistry) walk(acc map[string]*FlatPackage, root string) { +func (pr *PackageRegistry) walk(acc map[string]*packages.Package, root string) { pkg := pr.packagesByID[root] if pkg == nil { @@ -89,14 +115,21 @@ func (pr *PackageRegistry) walk(acc map[string]*FlatPackage, root string) { } acc[pkg.ID] = pkg - for _, pkgID := range pkg.Imports { - if _, ok := acc[pkgID]; !ok { - pr.walk(acc, pkgID) + for imp, pkgI := range pkg.Imports { + if pkgI == nil { + fmt.Fprintf(os.Stderr, "Error: import %s for package %v not resolved\n", imp, root) + if _, ok := pr.stdlib[imp]; ok { + fmt.Fprintf(os.Stderr, "import was stdlib\n") + } + continue + } + if _, ok := acc[pkgI.ID]; !ok { + pr.walk(acc, pkgI.ID) } } } -func (pr *PackageRegistry) Match(labels []string) ([]string, []*FlatPackage) { +func (pr *PackageRegistry) Match(labels []string) ([]string, []*packages.Package) { roots := map[string]struct{}{} for _, label := range labels { @@ -110,10 +143,8 @@ func (pr *PackageRegistry) Match(labels []string) ([]string, []*FlatPackage) { if label == RulesGoStdlibLabel { // For stdlib, we need to append all the subpackages as roots // since RulesGoStdLibLabel doesn't actually show up in the stdlib pkg.json - for _, pkg := range pr.packagesByID { - if pkg.Standard { - roots[pkg.ID] = struct{}{} - } + for _, pkg := range pr.stdlib { + roots[pkg.ID] = struct{}{} } } else { roots[label] = struct{}{} @@ -124,14 +155,14 @@ func (pr *PackageRegistry) Match(labels []string) ([]string, []*FlatPackage) { } } - walkedPackages := map[string]*FlatPackage{} + walkedPackages := map[string]*packages.Package{} retRoots := make([]string, 0, len(roots)) for rootPkg := range roots { retRoots = append(retRoots, rootPkg) pr.walk(walkedPackages, rootPkg) } - retPkgs := make([]*FlatPackage, 0, len(walkedPackages)) + retPkgs := make([]*packages.Package, 0, len(walkedPackages)) for _, pkg := range walkedPackages { retPkgs = append(retPkgs, pkg) } diff --git a/go/tools/gopackagesdriver/utils.go b/go/tools/gopackagesdriver/utils.go index 35d6243e9a..9af37443d7 100644 --- a/go/tools/gopackagesdriver/utils.go +++ b/go/tools/gopackagesdriver/utils.go @@ -22,6 +22,8 @@ import ( "os/signal" "path" "path/filepath" + + "golang.org/x/tools/go/packages" ) func getenvDefault(key, defaultValue string) string { @@ -76,7 +78,7 @@ func packageID(pattern string) string { return fmt.Sprintf("//%s", pattern) } -func findPackageByID(packages []*FlatPackage, id string) *FlatPackage { +func findPackageByID(packages []*packages.Package, id string) *packages.Package { for _, pkg := range packages { if pkg.ID == id { return pkg