Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

all: use go run for go-bindata go generate commands #4134

Merged
merged 7 commits into from
Dec 9, 2021
Merged

all: use go run for go-bindata go generate commands #4134

merged 7 commits into from
Dec 9, 2021

Conversation

leighmcculloch
Copy link
Member

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

WHAT

Use go run for go-bindata rather than install go-bindata.

WHY

There are many variations of go-bindata. The install script checks if a binary named go-bindata is present in the PATH. Because there are many variations of go-bindata a dev can have another installed that generates different files.

There's not really any need for us to install go-bindata and use it in the way we are. The go run command is now able to run a specific version of a tool without it being installed on the users PATH.

We use this pattern for goxdr generation, and the pattern works here too.

Known limitations

N/A

### WHAT
Use go run for go-bindata rather than install go-bindata.

### WHY
There are many variations of go-bindata. The install script checks if a binary named go-bindata is present in the PATH. Because there are many variations of go-bindata a dev can have another installed that generates different files.

There's not really any need for us to install go-bindata and use it in the way we are. The go run command is now able to run a specific version of a tool without it being installed on the users PATH.

We use this pattern for goxdr generation, and the pattern works here too.
@@ -5,7 +5,7 @@ import (
migrate "github.com/rubenv/sql-migrate"
)

//go:generate go-bindata -nometadata -ignore .+\.(go|swp)$ -pkg dbmigrate -o dbmigrate_generated.go ./migrations
//go:generate go run github.com/kevinburke/go-bindata/[email protected]+incompatible -nometadata -ignore .+\.(go|swp)$ -pkg dbmigrate -o dbmigrate_generated.go ./migrations
Copy link
Contributor

@2opremio 2opremio Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of specifying the version in every usage, I would use a tools.go file (see https://marcofranssen.nl/manage-go-tools-via-go-modules for instance) and delegate the dependency versioning to go.mod

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much more context at golang/go#25922

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used that pattern before and it carries some complexity that isn't as intuitive or simple as a go run command, and I don't think that additional complexity is outsized by the benefit of shortening these comments by a few characters.

That tools.go pattern was proposed in 2018 before the go run command supported running specific versions as it does today. I think it will be interesting to see if it continues to be common.

In regards to the complexity, adding tools to the module expands the dependency graph of the module, even if they are in a 'tools' tag and not compiled or used at runtime. The dependency graph of our module impacts the dependency graph of any importer of our module, i.e. any importer of the Go SDK. This tool is used in development, not by the compiler, so I don't think we should introduce them into the dependency graph.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it up to you, but embedding the version in every invocation isn't great. I wonder if there is a way to have a different go module just for this, so that it doesn't expand the main module's graph.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to use a separate mod file with some build commands, maybe run, I'll give it a go. It may mean there is yet another bespoke thing about our repo though that people need to learn and it'd be nice if we could be less bespoke rather than more. I'll see what it's like.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a go of using a separate go.mod file.

I named it go.tools.mod initially and placed it in the root directory. Every call site had this long go run -modfile=../../../../../../go.tools.mod. Running go mod tidy -modfile=go.tools.mod added all the regular dependencies though and got rid of the dependency I needed.

So I created a directory tools-deps and moved the mod file there, and added a tools.go, following the tools.go pattern. Every call site had this go run -modfile=../../../../../../tools-deps/go.mod.

It was all pretty fiddly, not intuitive to me, and much more fiddly than setting versions in a few places.

but embedding the version in every invocation isn't great.

Assuming you're referring to the inconvenience, I agree, it's inconvenient to have the version in a few places rather than in a single place. I think it is less inconvenient to the multi-mod file tools.go setup though. I don't see any other stand out costs. A little copying isn't so bad? Let me know if I'm missing anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at how another repo does tools.go, and I'm curious to explore this more, but I think we should merge this as is for now as it gets benefits over what we have today, and tools.go if we add it can be an improvement on this.

@leighmcculloch leighmcculloch enabled auto-merge (squash) December 9, 2021 23:45
@leighmcculloch leighmcculloch merged commit 6c6503e into stellar:master Dec 9, 2021
@leighmcculloch leighmcculloch deleted the gobindatarun branch December 10, 2021 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants