diff options
author | 2022-02-10 23:34:28 +0000 | |
---|---|---|
committer | 2022-02-10 23:36:06 +0000 | |
commit | 1ebef5b78c156098dc5ae30d547086187f24923e (patch) | |
tree | efdfafd2b66472848b0d48bd914b9b27b36f6818 /android/testing.go | |
parent | 26cb965d2f807cb8f1ff5c1204c0f43c428967e3 (diff) |
Move functionality to test install rules into testing.go.
In preparation for test in the cc package.
Test: m nothing
Bug: 211770050
Change-Id: I3f6190e102c607a0b6246d78d7bde7fcffa21650
Diffstat (limited to 'android/testing.go')
-rw-r--r-- | android/testing.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/android/testing.go b/android/testing.go index 39864e103..a9632e96b 100644 --- a/android/testing.go +++ b/android/testing.go @@ -15,6 +15,7 @@ package android import ( + "bytes" "fmt" "path/filepath" "regexp" @@ -23,6 +24,8 @@ import ( "sync" "testing" + mkparser "android/soong/androidmk/parser" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) @@ -115,6 +118,10 @@ var PrepareForTestWithNamespace = FixtureRegisterWithContext(func(ctx Registrati ctx.PreArchMutators(RegisterNamespaceMutator) }) +var PrepareForTestWithMakevars = FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.RegisterSingletonType("makevars", makeVarsSingletonFunc) +}) + // Test fixture preparer that will register most java build components. // // Singletons and mutators should only be added here if they are needed for a majority of java @@ -602,6 +609,62 @@ func (ctx *TestContext) SingletonForTests(name string) TestingSingleton { "\nall singletons: %v", name, allSingletonNames)) } +type InstallMakeRule struct { + Target string + Deps []string + OrderOnlyDeps []string +} + +func parseMkRules(t *testing.T, config Config, nodes []mkparser.Node) []InstallMakeRule { + var rules []InstallMakeRule + for _, node := range nodes { + if mkParserRule, ok := node.(*mkparser.Rule); ok { + var rule InstallMakeRule + + if targets := mkParserRule.Target.Words(); len(targets) == 0 { + t.Fatalf("no targets for rule %s", mkParserRule.Dump()) + } else if len(targets) > 1 { + t.Fatalf("unsupported multiple targets for rule %s", mkParserRule.Dump()) + } else if !targets[0].Const() { + t.Fatalf("unsupported non-const target for rule %s", mkParserRule.Dump()) + } else { + rule.Target = normalizeStringRelativeToTop(config, targets[0].Value(nil)) + } + + prereqList := &rule.Deps + for _, prereq := range mkParserRule.Prerequisites.Words() { + if !prereq.Const() { + t.Fatalf("unsupported non-const prerequisite for rule %s", mkParserRule.Dump()) + } + + if prereq.Value(nil) == "|" { + prereqList = &rule.OrderOnlyDeps + continue + } + + *prereqList = append(*prereqList, normalizeStringRelativeToTop(config, prereq.Value(nil))) + } + + rules = append(rules, rule) + } + } + + return rules +} + +func (ctx *TestContext) InstallMakeRulesForTesting(t *testing.T) []InstallMakeRule { + installs := ctx.SingletonForTests("makevars").Singleton().(*makeVarsSingleton).installsForTesting + buf := bytes.NewBuffer(append([]byte(nil), installs...)) + parser := mkparser.NewParser("makevars", buf) + + nodes, errs := parser.Parse() + if len(errs) > 0 { + t.Fatalf("error parsing install rules: %s", errs[0]) + } + + return parseMkRules(t, ctx.config, nodes) +} + func (ctx *TestContext) Config() Config { return ctx.config } |