Compare commits

...

8 Commits

Author SHA1 Message Date
Kasey Kirkham
8d2e5cfeb1 adding generated code 2024-07-17 16:25:14 -05:00
Kasey Kirkham
d2dc15b7d8 WIP 2024-07-12 17:19:52 -05:00
Kasey Kirkham
ef7e43c65e first green commit, generating attestation methodset 2024-07-11 10:23:38 -05:00
Kasey Kirkham
8e4103f6ea wip genception 2024-07-08 20:31:35 -05:00
Kasey Kirkham
0aa8a855f0 debug-mode bazel rule 2024-07-02 13:45:35 -05:00
Kasey Kirkham
d36b0a0f62 bazel wiring to materialize deps and json metadata in codgen context 2024-06-28 16:33:10 -05:00
Kasey Kirkham
258132ad3d wip 2024-06-25 11:12:51 -05:00
Kasey Kirkham
4b8b11e202 expose methodical subcommands via prysmctl 2024-06-24 13:37:13 -05:00
33 changed files with 17830 additions and 17020 deletions

View File

@@ -1,3 +1,4 @@
load("@prysm//tools/go:def.bzl", "go_library")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@com_github_atlassian_bazel_tools//gometalinter:def.bzl", "gometalinter")
load("@com_github_atlassian_bazel_tools//goimports:def.bzl", "goimports")
@@ -286,3 +287,14 @@ sh_binary(
srcs = ["prysm.sh"],
visibility = ["//visibility:public"],
)
go_library(
name = "go_default_library",
srcs = ["derp.go"],
importpath = "github.com/prysmaticlabs/prysm/v5",
visibility = ["//visibility:public"],
deps = [
"@com_github_prysmaticlabs_fastssz//:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
],
)

View File

@@ -9,6 +9,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//cmd/prysmctl/checkpointsync:go_default_library",
"//cmd/prysmctl/codegen:go_default_library",
"//cmd/prysmctl/db:go_default_library",
"//cmd/prysmctl/p2p:go_default_library",
"//cmd/prysmctl/testnet:go_default_library",

View File

@@ -0,0 +1,12 @@
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["cmd.go"],
importpath = "github.com/prysmaticlabs/prysm/v5/cmd/prysmctl/codegen",
visibility = ["//visibility:public"],
deps = [
"@com_github_offchainlabs_methodical_ssz//cmd/ssz/commands:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
)

View File

@@ -0,0 +1,14 @@
package codegen
import (
"github.com/OffchainLabs/methodical-ssz/cmd/ssz/commands"
"github.com/urfave/cli/v2"
)
var Commands = []*cli.Command{
{
Name: "ssz",
Usage: "ssz code generation utilities",
Subcommands: commands.All,
},
}

View File

@@ -4,6 +4,7 @@ import (
"os"
"github.com/prysmaticlabs/prysm/v5/cmd/prysmctl/checkpointsync"
"github.com/prysmaticlabs/prysm/v5/cmd/prysmctl/codegen"
"github.com/prysmaticlabs/prysm/v5/cmd/prysmctl/db"
"github.com/prysmaticlabs/prysm/v5/cmd/prysmctl/p2p"
"github.com/prysmaticlabs/prysm/v5/cmd/prysmctl/testnet"
@@ -32,4 +33,5 @@ func init() {
prysmctlCommands = append(prysmctlCommands, testnet.Commands...)
prysmctlCommands = append(prysmctlCommands, weaksubjectivity.Commands...)
prysmctlCommands = append(prysmctlCommands, validator.Commands...)
prysmctlCommands = append(prysmctlCommands, codegen.Commands...)
}

View File

@@ -678,6 +678,12 @@ def prysm_deps():
sum = "h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=",
version = "v1.5.5",
)
go_repository(
name = "com_github_dave_jennifer",
importpath = "github.com/dave/jennifer",
sum = "h1:uRbSBH9UTS64yXbh4FrMHfgfY762RD+C7bUPKODpSJE=",
version = "v1.7.0",
)
go_repository(
name = "com_github_davecgh_go_spew",
importpath = "github.com/davecgh/go-spew",
@@ -2586,6 +2592,12 @@ def prysm_deps():
sum = "h1:lsxEuwrXEAokXB9qhlbKWPpo3KMLZQ5WB5WLQRW1uq0=",
version = "v0.0.0-20170623195520-56545f4a5d46",
)
go_repository(
name = "com_github_offchainlabs_methodical_ssz",
importpath = "github.com/OffchainLabs/methodical-ssz",
sum = "h1:56W3xtZyeLcbKjt5staxK/jMdE6ql69rPhbb/XmZPhA=",
version = "v0.0.0-20240712201410-cd5a2975775c",
)
go_repository(
name = "com_github_oklog_oklog",
importpath = "github.com/oklog/oklog",
@@ -4798,8 +4810,8 @@ def prysm_deps():
go_repository(
name = "org_golang_x_crypto",
importpath = "golang.org/x/crypto",
sum = "h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=",
version = "v0.23.0",
sum = "h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=",
version = "v0.25.0",
)
go_repository(
name = "org_golang_x_exp",
@@ -4834,14 +4846,14 @@ def prysm_deps():
go_repository(
name = "org_golang_x_mod",
importpath = "golang.org/x/mod",
sum = "h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=",
version = "v0.17.0",
sum = "h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=",
version = "v0.19.0",
)
go_repository(
name = "org_golang_x_net",
importpath = "golang.org/x/net",
sum = "h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=",
version = "v0.25.0",
sum = "h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=",
version = "v0.27.0",
)
go_repository(
name = "org_golang_x_oauth2",
@@ -4864,26 +4876,26 @@ def prysm_deps():
go_repository(
name = "org_golang_x_sys",
importpath = "golang.org/x/sys",
sum = "h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=",
version = "v0.20.0",
sum = "h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=",
version = "v0.22.0",
)
go_repository(
name = "org_golang_x_telemetry",
importpath = "golang.org/x/telemetry",
sum = "h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY=",
version = "v0.0.0-20240228155512-f48c80bd79b2",
sum = "h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk=",
version = "v0.0.0-20240521205824-bda55230c457",
)
go_repository(
name = "org_golang_x_term",
importpath = "golang.org/x/term",
sum = "h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=",
version = "v0.20.0",
sum = "h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=",
version = "v0.22.0",
)
go_repository(
name = "org_golang_x_text",
importpath = "golang.org/x/text",
sum = "h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=",
version = "v0.15.0",
sum = "h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=",
version = "v0.16.0",
)
go_repository(
name = "org_golang_x_time",
@@ -4894,8 +4906,8 @@ def prysm_deps():
go_repository(
name = "org_golang_x_tools",
importpath = "golang.org/x/tools",
sum = "h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=",
version = "v0.21.0",
sum = "h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=",
version = "v0.23.0",
)
go_repository(
name = "org_golang_x_xerrors",

18
go.mod
View File

@@ -8,6 +8,7 @@ require (
contrib.go.opencensus.io/exporter/jaeger v0.2.1
github.com/MariusVanDerWijden/FuzzyVM v0.0.0-20240209103030-ec53fa766bf8
github.com/MariusVanDerWijden/tx-fuzz v1.3.3-0.20240227085032-f70dd7c85c97
github.com/OffchainLabs/methodical-ssz v0.0.0-20240712201410-cd5a2975775c
github.com/aristanetworks/goarista v0.0.0-20200805130819-fd197cf57d96
github.com/bazelbuild/rules_go v0.23.2
github.com/btcsuite/btcd/btcec/v2 v2.3.2
@@ -88,11 +89,11 @@ require (
go.opencensus.io v0.24.0
go.uber.org/automaxprocs v1.5.2
go.uber.org/mock v0.4.0
golang.org/x/crypto v0.23.0
golang.org/x/crypto v0.25.0
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/mod v0.17.0
golang.org/x/mod v0.19.0
golang.org/x/sync v0.7.0
golang.org/x/tools v0.21.0
golang.org/x/tools v0.23.0
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.34.1
@@ -125,6 +126,7 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/dave/jennifer v1.7.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/deckarep/golang-set/v2 v2.5.0 // indirect
@@ -250,10 +252,10 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
@@ -273,7 +275,7 @@ require (
github.com/go-playground/validator/v10 v10.13.0
github.com/peterh/liner v1.2.0 // indirect
github.com/prysmaticlabs/gohashtree v0.0.4-beta
golang.org/x/sys v0.20.0 // indirect
golang.org/x/sys v0.22.0 // indirect
google.golang.org/api v0.44.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
k8s.io/klog/v2 v2.80.0 // indirect
@@ -284,3 +286,5 @@ replace github.com/json-iterator/go => github.com/prestonvanloon/go v1.1.7-0.201
// See https://github.com/prysmaticlabs/grpc-gateway/issues/2
replace github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20230315201114-09284ba20446
//replace github.com/OffchainLabs/methodical-ssz => /Users/kasey/src/OffchainLabs/methodical-ssz

32
go.sum
View File

@@ -73,6 +73,8 @@ github.com/MariusVanDerWijden/tx-fuzz v1.3.3-0.20240227085032-f70dd7c85c97/go.mo
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OffchainLabs/methodical-ssz v0.0.0-20240712201410-cd5a2975775c h1:56W3xtZyeLcbKjt5staxK/jMdE6ql69rPhbb/XmZPhA=
github.com/OffchainLabs/methodical-ssz v0.0.0-20240712201410-cd5a2975775c/go.mod h1:Ndc6p2Xsj0fV3Mx4Ufv32RZ4K9SvWhzhOxtMuTXDU1I=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
@@ -206,6 +208,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U=
github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
github.com/dave/jennifer v1.7.0 h1:uRbSBH9UTS64yXbh4FrMHfgfY762RD+C7bUPKODpSJE=
github.com/dave/jennifer v1.7.0/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -1238,8 +1242,8 @@ golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98y
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -1282,8 +1286,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
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/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -1344,8 +1348,8 @@ golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/oauth2 v0.0.0-20170912212905-13449ad91cb2/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -1481,8 +1485,8 @@ golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -1494,8 +1498,8 @@ golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -1511,8 +1515,8 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
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/time v0.0.0-20170424234030-8be79e1e0910/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -1591,8 +1595,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
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=

View File

@@ -4,7 +4,8 @@
# Script to copy ssz.go files from bazel build folder to appropriate location.
# Bazel builds to bazel-bin/... folder, script copies them back to original folder where target is.
bazel query 'kind(ssz_gen_marshal, //proto/...)' | xargs bazel build $@
#bazel query 'kind(ssz_gen_marshal, //proto/...)' | xargs bazel build $@
bazel query 'kind(ssz_methodical, //proto/...) union kind(ssz_gen_marshal, //proto/...)' | xargs bazel build $@
# Get locations of proto ssz.go files.
file_list=()

View File

@@ -12,6 +12,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("//proto:ssz_proto_library.bzl", "ssz_proto_files")
load("//tools:ssz.bzl", "SSZ_DEPS", "ssz_gen_marshal")
load("//tools:methodical.bzl", "ssz_methodical")
proto_library(
name = "proto",
@@ -52,6 +53,7 @@ ssz_phase0_objs = [
"AttestationData",
"AttesterSlashing",
"BeaconBlock",
"BeaconBlockBody",
"BeaconBlockHeader",
"BeaconState",
"Checkpoint",
@@ -64,6 +66,7 @@ ssz_phase0_objs = [
"ForkData",
"HistoricalBatch",
"IndexedAttestation",
"PendingAttestation",
"PowBlock",
"ProposerSlashing",
"SignedAggregateAttestationAndProof",
@@ -72,7 +75,6 @@ ssz_phase0_objs = [
"SignedVoluntaryExit",
"SigningData",
"Status",
"Status",
"Validator",
"VoluntaryExit",
]
@@ -85,7 +87,6 @@ ssz_altair_objs = [
"SignedBeaconBlockAltair",
"SignedContributionAndProof",
"SyncAggregate",
"SyncAggregate",
"SyncAggregatorSelectionData",
"SyncCommittee",
"SyncCommitteeContribution",
@@ -114,7 +115,6 @@ ssz_capella_objs = [
"SignedBLSToExecutionChange",
"SignedBeaconBlockCapella",
"SignedBlindedBeaconBlockCapella",
"Withdrawal",
]
ssz_deneb_objs = [
@@ -138,14 +138,13 @@ ssz_electra_objs = [
"AttestationElectra",
"AttesterSlashingElectra",
"BeaconBlockElectra",
"BeaconBlockElectra",
"BeaconBlockBodyElectra",
"BeaconStateElectra",
"BlindedBeaconBlockBodyElectra",
"BlindedBeaconBlockElectra",
"Consolidation",
"IndexedAttestationElectra",
"PendingBalanceDeposit",
"PendingBalanceDeposits",
"PendingConsolidation",
"PendingPartialWithdrawal",
"SignedAggregateAttestationAndProofElectra",
@@ -154,83 +153,124 @@ ssz_electra_objs = [
"SignedConsolidation",
]
ssz_gen_marshal(
name = "ssz_generated_phase0",
go_proto = ":go_proto",
ssz_methodical(
name = "methodical_phase0",
deps = [":go_proto"],
type_names = ssz_phase0_objs,
target_package = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1",
target_package_name = "eth",
out = "phase0.ssz.go",
includes = [
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//math:go_default_library",
],
objs = ssz_phase0_objs,
)
ssz_gen_marshal(
name = "ssz_generated_altair",
go_proto = ":go_proto",
ssz_methodical(
name = "methodical_altair",
deps = [":go_proto"],
type_names = ssz_altair_objs,
target_package = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1",
target_package_name = "eth",
out = "altair.ssz.go",
includes = [
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//math:go_default_library",
],
objs = ssz_altair_objs,
exclude_objs = ssz_phase0_objs,
)
ssz_gen_marshal(
name = "ssz_generated_bellatrix",
go_proto = ":go_proto",
ssz_methodical(
name = "methodical_bellatrix",
deps = [":go_proto"],
type_names = ssz_bellatrix_objs,
target_package = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1",
target_package_name = "eth",
out = "bellatrix.ssz.go",
includes = [
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//math:go_default_library",
],
objs = ssz_bellatrix_objs,
exclude_objs = ssz_phase0_objs + ssz_altair_objs,
)
ssz_gen_marshal(
name = "ssz_generated_capella",
go_proto = ":go_proto",
ssz_methodical(
name = "methodical_capella",
deps = [":go_proto"],
type_names = ssz_capella_objs,
target_package = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1",
target_package_name = "eth",
out = "capella.ssz.go",
includes = [
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//math:go_default_library",
],
objs = ssz_capella_objs,
exclude_objs = ssz_phase0_objs + ssz_altair_objs + ssz_bellatrix_objs,
)
ssz_gen_marshal(
name = "ssz_generated_deneb",
go_proto = ":go_proto",
ssz_methodical(
name = "methodical_deneb",
deps = [":go_proto"],
type_names = ssz_deneb_objs,
target_package = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1",
target_package_name = "eth",
out = "deneb.ssz.go",
includes = [
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//math:go_default_library",
],
objs = ssz_deneb_objs,
exclude_objs = ssz_phase0_objs + ssz_altair_objs + ssz_bellatrix_objs + ssz_capella_objs,
)
ssz_gen_marshal(
name = "ssz_generated_electra",
go_proto = ":go_proto",
ssz_methodical(
name = "methodical_electra",
deps = [":go_proto"],
type_names = ssz_electra_objs,
target_package = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1",
target_package_name = "eth",
out = "electra.ssz.go",
includes = [
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//math:go_default_library",
],
objs = ssz_electra_objs,
exclude_objs = ssz_phase0_objs + ssz_altair_objs + ssz_bellatrix_objs + ssz_capella_objs + ssz_deneb_objs,
)
#ssz_gen_marshal(
# name = "ssz_generated_altair",
# go_proto = ":go_proto",
# out = "altair.ssz.go",
# includes = [
# "//consensus-types/primitives:go_default_library",
# "//proto/engine/v1:go_default_library",
# "//math:go_default_library",
# ],
# objs = ssz_altair_objs,
# exclude_objs = ssz_phase0_objs,
#)
#ssz_gen_marshal(
# name = "ssz_generated_bellatrix",
# go_proto = ":go_proto",
# out = "bellatrix.ssz.go",
# includes = [
# "//consensus-types/primitives:go_default_library",
# "//proto/engine/v1:go_default_library",
# "//math:go_default_library",
# ],
# objs = ssz_bellatrix_objs,
# exclude_objs = ssz_phase0_objs + ssz_altair_objs,
#)
#ssz_gen_marshal(
# name = "ssz_generated_capella",
# go_proto = ":go_proto",
# out = "capella.ssz.go",
# includes = [
# "//consensus-types/primitives:go_default_library",
# "//proto/engine/v1:go_default_library",
# "//math:go_default_library",
# ],
# objs = ssz_capella_objs,
# exclude_objs = ssz_phase0_objs + ssz_altair_objs + ssz_bellatrix_objs,
#)
#ssz_gen_marshal(
# name = "ssz_generated_deneb",
# go_proto = ":go_proto",
# out = "deneb.ssz.go",
# includes = [
# "//consensus-types/primitives:go_default_library",
# "//proto/engine/v1:go_default_library",
# "//math:go_default_library",
# ],
# objs = ssz_deneb_objs,
# exclude_objs = ssz_phase0_objs + ssz_altair_objs + ssz_bellatrix_objs + ssz_capella_objs,
#)
#ssz_gen_marshal(
# name = "ssz_generated_electra",
# go_proto = ":go_proto",
# out = "electra.ssz.go",
# includes = [
# "//consensus-types/primitives:go_default_library",
# "//proto/engine/v1:go_default_library",
# "//math:go_default_library",
# ],
# objs = ssz_electra_objs,
# exclude_objs = ssz_phase0_objs + ssz_altair_objs + ssz_bellatrix_objs + ssz_capella_objs + ssz_deneb_objs,
#)
ssz_gen_marshal(
name = "ssz_generated_non_core",
@@ -313,12 +353,17 @@ go_library(
"sync_committee_mainnet.go",
"sync_committee_minimal.go", # keep
":ssz_generated_non_core", # keep
":ssz_generated_phase0", # keep
":ssz_generated_altair", # keep
":ssz_generated_bellatrix", # keep
":ssz_generated_capella", # keep
":ssz_generated_deneb", # keep
":ssz_generated_electra", # keep
#":ssz_generated_altair", # keep
#":ssz_generated_bellatrix", # keep
#":ssz_generated_capella", # keep
#":ssz_generated_deneb", # keep
#":ssz_generated_electra", # keep
":methodical_phase0", # keep
":methodical_altair", # keep
":methodical_bellatrix", # keep
":methodical_capella", # keep
":methodical_deneb", # keep
":methodical_electra", # keep
],
embed = [
":go_grpc_gateway_library",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
alias(
name = "methodicalgen",
actual = "@com_github_offchainlabs_methodical_ssz//cmd/ssz:ssz",
visibility = ["//visibility:public"],
)
go_library(
name = "go_default_library",
srcs = [
"bazel.go",
"bazel_json_builder.go",
"build_context.go",
"driver_request.go",
"flatpackage.go",
"json_packages_driver.go",
"main.go",
"packageregistry.go",
"utils.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/tools/genception",
visibility = ["//visibility:private"],
)
go_binary(
name = "genception",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["gopackagesdriver_test.go"],
embed = [":go_default_library"],
deps = ["@io_bazel_rules_go//go/tools/bazel_testing:go_default_library"],
)

View File

@@ -0,0 +1,16 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/prysmaticlabs/prysm/v5/tools/genception/cmd",
visibility = ["//visibility:private"],
deps = ["//tools/genception/driver:go_default_library"],
)
go_binary(
name = "cmd",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,86 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"os/signal"
"strings"
"github.com/prysmaticlabs/prysm/v5/tools/genception/driver"
)
var log = driver.Logger
func run(_ context.Context, in io.Reader, out io.Writer, args []string) error {
rec, err := driver.NewRecorder()
if err != nil {
return fmt.Errorf("unable to initialize recorder: %w", err)
}
resolver, err := driver.NewPathResolver()
if err != nil {
return fmt.Errorf("unable to initialize path resolver: %w", err)
}
jsonFiles, err := driver.LoadJsonListing()
if err != nil {
return fmt.Errorf("unable to lookup package: %w", err)
}
pd, err := driver.NewJSONPackagesDriver(jsonFiles, resolver.Resolve)
if err != nil {
return fmt.Errorf("unable to load JSON files: %w", err)
}
request, err := driver.ReadDriverRequest(in)
if err != nil {
return fmt.Errorf("unable to read request: %w", err)
}
if err := rec.RecordRequest(args, request); err != nil {
return fmt.Errorf("unable to record request: %w", err)
}
// Note: we are returning all files required to build a specific package.
// For file queries (`file=`), this means that the CompiledGoFiles will
// include more than the only file being specified.
resp := pd.Handle(request, args)
if err := rec.RecordResponse(resp); err != nil {
return fmt.Errorf("unable to record response: %w", err)
}
data, err := json.Marshal(resp)
if err != nil {
return fmt.Errorf("unable to marshal response: %v", err)
}
_, err = out.Write(data)
return err
}
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
log.WithField("args", strings.Join(os.Args[1:], " ")).Info("genception lookup")
if err := run(ctx, os.Stdin, os.Stdout, os.Args[1:]); err != nil {
_, err := fmt.Fprintf(os.Stderr, "error: %v", err)
if err != nil {
log.WithError(err).Error("unhandled error in package resolution")
}
// gopls will check the packages driver exit code, and if there is an
// error, it will fall back to go list. Obviously we don't want that,
// so force a 0 exit code.
os.Exit(0)
}
}

View File

@@ -0,0 +1,33 @@
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"bazel_json_builder.go",
"build_context.go",
"driver_request.go",
"flatpackage.go",
"index.go",
"json_packages_driver.go",
"logger.go",
"packageregistry.go",
"recorder.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/tools/genception/driver",
visibility = ["//visibility:public"],
deps = [
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = [
"index_test.go",
"packageregistry_test.go",
],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = ["//testing/require:go_default_library"],
)

View File

@@ -0,0 +1,156 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package driver
import (
"os"
"strings"
)
var RulesGoStdlibLabel = "@io_bazel_rules_go//:stdlib"
/*
type BazelJSONBuilder struct {
packagesBaseDir string
includeTests bool
}
var _defaultKinds = []string{"go_library", "go_test", "go_binary"}
var externalRe = regexp.MustCompile(`.*\/external\/([^\/]+)(\/(.*))?\/([^\/]+.go)`)
func (b *BazelJSONBuilder) fileQuery(filename string) string {
label := filename
if strings.HasPrefix(filename, "./") {
label = strings.TrimPrefix(filename, "./")
}
if matches := externalRe.FindStringSubmatch(filename); len(matches) == 5 {
// if filepath is for a third party lib, we need to know, what external
// library this file is part of.
matches = append(matches[:2], matches[3:]...)
label = fmt.Sprintf("@%s//%s", matches[1], strings.Join(matches[2:], ":"))
}
relToBin, err := filepath.Rel(b.bazel.info["output_path"], filename)
if err == nil && !strings.HasPrefix(relToBin, "../") {
parts := strings.SplitN(relToBin, string(filepath.Separator), 3)
relToBin = parts[2]
// We've effectively converted filename from bazel-bin/some/path.go to some/path.go;
// Check if a BUILD.bazel files exists under this dir, if not walk up and repeat.
relToBin = filepath.Dir(relToBin)
_, err = os.Stat(filepath.Join(b.bazel.WorkspaceRoot(), relToBin, "BUILD.bazel"))
for errors.Is(err, os.ErrNotExist) && relToBin != "." {
relToBin = filepath.Dir(relToBin)
_, err = os.Stat(filepath.Join(b.bazel.WorkspaceRoot(), relToBin, "BUILD.bazel"))
}
if err == nil {
// return package path found and build all targets (codegen doesn't fall under go_library)
// Otherwise fallback to default
if relToBin == "." {
relToBin = ""
}
label = fmt.Sprintf("//%s:all", relToBin)
}
}
return label
}
func isLocalImport(path string) bool {
return path == "." || path == ".." ||
strings.HasPrefix(path, "./") || strings.HasPrefix(path, "../") ||
filepath.IsAbs(path)
}
func NewBazelJSONBuilder(includeTests bool) (*BazelJSONBuilder, error) {
return &BazelJSONBuilder{
includeTests: includeTests,
}, nil
}
func (b *BazelJSONBuilder) Labels(ctx context.Context, requests []string) ([]string, error) {
ret := make([]string, 0, len(requests))
for _, request := range requests {
result := ""
if strings.HasSuffix(request, ".go") {
f := strings.TrimPrefix(request, "file=")
result = b.fileQuery(f)
} else if request == "builtin" || request == "std" {
result = fmt.Sprintf(RulesGoStdlibLabel)
}
if result != "" {
ret = append(ret, result)
}
}
if len(ret) == 0 {
return []string{RulesGoStdlibLabel}, nil
}
return ret, nil
}
func (b *BazelJSONBuilder) PathResolver() PathResolverFunc {
return func(p string) string {
p = strings.Replace(p, "__BAZEL_EXECROOT__", os.Getenv("PWD"), 1)
p = strings.Replace(p, "__BAZEL_OUTPUT_BASE__", b.packagesBaseDir, 1)
return p
}
}
*/
func NewPathResolver() (*PathResolver, error) {
outBase, err := PackagesBaseFromEnv()
if err != nil {
return nil, err
}
return &PathResolver{
execRoot: os.Getenv("PWD"),
outputBase: outBase,
}, nil
}
type PathResolver struct {
outputBase string
execRoot string
}
const (
prefixExecRoot = "__BAZEL_EXECROOT__"
prefixOutputBase = "__BAZEL_OUTPUT_BASE__"
prefixWorkspace = "__BAZEL_WORKSPACE__"
)
var prefixes = []string{prefixExecRoot, prefixOutputBase, prefixWorkspace}
func (r PathResolver) Resolve(path string) string {
for _, prefix := range prefixes {
if strings.HasPrefix(path, prefix) {
for _, rpl := range []string{r.execRoot, r.outputBase} {
rp := strings.Replace(path, prefix, rpl, 1)
_, err := os.Stat(rp)
if err == nil {
return rp
}
}
return path
}
}
log.WithField("path", path).Warn("unrecognized path prefix when resolving source paths in json import metadata")
return path
}

View File

@@ -0,0 +1,44 @@
package driver
import (
"go/build"
"os"
"path/filepath"
"strings"
)
var buildContext = makeBuildContext()
func makeBuildContext() *build.Context {
bctx := build.Default
bctx.BuildTags = strings.Split(getenvDefault("GOTAGS", ""), ",")
return &bctx
}
func filterSourceFilesForTags(files []string) []string {
ret := make([]string, 0, len(files))
for _, f := range files {
dir, filename := filepath.Split(f)
ext := filepath.Ext(f)
match, err := buildContext.MatchFile(dir, filename)
if err != nil {
log.WithError(err).WithField("file", f).Warn("error matching file")
}
// MatchFile filters out anything without a file extension. In the
// case of CompiledGoFiles (in particular gco processed files from
// the cache), we want them.
if match || ext == "" {
ret = append(ret, f)
}
}
return ret
}
func getenvDefault(key, defaultValue string) string {
if v, ok := os.LookupEnv(key); ok {
return v
}
return defaultValue
}

View File

@@ -0,0 +1,91 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package driver
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
)
// 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{}
if err := json.NewDecoder(r).Decode(&req); err != nil {
return nil, fmt.Errorf("unable to decode driver request: %w", err)
}
return req, nil
}

View File

@@ -0,0 +1,217 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package driver
import (
"encoding/json"
"fmt"
"go/parser"
"go/token"
"os"
"strconv"
"strings"
)
type ResolvePkgFunc func(importPath string) string
// Copy and pasted from golang.org/x/tools/go/packages
type FlatPackagesError struct {
Pos string // "file:line:col" or "file:line" or "" or "-"
Msg string
Kind FlatPackagesErrorKind
}
type FlatPackagesErrorKind int
const (
UnknownError FlatPackagesErrorKind = iota
ListError
ParseError
TypeError
)
func (err FlatPackagesError) Error() string {
pos := err.Pos
if pos == "" {
pos = "-" // like token.Position{}.String()
}
return pos + ": " + err.Msg
}
// FlatPackage is the JSON form of Package
// It drops all the type and syntax fields, and transforms the Imports
type FlatPackage struct {
ID string
Name string `json:",omitempty"`
PkgPath string `json:",omitempty"`
Errors []FlatPackagesError `json:",omitempty"`
GoFiles []string `json:",omitempty"`
CompiledGoFiles []string `json:",omitempty"`
OtherFiles []string `json:",omitempty"`
ExportFile string `json:",omitempty"`
Imports map[string]string `json:",omitempty"`
Standard bool `json:",omitempty"`
}
type (
PackageFunc func(pkg *FlatPackage)
PathResolverFunc func(path string) string
)
func resolvePathsInPlace(prf PathResolverFunc, paths []string) {
for i, path := range paths {
paths[i] = prf(path)
}
}
func WalkFlatPackagesFromJSON(jsonFile string, onPkg PackageFunc) error {
f, err := os.Open(jsonFile)
if err != nil {
return fmt.Errorf("unable to open package JSON file: %w", err)
}
defer func() {
if err := f.Close(); err != nil {
log.WithError(err).WithField("file", f.Name()).Error("unable to close file")
}
}()
decoder := json.NewDecoder(f)
for decoder.More() {
pkg := &FlatPackage{}
if err := decoder.Decode(&pkg); err != nil {
return fmt.Errorf("unable to decode package in %s: %w", f.Name(), err)
}
onPkg(pkg)
}
return nil
}
func (fp *FlatPackage) ResolvePaths(prf PathResolverFunc) {
resolvePathsInPlace(prf, fp.CompiledGoFiles)
resolvePathsInPlace(prf, fp.GoFiles)
resolvePathsInPlace(prf, fp.OtherFiles)
fp.ExportFile = prf(fp.ExportFile)
}
// 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 (fp *FlatPackage) filterTestSuffix(files []string) (err error, testFiles []string, xTestFiles, nonTestFiles []string) {
for _, filename := range files {
if strings.HasSuffix(filename, "_test.go") {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, filename, nil, parser.PackageClauseOnly)
if err != nil {
return err, nil, nil, nil
}
if f.Name.Name == fp.Name {
testFiles = append(testFiles, filename)
} else {
xTestFiles = append(xTestFiles, filename)
}
} else {
nonTestFiles = append(nonTestFiles, filename)
}
}
return
}
func (fp *FlatPackage) MoveTestFiles() *FlatPackage {
err, tgf, xtgf, gf := fp.filterTestSuffix(fp.GoFiles)
if err != nil {
return nil
}
fp.GoFiles = append(gf, tgf...)
fp.CompiledGoFiles = append(gf, tgf...)
if len(xtgf) == 0 {
return nil
}
newImports := make(map[string]string, len(fp.Imports))
for k, v := range fp.Imports {
newImports[k] = v
}
newImports[fp.PkgPath] = fp.ID
// Clone package, only xtgf files
return &FlatPackage{
ID: fp.ID + "_xtest",
Name: fp.Name + "_test",
PkgPath: fp.PkgPath + "_test",
Imports: newImports,
Errors: fp.Errors,
GoFiles: append([]string{}, xtgf...),
CompiledGoFiles: append([]string{}, xtgf...),
OtherFiles: fp.OtherFiles,
ExportFile: fp.ExportFile,
Standard: fp.Standard,
}
}
func (fp *FlatPackage) IsStdlib() bool {
return fp.Standard
}
func (fp *FlatPackage) ResolveImports(resolve ResolvePkgFunc) error {
// Stdlib packages are already complete import wise
if fp.IsStdlib() {
return nil
}
fset := token.NewFileSet()
for _, file := range fp.CompiledGoFiles {
f, err := parser.ParseFile(fset, file, nil, parser.ImportsOnly)
if err != nil {
return err
}
// If the name is not provided, fetch it from the sources
if fp.Name == "" {
fp.Name = f.Name.Name
}
for _, rawImport := range f.Imports {
imp, err := strconv.Unquote(rawImport.Path.Value)
if err != nil {
continue
}
// We don't handle CGo for now
if imp == "C" {
continue
}
if _, ok := fp.Imports[imp]; ok {
continue
}
if pkgID := resolve(imp); pkgID != "" {
fp.Imports[imp] = pkgID
}
}
}
return nil
}
func (fp *FlatPackage) IsRoot() bool {
return strings.HasPrefix(fp.ID, "//")
}

View File

@@ -0,0 +1,56 @@
package driver
import (
"encoding/json"
"os"
"github.com/pkg/errors"
)
const (
ENV_JSON_INDEX_PATH = "PACKAGE_JSON_INVENTORY"
ENV_PACKAGES_BASE = "PACKAGES_BASE"
)
var ErrUnsetEnvVar = errors.New("required env var not set")
// LoadJsonListing reads the list of json package index files created by the bazel gopackagesdriver aspect:
// https://github.com/bazelbuild/rules_go/blob/master/go/tools/gopackagesdriver/aspect.bzl
// This list is serialized as a []string paths, relative to the bazel exec root.
func LoadJsonListing() ([]string, error) {
path, err := JsonIndexPathFromEnv()
if err != nil {
return nil, err
}
return ReadJsonIndex(path)
}
func ReadJsonIndex(path string) ([]string, error) {
um := make([]string, 0)
b, err := os.ReadFile(path)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &um); err != nil {
return nil, err
}
return um, nil
}
// JsonIndexPathFromEnv reads the path to the json index file from the environment.
func JsonIndexPathFromEnv() (string, error) {
p := os.Getenv(ENV_JSON_INDEX_PATH)
if p == "" {
return "", errors.Wrap(ErrUnsetEnvVar, ENV_JSON_INDEX_PATH)
}
return p, nil
}
func PackagesBaseFromEnv() (string, error) {
p := os.Getenv(ENV_PACKAGES_BASE)
if p == "" {
return "", errors.Wrap(ErrUnsetEnvVar, ENV_PACKAGES_BASE)
}
return p, nil
}

View File

@@ -0,0 +1,58 @@
package driver
import (
"fmt"
"testing"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)
func TestJsonList(t *testing.T) {
path := "testdata/json-list.json"
files, err := ReadJsonIndex(path)
require.NoError(t, err)
require.Equal(t, 4, len(files))
}
func TestJsonIndexPathFromEnv(t *testing.T) {
cases := []struct {
val string
err error
envname string
getter func() (string, error)
}{
{
getter: JsonIndexPathFromEnv,
err: ErrUnsetEnvVar,
},
{
getter: JsonIndexPathFromEnv,
envname: ENV_JSON_INDEX_PATH,
val: "/path/to/file",
},
{
getter: PackagesBaseFromEnv,
err: ErrUnsetEnvVar,
},
{
getter: PackagesBaseFromEnv,
envname: ENV_PACKAGES_BASE,
val: "/path/to/base",
},
}
for i, c := range cases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
if c.envname != "" {
t.Setenv(c.envname, c.val)
}
v, err := c.getter()
if c.err != nil {
require.ErrorIs(t, err, c.err)
return
}
require.NoError(t, err)
require.Equal(t, c.val, v)
})
}
}

View File

@@ -0,0 +1,98 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package driver
import (
"fmt"
"runtime"
)
type JSONPackagesDriver struct {
registry *PackageRegistry
}
func NewJSONPackagesDriver(jsonFiles []string, prf PathResolverFunc) (*JSONPackagesDriver, error) {
jpd := &JSONPackagesDriver{
registry: NewPackageRegistry(),
}
for _, f := range jsonFiles {
if err := WalkFlatPackagesFromJSON(f, func(pkg *FlatPackage) {
jpd.registry.Add(pkg)
}); err != nil {
return nil, fmt.Errorf("unable to walk json: %w", err)
}
}
if err := jpd.registry.ResolvePaths(prf); err != nil {
return nil, fmt.Errorf("unable to resolve paths: %w", err)
}
if err := jpd.registry.ResolveImports(); err != nil {
return nil, fmt.Errorf("unable to resolve paths: %w", err)
}
return jpd, nil
}
func (b *JSONPackagesDriver) Handle(req *DriverRequest, queries []string) *driverResponse {
r, p := b.registry.Query(req, queries)
return &driverResponse{
NotHandled: false,
Compiler: "gc",
Arch: runtime.GOARCH,
Roots: r,
Packages: p,
}
}
func (b *JSONPackagesDriver) GetResponse(labels []string) *driverResponse {
rootPkgs, packages := b.registry.Match(labels)
return &driverResponse{
NotHandled: false,
Compiler: "gc",
Arch: runtime.GOARCH,
Roots: rootPkgs,
Packages: packages,
}
}
type driverResponse struct {
// NotHandled is returned if the request can't be handled by the current
// driver. If an external driver returns a response with NotHandled, the
// rest of the driverResponse is ignored, and go/packages will fallback
// to the next driver. If go/packages is extended in the future to support
// lists of multiple drivers, go/packages will fall back to the next driver.
NotHandled bool
// Compiler and Arch are the arguments pass of types.SizesFor
// to get a types.Sizes to use when type checking.
Compiler string
Arch string
// Roots is the set of package IDs that make up the root packages.
// We have to encode this separately because when we encode a single package
// we cannot know if it is one of the roots as that requires knowledge of the
// graph it is part of.
Roots []string `json:",omitempty"`
// Packages is the full set of packages in the graph.
// The packages are not connected into a graph.
// The Imports if populated will be stubs that only have their ID set.
// Imports will be connected and then type and syntax information added in a
// later pass (see refine).
Packages []*FlatPackage
}

View File

@@ -0,0 +1,26 @@
package driver
import (
"os"
"path/filepath"
"github.com/sirupsen/logrus"
)
// Create a new instance of the logger. You can have any number of instances.
var log = logrus.New()
var Logger *logrus.Logger
func init() {
path := os.Getenv("GOPACKAGESDRIVER_LOG_PATH")
if path == "" {
path = filepath.Join(os.Getenv("PWD"), "genception.log")
}
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err == nil {
log.Out = file
} else {
log.Info("Failed to log to file, using default stderr")
}
Logger = log
}

View File

@@ -0,0 +1,193 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package driver
import (
"fmt"
"strings"
)
type PackageRegistry struct {
packages map[string]*FlatPackage
stdlib map[string]string
}
func NewPackageRegistry(pkgs ...*FlatPackage) *PackageRegistry {
pr := &PackageRegistry{
packages: map[string]*FlatPackage{},
stdlib: map[string]string{},
}
pr.Add(pkgs...)
return pr
}
func rewritePackage(pkg *FlatPackage) {
pkg.ID = pkg.PkgPath
for k := range pkg.Imports {
// rewrite package ID mapping to be the same as the path
pkg.Imports[k] = k
}
}
// returns true if a is a superset of b
func isSuperset(a, b []string) bool {
if len(a) < len(b) {
return false
}
bi := 0
for i := range a {
if a[i] == b[bi] {
bi++
if bi == len(b) {
return true
}
}
}
return false
}
// Update merges the contents of 2 packages together in the instance where they have the same package path.
// This can happen when the gopackages aspect traverses to a child label and generates separate json files transitive targets.
// For example, in //proto/prysm/v1alpha1 we see both `:go_default_library` and `:go_proto` from `//proto/engine/v1`.
// Without the merge, `:go_proto` can overwrite `:go_default_library`, leaving sources files out of the final graph.
func (pr *PackageRegistry) Update(pkg *FlatPackage) {
existing, ok := pr.packages[pkg.PkgPath]
if !ok {
pr.packages[pkg.PkgPath] = pkg
return
}
if isSuperset(pkg.GoFiles, existing.GoFiles) {
existing.GoFiles = pkg.GoFiles
}
}
func (pr *PackageRegistry) Add(pkgs ...*FlatPackage) *PackageRegistry {
for _, pkg := range pkgs {
rewritePackage(pkg)
pr.packages[pkg.PkgPath] = pkg
if pkg.IsStdlib() {
pr.stdlib[pkg.PkgPath] = pkg.ID
}
}
return pr
}
func (pr *PackageRegistry) ResolvePaths(prf PathResolverFunc) error {
for _, pkg := range pr.packages {
pkg.ResolvePaths(prf)
pkg.FilterFilesForBuildTags()
}
return nil
}
// ResolveImports adds stdlib imports to packages. This is required because
// stdlib packages are not part of the JSON file exports as bazel is unaware of
// them.
func (pr *PackageRegistry) ResolveImports() error {
resolve := func(importPath string) string {
if pkgID, ok := pr.stdlib[importPath]; ok {
return pkgID
}
return ""
}
for _, pkg := range pr.packages {
if err := pkg.ResolveImports(resolve); err != nil {
return err
}
testFp := pkg.MoveTestFiles()
if testFp != nil {
pr.packages[testFp.ID] = testFp
}
}
return nil
}
func (pr *PackageRegistry) walk(acc map[string]*FlatPackage, root string) {
pkg := pr.packages[root]
if pkg == nil {
log.WithField("root", root).Error("package ID not found")
return
}
acc[pkg.ID] = pkg
for _, pkgID := range pkg.Imports {
if _, ok := acc[pkgID]; !ok {
pr.walk(acc, pkgID)
}
}
}
func (pr *PackageRegistry) Query(req *DriverRequest, queries []string) ([]string, []*FlatPackage) {
walkedPackages := map[string]*FlatPackage{}
retRoots := make([]string, 0, len(queries))
for _, rootPkg := range queries {
retRoots = append(retRoots, rootPkg)
pr.walk(walkedPackages, rootPkg)
}
retPkgs := make([]*FlatPackage, 0, len(walkedPackages))
for _, pkg := range walkedPackages {
retPkgs = append(retPkgs, pkg)
}
return retRoots, retPkgs
}
func (pr *PackageRegistry) Match(labels []string) ([]string, []*FlatPackage) {
roots := map[string]struct{}{}
for _, label := range labels {
// When packagesdriver is ran from rules go, rulesGoRepositoryName will just be @
if !strings.HasPrefix(label, "@") {
// Canonical labels is only since Bazel 6.0.0
label = fmt.Sprintf("@%s", label)
}
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.packages {
if pkg.Standard {
roots[pkg.ID] = struct{}{}
}
}
} else {
roots[label] = struct{}{}
// If an xtest package exists for this package add it to the roots
if _, ok := pr.packages[label+"_xtest"]; ok {
roots[label+"_xtest"] = struct{}{}
}
}
}
walkedPackages := map[string]*FlatPackage{}
retRoots := make([]string, 0, len(roots))
for rootPkg := range roots {
retRoots = append(retRoots, rootPkg)
pr.walk(walkedPackages, rootPkg)
}
retPkgs := make([]*FlatPackage, 0, len(walkedPackages))
for _, pkg := range walkedPackages {
retPkgs = append(retPkgs, pkg)
}
return retRoots, retPkgs
}

View File

@@ -0,0 +1,27 @@
package driver
import (
"strings"
"testing"
)
func TestIsSuperset(t *testing.T) {
cases := []struct {
a []string
b []string
expected bool
}{
{[]string{"a", "b", "c", "d"}, []string{"a", "b"}, true},
{[]string{"a", "b", "c", "d"}, []string{"a", "b", "c", "d"}, true},
{[]string{"a", "b", "c", "d"}, []string{"a", "b", "c", "d", "e"}, false},
{[]string{"a", "b", "c", "d"}, []string{"a", "b", "c"}, true},
{[]string{}, []string{"a"}, false},
}
for _, c := range cases {
t.Run(strings.Join(c.a, "_")+"__"+strings.Join(c.b, "_"), func(t *testing.T) {
if isSuperset(c.a, c.b) != c.expected {
t.Errorf("isSuperset(%v, %v) != %v", c.a, c.b, c.expected)
}
})
}
}

View File

@@ -0,0 +1,52 @@
package driver
import (
"encoding/json"
"os"
"path"
"strconv"
"time"
)
type Recorder struct {
base string
t time.Time
}
func NewRecorder() (*Recorder, error) {
base := os.Getenv("PWD")
r := &Recorder{base: base, t: time.Now()}
if err := r.Mkdir(); err != nil {
return nil, err
}
return r, nil
}
func (r *Recorder) Dir() string {
return path.Join(r.base, strconv.FormatInt(r.t.UTC().UnixNano(), 10))
}
func (r *Recorder) Mkdir() error {
return os.MkdirAll(r.Dir(), 0755)
}
func (r *Recorder) RecordRequest(args []string, req *DriverRequest) error {
b, err := json.Marshal(struct {
Args []string
Request *DriverRequest
}{
Args: args,
Request: req,
})
if err != nil {
return err
}
return os.WriteFile(path.Join(r.Dir(), "request.json"), b, 0644)
}
func (r *Recorder) RecordResponse(resp *driverResponse) error {
b, err := json.Marshal(resp)
if err != nil {
return err
}
return os.WriteFile(path.Join(r.Dir(), "response.json"), b, 0644)
}

View File

@@ -0,0 +1,6 @@
[
"bazel-out/darwin_arm64-fastbuild/bin/external/io_bazel_rules_go/stdlib_/stdlib.pkg.json",
"bazel-out/darwin_arm64-fastbuild/bin/external/com_github_thomaso_mirodin_intmath/constants/c64/c64.pkg.json",
"bazel-out/darwin_arm64-fastbuild/bin/external/com_github_thomaso_mirodin_intmath/u64/u64.pkg.json",
"bazel-out/darwin_arm64-fastbuild/bin/proto/prysm/v1alpha1/go_proto.pkg.json"
]

127
tools/methodical.bzl Normal file
View File

@@ -0,0 +1,127 @@
load("@io_bazel_rules_go//go:def.bzl", "GoLibrary", "GoSource", "go_context")
load("@io_bazel_rules_go//go/tools/gopackagesdriver:aspect.bzl", "go_pkg_info_aspect", "GoPkgInfo")
_METHODICAL_TOOL = Label("//tools/genception:methodicalgen")
_GENCEPTION_TOOL = Label("//tools/genception/cmd:cmd")
_FASTSSZ_DEP = Label("@com_github_prysmaticlabs_fastssz//:go_default_library")
def _ssz_methodical_impl(ctx):
go_ctx = go_context(ctx)
all_json_files = {}
stdlib = ''
inputs = []
#inputs += go_ctx.sdk.srcs
#inputs += go_ctx.sdk.headers + go_ctx.sdk.srcs + go_ctx.sdk.tools
ssz_sources = go_ctx.library_to_source(go_ctx, ctx.attr, ctx.attr.fastssz_lib[GoLibrary], ctx.coverage_instrumented())
inputs += ssz_sources.srcs
#sample = go_ctx.sdk.srcs[0].path
for dep in ctx.attr.deps + [ctx.attr.fastssz_lib]:
pkginfo = dep[OutputGroupInfo]
if hasattr(pkginfo, "go_generated_srcs"):
inputs += pkginfo.go_generated_srcs.to_list()
# collect all the paths to json files dict keys for uniqueness
json_files = pkginfo.go_pkg_driver_json_file.to_list()
inputs += json_files
if len(json_files) > 0:
for jf in json_files:
# presumably path is full path from exec root
all_json_files[jf.path] = ""
inputs += pkginfo.go_pkg_driver_srcs.to_list()
inputs += pkginfo.go_pkg_driver_export_file.to_list()
# we just ned to get the stdlib once
#if stdlib == '' and hasattr(pkginfo, "go_pkg_driver_stdlib_json_file"):
if stdlib == '':
std_ds = pkginfo.go_pkg_driver_stdlib_json_file.to_list()
if len(std_ds) > 0:
stdlib = std_ds[0].path
inputs += std_ds
# concat the stdlib with all the other json file paths and write to disk
json_out = [stdlib] + all_json_files.keys()
all_pkg_list = ctx.actions.declare_file("methodical-pkg-list.json")
ctx.actions.write(all_pkg_list, content = json.encode(json_out))
#echo "sample = {sample}" &&
#echo "{out_base}" &&
out_base = ctx.outputs.out.root.path
args = [
"gen",
"--type-names=" + ",".join(ctx.attr.type_names),
"--output=" + ctx.outputs.out.path,
]
if ctx.attr.target_package_name != "":
args.append("--override-package-name=" + ctx.attr.target_package_name)
# Positional arg, needs to be after other --flags.
args.append(ctx.attr.target_package)
codegen_bins = [ctx.file.genception, ctx.file.methodical_tool]
ctx.actions.run_shell(
env = {
"PACKAGE_JSON_INVENTORY": all_pkg_list.path,
"PACKAGES_BASE": out_base,
# GOCACHE is required starting in Go 1.12
"GOCACHE": "./.gocache",
"GOPACKAGESDRIVER": ctx.file.genception.path,
"GOPACKAGESDRIVER_LOG_PATH": out_base + "/gopackagesdriver.log",
},
inputs = [all_pkg_list] + inputs + codegen_bins,
outputs = [ctx.outputs.out],
command = """
echo $PACKAGE_JSON_INVENTORY &&
echo $PACKAGES_BASE &&
echo $PWD &&
{cmd} {args}
""".format(
#sample = sample,
out_base = out_base,
json_list = all_pkg_list.path,
cmd = "$(pwd)/" + ctx.file.methodical_tool.path,
args = " ".join(args),
out = ctx.outputs.out.path,
),
)
ssz_methodical = rule(
implementation = _ssz_methodical_impl,
attrs = {
"type_names": attr.string_list(
allow_empty = False,
doc = "The names of the Go types to generate methods for.",
mandatory = True,
),
'deps' : attr.label_list(aspects = [go_pkg_info_aspect]),
"out": attr.output(
doc = "The new Go file to emit the generated mocks into",
),
"_go_context_data": attr.label(
default = "@io_bazel_rules_go//:go_context_data",
),
"methodical_tool": attr.label(
doc = "The methodical tool (binary) to run",
default = _METHODICAL_TOOL,
allow_single_file = True,
executable = True,
cfg = "exec",
mandatory = False,
),
"fastssz_lib": attr.label(providers = [GoLibrary], default = _FASTSSZ_DEP, aspects = [go_pkg_info_aspect]),
"target_package": attr.string(
doc = "The package path containing the types in type_names.",
mandatory = True,
),
"target_package_name": attr.string(
doc = "Override the name of the package the generated file is in (eg 'eth' for proto/prysm/v1alpha1)",
mandatory = False,
),
"genception": attr.label(
doc = "gopackagesdriver tool for package discovery inside bazel sandbox",
default = _GENCEPTION_TOOL,
allow_single_file = True,
executable = True,
cfg = "exec",
mandatory = False,
),
},
toolchains = ["@io_bazel_rules_go//go:toolchain"],
)