Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Gopkg.toml in subdirectory of git project should not try to vendor other directories in same git project #2116

Closed
coriolinus opened this issue Mar 4, 2019 · 7 comments

Comments

@coriolinus
Copy link

Given a repository which contains a cmd folder which builds some number of executables, and an arbitrarily large number of other folders outside of cmd intended to be imported by other packages as libraries. In order to follow the principle that binaries handle vendoring, and libraries do not, it is desirable to always run dep ensure within the cmd folder. This ensures that Gopkg.* and vendor all appear there, so that external applications may depend on the libraries without encountering the constraints of the binaries.

dep handles this case poorly: the library portions of the repo, because they are not subfolders of the CWD in which dep is being run, are treated as external libraries and vendored. This is not desirable: a single repository should be considered to always be up-to-date with itself.

Example

$ tree -L 1
Mon Mar  4 12:09:11 CET 2019
.
├── cmd
├── crypto
├── libs
└── version

cmd contains a number of commands. crypto, libs, and version contain libraries we desire to export to other packages. When Gopkg.toml exists within cmd/, everything in those libraries is considered an external package, and must have a version specified. This is not desirable: by default, the most recent tagged version will be vendored. This does not allow for continued development on a dev branch.

Putting Gopkg.toml at the repo root fixes the problem for this package, but it makes things worse for packages downstream, using these libraries: whatever their constraints are must now also coexist with the constraints of this project. If this project has a command which has a constraint incompatible with the downstream project's constraint set, then they cannot solve their dependency graph, even if that constraint doesn't apply to the library portion of the code at all.

Desired fix

dep currently assumes that everything in the directory containing Gopkg.toml and its subfolders is a single project, always up-to-date with itself. These folders are therefore not vendored. This assumption should be broadened: everything within a single repository should be considered a single project, always up-to-date with itself, and excluded from vendoring. The repository root can be found very simply in the most common repositories:

  • git rev-parse --show-toplevel
  • hg root
  • etc

What version of dep are you using (dep version)?

$ dep version
Mon Mar  4 11:57:30 CET 2019
dep:
 version     : v0.5.0
 build date  : 2018-08-16
 git hash    : 224a564
 go version  : go1.10.3
 go compiler : gc
 platform    : darwin/amd64
 features    : ImportDuringSolve=false
@kevinburke
Copy link
Collaborator

I believe this is the same issue as #1775 and #1768. Suggestion in #1775 is to use an ignored flag in Gopkg.toml to ignore the current library.

@coriolinus
Copy link
Author

This may be the same issue, but that fix doesn't work: using an ignored flag, dep complains that there are no non-ignored go files in the repo, and refuses to continue.

@kevinburke
Copy link
Collaborator

Does the ignored flag cover the cmd subdirectory as well?

@coriolinus
Copy link
Author

Yes--I'm not sure how to write an ignored flag which covers all subdirectories (many more than in the example) except the cmd directory without enumerating them all, which is a pain. Hence the feature request: at best, the ignored flag is a workaround, not desired behavior.

@kevinburke
Copy link
Collaborator

One common solution is to nest libraries under a src or lib subdirectory.

I'm open to making the change you suggest but not sure if/how soon you could expect to see it, or how many users that would break.

@coriolinus
Copy link
Author

coriolinus commented Mar 4, 2019 via email

@kevinburke kevinburke changed the title dep should exclude the entire working repository from vendoring Gopkg.toml in subdirectory of git project should not try to vendor other directories in same git project Mar 9, 2019
@mvdan
Copy link
Member

mvdan commented Sep 4, 2020

Dep was officially deprecated earlier this year, and the proposal to archive this repository was accepted. As such, I'm closing outstanding issues before archiving the repository. For any further comments, please use the proposal thread on the Go issue tracker. Thanks!

@mvdan mvdan closed this as completed Sep 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants