forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
64 lines (56 loc) · 1.69 KB
/
project.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
package gb
import (
"path/filepath"
)
// Project represents a gb project. A gb project has a simlar layout to
// a $GOPATH workspace. Each gb project has a standard directory layout
// starting at the project root, which we'll refer too as $PROJECT.
//
// $PROJECT/ - the project root
// $PROJECT/.gogo/ - used internally by gogo and identifies
// the root of the project.
// $PROJECT/src/ - base directory for the source of packages
// $PROJECT/bin/ - base directory for the compiled binaries
type Project struct {
rootdir string
srcdirs []Srcdir
}
func togopath(srcdirs []string) string {
var s []string
for _, srcdir := range srcdirs {
s = append(s, filepath.Dir(srcdir))
}
return joinlist(s)
}
func NewProject(root string) *Project {
return &Project{
rootdir: root,
srcdirs: []Srcdir{
{Root: filepath.Join(root, "src")},
{Root: filepath.Join(root, "vendor", "src")},
},
}
}
// Pkgdir returns the path to precompiled packages.
func (p *Project) Pkgdir() string {
return filepath.Join(p.rootdir, "pkg")
}
// Projectdir returns the path root of this project.
func (p *Project) Projectdir() string {
return p.rootdir
}
// Srcdirs returns the path to the source directories.
// The first source directory will always be
// filepath.Join(Projectdir(), "src")
// but there may be additional directories.
func (p *Project) Srcdirs() []string {
var dirs []string
for _, s := range p.srcdirs {
dirs = append(dirs, s.Root)
}
return dirs
}
// Bindir returns the path for compiled programs.
func (p *Project) Bindir() string {
return filepath.Join(p.rootdir, "bin")
}