-
Notifications
You must be signed in to change notification settings - Fork 83
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
vfsgendev cannot handle main package #36
Comments
For others who run into the same issue: A workaround is to use the dedicated // +build ignore
package main
import (
"log"
"github.com/shurcooL/vfsgen"
target "github.com/fawick/vfsmain"
)
func main() {
err := vfsgen.Generate(target.Assets, vfsgen.Options{
BuildTags: "!dev",
VariableName: "Assets",
})
if err != nil {
log.Fatalln(err)
}
} |
Yes, this is a limitation of I'm not sure how to work around it other than require users to put assets in a non- It might be possible to work around it by making a copy of the |
That said, the error you got seems unrelated to the issue:
What was the exact command you ran? The error message can be improved to be more clear. |
Ok, I can reproduce that error by running this in bash:
The issue is how bash interprets that parameter, it drops the quotes. So you'll need to wrap the entire parameter in single quotes for bash:
|
The |
Interesting. Perhaps I'm misremembering about inability to import If importing a
|
Nope, I wasn't. The Go compiler ( package main
import (
"fmt"
target "github.com/shurcooL/play/31"
)
func main() { fmt.Println(target.Assets) }
|
EDIT: I was wrong. The real difference is where |
See my comment above. I tried renaming, it still doesn't work. Not with Go 1.9. It worked with older versions of Go (1.6 or so, I can't remember when exactly it stopped working). |
vfsgen/cmd/vfsgendev/generate.go Line 30 in bb654ea
PackageName struct field of vfsgen.Options should not be set if it target is a main package.EDIT: No, that was nonsense. |
Hmm, the workaround from #36 (comment) only runs if |
Thank you for providing that insight, that is very helpful and explains why I wasn't able to reproduce this previously.
I have a really good guess. Looking at commit golang/go@0f06d0a helped me get to it. I think the exception, letting I will need to think about the implications of that, and whether it's something I can accept to rely on. |
Thank you very much for taking the time to investigate! I really appreciate your efforts to get to the bottom of this and help me understand! From what I can grasp from that commit is that my PR #37 in its current form might be a really bad idea, as future Go versions might add further checks that prevent this from working. With some minor changes, however, it might become a bit more reliable and versatile:
The advantages I would come to expect are:
What do you think? |
Using I will need at least a few days to think this over. For me, the biggest concern and part of the decision here is whether I'm willing to move into the territory of creating temporary files in the user's real GOPATH workspace. So far, I've been very careful to never do that, and only ever create temporary .go files in a temporary directory. This gives me full certainty that I will never inadvertently cause user to lose data, or leave unwanted files behind. That's why I am quite hesitant to write (and delete) anything to the user's real GOPATH. Another option to consider here may be copying the target package to a temporary directory and modifying it there. This issue is not very high priority for me at this time, but I will think about it and post updates. If you're in a rush to have something working sooner, I suggest using your fork, and waiting for me to slowly upstream these enhancements. Thanks! |
Okay, understood. Take all the time you need. I have a working solution in place that fully covers my use case. If you are interested, on the weekend I may find time to rerfactor #37 into a draft for the Just to give my two cents on the rationale: |
I have a
main
package for which I want to compile assets with vfsgendev, but it fails:The minimum viable demo case is:
The text was updated successfully, but these errors were encountered: