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
Go: unable to build snap when using go mod
and main package is not in the root
#2962
Go: unable to build snap when using go mod
and main package is not in the root
#2962
Conversation
When using go modules, `go build -o <path>` will pick up main package only if it's in the root of repository. The `./...` pattern matches all the packages within the current module and `go build` will automatically build main packages in all subdirectories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed by https://github.com/golang/go/wiki/Modules#how-to-define-a-module
LGTM, pending tests pass.
A couple of unit tests need to be updated: |
edd8090
to
7eb996b
Compare
This is great, an integration test would be really good though, it can look exactly like the current go mod one but with a main package in a subdir. I can add it to this PR if you cannot do so. |
@sergiusens, thanks, I've added an integration test. Unfortunately, I haven't figured out how to run it locally, I hope I did it correctly :) |
Nice! @pavel-d: If you have lxd installed, you can test it with:
I am running it now myself... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, LGTM
Unfortunately the CLA check is failing because one (or more) of the commits were made with |
* Update test summary
ecc67de
to
1847c5c
Compare
@cjp256, oh, thanks. I've fixed my email address in commits. |
When using go modules,
go build -o <path>
will pick up main package only if it's in the root of repository.Steps to reproduce:
./cli
subdirectorycd snaptest
snapcraft build --use-lxd --debug
Result:
The
./...
pattern matches all the packages within the current module andgo build
will automatically build main packages in subdirectories../runtests.sh static
?./runtests.sh tests/unit
?