markbates / pkger

Embed static files in Go binaries (replacement for gobuffalo/packr)
MIT License
1.19k stars 60 forks source link

Uses `package main` even with -o #56

Closed porridge closed 4 years ago

porridge commented 4 years ago

Contrary to what documentation claims the package directive is still main if I ask pkger to write the file in another directory.

$ pkger -o config
$ head -n 1 config/pkged.go 
package main
jwriteclub commented 4 years ago

👍

fpaniagua commented 4 years ago

Ran into this issue recently when upgrading, and had to revert to v0.12.8.

Did a git bisect, and it indicated: https://github.com/markbates/pkger/commit/b334bd73acb5839bc08969a0c85960ef64dca383

Lines 146 to 148 may be reverting name back to main. https://github.com/markbates/pkger/commit/b334bd73acb5839bc08969a0c85960ef64dca383#diff-37da6fe8e05dcc60369f46c82b2359dfR146-R148

mschristensen commented 4 years ago

👍

al45tair commented 4 years ago

Using v0.12.7 appears to avoid this problem (thanks @fpaniagua for doing a bisect).

markbates commented 4 years ago

PRs are welcome

al45tair commented 4 years ago

@markbates It would help if it was more obvious why b334bd7 does what it does. I'm quite happy to work up a fix if I know what I'm fixing :-)

markbates commented 4 years ago

Without digging in my gut is that it is meant to check if the output directory is main and set the name to that regardless.

-- Mark Bates

On Feb 14, 2020, at 6:19 PM, Alastair Houghton notifications@github.com wrote:

 @markbates It would help if it was more obvious why b334bd7 does what it does. I'm quite happy to work up a fix if I know what I'm fixing :-)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

taiyangc commented 4 years ago

Facing a similar issue here - if the root directory is a module, i.e. is not of package main and has any *.go files under root, pkger -include xxx will fail (on package name conflict).

@markbates I don't think the assumption that "check if the output directory is main" is correct for the PR https://github.com/markbates/pkger/pull/53 It should be inspecting the actual output dir's current package name and set it to that, even if at top level, it's not guaranteed to be main.

To show how painful it is for me to generate pkger.go correctly:

  1. Rename all the *.go's package names to main.
  2. Call pkger -include xxx.
  3. Change all *.go package names back to <original>.
  4. Rename pkger.go's package name to <original>.
  5. Build.

---end of rant---

I am providing a fix for both my and OP's problem here: https://github.com/markbates/pkger/pull/80 Thanks for consideration.

markbates commented 4 years ago

Thank you everyone for tracking this down and for fixing it. Release in the making.

aaahrens commented 4 years ago

Is this fixed? I am having this issue