github.com/aca02djr/gb@v0.4.1/project.go (about) 1 package gb 2 3 import ( 4 "path/filepath" 5 ) 6 7 // Project represents a gb project. A gb project has a simlar layout to 8 // a $GOPATH workspace. Each gb project has a standard directory layout 9 // starting at the project root, which we'll refer too as $PROJECT. 10 // 11 // $PROJECT/ - the project root 12 // $PROJECT/src/ - base directory for the source of packages 13 // $PROJECT/bin/ - base directory for the compiled binaries 14 type Project struct { 15 rootdir string 16 srcdirs []Srcdir 17 } 18 19 func SourceDir(root string) func(*Project) { 20 return func(p *Project) { 21 p.srcdirs = append(p.srcdirs, Srcdir{Root: root}) 22 } 23 } 24 25 func NewProject(root string, options ...func(*Project)) *Project { 26 proj := Project{ 27 rootdir: root, 28 } 29 30 for _, opt := range options { 31 opt(&proj) 32 } 33 34 return &proj 35 } 36 37 // Pkgdir returns the path to precompiled packages. 38 func (p *Project) Pkgdir() string { 39 return filepath.Join(p.rootdir, "pkg") 40 } 41 42 // Projectdir returns the path root of this project. 43 func (p *Project) Projectdir() string { 44 return p.rootdir 45 } 46 47 // Srcdirs returns the path to the source directories. 48 // The first source directory will always be 49 // filepath.Join(Projectdir(), "src") 50 // but there may be additional directories. 51 func (p *Project) Srcdirs() []string { 52 var dirs []string 53 for _, s := range p.srcdirs { 54 dirs = append(dirs, s.Root) 55 } 56 return dirs 57 } 58 59 // Bindir returns the path for compiled programs. 60 func (p *Project) Bindir() string { 61 return filepath.Join(p.rootdir, "bin") 62 }