diff options
author | Dan Willemsen <dwillemsen@google.com> | 2015-09-23 15:26:20 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2015-12-09 14:29:12 -0800 |
commit | 34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb (patch) | |
tree | ecaff919037e29033fa9b3bbfb33baa8e93196cf /cc/gen.go | |
parent | fafa3dc7e267675610a34b0c335be350eb30936d (diff) | |
download | build_soong-34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb.tar.gz build_soong-34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb.tar.bz2 build_soong-34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb.zip |
Use `Path` instead of string for file paths
This centralizes verification and common operations, like converting the
path to a source file to the path for a built object.
It also embeds the configuration knowledge into the path, so that we can
remove "${SrcDir}/path" from the ninja file. When SrcDir is '.', that
leads to paths like './path' instead of just 'path' like make is doing,
causing differences in compiled binaries.
Change-Id: Ib4e8910a6e867ce1b7b420d927c04f1142a7589e
Diffstat (limited to 'cc/gen.go')
-rw-r--r-- | cc/gen.go | 53 |
1 files changed, 23 insertions, 30 deletions
@@ -19,18 +19,15 @@ package cc // functions. import ( - "path/filepath" - "github.com/google/blueprint" - "github.com/google/blueprint/pathtools" "android/soong/common" ) func init() { - pctx.StaticVariable("lexCmd", "${SrcDir}/prebuilts/misc/${HostPrebuiltTag}/flex/flex-2.5.39") - pctx.StaticVariable("yaccCmd", "${SrcDir}/prebuilts/misc/${HostPrebuiltTag}/bison/bison") - pctx.StaticVariable("yaccDataDir", "${SrcDir}/external/bison/data") + pctx.SourcePathVariable("lexCmd", "prebuilts/misc/${HostPrebuiltTag}/flex/flex-2.5.39") + pctx.SourcePathVariable("yaccCmd", "prebuilts/misc/${HostPrebuiltTag}/bison/bison") + pctx.SourcePathVariable("yaccDataDir", "external/bison/data") } var ( @@ -51,49 +48,45 @@ var ( }) ) -func genYacc(ctx common.AndroidModuleContext, yaccFile, yaccFlags string) (cppFile, headerFile string) { - cppFile = common.SrcDirRelPath(ctx, yaccFile) - cppFile = filepath.Join(common.ModuleGenDir(ctx), cppFile) - cppFile = pathtools.ReplaceExtension(cppFile, "cpp") - hppFile := pathtools.ReplaceExtension(cppFile, "hpp") - headerFile = pathtools.ReplaceExtension(cppFile, "h") +func genYacc(ctx common.AndroidModuleContext, yaccFile common.Path, yaccFlags string) (cppFile, headerFile common.ModuleGenPath) { + cppFile = common.GenPathWithExt(ctx, yaccFile, "cpp") + hppFile := common.GenPathWithExt(ctx, yaccFile, "hpp") + headerFile = common.GenPathWithExt(ctx, yaccFile, "h") - ctx.Build(pctx, blueprint.BuildParams{ + ctx.ModuleBuild(pctx, common.ModuleBuildParams{ Rule: yacc, - Outputs: []string{cppFile, headerFile}, - Inputs: []string{yaccFile}, + Outputs: common.WritablePaths{cppFile, headerFile}, + Input: yaccFile, Args: map[string]string{ "yaccFlags": yaccFlags, - "cppFile": cppFile, - "hppFile": hppFile, - "hFile": headerFile, + "cppFile": cppFile.String(), + "hppFile": hppFile.String(), + "hFile": headerFile.String(), }, }) return cppFile, headerFile } -func genLex(ctx common.AndroidModuleContext, lexFile string) (cppFile string) { - cppFile = common.SrcDirRelPath(ctx, lexFile) - cppFile = filepath.Join(common.ModuleGenDir(ctx), cppFile) - cppFile = pathtools.ReplaceExtension(cppFile, "cpp") +func genLex(ctx common.AndroidModuleContext, lexFile common.Path) (cppFile common.ModuleGenPath) { + cppFile = common.GenPathWithExt(ctx, lexFile, "cpp") - ctx.Build(pctx, blueprint.BuildParams{ - Rule: lex, - Outputs: []string{cppFile}, - Inputs: []string{lexFile}, + ctx.ModuleBuild(pctx, common.ModuleBuildParams{ + Rule: lex, + Output: cppFile, + Input: lexFile, }) return cppFile } -func genSources(ctx common.AndroidModuleContext, srcFiles []string, - buildFlags builderFlags) ([]string, []string) { +func genSources(ctx common.AndroidModuleContext, srcFiles common.Paths, + buildFlags builderFlags) (common.Paths, common.Paths) { - var deps []string + var deps common.Paths for i, srcFile := range srcFiles { - switch filepath.Ext(srcFile) { + switch srcFile.Ext() { case ".y", ".yy": cppFile, headerFile := genYacc(ctx, srcFile, buildFlags.yaccFlags) srcFiles[i] = cppFile |