aboutsummaryrefslogtreecommitdiffstats
path: root/genrule
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2015-09-23 15:26:20 -0700
committerDan Willemsen <dwillemsen@google.com>2015-12-09 14:29:12 -0800
commit34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb (patch)
treeecaff919037e29033fa9b3bbfb33baa8e93196cf /genrule
parentfafa3dc7e267675610a34b0c335be350eb30936d (diff)
downloadbuild_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 'genrule')
-rw-r--r--genrule/genrule.go43
1 files changed, 20 insertions, 23 deletions
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 76b4f16a..b5543570 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -15,10 +15,7 @@
package genrule
import (
- "path/filepath"
-
"github.com/google/blueprint"
- "github.com/google/blueprint/pathtools"
"android/soong"
"android/soong/common"
@@ -32,20 +29,20 @@ func init() {
}
var (
- pctx = blueprint.NewPackageContext("android/soong/genrule")
+ pctx = common.NewPackageContext("android/soong/genrule")
)
func init() {
- pctx.VariableConfigMethod("srcDir", common.Config.SrcDir)
- pctx.VariableConfigMethod("hostBin", common.Config.HostBin)
+ pctx.SourcePathVariable("srcDir", "")
+ pctx.HostBinToolVariable("hostBin", "")
}
type SourceFileGenerator interface {
- GeneratedSourceFiles() []string
+ GeneratedSourceFiles() common.Paths
}
type HostToolProvider interface {
- HostToolPath() string
+ HostToolPath() common.OptionalPath
}
type generatorProperties struct {
@@ -68,20 +65,20 @@ type generator struct {
tasks taskFunc
- deps []string
+ deps common.Paths
rule blueprint.Rule
- outputFiles []string
+ outputFiles common.Paths
}
type taskFunc func(ctx common.AndroidModuleContext) []generateTask
type generateTask struct {
- in []string
- out string
+ in common.Paths
+ out common.ModuleGenPath
}
-func (g *generator) GeneratedSourceFiles() []string {
+func (g *generator) GeneratedSourceFiles() common.Paths {
return g.outputFiles
}
@@ -104,8 +101,8 @@ func (g *generator) GenerateAndroidBuildActions(ctx common.AndroidModuleContext)
ctx.VisitDirectDeps(func(module blueprint.Module) {
if t, ok := module.(HostToolProvider); ok {
p := t.HostToolPath()
- if p != "" {
- g.deps = append(g.deps, p)
+ if p.Valid() {
+ g.deps = append(g.deps, p.Path())
} else {
ctx.ModuleErrorf("host tool %q missing output file", ctx.OtherModuleName(module))
}
@@ -120,12 +117,11 @@ func (g *generator) GenerateAndroidBuildActions(ctx common.AndroidModuleContext)
}
func (g *generator) generateSourceFile(ctx common.AndroidModuleContext, task generateTask) {
-
- ctx.Build(pctx, blueprint.BuildParams{
+ ctx.ModuleBuild(pctx, common.ModuleBuildParams{
Rule: g.rule,
+ Output: task.out,
Inputs: task.in,
Implicits: g.deps,
- Outputs: []string{task.out},
})
g.outputFiles = append(g.outputFiles, task.out)
@@ -148,9 +144,10 @@ func GenSrcsFactory() (blueprint.Module, []interface{}) {
srcFiles := ctx.ExpandSources(properties.Srcs, nil)
tasks := make([]generateTask, 0, len(srcFiles))
for _, in := range srcFiles {
- out := pathtools.ReplaceExtension(in, properties.Output_extension)
- out = filepath.Join(common.ModuleGenDir(ctx), out)
- tasks = append(tasks, generateTask{[]string{in}, out})
+ tasks = append(tasks, generateTask{
+ in: common.Paths{in},
+ out: common.GenPathWithExt(ctx, in, properties.Output_extension),
+ })
}
return tasks
}
@@ -173,7 +170,7 @@ func GenRuleFactory() (blueprint.Module, []interface{}) {
return []generateTask{
{
in: ctx.ExpandSources(properties.Srcs, nil),
- out: filepath.Join(common.ModuleGenDir(ctx), properties.Out),
+ out: properties.Out,
},
}
}
@@ -186,5 +183,5 @@ type genRuleProperties struct {
Srcs []string
// name of the output file that will be generated
- Out string
+ Out common.ModuleGenPath
}