-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: add //go:embed all:<pattern> to allow . and _ matches #43854
Comments
From #42328
I acknowledged that. I'm still confused why you didn't even mention it in your list - but did include the option of a third-party embedding tool, which has largely the same drawbacks (with the exception that
I think this really depends - the complexity of flags for But, to be clear, I don't really have strong opinions, one way or another. If I where you, I'd at least consider generating the list until you get an answer. I don't think there is any real new information here that wasn't available when we discussed #42328 - we where aware, at the time, that there will be users who will want hidden files included, so getting a confirmation isn't really new. However, at the time, my main concern was to get safe default behavior - I'm not opposed to adding optional other behaviors. |
Although my initial inclination was to add a One alternative may be to have a second directive with different semantics:
This could become unwieldy if many permutations were anticipated to be added in the future. One additional thought: does the module proxy respect embed directives? If not, the files may be excluded before the embed directive takes place anyway. |
Fair comment; I've updated the list. As I think you agree, a generator for explicit per-file //go:embed directives is still a burden. |
File can be embedded if they are included in the module zip file. And if they're in the zip-file, the proxy serves them. |
@Merovius: Sorry, I think I may have expressed my thought poorly, let me try one more time! It's my understanding that directories that do not contain If embed directives don't modify the list of files included in the module zip, that seems like it's going to severely hamper the usefulness of the feature, as you won't be able to embed files that don't exist in the module zip. |
I don't think this understanding is correct. For example, if I run So, the answer is still "yes, everything works just fine". |
@Merovius: Ah, good to know! Now I wish I could remember what made me think otherwise… 🤔 Either way, I do think something like |
Should be titled "embed: ..." vs cmd/go. Might explain why it's been overlooked. |
[mostly including my comment from the other issue for reference here] #42328 ignored dot-files since including them will cause problems on many systems. I'm not sure there is any benefit to discussing the pros/cons again here, the same arguments still apply. Providing
Fortunately, it sounds like simply including underscore files would solve the the original problem highlighted in this issue. I'm not aware of any situations where including underscore files would be problematic (_netrc was suggested, but it's highly unlikely it would inadvertently appear within a module). Prior comments on this topic: 1, 2 Using code generation when dot-files are required has a significant advantage: It guarantees that the correct files are included on other systems. From what I've seen including dot-files is very uncommon, so this inconvenience should be fairly rare. If not, it would be trivial to create a tool the community can use with go:generate. |
It's always going to be possible to come up with a use case that embed does not support. |
This proposal has been added to the active column of the proposals project |
On the dot/underscore file discussion, the summary at the end of the top-post of #42328 has some good suggestions to keep in mind. Some new suggestions below.
On the empty embed error, I hope we can just drop it. Warning the user that an embed is empty is probably better suited for |
Any suggestions which automatically include dot-files will misbehave on some systems (not to mention adding more complexity for an edge case). This goes against the extensively explored reasoning for accepting #42328. The window to fix this in Go1.16 is vanishingly small (if it exists at all). The barrier to fixing it later will be higher again. I'd recommend focusing on simply adding underscore files back in. It's a trivial change now (also less likely after release), and it would solve the motivating example behind this issue. So far, there have been no explicit examples where doing so would cause a problem. @rsc, you mentioned earlier that it would be better to release the beta and gather feedback. Given this issue, I think it would be worth rapidly reconsidering including underscore files. I suspect underscore files will be more desirable to the wider community, despite being much less of a risk than dot-files. |
I am still not clear about what the use case being described in the top comment is exactly. I would also point out that we basically cannot include empty directories, since they do not exist as a concept in Git. |
My use-case was described briefly in #42328, but only after it was already closed. It was suggested there that I create a new issue. Some further detail:
This is new feedback, based on a project that attempted to use the new feature and found the current design to be overly constraining. (As you know, the filename filtering wasn't in your draft design, added because of #42328, and was otherwise undocumented at the time.) Most of the posts in #42328 are users voicing their preference or opinion on how filtering should behave and not feedback based on practice. The closest thing to that are these posts:
The need for dropping the empty-dir error can arise without the developer ever invoking git. The chicken or the egg problem can appear when writing a new package for the first time, or updating an embed from scratch within an existing checkout, when using a Go program that imports the package containing the //go:embed to (re)write its contents. The latter can happen even when the final update is transmitted to a remote vcs with a fully populated embed dir. Separate to that, I urge you to reconsider coupling //go:embed so tightly to git, when go supports other vcs like bzr and svn that do allow empty dirs in a repo. (Even on git, it is also common to use .gitignore or other a One path forward is to drop the error, and add a |
One could imagine an |
That's only the consumption side of the story: you also need to ensure the production side matches. One would need to ensure the files on disk have been renamed, so that they can get past the great |
My use case for But, I can't include those files with //go:embed - so I had to rename that It's a kludge, and not obvious to anyone looking at my repo for the first time.. but still beats the third party bundlers. I very much would like to be able to, perhaps by way of my embed criteria, be able to intentionally include |
It seems like we could add We would have to figure out how to change the go/build.Package encoding as well. Thoughts on all of this, @jayconrod and @matloob? |
Change https://golang.org/cl/359413 mentions this issue: |
This patch must be accepted after golang/go#43854 Closes #631
This patch must be accepted after golang/go#43854 Closes #631 Update modules and use fixed go Maybe this will be enough? This should help Wait what this? Fix using stable Fix .keep Complicated templates? Finally? What is wrong with you ??? I dunno lets try I hate Go traditions Fix imports Fix imports
To solve #631 issue, we need to use Go with fixed embedding of folders for case when only contents are files starting with dot [1]. It should be introduced in Go 1.18, but it is not released yet. 1. golang/go#43854 Part of #637
To solve #631 issue, we need to use Go with fixed embedding of folders for case when only contents are files starting with dot [1]. It should be introduced in Go 1.18, but it is not released yet. 1. golang/go#43854 Part of #637
Change https://go.dev/cl/393234 mentions this issue: |
For golang/go#43854 Change-Id: I3724f620e0e2f122e7bbb615db8c0ce1b4151a8d Reviewed-on: https://go-review.googlesource.com/c/website/+/393234 Reviewed-by: Bryan Mills <[email protected]> Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
To solve #631 issue, we need to use Go with fixed embedding of folders for case when only contents are files starting with dot [1]. The fix was introduced in Go 1.18. 1. golang/go#43854 Part of #631
To solve #631 issue, we need to use Go with fixed embedding of folders for case when only contents are files starting with dot [1]. The fix was introduced in Go 1.18. 1. golang/go#43854 Part of #631
To solve #631 issue, we need to use Go with fixed embedding of folders for case when only contents are files starting with dot [1]. The fix was introduced in Go 1.18. 1. golang/go#43854 Part of #631
For golang/go#43854 Change-Id: I3724f620e0e2f122e7bbb615db8c0ce1b4151a8d Reviewed-on: https://go-review.googlesource.com/c/website/+/393234 Reviewed-by: Bryan Mills <[email protected]> Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
This issue follows from #42328 which is now closed, and where @mpx suggested I create a new one.
Overview
I have a //go:embed of ~700 files, ~70 directories and where some files have a leading underscore. These are not dot files, nor go source files, and it took me some time to work out that the reason I couldn't open some of them without error was that they were excluded from the build.
The draft proposal doesn't mention this restriction. It was written in July and the exclusion of these files was made in December by a change resulting from #42328.
It was counterintuitive to me that files would be arbitrarily excluded because they're considered "hidden" on some platforms. Why counterintuitive? I don't know of any other tools that automatically exclude dot or leading-underscore files, other than ls for dot files, which provides the well-known
-a
escape hatch. Git, find, tar, etc., include such files by default. Even the macOS Finder allows you to toggle display dot files with⌘-shift-.
.Related to this, I sometimes use "filesystem templates" that include empty directories that are later populated by code: these are either initially extracted to the filesystem, or used with a virtual in-memory filesystem. To embed such a template using //go:embed, I'd have to add placeholder files like a
readme.txt
with contents "This file intentionally left blank.". (When forced to do this, it is preferable to use.empty
dot files, but they're also unsupported by //go:embed!)I've also experienced a similar chicken or the egg problem with an empty embed dir; see [1] below.
Sometimes we need to include everything in an embed of a directory tree. Please give us a way out! :)
Suggestions and feedback
A simple opt-in flag like
//go:embed -all dir
to include everything indir
without filtering, and without declaring an error if the directory is empty [1]. This flag would instruct //go:embed to include all files, including those having a leading underscore, and any dot files. For the edge-case of a file named "-all", we can use a simple flag terminator://go:embed -all -- -all
. Theflag
package makes this implementation straightforward.Otherwise having some explicit filtering option in the directive (with an "otherwise include-all") would be welcomed, as was suggested in #42325.
The proposal in #42328 for //go:embed dir vs. //go:embed dir/** is very subtle and reminds me of the arcane build constraint syntax that was thankfully recently revisited. An explicit inclusion-list, written by hand or code generated, is a big turn-off.
[1] In one project, I have a package that embeds a directory tree that is generated by another program. The generator needs to use the same package, which leads to a chicken or the egg problem. I currently resolve this by having a Makefile add a
readme.txt
file into the embed directory before each build (which unfortunately remains in the embed). I am not using the Makefile for any other purpose here.Workarounds
The first two options are not preferred because they burden the project with an external generator. The third option would force design changes to a larger surface area of an otherwise already complex project just to simplify the build.
I'd love to avoid the use of Makefiles in the last workaround, especially when they serve no other purpose.
The text was updated successfully, but these errors were encountered: