3

I am trying to create an auto-generated file "txstatus_string.go" within Bazel sandbox which relies on a go file and it is getting created with below stringer command:

go:generate stringer -type TxStatus

I am using a bazel genrule like this:

genrule(
name = "gen-txstatus-stringer",
srcs = [
    "schemachange.go",
],
outs = ["txstatus_string.go"],
cmd = """
   GO_REL_PATH=`dirname $(location @go_sdk//:bin/go)`
   GO_ABS_PATH=`cd $$GO_REL_PATH && pwd`
   env PATH=$$GO_ABS_PATH HOME=$(GENDIR) \
   $(location @org_golang_x_tools//cmd/stringer:stringer) -output=$@ \
   -type=TxStatus $(location schemachange.go)
""",
tools = [
    "@go_sdk//:bin/go",
    "@org_golang_x_tools//cmd/stringer",
],

)

But not sure why in this case stringer is failing due to "stringer: can't happen: constant is not an integer" Any one has a better idea on how to approach or why this is happening?

I already created some other stringer files using a common stringer genrule and everything goes well.

If you want to go deeper in code this is an opensource Github repo, that you can go and check =)

starball
  • 20,030
  • 7
  • 43
  • 238
alanmas
  • 61
  • 4
  • 1
    Have you tried building without stringer? I'm thinking you have a dependency issue with github.com/jackc/pgx – Hymns For Disco Mar 05 '21 at 22:15
  • 1
    Is the stringer tool up to date? This works on the cli, but it does look like stringer is not resolving the correct types from pgx. – JimB Mar 06 '21 at 13:59
  • I also tried adding `github.com/jackc/pgx` inside `tools` in my `genrule`, but it is still failing. @HymnsForDisco – alanmas Mar 08 '21 at 15:48
  • The version I am using for pgx is: v3.6.2+incompatible but even if I tried with v4.6.0 is failing. I might be adding them wrong, possibly? @JimB – alanmas Mar 08 '21 at 16:21
  • 1
    It looks like you are not using go modules, or not using them correctly, which stringer is going to need to resolve that dependency correctly. I can only replicate the error using `GO111MODULE=off`. – JimB Mar 08 '21 at 17:23
  • I think should be something like that, a friend of mine was able to replicate the error https://github.com/pitakill/stringertest and then solve it only running `go get` as with that command go will modify `go.{mod, sum}`and will install all the dependencies. @JimB – alanmas Mar 08 '21 at 17:35

0 Answers0