forked from golang/dep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.go
107 lines (87 loc) · 2.58 KB
/
result.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gps
import (
"fmt"
"os"
"path/filepath"
)
// A Solution is returned by a solver run. It is mostly just a Lock, with some
// additional methods that report information about the solve run.
type Solution interface {
Lock
// The name of the ProjectAnalyzer used in generating this solution.
AnalyzerName() string
// The version of the ProjectAnalyzer used in generating this solution.
AnalyzerVersion() int
// The name of the Solver used in generating this solution.
SolverName() string
// The version of the Solver used in generating this solution.
SolverVersion() int
Attempts() int
}
type solution struct {
// A list of the projects selected by the solver.
p []LockedProject
// The number of solutions that were attempted
att int
// The hash digest of the input opts
hd []byte
// The analyzer info
analyzerInfo ProjectAnalyzerInfo
// The solver used in producing this solution
solv Solver
}
// WriteDepTree takes a basedir and a Lock, and exports all the projects
// listed in the lock to the appropriate target location within the basedir.
//
// If the goal is to populate a vendor directory, basedir should be the absolute
// path to that vendor directory, not its parent (a project root, typically).
//
// It requires a SourceManager to do the work, and takes a flag indicating
// whether or not to strip vendor directories contained in the exported
// dependencies.
func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool) error {
if l == nil {
return fmt.Errorf("must provide non-nil Lock to WriteDepTree")
}
err := os.MkdirAll(basedir, 0777)
if err != nil {
return err
}
// TODO(sdboyer) parallelize
for _, p := range l.Projects() {
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))
err = sm.ExportProject(p.Ident(), p.Version(), to)
if err != nil {
removeAll(basedir)
return fmt.Errorf("error while exporting %s: %s", p.Ident().ProjectRoot, err)
}
if sv {
filepath.Walk(to, stripVendor)
}
}
return nil
}
func (r solution) Projects() []LockedProject {
return r.p
}
func (r solution) Attempts() int {
return r.att
}
func (r solution) InputHash() []byte {
return r.hd
}
func (r solution) AnalyzerName() string {
return r.analyzerInfo.Name
}
func (r solution) AnalyzerVersion() int {
return r.analyzerInfo.Version
}
func (r solution) SolverName() string {
return r.solv.Name()
}
func (r solution) SolverVersion() int {
return r.solv.Version()
}