-
-
Notifications
You must be signed in to change notification settings - Fork 21
Conversation
When vgo2nix was run in a repository with both a vendor directory and a go.mod, such as the result of `go mod vendor`, `go list` would fail with: go list -m: can't compute 'all' using the vendor directory (Use -mod=mod or -mod=readonly to bypass.) This is fixed as suggested, which ensures `go list` uses the go.mod file if it exists.
Just tried on k3s master:
|
Vanity URLs are a great feature... I will take a look at this the next days. |
which is created when running nix-build which I used to debug the build failures.
@dsx the error is unrelated to this tool and caused by vbom.ml being no longer available. k3s probably needs to add something like ceph/ceph-csi@22158eb. |
K3S just keeps it in /vendor. I wonder if there is any way to take into the account vendored packages. |
With the regex modification, vgo2nix works for https://github.com/cosmos/cosmos-sdk, but build still failed:
Not sure if it's an issue of vgo2nix though, still new to both golang and nix.
|
There is always a way but is it worth implementing? It is probably easier to just use
I don't think we parse repulsively like this. |
A small test case that fails:
Run:
Error output:
The package |
Solution: - using vgo2nix (nix-community/vgo2nix#42)
This is actually a very good point! |
When run nix-shell in the pervious test case:
It's trying to create |
NixOS/nixpkgs#98604 |
With this patch in nixpkgs: NixOS/nixpkgs#98632 20,28c20,30
< }
< {
< goPackagePath = "github.com/cespare/xxhash/v2";
< fetch = {
< type = "git";
< url = "https://github.com/cespare/xxhash";
< rev = "v2.1.1";
< sha256 = "0rl5rs8546zj1vzggv38w93wx0b5dvav7yy5hzxa8kw7iikv1cgr";
< };
---
> otherMajorVersions = [
> {
> majorVersion = "v2";
> fetch = {
> type = "git";
> url = "https://github.com/cespare/xxhash";
> rev = "v2.1.1";
> sha256 = "0rl5rs8546zj1vzggv38w93wx0b5dvav7yy5hzxa8kw7iikv1cgr";
> };
> }
> ]; |
main.go
Outdated
func getModules() ([]*modEntry, error) { | ||
var entries []*modEntry | ||
|
||
commitShaRev := regexp.MustCompile(`^v\d+\.\d+\.\d+-(?:\d+\.)?[0-9]{14}-(.*?)$`) | ||
commitShaRev := regexp.MustCompile(`^v\d+\.\d+\.\d+-(?:rc\d+\.)?(?:\d+\.)?[0-9]{14}-(.*?)(?:\+incompatible)?$`) |
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.
vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefxyz when most recent versioned commit before the target commit is vX.Y.Z-pre
I think the rc part should not be hardcoded.
https://github.com/golang/go/blob/master/src/cmd/go/internal/modfetch/pseudo.go#L14
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.
You are right. What do you think about the following change?
commitShaRev := regexp.MustCompile(`^v\d+\.\d+\.\d+-(?:rc\d+\.)?(?:\d+\.)?[0-9]{14}-(.*?)(?:\+incompatible)?$`) | |
commitShaRev := regexp.MustCompile(`^v\d+\.\d+\.\d+-(?:\w+\d+\.)?(?:\d+\.)?[0-9]{14}-(.*?)(?:\+incompatible)?$`) |
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.
I'm trying this patch, more similar to how golang internally do:
diff --git a/main.go b/main.go
index b4bac00..b2bbe1b 100644
--- a/main.go
+++ b/main.go
@@ -13,6 +13,8 @@ import (
"sort"
"strings"
+ "golang.org/x/mod/module"
+ "golang.org/x/mod/semver"
"golang.org/x/tools/go/vcs"
)
@@ -49,10 +51,6 @@ var versionNumber = regexp.MustCompile(`^v\d+`)
func getModules() ([]*modEntry, error) {
var entries []*modEntry
- commitShaRev := regexp.MustCompile(`^v\d+\.\d+\.\d+-(?:rc\d+\.)?(?:\d+\.)?[0-9]{14}-(.*?)(?:\+incompatible)?$`)
- commitRevV2 := regexp.MustCompile("^v.*-(.{12})\\+incompatible$")
- commitRevV3 := regexp.MustCompile(`^(v\d+\.\d+\.\d+)\+incompatible$`)
-
var stderr bytes.Buffer
cmd := exec.Command("go", "list", "-mod", "mod", "-json", "-m", "all")
cmd.Stderr = &stderr
@@ -110,16 +108,22 @@ func getModules() ([]*modEntry, error) {
return nil, err
}
- if commitShaRev.MatchString(rev) {
- rev = commitShaRev.FindAllStringSubmatch(rev, -1)[0][1]
- } else if commitRevV2.MatchString(rev) {
- rev = commitRevV2.FindAllStringSubmatch(rev, -1)[0][1]
- } else if commitRevV3.MatchString(rev) {
- rev = commitRevV3.FindAllStringSubmatch(rev, -1)[0][1]
- } else if mod.Path != url.Root {
- subPath := strings.Split(mod.Path, url.Root+"/")[1]
- if !versionNumber.MatchString(subPath) {
- rev = subPath + "/" + rev
+ path, _, ok := module.SplitPathVersion(mod.Path)
+ if !ok {
+ return nil, fmt.Errorf("invalid mod path: %s", mod.Path)
+ }
+
+ build := semver.Build(rev) // +incompatible
+ gitRef := strings.TrimSuffix(rev, build)
+ if strings.Count(gitRef, "-") >= 2 {
+ // pseudo-version, use the commit hash
+ gitRef = gitRef[strings.LastIndex(gitRef, "-")+1:]
+ } else {
+ // fix tag
+ subModule := strings.TrimPrefix(path, url.Root)
+ if len(subModule) > 0 {
+ // trim the leading "/"
+ gitRef = subModule[1:] + "/" + gitRef
}
}
@@ -131,7 +135,7 @@ func getModules() ([]*modEntry, error) {
entries = append(entries, &modEntry{
replacePath: replacePath,
importPath: mod.Path,
- rev: rev,
+ rev: gitRef,
})
}
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.
https://github.com/golang/go/blob/master/src/cmd/go/internal/modfetch/coderepo.go#L656
this is the go internal code for this part of logic.
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.
Nice. I searched for a function for hours but couldn't find one.
https://gist.github.com/yihuang/7e9e3cfb5ab3f126f077c1e5b66002ad |
So after NixOS/nixpkgs#98632 and the changes proposed by @yihuang we can merge this? |
I think buildGoModule can build everything from vendor, if all dependencies are there. |
we have not passed all the test cases yet, like the one I made above. |
@yihuang I have added your new test. I take suggestions for the name cause I am not to happy with it. Also it currently fails with the following:
|
We can also make the test case a little bit tricker, to have different minor version between two packages in same repo, I think current
|
With that change the tests look like. |
I mean you can only specify one version for the root module, can't specify a different minor version for a sub module. |
@SuperSandro2000 I made a PR to you, https://github.com/SuperSandro2000/vgo2nix/pull/1 I also added gopkg.in in that testcase. |
I have picked your PR into master and updated the test. |
I can still construct failed test case though, the reason is |
|
@Mic92 bump |
@SuperSandro2000 Please ping me also on the PRs that can be closed after that. |
Now we can also bump in nixpkgs. |
This PR combines #36, parts of #40 and adds the final bits to support modern go.mods. I tested this successfully with github.com/StackExchange/dnscontrol and updated it to 3.3.0.
It also fixes the tests and updates dependencies.
Any feedback is appreciated as this is the first time I am touching any such tool in the nix and go world.
I plan to keep this tool runnable in the future.
@dsx @Lucus16
Closes #36, #40