github.com/aca02djr/gb@v0.4.1/gb.go (about) 1 // Package gb is a tool kit for building Go packages and programs. 2 // 3 // The executable, cmd/gb, is located in the respective subdirectory 4 // along with several plugin programs. 5 package gb 6 7 import ( 8 "go/build" 9 "os" 10 "path/filepath" 11 ) 12 13 var releaseTags = build.Default.ReleaseTags 14 15 // Toolchain represents a standardised set of command line tools 16 // used to build and test Go programs. 17 type Toolchain interface { 18 Gc(pkg *Package, searchpaths []string, importpath, srcdir, outfile string, files []string) error 19 Asm(pkg *Package, srcdir, ofile, sfile string) error 20 Pack(pkg *Package, afiles ...string) error 21 Ld(*Package, []string, string, string) error 22 Cc(pkg *Package, ofile string, cfile string) error 23 24 // compiler returns the location of the compiler for .go source code 25 compiler() string 26 27 // linker returns the location of the linker for this toolchain 28 linker() string 29 } 30 31 // Actions and Tasks. 32 // 33 // Actions and Tasks allow gb to separate the role of describing the 34 // order in which work will be done, from the work itself. 35 // Actions are the former, they describe the graph of dependencies 36 // between actions, and thus the work to be done. By traversing the action 37 // graph, we can do the work, executing Tasks in a sane order. 38 // 39 // Tasks describe the work to be done, without being concerned with 40 // the order in which the work is done -- that is up to the code that 41 // places Tasks into actions. Tasks also know more intimate details about 42 // filesystems, processes, file lists, etc, that Actions do not. 43 // 44 // Action graphs (they are not strictly trees as branchs converge on base actions) 45 // contain only work to be performed, there are no Actions with empty Tasks 46 // or Tasks which do no work. 47 // 48 // Actions are executed by Executors, but can also be transformed, mutated, 49 // or even graphed. 50 51 // An Action describes a task to be performed and a set 52 // of Actions that the task depends on. 53 type Action struct { 54 55 // Name describes the action. 56 Name string 57 58 // Deps identifies the Actions that this Action depends. 59 Deps []*Action 60 61 // Run identifies the task that this action represents. 62 Run func() error 63 } 64 65 func mkdir(path string) error { 66 return os.MkdirAll(path, 0755) 67 } 68 69 // stripext strips the extension from a filename. 70 // The extension is defined by filepath.Ext. 71 func stripext(path string) string { 72 return path[:len(path)-len(filepath.Ext(path))] 73 } 74 75 func relImportPath(root, path string) (string, error) { 76 if isRel(path) { 77 return filepath.Rel(root, path) 78 } 79 return path, nil 80 } 81 82 // isRel returns if an import path is relative or absolute. 83 func isRel(path string) bool { 84 // TODO(dfc) should this be strings.StartsWith(".") 85 return path == "." 86 }