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

Add ability to remove nested vendor and Godeps/_workspace directories #339

Merged
merged 5 commits into from
Mar 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install: build
install -m 755 ./glide ${DESTDIR}/usr/local/bin/glide

test:
go test . ./gb ./path ./action ./tree ./util ./godep ./gpm ./cfg ./dependency ./importer ./msg ./repo
go test . ./gb ./path ./action ./tree ./util ./godep ./godep/strip ./gpm ./cfg ./dependency ./importer ./msg ./repo

clean:
rm -f ./glide.test
Expand Down
14 changes: 13 additions & 1 deletion action/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/Masterminds/glide/cfg"
"github.com/Masterminds/glide/godep"
"github.com/Masterminds/glide/msg"
gpath "github.com/Masterminds/glide/path"
"github.com/Masterminds/glide/repo"
Expand All @@ -15,7 +16,7 @@ import (
// Get fetches one or more dependencies and installs.
//
// This includes resolving dependency resolution and re-generating the lock file.
func Get(names []string, installer *repo.Installer, insecure, skipRecursive, strip bool) {
func Get(names []string, installer *repo.Installer, insecure, skipRecursive, strip, stripVendor bool) {
base := gpath.Basepath()
EnsureGopath()
EnsureVendorDir()
Expand Down Expand Up @@ -75,6 +76,9 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str
}
if !skipRecursive {
// Write lock
if stripVendor {
confcopy = godep.RemoveGodepSubpackages(confcopy)
}
writeLock(conf, confcopy, base)
} else {
msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated")
Expand All @@ -84,6 +88,14 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str
msg.Info("Removing version control data from vendor directory...")
gpath.StripVcs()
}

if stripVendor {
msg.Info("Removing nested vendor and Godeps/_workspace directories...")
err := gpath.StripVendor()
if err != nil {
msg.Err("Unable to strip vendor directories: %s", err)
}
}
}

func writeLock(conf, confcopy *cfg.Config, base string) {
Expand Down
12 changes: 10 additions & 2 deletions action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// Install installs a vendor directory based on an existing Glide configuration.
func Install(installer *repo.Installer, strip bool) {
func Install(installer *repo.Installer, strip, stripVendor bool) {
base := "."
// Ensure GOPATH
EnsureGopath()
Expand All @@ -22,7 +22,7 @@ func Install(installer *repo.Installer, strip bool) {
// Lockfile exists
if !gpath.HasLock(base) {
msg.Info("Lock file (glide.lock) does not exist. Performing update.")
Update(installer, false, strip)
Update(installer, false, strip, stripVendor)
return
}
// Load lockfile
Expand Down Expand Up @@ -63,6 +63,14 @@ func Install(installer *repo.Installer, strip bool) {
msg.Info("Removing version control data from vendor directory...")
gpath.StripVcs()
}

if stripVendor {
msg.Info("Removing nested vendor and Godeps/_workspace directories...")
err := gpath.StripVendor()
if err != nil {
msg.Err("Unable to strip vendor directories: %s", err)
}
}
}

// LoadLockfile loads the contents of a glide.lock file.
Expand Down
15 changes: 14 additions & 1 deletion action/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (

"github.com/Masterminds/glide/cfg"
"github.com/Masterminds/glide/dependency"
"github.com/Masterminds/glide/godep"
"github.com/Masterminds/glide/msg"
gpath "github.com/Masterminds/glide/path"
"github.com/Masterminds/glide/repo"
)

// Update updates repos and the lock file from the main glide yaml.
func Update(installer *repo.Installer, skipRecursive, strip bool) {
func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) {
base := "."
EnsureGopath()
EnsureVendorDir()
Expand Down Expand Up @@ -73,6 +74,10 @@ func Update(installer *repo.Installer, skipRecursive, strip bool) {
// from the project. A removed dependency should warn and an added dependency
// should be added to the glide.yaml file. See issue #193.

if stripVendor {
confcopy = godep.RemoveGodepSubpackages(confcopy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codewise, do you want to hardcode anything godep in a non-godep dir? If it were me, I would do something like:

main():

plugins := []ToolPlugin{NewGoToolPlugin()}
plugins = append(plugins, godep.ProbePlugins()...)
plugins = append(plugins, gom.ProbePlugins()...)
// etc

...where ToolPlugin is an interface. One of the methods on ToolPlugin might be RemoveVendoredJunk(). So here you would just loop over all plugins and have them remove their own vendored junk.

Something like that...(I am a big fan of opaque plugins)

}

if !skipRecursive {
// Write lock
hash, err := conf.Hash()
Expand All @@ -94,4 +99,12 @@ func Update(installer *repo.Installer, skipRecursive, strip bool) {
msg.Info("Removing version control data from vendor directory...")
gpath.StripVcs()
}

if stripVendor {
msg.Info("Removing nested vendor and Godeps/_workspace directories...")
err := gpath.StripVendor()
if err != nil {
msg.Err("Unable to strip vendor directories: %s", err)
}
}
}
57 changes: 49 additions & 8 deletions glide.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,18 @@ func commands() []cli.Command {
When adding a new dependency Glide will perform an update to work out the
the versions to use from the dependency tree. This will generate an updated
glide.lock file with specific locked versions to use.
`,

If you are storing the outside dependencies in your version control system
(VCS), also known as vendoring, there are a few flags that may be useful.
The '--update-vendored' flag will cause Glide to update packages when VCS
information is unavailable. This can be used with the '--strip-vcs' flag which
will strip VCS data found in the vendor directory. This is useful for
removing VCS data from transitive dependencies and initial setups. The
'--strip-vendor' flag will remove any nested 'vendor' folders and
'Godeps/_workspace' folders after an update (along with undoing any Godep
import rewriting). Note, The Godeps specific functionality is deprecated and
will be removed when most Godeps users have migrated to using the vendor
folder.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "insecure",
Expand Down Expand Up @@ -211,8 +222,16 @@ func commands() []cli.Command {
Name: "strip-vcs, s",
Usage: "Removes version control metada (e.g, .git directory) from the vendor folder.",
},
cli.BoolFlag{
Name: "strip-vendor, v",
Usage: "Removes nested vendor and Godeps/_workspace directories. Requires --strip-vcs.",
},
},
Action: func(c *cli.Context) {
if c.Bool("strip-vendor") && !c.Bool("strip-vcs") {
msg.Die("--strip-vendor cannot be used without --strip-vcs")
}

if len(c.Args()) < 1 {
fmt.Println("Oops! Package name is required.")
os.Exit(1)
Expand All @@ -232,7 +251,7 @@ func commands() []cli.Command {
inst.ResolveAllFiles = c.Bool("all-dependencies")
packages := []string(c.Args())
insecure := c.Bool("insecure")
action.Get(packages, inst, insecure, c.Bool("no-recursive"), c.Bool("strip-vcs"))
action.Get(packages, inst, insecure, c.Bool("no-recursive"), c.Bool("strip-vcs"), c.Bool("strip-vendor"))
},
},
{
Expand Down Expand Up @@ -412,8 +431,16 @@ Example:
Name: "strip-vcs, s",
Usage: "Removes version control metada (e.g, .git directory) from the vendor folder.",
},
cli.BoolFlag{
Name: "strip-vendor, v",
Usage: "Removes nested vendor and Godeps/_workspace directories. Requires --strip-vcs.",
},
},
Action: func(c *cli.Context) {
if c.Bool("strip-vendor") && !c.Bool("strip-vcs") {
msg.Die("--strip-vendor cannot be used without --strip-vcs")
}

installer := repo.NewInstaller()
installer.Force = c.Bool("force")
installer.UseCache = c.Bool("cache")
Expand All @@ -423,7 +450,7 @@ Example:
installer.Home = gpath.Home()
installer.DeleteUnused = c.Bool("deleteOptIn")

action.Install(installer, c.Bool("strip-vcs"))
action.Install(installer, c.Bool("strip-vcs"), c.Bool("strip-vendor"))
},
},
{
Expand All @@ -446,10 +473,17 @@ Example:
It will create a glide.yaml file from the Godeps data, and then update. This
has no effect if '--no-recursive' is set.

If the '--update-vendored' flag (aliased to '-u') is present vendored
dependencies, stored in your projects VCS repository, will be updated. This
works by removing the old package, checking out an the repo and setting the
version, and removing the VCS directory.
If you are storing the outside dependencies in your version control system
(VCS), also known as vendoring, there are a few flags that may be useful.
The '--update-vendored' flag will cause Glide to update packages when VCS
information is unavailable. This can be used with the '--strip-vcs' flag which
will strip VCS data found in the vendor directory. This is useful for
removing VCS data from transitive dependencies and initial setups. The
'--strip-vendor' flag will remove any nested 'vendor' folders and
'Godeps/_workspace' folders after an update (along with undoing any Godep
import rewriting). Note, The Godeps specific functionality is deprecated and
will be removed when most Godeps users have migrated to using the vendor
folder.

By default, packages that are discovered are considered transient, and are
not stored in the glide.yaml file. The --file=NAME.yaml flag allows you
Expand Down Expand Up @@ -500,8 +534,15 @@ Example:
Name: "strip-vcs, s",
Usage: "Removes version control metada (e.g, .git directory) from the vendor folder.",
},
cli.BoolFlag{
Name: "strip-vendor, v",
Usage: "Removes nested vendor and Godeps/_workspace directories. Requires --strip-vcs.",
},
},
Action: func(c *cli.Context) {
if c.Bool("strip-vendor") && !c.Bool("strip-vcs") {
msg.Die("--strip-vendor cannot be used without --strip-vcs")
}

if c.Bool("resolve-current") {
util.ResolveCurrent = true
Expand All @@ -518,7 +559,7 @@ Example:
installer.Home = gpath.Home()
installer.DeleteUnused = c.Bool("deleteOptIn")

action.Update(installer, c.Bool("no-recursive"), c.Bool("strip-vcs"))
action.Update(installer, c.Bool("no-recursive"), c.Bool("strip-vcs"), c.Bool("strip-vendor"))
},
},
{
Expand Down
27 changes: 27 additions & 0 deletions godep/godep.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"strings"

"github.com/Masterminds/glide/cfg"
"github.com/Masterminds/glide/msg"
Expand Down Expand Up @@ -96,3 +97,29 @@ func Parse(dir string) ([]*cfg.Dependency, error) {

return buf, nil
}

// RemoveGodepSubpackages strips subpackages from a cfg.Config dependencies that
// contain "Godeps/_workspace/src" as part of the path.
func RemoveGodepSubpackages(c *cfg.Config) *cfg.Config {
for _, d := range c.Imports {
n := []string{}
for _, v := range d.Subpackages {
if !strings.HasPrefix(v, "Godeps/_workspace/src") {
n = append(n, v)
}
}
d.Subpackages = n
}

for _, d := range c.DevImports {
n := []string{}
for _, v := range d.Subpackages {
if !strings.HasPrefix(v, "Godeps/_workspace/src") {
n = append(n, v)
}
}
d.Subpackages = n
}

return c
}
Loading