-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/go: directories named vendor
are ignored in //go:embed
#45744
Comments
vendor
are ignored in //go:embed
vendor
are ignored in //go:embed
We can only embed files that are saved in the packaging of the module, and directories named vendor are excluded from the module. Therefore they need to be excluded from the embed as well. |
Could you just make sure it's at least mentioned in the go:embed documentation at least? This isn't obvious. |
This is currently mentioned in the Today (https://pkg.go.dev/embed@go1.17.2) it says:
Perhaps we are also missing a check to cause the build to error out if the pattern does match files in the |
Change https://go.dev/cl/633815 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Used
//go:embed <dir>
to recursively embed static website assets into anembed.FS
variable, and then rango install <repo>
to install the binary into gobin.What did you expect to see?
All assets embedded into the
embed.FS
variable in the final binary in gobin.What did you see instead?
Only some assets were embedded in the
embed.FS
variable in the final binary in gobin.The problem comes from having folders named
vendor
within the directory that gets embedded.If you create a project that embeds a directory, for example
//go:embed static
, which includes some sub-directory namedvendor
, for examplestatic/vendor/style.css
, then the embed behaviour is different depending on how you install the project into gobin.If you have the entire project source locally and you run
go install
within the project then thevendor
directory is correctly included and embedded into the final binary.If you push the project to somewhere like GitHub and then try to install via
go install <repo>
orgo get <repo>
, then all files are correctly embedded according to the documentation except for the entirevendor
folder, which is ignored. You can work around this by settingGO111MODULE=auto
. If this is set then thevendor
directory is no longer ignored and is correctly embedded in the final binary.I believe this is just an unintended side-effect of
go get
/go install
and how they deal withvendor
ed dependencies. If it is actually intended then it at the very least needs to be documented and made consistent across the different methods of installation.The text was updated successfully, but these errors were encountered: