Skip to content
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

x/vgo: “unknown revision” when attempting to build from multi-module repo #25758

Closed
bcmills opened this issue Jun 6, 2018 · 2 comments

Comments

@bcmills
Copy link
Member

commented Jun 6, 2018

Based on discussion in https://golang.org/cl/116235, I decided to do some experimentation with cyclic modules hosted in the same repository. (I'm not actually sure whether that's a sensible thing to do, which is why I wanted to experiment.)

Unfortunately, I can't even get acyclic modules working in a multi-module repo. The “Multiple-Module Repositories” section of https://research.swtch.com/vgo-module seems to claim that it's supported, but vgo list -t won't list versions for any of the submodules and vgo get won't fetch them.

My attempt is in https://github.com/bcmills/vgotest. It's entirely possible that I'm missing something obvious, but I'm not sure what: this may just be a documentation problem. (I'm fairly new to both vgo and Git tags.)

~$ cd $(mktemp -d)

/tmp/tmp.eQdtHRpVrY$ git clone git@github.com:bcmills/vgotest.git
Cloning into 'vgotest'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 11 (delta 0), reused 11 (delta 0), pack-reused 0
Receiving objects: 100% (11/11), done.

/tmp/tmp.eQdtHRpVrY$ cd vgotest

/tmp/tmp.eQdtHRpVrY/vgotest$ git checkout v0.1.0
HEAD is now at 434c49a a,b: add mutually-dependent modules

/tmp/tmp.eQdtHRpVrY/vgotest$ find ./*
./a
./a/go.mod
./a/a.go
./b
./b/go.mod
./b/b.go
./LICENSE


/tmp/tmp.eQdtHRpVrY/vgotest$ cd a

/tmp/tmp.eQdtHRpVrY/vgotest/a$ vgo build .
vgo: finding github.com/bcmills/vgotest/b v0.1.0
vgo: github.com/bcmills/vgotest/b v0.1.0: unknown revision "b/v0.1.0"
vgo: finding github.com/bcmills/vgotest/b v0.1.0
vgo: github.com/bcmills/vgotest/b v0.1.0: unknown revision "b/v0.1.0"
vgo: unknown revision "b/v0.1.0"

CC: @rsc @myitcv

@gopherbot gopherbot added this to the vgo milestone Jun 6, 2018

@myitcv

This comment has been minimized.

Copy link
Member

commented Jun 6, 2018

...cyclic modules...

I'm intrigued!

It's entirely possible that I'm missing something obvious, but I'm not sure what: this may just be a documentation problem

It looks like:

  • you're missing a go.mod at the root of the repo (I haven't seen it written anywhere that that's a requirement, but it seems to "make sense")
  • the tags you pushed don't appear to be in the right format (although I'll note they don't appear to correspond to what you included in the description so I'm a bit confused)

I pulled together a complete example from beginning-to-end to show things working.


Initialise a directory as a git repo, and add an appropriate remote:

$ mkdir vgo-by-example-submodules
$ cd vgo-by-example-submodules
$ git init
Initialized empty Git repository in /go/vgo-by-example-submodules/.git/
$ git remote add origin https://github.com/$GITHUB_USERNAME/vgo-by-example-submodules

Now define our root module, at the root of the repo, commit and push:

$ cat <<EOD >go.mod
module github.com/$GITHUB_USERNAME/vgo-by-example-submodules
EOD
$ git add go.mod
$ git commit -am 'Initial commit'
[master (root-commit) 86bc648] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 go.mod
$ git push
To https://github.com/myitcv/vgo-by-example-submodules
 * [new branch]      master -> master

Now create a package b and test that it builds:

$ mkdir b
$ cd b
$ cat <<EOD >b.go
package b // import "github.com/$GITHUB_USERNAME/vgo-by-example-submodules/b"

const Name = "Gopher"
EOD
$ echo >go.mod
$ vgo test
?   	github.com/myitcv/vgo-by-example-submodules/b	[no test files]

Now commit, tag and push our new package:

$ cd ..
$ git add b
$ git commit -am 'Add package b'
[master a63b23f] Add package b
 2 files changed, 4 insertions(+)
 create mode 100644 b/b.go
 create mode 100644 b/go.mod
$ git push
To https://github.com/myitcv/vgo-by-example-submodules
   86bc648..a63b23f  master -> master
$ git tag b/v0.1.1
$ git push origin b/v0.1.1
To https://github.com/myitcv/vgo-by-example-submodules
 * [new tag]         b/v0.1.1 -> b/v0.1.1

Now create a main package that will use b:

$ mkdir a
$ cd a
$ cat <<EOD >a.go
package main // import "github.com/$GITHUB_USERNAME/vgo-by-example-submodules/a"

import (
	"github.com/$GITHUB_USERNAME/vgo-by-example-submodules/b"
	"fmt"
)

const Name = b.Name

func main() {
	fmt.Println(Name)
}
EOD
$ echo >go.mod

Now let's build and run our package:

$ vgo build
vgo: resolving import "github.com/myitcv/vgo-by-example-submodules/b"
vgo: finding github.com/myitcv/vgo-by-example-submodules/b (latest)
vgo: adding github.com/myitcv/vgo-by-example-submodules/b v0.1.1
vgo: finding github.com/myitcv/vgo-by-example-submodules/b v0.1.1
vgo: downloading github.com/myitcv/vgo-by-example-submodules/b v0.1.1
$ ./a
Gopher
$ cat go.mod
module github.com/myitcv/vgo-by-example-submodules/a

require github.com/myitcv/vgo-by-example-submodules/b v0.1.1

See how we resolve to the tagged version of package b.

Finally we commit, tag and push our main package:

$ cd ..
$ git add a
$ git commit -am 'Add package a'
[master a69a475] Add package a
 3 files changed, 15 insertions(+)
 create mode 100755 a/a
 create mode 100644 a/a.go
 create mode 100644 a/go.mod
$ git push
To https://github.com/myitcv/vgo-by-example-submodules
   a63b23f..a69a475  master -> master
$ git tag a/v1.0.0
$ git push origin a/v1.0.0
To https://github.com/myitcv/vgo-by-example-submodules
 * [new tag]         a/v1.0.0 -> a/v1.0.0

Version details

go version go1.10.2 linux/amd64 vgo:2018-02-20.1
vgo commit: 6a94eb3b5ccc04453d2fb45c23641e5993118068
@bcmills

This comment has been minimized.

Copy link
Member Author

commented Jun 6, 2018

you're missing a go.mod at the root of the repo

I tried that in v0.3.0, but it still didn't work for me.

the tags you pushed don't appear to be in the right format

Ah, that's what I was missing. The relevant documentation is buried in the fourth sentence of the second paragraph of the section:

In this case, the source control commit tags addressing that module would take the form blue/v1.x.x. Similarly, the tag blue/v2.x.x would address the blue/v2/ subdirectory.

(I really wish we had some vgo documentation in quick-reference form. As you can see, I have trouble with skipping over relevant information in prose, and I have the same problem with tutorials: I get bored and glaze over during the important parts!)

@bcmills bcmills closed this Jun 6, 2018

@golang golang locked and limited conversation to collaborators Jun 6, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.