diff options
-rw-r--r-- | make.go | 96 | ||||
-rw-r--r-- | maker/command.go | 2 | ||||
-rw-r--r-- | maker/config.go | 45 | ||||
-rw-r--r-- | maker/copy.go | 6 | ||||
-rw-r--r-- | maker/entity.go | 3 | ||||
-rw-r--r-- | maker/file.go | 64 | ||||
-rw-r--r-- | maker/go.go | 34 | ||||
-rw-r--r-- | maker/path.go | 37 |
8 files changed, 151 insertions, 136 deletions
@@ -18,7 +18,6 @@ package main import ( "fmt" "os" - "path/filepath" "strings" "android.googlesource.com/platform/tools/gpu/build" @@ -32,16 +31,17 @@ const ( ) var ( - glespath = GPUPath("gfxapi/gles") - gapirpath = GPUPath("cc/gapir") - spypath = GPUPath("cc/gfxspy2/src") - spywinpath = GPUPath("cc/gfxspy2/src/windows") - spyosxpath = GPUPath("cc/gfxspy2/src/osx") - testpath = GPUPath("gfxapi/test") - glesapi = GPUPath("gfxapi/gles/gles.api") - testapi = GPUPath("gfxapi/test/gfxapi_test.api") - javacore = filepath.Join(GoPath, "../base/rpclib/src/main/java/com/android/tools/rpclib/rpccore/") - javarpc = filepath.Join(GoPath, "../adt/idea/android/src/com/android/tools/idea/editors/gfxtrace/rpc") + glespath = Path(gpusrc, "gfxapi/gles") + gapirpath = Path(gpusrc, "cc/gapir") + spypath = Path(gpusrc, "cc/gfxspy2/src") + spywinpath = Path(gpusrc, "cc/gfxspy2/src/windows") + spyosxpath = Path(gpusrc, "cc/gfxspy2/src/osx") + testpath = Path(gpusrc, "gfxapi/test") + glesapi = Path(gpusrc, "gfxapi/gles/gles.api") + testapi = Path(gpusrc, "gfxapi/test/gfxapi_test.api") + javacore = Path(Paths.Root, "../base/rpclib/src/main/java/com/android/tools/rpclib/rpccore/") + javarpc = Path(Paths.Root, "../adt/idea/android/src/com/android/tools/idea/editors/gfxtrace/rpc") + gpusrc = GoSrcPath(GPURoot) Tools struct { Embed Entity @@ -67,42 +67,42 @@ func init() { Tools.Stringer = GoInstall("golang.org/x/tools/cmd/stringer") List("tools").DependsStruct(Tools) // All the embed rules - embedRPC := Embed(GPUPath("rpc/generate")) - embedCopyright := Embed(GPUPath("tools/copyright")) - embedBinary := Embed(GPUPath("binary/generate")) + embedRPC := Embed(Path(gpusrc, "rpc/generate")) + embedCopyright := Embed(Path(gpusrc, "tools/copyright")) + embedBinary := Embed(Path(gpusrc, "binary/generate")) Creator(Tools.Rpcapi).DependsOn(embedCopyright, embedRPC) Creator(Tools.Apic).DependsOn(embedCopyright) Creator(Tools.Codergen).DependsOn(embedCopyright, embedBinary) // All the rpc rules - servicerpc := File(GPUPath("service/service.api")) - RpcApiGo(File(GPUPath("rpc/test/rpc_test.api"))) + servicerpc := File(gpusrc, "service/service.api") + RpcApiGo(File(gpusrc, "rpc/test/rpc_test.api")) RpcApiGo(servicerpc) // All the apic rules - Apic(glespath, glesapi, GPUPath("gfxapi/templates/api.go.tmpl")) - Apic(glespath, glesapi, GPUPath("gfxapi/templates/replay_writer.go.tmpl")) - Apic(glespath, glesapi, GPUPath("gfxapi/templates/schema.go.tmpl")) - Apic(glespath, glesapi, GPUPath("gfxapi/templates/state_mutator.go.tmpl")) - Apic(gapirpath, glesapi, GPUPath("gfxapi/templates/gfx_api.cpp.tmpl")) - Apic(gapirpath, glesapi, GPUPath("gfxapi/templates/gfx_api.h.tmpl")) - Apic(spypath, glesapi, GPUPath("gfxapi/templates/api_exports.cpp.tmpl")) - Apic(spypath, glesapi, GPUPath("gfxapi/templates/api_imports.cpp.tmpl")) - Apic(spypath, glesapi, GPUPath("gfxapi/templates/api_imports.h.tmpl")) - Apic(spypath, glesapi, GPUPath("gfxapi/templates/api_spy.h.tmpl")) - Apic(spypath, glesapi, GPUPath("gfxapi/templates/api_state.h.tmpl")) - Apic(spypath, glesapi, GPUPath("gfxapi/templates/api_types.h.tmpl")) - Apic(spywinpath, glesapi, GPUPath("gfxapi/templates/opengl32_exports.def.tmpl")) - Apic(spywinpath, glesapi, GPUPath("gfxapi/templates/opengl32_resolve.cpp.tmpl")) - Apic(spywinpath, glesapi, GPUPath("gfxapi/templates/opengl32_x64.asm.tmpl")) - Apic(spyosxpath, glesapi, GPUPath("gfxapi/templates/opengl_framework_exports.cpp.tmpl")) - Apic(testpath, testapi, GPUPath("gfxapi/templates/api.go.tmpl")) - Apic(testpath, testapi, GPUPath("gfxapi/templates/replay_writer.go.tmpl")) - Apic(testpath, testapi, GPUPath("gfxapi/templates/schema.go.tmpl")) - Apic(testpath, testapi, GPUPath("gfxapi/templates/state_mutator.go.tmpl")) + Apic(glespath, glesapi, Path(gpusrc, "gfxapi/templates/api.go.tmpl")) + Apic(glespath, glesapi, Path(gpusrc, "gfxapi/templates/replay_writer.go.tmpl")) + Apic(glespath, glesapi, Path(gpusrc, "gfxapi/templates/schema.go.tmpl")) + Apic(glespath, glesapi, Path(gpusrc, "gfxapi/templates/state_mutator.go.tmpl")) + Apic(gapirpath, glesapi, Path(gpusrc, "gfxapi/templates/gfx_api.cpp.tmpl")) + Apic(gapirpath, glesapi, Path(gpusrc, "gfxapi/templates/gfx_api.h.tmpl")) + Apic(spypath, glesapi, Path(gpusrc, "gfxapi/templates/api_exports.cpp.tmpl")) + Apic(spypath, glesapi, Path(gpusrc, "gfxapi/templates/api_imports.cpp.tmpl")) + Apic(spypath, glesapi, Path(gpusrc, "gfxapi/templates/api_imports.h.tmpl")) + Apic(spypath, glesapi, Path(gpusrc, "gfxapi/templates/api_spy.h.tmpl")) + Apic(spypath, glesapi, Path(gpusrc, "gfxapi/templates/api_state.h.tmpl")) + Apic(spypath, glesapi, Path(gpusrc, "gfxapi/templates/api_types.h.tmpl")) + Apic(spywinpath, glesapi, Path(gpusrc, "gfxapi/templates/opengl32_exports.def.tmpl")) + Apic(spywinpath, glesapi, Path(gpusrc, "gfxapi/templates/opengl32_resolve.cpp.tmpl")) + Apic(spywinpath, glesapi, Path(gpusrc, "gfxapi/templates/opengl32_x64.asm.tmpl")) + Apic(spyosxpath, glesapi, Path(gpusrc, "gfxapi/templates/opengl_framework_exports.cpp.tmpl")) + Apic(testpath, testapi, Path(gpusrc, "gfxapi/templates/api.go.tmpl")) + Apic(testpath, testapi, Path(gpusrc, "gfxapi/templates/replay_writer.go.tmpl")) + Apic(testpath, testapi, Path(gpusrc, "gfxapi/templates/schema.go.tmpl")) + Apic(testpath, testapi, Path(gpusrc, "gfxapi/templates/state_mutator.go.tmpl")) // The codergen rule Codergen("codergen", "--go", GPURoot+"/...") // Enum string rules - Stringer(GPUPath("binary/generate"), "Kind") - Stringer(GPUPath("log"), "Kind") + Stringer(Path(gpusrc, "binary/generate"), "Kind") + Stringer(Path(gpusrc, "log"), "Kind") // The java code generation rules Codergen("javacoders", "--java", javacore, GPURoot+"/rpc/...") RpcApi("--java", javarpc, servicerpc).Creates(Virtual("javarpc")) @@ -111,7 +111,7 @@ func init() { List("code").DependsOn("embed", "rpcapi", "apic", "codergen", "stringer") // The native code rules Apps.Gapir = Virtual("gapir") - GoRun(GPUPath("cc/build.go"), + GoRun(Path(gpusrc, "cc/build.go"), "--runtests", "--targets="+build.HostOS+",android-arm", ).Creates(Apps.Gapir).DependsOn("code") @@ -126,18 +126,14 @@ func init() { // Application launchers Command(Apps.Gapis).Creates(Virtual("gapis")).DependsOn(Apps.Gapir) // Utilties - GoRun(GPUPath("tools/clean_generated/main.go"), GPUPath("")).Creates(Virtual("clean_gpu")) + GoRun(Path(gpusrc, "tools/clean_generated/main.go"), gpusrc).Creates(Virtual("clean_gpu")) // The default rules List(Default).DependsOn("apps", "test") }) } -func GPUPath(path string) string { - return filepath.Join(GoPath, "src", GPURoot, path) -} - func Embed(path string) Entity { - out := File(filepath.Join(path, "embed.go")) + out := File(path, "embed.go") args := []string{"--out", out.Name()} files := FilesOf(path, func(i os.FileInfo) bool { return !i.IsDir() && !strings.HasSuffix(i.Name(), ".go") @@ -167,7 +163,9 @@ func Apic(path string, api string, template string) { dst := Dir(path) a := File(api) t := File(template) - deps := File(DepsPath(fmt.Sprintf("%v_%v.deps", filepath.Base(api), filepath.Base(template)))) + _, apiname := PathSplit(api) + _, templatename := PathSplit(template) + deps := File(Paths.Deps, fmt.Sprintf("%v_%v.deps", apiname, templatename)) s := Command(Tools.Apic, "template", "--dir", dst.Name(), @@ -182,9 +180,9 @@ func Codergen(name string, args ...string) { } func Stringer(path, name string) { - r := Config.RootPath - defer func() { Config.RootPath = r }() - Config.RootPath = path + r := Paths.Root + defer func() { Paths.Root = r }() + Paths.Root = path e := Virtual("") Command(Tools.Stringer, "--type", name).Creates(e) List("stringer").DependsOn(e) diff --git a/maker/command.go b/maker/command.go index a1115c779..be92f3901 100644 --- a/maker/command.go +++ b/maker/command.go @@ -33,7 +33,7 @@ var ( // with the supplied arguments. The newly created Step will be made to depend on // the binary. func Command(binary Entity, args ...string) *Step { - wd := Config.RootPath + wd := Paths.Root return NewStep(func(step *Step) error { cmd := exec.Command(binary.Name(), args...) var output bytes.Buffer diff --git a/maker/config.go b/maker/config.go index 47f3db94d..cbb5c6c05 100644 --- a/maker/config.go +++ b/maker/config.go @@ -14,7 +14,11 @@ package maker -import "path/filepath" +import ( + "log" + "os" + "path/filepath" +) var ( // Config holds the current configuration of the maker system. @@ -25,19 +29,38 @@ var ( TargetArchitecture string // TargetOS is the OS to build for. TargetOS string - // RootPath is the root directory to work in. - RootPath string // DisableParallel turns of all parallel build support. DisableParallel bool } + // Paths holds the set of path roots for the build. + Paths struct { + // The root path of the build + Root string + // The dependancy cache directory + Deps string + // The application data directory. + Data string + // The application binary directory. + Bin string + } + //GoPath is the GOPATH environment setting + GoPath []string + goTool Entity ) -// DepsPath joins the supplied path to the dependancy cache directory. -func DepsPath(path string) string { - return filepath.Join(Config.RootPath, "deps", path) -} - -// DataPath joins the supplied path to the application data directory. -func DataPath(path string) string { - return filepath.Join(Config.RootPath, "data", path) +func init() { + GoPath = filepath.SplitList(os.Getenv("GOPATH")) + if len(GoPath) == 0 { + log.Fatalf("GOPATH %q not valid", os.Getenv("GOPATH")) + } + root, err := OSPath(GoPath[0]) + if err != nil { + log.Fatalf("GOPATH %s not valid", GoPath[0]) + } + Paths.Root = root + Paths.Deps = Path(root, "deps") + Paths.Data = Path(root, "data") + Paths.Bin = Path(root, "bin") + EnvVars["PATH"] = []string{Paths.Bin} + goTool = FindTool("go") } diff --git a/maker/copy.go b/maker/copy.go index ed9fe8487..161b7c632 100644 --- a/maker/copy.go +++ b/maker/copy.go @@ -25,10 +25,8 @@ import ( // the dst entity. // The step will depend on the src, and the existance of the directory dst is // inside. -func CopyFile(dst, src interface{}) Entity { - out := File(dst) - NewStep(copyFile).Creates(out).DependsOn(File(src), DirOf(out)) - return out +func CopyFile(dst, src Entity) { + NewStep(copyFile).Creates(dst).DependsOn(src, DirOf(dst)) } func copyFile(s *Step) error { diff --git a/maker/entity.go b/maker/entity.go index 008fbb558..52fd31ab0 100644 --- a/maker/entity.go +++ b/maker/entity.go @@ -16,7 +16,6 @@ package maker import ( "log" - "path/filepath" "strings" "time" ) @@ -69,7 +68,7 @@ func FindPathEntity(name string) Entity { if e := FindEntity(name); e != nil { return e } - if abs, err := filepath.Abs(name); err == nil { + if abs, err := OSPath(name); err == nil { if e := FindEntity(abs); e != nil { return e } diff --git a/maker/file.go b/maker/file.go index 1f8d0e209..8f4b82aa9 100644 --- a/maker/file.go +++ b/maker/file.go @@ -18,52 +18,38 @@ import ( "io/ioutil" "log" "os" - "path/filepath" "time" ) -// File returns an Entity that represents a file. -// The entities name will be the absolute path of the file. -// If path is an entity already, it will be tested to make sure it is a file and -// returned. -// If it is a string, the the entity map will be checked for a matching file +// File returns an Entity that represents a file. The entities name will be the +// absolute path of the file. The entity map will be checked for a matching file // entry and if one is not found, a new one will be added and returned. -func File(path interface{}) *file { - switch path := path.(type) { - case string: - abs, err := filepath.Abs(path) - if err != nil { - log.Fatalf("%s", err) - } - e := FindEntity(abs) - if e != nil { - f, is := e.(*file) - if !is { - log.Fatalf("%s is not a file entity (%T)", abs, e) - } - return f +func File(path ...string) *file { + abs, err := OSPath(path...) + if err != nil { + log.Fatalf("%s", err) + } + e := FindEntity(abs) + if e != nil { + f, is := e.(*file) + if !is { + log.Fatalf("%s is not a file entity (%T)", abs, e) } - f := &file{abs: abs} - f.stat, _ = os.Stat(f.abs) - AddEntity(f) return f - case *file: - return path - default: - log.Fatalf("cannot convert from %T to file entity", path) - return nil } + f := &file{abs: abs} + f.stat, _ = os.Stat(f.abs) + AddEntity(f) + return f } -// Dir returns an Entity that represents a directory. -// The entities name will be the absolute path of the directory. -// If path is an entity already, it will be tested to make sure it is a -// directory and returned. -// If it is a string, the the entity map will be checked for a matching directory -// entry and if one is not found, a new one will be added and returned. +// Dir returns an Entity that represents a directory. The entities name will be +// the absolute path of the directory. The entity map will be checked for a +// matching directory entry and if one is not found, a new one will be added and +// returned. // It also adds the rules to create the directory if needed. -func Dir(path interface{}) *file { - d := File(path) +func Dir(path ...string) *file { + d := File(path...) if Creator(d) == nil { NewStep(makeDir).Creates(d) } @@ -85,13 +71,13 @@ func DirOf(path interface{}) *file { // FilesOf reads the list of files in path, filters them with the supplied // filter and returns the set of file entities that matched. -func FilesOf(path interface{}, filter func(os.FileInfo) bool) []*file { +func FilesOf(path string, filter func(os.FileInfo) bool) []*file { dir := Dir(path) infos, _ := ioutil.ReadDir(dir.Name()) files := []*file{} for _, i := range infos { if filter(i) { - files = append(files, File(filepath.Join(dir.Name(), i.Name()))) + files = append(files, File(dir.Name(), i.Name())) } } return files @@ -138,7 +124,7 @@ func (f *file) NeedsUpdate(t time.Time) bool { func (f *file) Updated() { f.stat, _ = os.Stat(f.abs) } func dirOf(name string) *file { - path := filepath.Dir(name) + path, _ := PathSplit(name) if len(path) == 0 { return nil } diff --git a/maker/go.go b/maker/go.go index fd77f3b9b..cb553b3a5 100644 --- a/maker/go.go +++ b/maker/go.go @@ -14,34 +14,13 @@ package maker -import ( - "os" - "path/filepath" -) - -var ( - goTool Entity -) - -var ( - //GoPath is the GOPATH environment setting - GoPath string -) - -func init() { - GoPath = os.Getenv("GOPATH") - goTool = FindTool("go") - Config.RootPath = GoPath - EnvVars["PATH"] = []string{filepath.Join(GoPath, "bin")} -} - // GoInstall builds a new Step that runs "go install" on the supplied module. // It will return the resulting binary entity. // The step will depend on the go tool, and will be set to always run if // depended on. func GoInstall(module string) Entity { - name := filepath.Base(module) - dst := File(GoBinPath(name + HostExecutableExtension)) + _, name := PathSplit(module) + dst := File(Paths.Bin, name+HostExecutableExtension) if Creator(dst) == nil { Command(goTool, "install", module).Creates(dst).AlwaysRun() } @@ -64,11 +43,6 @@ func GoRun(gofile string, args ...string) *Step { // GoSrcPath returns the full path to a file or directory inside the GoPath. func GoSrcPath(path string) string { - return filepath.Join(GoPath, "src", path) -} - -// GoBinPath returns the full path to a file or directory inside the go binary -// directory. -func GoBinPath(path string) string { - return filepath.Join(GoPath, "bin", path) + // TODO: search GoPath + return Path(GoPath[0], "src", path) } diff --git a/maker/path.go b/maker/path.go new file mode 100644 index 000000000..93b205a74 --- /dev/null +++ b/maker/path.go @@ -0,0 +1,37 @@ +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package maker + +import ( + "path/filepath" + "strings" +) + +func Path(path ...string) string { + return strings.Join(path, "/") +} + +func OSPath(path ...string) (string, error) { + ospath := filepath.FromSlash(Path(path...)) + abs, err := filepath.Abs(ospath) + if err != nil { + return abs, err + } + return filepath.Clean(abs), nil +} + +func PathSplit(path ...string) (dir, base string) { + return filepath.Split(Path(path...)) +} |