github.com/mfycheng/glide@v0.11.2-0.20160818232903-be8a502f4bc4/action/install.go (about)

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