-
Notifications
You must be signed in to change notification settings - Fork 34
/
handle_install.go
92 lines (76 loc) · 1.68 KB
/
handle_install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"strings"
"github.com/reconquest/karma-go"
)
func handleInstall(recursive bool, withTests bool,
dependencies []string) error {
imports, err := parseImports(recursive, withTests)
if err != nil {
return err
}
installAll := len(dependencies) == 0
if installAll {
dependencies = imports
}
submodules, err := getVendorSubmodules()
if err != nil {
return err
}
added := 0
for _, dependency := range dependencies {
parts := strings.Split(dependency, "=")
if len(parts) > 2 {
return fmt.Errorf("too many `=` delimiters: %s", dependency)
}
var version string
if len(parts) == 2 {
dependency, version = parts[0], parts[1]
}
if !installAll {
found := false
for _, importpath := range imports {
// there is HasPrefix for handling subpackages
if strings.HasPrefix(importpath, dependency) {
found = true
break
}
}
if !found {
return fmt.Errorf("unknown dependency: %s", dependency)
}
}
vendored := false
for submodule := range submodules {
if dependency == submodule {
vendored = true
break
}
}
if vendored {
logger.Debugf("skipping %s, already vendored", dependency)
continue
}
logger.Infof("adding submodule for %s", dependency)
errs := addVendorSubmodule(dependency, version)
if errs != nil {
top := fmt.Errorf("unable to add submodule for %s", dependency)
for _, err := range errs {
top = karma.Push(top, err)
}
return top
}
added++
}
if added > 0 {
if added == 1 {
logger.Infof("added 1 submodule")
} else {
logger.Infof("added %d submodules", added)
}
} else {
logger.Infof("all dependencies already vendored\n")
}
return nil
}