Masterminds / glide

Package Management for Golang
https://glide.sh
Other
8.15k stars 540 forks source link

Unable to generate glide.lock when testImport is being used #597

Open HelloGrayson opened 7 years ago

HelloGrayson commented 7 years ago

I'm trying to move my libs test deps out of import and into testImport, so that my lib doesn't impose constraints on my users test dependencies.

I've updated my glide.yaml to move the test deps into testImport:

package: github.com/yarpc/yarpc-go

import:
- package: golang.org/x/net
  version: master
  subpackages:
  - context
  - context/ctxhttp
- package: github.com/thriftrw/thriftrw-go
  version: ~0.1
- package: github.com/uber/tchannel-go
  version: ^1.0.9

testImport:
- package: github.com/stretchr/testify
  version: master
  subpackages:
  - assert
  - require
- package: github.com/golang/mock
  version: master
  subpackages:
  - gomock
- package: github.com/crossdock/crossdock-go
  version: master

But when I run glide up I get the error Failed to generate lock file: Generating lock produced conflicting versions of github.com/golang/mock. import (), testImport (master):

yarpc/yarpc-go - [move-test-deps] » rm -rf vendor
yarpc/yarpc-go - [move-test-deps] » rm -rf glide.lock
yarpc/yarpc-go - [move-test-deps] » glide up
[INFO]  Downloading dependencies. Please wait...
[INFO]  --> Fetching updates for github.com/uber/tchannel-go.
[INFO]  --> Fetching updates for github.com/thriftrw/thriftrw-go.
[INFO]  --> Fetching updates for golang.org/x/net.
[INFO]  --> Fetching updates for github.com/crossdock/crossdock-go.
[INFO]  --> Fetching updates for github.com/stretchr/testify.
[INFO]  --> Fetching updates for github.com/golang/mock.
[INFO]  --> Setting version for github.com/golang/mock to master.
[INFO]  --> Setting version for github.com/stretchr/testify to master.
[INFO]  --> Setting version for github.com/crossdock/crossdock-go to master.
[INFO]  --> Detected semantic version. Setting version for github.com/thriftrw/thriftrw-go to v0.1.0.
[INFO]  --> Detected semantic version. Setting version for github.com/uber/tchannel-go to v1.1.0.
[INFO]  --> Setting version for golang.org/x/net to master.
[INFO]  Resolving imports
[INFO]  --> Fetching updates for github.com/opentracing/opentracing-go.
[INFO]  --> Fetching updates for github.com/uber-go/atomic.
[INFO]  --> Fetching updates for github.com/apache/thrift.
[INFO]  --> Setting version for github.com/apache/thrift to master.
[INFO]  --> Fetching updates for github.com/davecgh/go-spew.
[INFO]  --> Setting version for github.com/davecgh/go-spew to master.
[INFO]  --> Setting version for github.com/stretchr/testify to master.
[INFO]  --> Fetching updates for github.com/pmezard/go-difflib.
[INFO]  --> Setting version for github.com/pmezard/go-difflib to master.
[INFO]  Downloading dependencies. Please wait...
[INFO]  Setting references for remaining imports
[INFO]  Exporting resolved dependencies...
[INFO]  --> Exporting github.com/thriftrw/thriftrw-go
[INFO]  --> Exporting github.com/crossdock/crossdock-go
[INFO]  --> Exporting github.com/uber-go/atomic
[INFO]  --> Exporting github.com/uber/tchannel-go
[INFO]  --> Exporting github.com/apache/thrift
[INFO]  --> Exporting github.com/stretchr/testify
[INFO]  --> Exporting github.com/davecgh/go-spew
[INFO]  --> Exporting github.com/pmezard/go-difflib
[INFO]  --> Exporting github.com/golang/mock
[INFO]  --> Exporting github.com/opentracing/opentracing-go
[INFO]  --> Exporting golang.org/x/net
[INFO]  --> Exporting github.com/stretchr/testify
[INFO]  --> Exporting github.com/crossdock/crossdock-go
[INFO]  --> Exporting github.com/golang/mock
[INFO]  Replacing existing vendor dependencies
[ERROR] Failed to generate lock file: Generating lock produced conflicting versions of github.com/golang/mock. import (), testImport (master)

