Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use local versions of glide dependencies?

I'm working on a Go project that uses Glide for dependency management. I need to make changes to the project, but also to several dependencies used by the project. I need to test these changes together, before committing the alterations to each project separately.

How can I tell Glide (or Go) to use local versions of these projects (e.g. found in $GOPATH/src/...) rather than pulling down something and stuffing it in the vendor directory)?

To give an example:

  • github.com/hyperledger/burrow depends on:
  • github.com/tendermint/tendermint, which depends on:
  • github.com/tendermint/go-crypto

I need to make some changes spanning all three projects. I want to test the changes by executing things in the burrow project, but I need it to execute my development versions of tendermint and go-crypto, which I have locally.

like image 590
Duncan Jones Avatar asked Jun 28 '17 12:06

Duncan Jones


People also ask

How do I check Glide version?

glide --version Print the version and exit.

What is Glide command?

Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google.

What is Glide Yaml?

yaml File. The glide. yaml file contains information about the project and the dependent packages. Here the elements of the glide.


2 Answers

If you want to test the dependencies under '$GOPATH/src/...' just temporally remove every glide file in the root of your project (glide.yaml, glide.lock,etc...). Then you can put back those files if you need to use 'vendor' dependencies again.

Update 1

I was looking for the same solution for my projects then I figured out that glide documentation specifies an extra useful parameter on glide.yaml for imports. According to the official documentation:

repo: If the package name isn't the repo location or this is a private repository it can go here. The package will be checked out from the repo and put where the package name specifies. This allows using forks.

In that case you just push your code somewhere (GitHub or Gitlab for private repos of your $GOPATH/src/github.com/hyperledger/burrow I guess) then edit your glide.yaml:

- package: github.com/tendermint/tendermint <-- vendor name dependencies
  repo:    github.com/myrepo/tendermint   <-- your remote fork
  version: vx.x.x or your sha commit code

In this way you can switch from your official version to your fork and make your tests. To turn back to your official version just remove or comment repo and version attributes:

- package: github.com/tendermint/tendermint <-- vendor name dependencies
#  repo:    github.com/myrepo/tendermint   <-- your remote fork
#  version: vx.x.x or your sha commit code

I'm testing my forks in this way now and you don't need to change your import paths into your code, hope this helps.

Update 2

Another useful way is to use glide mirror:

Mirrors provide the ability to replace a repo location with another location that's a mirror of the original. This is useful when you want to have a cache for your continuous integration (CI) system or if you want to work on a dependency in a local location.

I guess this one is the best solution, for example, on command line type:

$ glide mirror set github.com/tendermint/tendermint file:///User/yourname/Gospace/src/github.com/tendermint/tendermint

This will create a mirror.yaml in your GLIDE_HOME (if not exists then will be placed under your $USER/.glide folder). Now you can test your local version (under GOPATH) without fork your project (as I wrote above). Once you finished your tests just remove it:

$ glide mirror remove github.com/tendermint/tendermint
like image 184
Alejandro Alvarado Avatar answered Sep 17 '22 14:09

Alejandro Alvarado


Given the Go vendoring is first looking up packages in your project root /vendor folder and when not found then in the GOPATH and that Glide installs your dependencies to the /vendor folder means that you can just set up your project with glide install, then manually remove the dependencies that have been locally modified (or you are going to modify) in their local installations from your project's /vendor folder and Go vendoring will then pick your locally modified versions found under GOPATH.

Once you have tested everything, you first have to commit all the modified dependencies and then head back to your project and modify the glide.yaml file to use the new versions of these dependencies.

This should work.

like image 20
shadyyx Avatar answered Sep 19 '22 14:09

shadyyx