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

Fix: goa gen ignores vendor directory #2979

Merged
merged 2 commits into from
Jan 21, 2022

Conversation

davepgreene
Copy link
Contributor

This PR fixes #2978 by only running go get from generator code if the module does not have a vendor directory. The gotcha is that the vendor directory must contain the goa.design/goa/v3/codegen/generator.

Because of the general guarantee that using a vendor directory provides a measure of predictability in builds, I'm reluctant to find some way to install that package as part of the code generation process. Instead, it may be more appropriate to document this requirement and suggest the user use the tools.go model to ensure the package is included.

I'm open to suggestions for how to handle this case.

@raphael
Copy link
Member

raphael commented Jan 17, 2022

This looks great, thank you. Make sense that the goa tool wouldn't automatically update the vendor directory. Could it check whether it's there and print a nice error message explaining that it needs to be?

@davepgreene
Copy link
Contributor Author

I like that idea and have some ideas as to how I might implement it. I'll update this PR when I get a chance.

@davepgreene
Copy link
Contributor Author

davepgreene commented Jan 18, 2022

Back to the drawing board. There's no consistency between what the packages package and go list reports in terms of identified, vendored dependencies. Might have to parse the vendor/modules.txt or go.sum to actually determine whether the goa.design/goa/v3/codegen/generator package is actually stored on-disk.

@raphael
Copy link
Member

raphael commented Jan 18, 2022

Could it do something as simple as whether the goa sub-directory exist?

@davepgreene
Copy link
Contributor Author

davepgreene commented Jan 18, 2022

Could it do something as simple as whether the goa sub-directory exist?

I was hoping for something more elegant than that but the vendor directory has a known enough structure to be able to walk it.

The other thing is that the presence of the directory doesn't necessarily indicate the completeness of the package contained within.

Another approach that might be awful but would certainly give us enough info would be to create another temp dir, write a go file with a bare import of the relevant package and attempt to build it, capturing errors with enough info to make it actionable.

Alternatively we could test the output of the go build command that is called from Compile and if it matches the error we expect for not having the vendored dependencies, surface it in an actionable way for the user.

@raphael
Copy link
Member

raphael commented Jan 18, 2022

Yeah it's not the most elegant for sure, an alternative could be to add a error handler (instead of checking proactively) that would understand that vendoring is enabled and suggest making sure that Goa is vendored. It depends a bit on how easy or hard it is to write such a handler...

@davepgreene
Copy link
Contributor Author

Unfortunately the biggest issue at hand is just that the go command understand vendor context but the code it relies on is deep in internal packages. We're forced to either be proactive in testing whether the go build command works or be reactive in testing the output from the compiler.

@davepgreene
Copy link
Contributor Author

@raphael is there a good location to document troubleshooting information? I noticed the docs aren't in the docs directory and, beyond that, I don't see a good place to point users to in order to describe what might be going wrong either in the README or at https://goa.design.

@raphael
Copy link
Member

raphael commented Jan 18, 2022

The closest that exists to this atm is the FAQ https://goa.design/learn/faq/ - but happy to create an explicit troubleshooting document if that makes more sense.

@davepgreene
Copy link
Contributor Author

I've updated with the best approach I could come up with. Instead of trying to determine if the dependency is satisfied ahead of time, we just check the error that comes from go build (which will happen every time we try to generate without the goa.design/goa/v3/codegen/generator package available) and if we have a vendor directory, surface the error to direct the user to the troubleshooting section of the README I added.

@raphael
Copy link
Member

raphael commented Jan 18, 2022

Looks great, thank you!

@raphael raphael merged commit 533d5fb into goadesign:v3 Jan 21, 2022
@davepgreene davepgreene deleted the fix-go-get-in-vendor-context branch April 18, 2022 00:13
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.

Goa gen bypasses vendor directory
3 participants