github.com/MealCraft/glide@v0.13.4/action/install.go (about)

     1  package action
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/Masterminds/glide/cache"
     7  	"github.com/Masterminds/glide/cfg"
     8  	"github.com/Masterminds/glide/msg"
     9  	gpath "github.com/Masterminds/glide/path"
    10  	"github.com/Masterminds/glide/repo"
    11  )
    12  
    13  // Install installs a vendor directory based on an existing Glide configuration.
    14  func Install(installer *repo.Installer, stripVendor bool) {
    15  	cache.SystemLock()
    16  
    17  	base := "."
    18  	// Ensure GOPATH
    19  	EnsureGopath()
    20  	EnsureVendorDir()
    21  	conf := EnsureConfig()
    22  
    23  	// Lockfile exists
    24  	if !gpath.HasLock(base) {
    25  		msg.Info("Lock file (glide.lock) does not exist. Performing update.")
    26  		Update(installer, false, stripVendor)
    27  		return
    28  	}
    29  	// Load lockfile
    30  	lock, err := cfg.ReadLockFile(filepath.Join(base, gpath.LockFile))
    31  	if err != nil {
    32  		msg.Die("Could not load lockfile.")
    33  	}
    34  	// Verify lockfile hasn't changed
    35  	hash, err := conf.Hash()
    36  	if err != nil {
    37  		msg.Die("Could not load lockfile.")
    38  	} else if hash != lock.Hash {
    39  		msg.Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'")
    40  	}
    41  
    42  	// Install
    43  	newConf, err := installer.Install(lock, conf)
    44  	if err != nil {
    45  		msg.Die("Failed to install: %s", err)
    46  	}
    47  
    48  	msg.Info("Setting references.")
    49  
    50  	// Set reference
    51  	if err := repo.SetReference(newConf, installer.ResolveTest); err != nil {
    52  		msg.Die("Failed to set references: %s (Skip to cleanup)", err)
    53  	}
    54  
    55  	err = installer.Export(newConf)
    56  	if err != nil {
    57  		msg.Die("Unable to export dependencies to vendor directory: %s", err)
    58  	}
    59  
    60  	if stripVendor {
    61  		msg.Info("Removing nested vendor and Godeps/_workspace directories...")
    62  		err := gpath.StripVendor()
    63  		if err != nil {
    64  			msg.Err("Unable to strip vendor directories: %s", err)
    65  		}
    66  	}
    67  }