Merge "Create 'androidmk' rule to automatically run androidbp" into master-soong
This commit is contained in:
@@ -15,7 +15,10 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
|
"github.com/google/blueprint/bootstrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -24,6 +27,13 @@ var (
|
|||||||
cpPreserveSymlinks = pctx.VariableConfigMethod("cpPreserveSymlinks",
|
cpPreserveSymlinks = pctx.VariableConfigMethod("cpPreserveSymlinks",
|
||||||
Config.CpPreserveSymlinksFlags)
|
Config.CpPreserveSymlinksFlags)
|
||||||
|
|
||||||
|
androidbpCmd = filepath.Join(bootstrap.BinDir, "androidbp")
|
||||||
|
androidbp = pctx.StaticRule("androidbp",
|
||||||
|
blueprint.RuleParams{
|
||||||
|
Command: androidbpCmd + " $in $out",
|
||||||
|
Description: "androidbp $out",
|
||||||
|
})
|
||||||
|
|
||||||
// A phony rule that is not the built-in Ninja phony rule. The built-in
|
// A phony rule that is not the built-in Ninja phony rule. The built-in
|
||||||
// phony rule has special behavior that is sometimes not desired. See the
|
// phony rule has special behavior that is sometimes not desired. See the
|
||||||
// Ninja docs for more details.
|
// Ninja docs for more details.
|
||||||
|
@@ -17,6 +17,8 @@ package common
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"android/soong/glob"
|
"android/soong/glob"
|
||||||
|
|
||||||
@@ -523,12 +525,15 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonConte
|
|||||||
checkbuildDeps := []string{}
|
checkbuildDeps := []string{}
|
||||||
|
|
||||||
dirModules := make(map[string][]string)
|
dirModules := make(map[string][]string)
|
||||||
|
hasBPFile := make(map[string]bool)
|
||||||
|
bpFiles := []string{}
|
||||||
|
|
||||||
ctx.VisitAllModules(func(module blueprint.Module) {
|
ctx.VisitAllModules(func(module blueprint.Module) {
|
||||||
if a, ok := module.(AndroidModule); ok {
|
if a, ok := module.(AndroidModule); ok {
|
||||||
blueprintDir := a.base().blueprintDir
|
blueprintDir := a.base().blueprintDir
|
||||||
installTarget := a.base().installTarget
|
installTarget := a.base().installTarget
|
||||||
checkbuildTarget := a.base().checkbuildTarget
|
checkbuildTarget := a.base().checkbuildTarget
|
||||||
|
bpFile := ctx.BlueprintFile(module)
|
||||||
|
|
||||||
if checkbuildTarget != "" {
|
if checkbuildTarget != "" {
|
||||||
checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
|
checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
|
||||||
@@ -538,6 +543,11 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonConte
|
|||||||
if installTarget != "" {
|
if installTarget != "" {
|
||||||
dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget)
|
dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !hasBPFile[bpFile] {
|
||||||
|
hasBPFile[bpFile] = true
|
||||||
|
bpFiles = append(bpFiles, bpFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -560,4 +570,43 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonConte
|
|||||||
Optional: true,
|
Optional: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create Android.bp->mk translation rules
|
||||||
|
androidMks := []string{}
|
||||||
|
srcDir := ctx.Config().(Config).SrcDir()
|
||||||
|
intermediatesDir := filepath.Join(ctx.Config().(Config).IntermediatesDir(), "androidmk")
|
||||||
|
sort.Strings(bpFiles)
|
||||||
|
for _, origBp := range bpFiles {
|
||||||
|
bpFile := filepath.Join(srcDir, origBp)
|
||||||
|
mkFile := filepath.Join(srcDir, filepath.Dir(origBp), "Android.mk")
|
||||||
|
|
||||||
|
files, err := Glob(ctx, intermediatesDir, mkFile, nil)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Errorf("glob: %s", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Existing Android.mk file, use that instead
|
||||||
|
if len(files) > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
transMk := filepath.Join("androidmk", "Android_"+strings.Replace(filepath.Dir(origBp), "/", "_", -1)+".mk")
|
||||||
|
ctx.Build(pctx, blueprint.BuildParams{
|
||||||
|
Rule: androidbp,
|
||||||
|
Outputs: []string{transMk},
|
||||||
|
Inputs: []string{bpFile},
|
||||||
|
Implicits: []string{androidbpCmd},
|
||||||
|
Optional: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
androidMks = append(androidMks, transMk)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Build(pctx, blueprint.BuildParams{
|
||||||
|
Rule: blueprint.Phony,
|
||||||
|
Outputs: []string{"androidmk"},
|
||||||
|
Implicits: androidMks,
|
||||||
|
Optional: true,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user