Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Uses package main even with -o #56

Closed
porridge opened this issue Dec 18, 2019 · 10 comments
Closed

Uses package main even with -o #56

porridge opened this issue Dec 18, 2019 · 10 comments

Comments

@porridge
Copy link

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
Copy link

👍

@fpaniagua
Copy link

fpaniagua commented Jan 14, 2020

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

Did a git bisect, and it indicated:
b334bd7

Lines 146 to 148 may be reverting name back to main.
b334bd7#diff-37da6fe8e05dcc60369f46c82b2359dfR146-R148

@mschristensen
Copy link

👍

@al45tair
Copy link

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

@markbates
Copy link
Owner

PRs are welcome

@al45tair
Copy link

@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
Copy link
Owner

markbates commented Feb 15, 2020 via email

al45tair added a commit to al45tair/pkger that referenced this issue Feb 15, 2020
It looks like the problem is that pkger gets the information for the current
directory, *then* appends the path from the '-o' option, but that means that
the package name will always be main if it's started from the main package,
regardless of '-o'.

Fixes markbates#56.
al45tair added a commit to al45tair/pkger that referenced this issue Mar 4, 2020
It looks like the problem is that pkger gets the information for the current
directory, *then* appends the path from the '-o' option, but that means that
the package name will always be main if it's started from the main package,
regardless of '-o'.

Fixes markbates#56.
@taiyangc
Copy link
Contributor

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 #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: #80
Thanks for consideration.

@markbates
Copy link
Owner

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

@aaahrens
Copy link

Is this fixed? I am having this issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants