forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
62 lines (52 loc) · 1.5 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
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/src/ - base directory for the source of packages
// $PROJECT/bin/ - base directory for the compiled binaries
type Project struct {
rootdir string
srcdirs []Srcdir
}
func SourceDir(root string) func(*Project) {
return func(p *Project) {
p.srcdirs = append(p.srcdirs, Srcdir{Root: root})
}
}
func NewProject(root string, options ...func(*Project)) *Project {
proj := Project{
rootdir: root,
}
for _, opt := range options {
opt(&proj)
}
return &proj
}
// 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")
}