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

Remove GOPATH (breaking change for using wag outside of GOPATH) #423

Merged
merged 2 commits into from
Apr 21, 2022

Conversation

taylor-sutton
Copy link
Contributor

@taylor-sutton taylor-sutton commented Apr 21, 2022

This is a merge request into the v9.x dev branch, currently even with master but this will be where it starts to diverge.

This PR is split into two commits.

The first commit is fairly mechanical: the idea is to reduce any remaining uses of GOPATH to the top-level, rather than using it deeper into the generator. The deeper usage of GOPATH that needed to be eliminated is in the Generator type in our swagger package. Previously this struct was receiving a path that was interpreted relative to GOPATH, now it's receiving an absolute path.

In addition, I tried to simplify a bit by removing the number of *path variables. For example, in practice, modelsPath was always {basePath}/models; yet at the same time, the assumption that models lived in that directory was hardcoded in other places, so that if we just changed modelsPath, things would actually break.

The second commit included a BREAKING CHANGE ⚠️ 🔴 . This change was necessary to completely remove any dependence on GOPATH. Now the -output-path, if it's relative, is interpreted relative to current working directory. Previously, we would combine GOPATH with the module path in go.mod to guesstimate where to interpret it relative to.

This change is only sorta kinda breaking. If you were using wag inside ${GOPATH}/src/path/to/package already, nothing changes for you. Using wag outside such a directory... was already kinda broken. So while this is a breaking change, it's really fixing things. Previously, if I ran wag in ~/someDir (i.e. outside of GOPATH), wag would put the generated files inside of GOPATH, which is basically never what you want.

Testing

Running make test not only passes the test, it also results in literally zero diffs inside samples, meaning that this is not changing anything in the use cases we are about.

I also tried running wag outside of GOPATH... and it actually worked! It produced generated files inside the working directory instead of randomly far away.

Merge Checklist

  • Run make build
  • Run make generate
  • Update the current version in the /VERSION file - N/A, not trying to release yet.

Closes #328

With this change, GOPATH is still used, but only at the top level (main.go) where it's used to
determine the absolute path for output.
This is a breaking change: now the -output-path, if it's relative, is interpreted relative to
current working directory. Previously, we would combine GOPATH with the module path in go.mod to
guesstimate where to interpret it relative to.
@taylor-sutton taylor-sutton marked this pull request as ready for review April 21, 2022 21:30
@taylor-sutton taylor-sutton requested a review from a team as a code owner April 21, 2022 21:30
@taylor-sutton taylor-sutton requested review from andruwm and removed request for a team April 21, 2022 21:30
@taylor-sutton taylor-sutton changed the title Remove gopath simple Remove GOPATH (breaking change for using wag outside of GOPATH) Apr 21, 2022
Copy link
Contributor

@andruwm andruwm left a comment

Choose a reason for hiding this comment

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

Nice cleanup!

@taylor-sutton taylor-sutton merged commit d8c95b0 into v9.x Apr 21, 2022
@taylor-sutton taylor-sutton deleted the remove-gopath-simple branch April 21, 2022 21:40
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.

2 participants