Skip to content

Commit 0d5560d

Browse files
committed
Support for the ./vendor directory
closes #20
1 parent 9abc97b commit 0d5560d

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ gdm
77
# Folders
88
_obj
99
_test
10+
vendor
1011

1112
# Architecture specific extensions/prefixes
1213
*.[568vq]

Godeps

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
golang.org/x/tools 6f233b96dfbc53e33b302e31b88814cf74697ff6
1+
golang.org/x/tools 3b1faeda9afbcba128c2d794b38ffe7982141139

imports.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ type Import struct {
3232

3333
// RestoreImport takes the import and restores it at the given GOPATH.
3434
// There are four steps to this:
35-
// 1. cd $GOPATH/src/<import_path>
35+
// 1. cd $CHECKOUT_PATH/<import_path>
3636
// 2. Checkout default branch (ie, git checkout master)
3737
// 3. Download changes (ie, git pull --ff-only)
3838
// 4. Checkout revision (ie, git checkout 759e96ebaffb01c3cba0e8b129ef29f56507b323)
39-
func (i *Import) RestoreImport(gopath string) error {
39+
func (i *Import) RestoreImport(path string) error {
4040
vcs.ShowCmd = i.Verbose
41-
fullpath := filepath.Join(gopath, "src", i.ImportPath)
41+
fullpath := filepath.Join(path, i.ImportPath)
4242
fmt.Printf("> Restoring %s to %s\n", fullpath, i.Rev)
4343

4444
// If the repo doesn't exist already, create it
@@ -49,7 +49,7 @@ func (i *Import) RestoreImport(gopath string) error {
4949
}
5050

5151
// Create parent directory
52-
rootpath := filepath.Join(gopath, "src", i.Repo.Root)
52+
rootpath := filepath.Join(path, i.Repo.Root)
5353
if err = os.MkdirAll(rootpath, os.ModePerm); err != nil {
5454
return fmt.Errorf("Could not create parent directory %s for repo %s\n",
5555
rootpath, fullpath)

main.go

+21-20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Usage:
3232
3333
The commands are:
3434
35+
vendor Check out revisions defined in Godeps file in ./vendor directory.
3536
restore Check out revisions defined in Godeps file to $GOPATH.
3637
save Saves currently checked-out dependencies from $GOPATH to Godeps file.
3738
brew Outputs homebrew go_resource entries to stdout.
@@ -65,13 +66,17 @@ func main() {
6566

6667
switch args[0] {
6768
case "save", "bootstrap":
68-
splash(wd, gopath)
69+
splash(wd, "NA", gopath)
6970
save(wd, gopath, verbose)
71+
case "vendor":
72+
path := filepath.Join(wd, "vendor")
73+
splash(wd, path, gopath)
74+
restore(wd, path, verbose)
7075
case "restore", "get", "sync", "checkout":
71-
splash(wd, gopath)
72-
restore(wd, gopath, verbose)
76+
path := filepath.Join(gopath, "src")
77+
splash(wd, path, gopath)
78+
restore(wd, path, verbose)
7379
case "brew", "homebrew":
74-
splash(wd, gopath)
7580
homebrew(wd, gopath, verbose)
7681
case "version":
7782
fmt.Printf("gdm - version %s\n", Version)
@@ -80,10 +85,11 @@ func main() {
8085
}
8186
}
8287

83-
func splash(wd, gopath string) {
88+
func splash(wd, path, gopath string) {
8489
fmt.Println("======= Go Dependency Manager =======")
85-
fmt.Println("= working dir:", wd)
86-
fmt.Println("= GOPATH: ", gopath)
90+
fmt.Println("= working dir: ", wd)
91+
fmt.Println("= checkout dir:", path)
92+
fmt.Println("= GOPATH: ", gopath)
8793
fmt.Println("=====================================")
8894
}
8995

@@ -121,12 +127,7 @@ func getGoPath(wd string) (string, error) {
121127
}
122128

123129
func homebrew(wd, gopath string, verbose bool) {
124-
imports, err := ImportsFromPath(wd, gopath, verbose)
125-
if err != nil {
126-
fmt.Printf("Fatal error: %s", err)
127-
os.Exit(1)
128-
}
129-
130+
imports := ImportsFromFile(filepath.Join(wd, DepsFile))
130131
fmt.Println()
131132
for _, i := range imports {
132133
fmt.Printf(" go_resource \"%s\" do\n", i.ImportPath)
@@ -162,24 +163,24 @@ func save(wd, gopath string, verbose bool) {
162163
w.Flush()
163164
}
164165

165-
func restore(wd, gopath string, verbose bool) {
166+
func restore(wd, path string, verbose bool) {
166167
imports := ImportsFromFile(filepath.Join(wd, DepsFile))
167168
if Parallel {
168-
restoreParallel(imports, gopath, verbose)
169+
restoreParallel(imports, path, verbose)
169170
} else {
170-
restoreSerial(imports, gopath, verbose)
171+
restoreSerial(imports, path, verbose)
171172
}
172173
}
173174

174-
func restoreParallel(imports []*Import, gopath string, verbose bool) {
175+
func restoreParallel(imports []*Import, path string, verbose bool) {
175176
var wg sync.WaitGroup
176177
wg.Add(len(imports))
177178
errC := make(chan error, len(imports))
178179
for _, i := range imports {
179180
i.Verbose = verbose
180181
go func(I *Import) {
181182
defer wg.Done()
182-
err := I.RestoreImport(gopath)
183+
err := I.RestoreImport(path)
183184
if err != nil {
184185
errC <- err
185186
}
@@ -199,9 +200,9 @@ func restoreParallel(imports []*Import, gopath string, verbose bool) {
199200
}
200201
}
201202

202-
func restoreSerial(imports []*Import, gopath string, verbose bool) {
203+
func restoreSerial(imports []*Import, path string, verbose bool) {
203204
for _, i := range imports {
204205
i.Verbose = verbose
205-
i.RestoreImport(gopath)
206+
i.RestoreImport(path)
206207
}
207208
}

0 commit comments

Comments
 (0)