The version of glide at hand is 0.12.0:

$ glide --version
glide version 0.12.0-dev

And there is a branch to reproduce this here, just run this:

$ git clone git@github.com:yarpc/yarpc-go.git
$ git co move-test-deps
$ glide up

Is there a way to dump more info about the error?

aeneasr commented 7 years ago

I can confirm this. I am using the latest master (because no easy way to install binaries on windows).

glide.yaml

package: github.com/ory-am/editor-platform/firewall-reverse-proxy
import:
- package: github.com/Sirupsen/logrus
  version: ~0.10.0
- package: github.com/golang/mock
  subpackages:
  - gomock
- package: github.com/ory-am/common
  subpackages:
  - compiler
  - env
- package: github.com/ory-am/fosite
  version: ~0.3.2
- package: github.com/ory-am/hydra
  version: ~0.5.2
  subpackages:
  - firewall
  - sdk
- package: github.com/ory-am/ladon
  version: ~0.2.0
- package: github.com/pkg/errors
  version: ~0.7.0
- package: golang.org/x/net
  subpackages:
  - context
testImport:
- package: github.com/stretchr/testify
  version: ~1.1.0
  subpackages:
  - assert
  - require

log:

...
[INFO]  --> Exporting gopkg.in/yaml.v2
[INFO]  --> Exporting github.com/spf13/jwalterweatherman
[INFO]  --> Exporting github.com/stretchr/testify
[INFO]  --> Exporting github.com/spf13/cast
[INFO]  --> Exporting gopkg.in/dancannon/gorethink.v2
[INFO]  --> Exporting github.com/kr/fs
[INFO]  --> Exporting gopkg.in/fatih/pool.v2
[INFO]  --> Exporting golang.org/x/text
[INFO]  --> Exporting gopkg.in/square/go-jose.v1
[INFO]  Replacing existing vendor dependencies
[ERROR] Failed to generate lock file: Generating lock produced conflicting versions of github.com/stretchr/testify. import (~1.1.3), testImport (~1.1.0)
novas0x2a commented 7 years ago

Neither of these two above yaml files produce an error for me with the current release of glide (0.12.3); however, I ran into a very similar problem. I'm not sure if this is the entire problem or not, but I think what is happening is that:

  1. Top-level glide.yaml indicates that pkg-A and pkg-B are testImport
  2. During glide update, glide notices that pkg-B has a Godeps.json that depends on pkg-A
  3. Glide loads pkg-A as an import even though it came in via a testImport Godeps
  4. Conflict if pkg-B -> pkg-A (import) is a different version from pkg-A (testImport).

I think common packages are almost certain to cause this problem; my conflict was on go-diff, which is a dep of testify, and my workaround was to move go-diff from a testImport to an import in my glide.yaml since import package versions trump testImport package versions.

glibsm commented 7 years ago

Ran into the same problem. Can confirm that moving to regular import works (@novas0x2a solution)

mwf commented 7 years ago

I ran into the same problem.

It's interesting. After moving testImport to import and making glide up I moved the dependencies back to testImport. Then ran glide up again, and it ran without errors!

stevenroose commented 7 years ago

I think the best solution easiest workaround is to don't have a version constraint on your test dependencies.

aeneasr commented 7 years ago

I think the best solution is to don't have a version constraint on your test dependencies.

I strongly disagree

stevenroose commented 7 years ago

@arekkas well, "best solution" might have been a bad expression of what I meant. Let me rephrase to "easiest workaround".

hoshsadiq commented 6 years ago

Not having a version constraint doesn't work either:

package: company/team/myapp
testImport:
- package: github.com/imdario/mergo

resulting in the following error

[INFO]  Replacing existing vendor dependencies
[ERROR] Failed to generate lock file: Generating lock produced conflicting versions of github.com/imdario/mergo. import (6633656539c1639d9d78127b7d47c622b5d7b6dc), testImport ()