blob: 80980f78b60e5eb128383cbe161f8a1c6e83ba19 [file] [log] [blame]
Colin Cross0e991752019-06-10 15:41:28 -07001// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package android
16
17import (
18 "testing"
19
20 "github.com/google/blueprint/proptools"
21)
22
23type defaultsTestProperties struct {
24 Foo []string
25}
26
27type defaultsTestModule struct {
28 ModuleBase
29 DefaultableModuleBase
30 properties defaultsTestProperties
31}
32
33func (d *defaultsTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
34 ctx.Build(pctx, BuildParams{
35 Rule: Touch,
36 Output: PathForModuleOut(ctx, "out"),
37 })
38}
39
40func defaultsTestModuleFactory() Module {
41 module := &defaultsTestModule{}
42 module.AddProperties(&module.properties)
43 InitDefaultableModule(module)
44 InitAndroidModule(module)
45 return module
46}
47
48type defaultsTestDefaults struct {
49 ModuleBase
50 DefaultsModuleBase
51}
52
53func defaultsTestDefaultsFactory() Module {
54 defaults := &defaultsTestDefaults{}
55 defaults.AddProperties(&defaultsTestProperties{})
56 InitDefaultsModule(defaults)
57 return defaults
58}
59
60func TestDefaultsAllowMissingDependencies(t *testing.T) {
61 config := TestConfig(buildDir, nil)
62 config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
63
64 ctx := NewTestContext()
65 ctx.SetAllowMissingDependencies(true)
66
Colin Cross4b49b762019-11-22 15:25:03 -080067 ctx.RegisterModuleType("test", defaultsTestModuleFactory)
68 ctx.RegisterModuleType("defaults", defaultsTestDefaultsFactory)
Colin Cross0e991752019-06-10 15:41:28 -070069
70 ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
71
72 ctx.Register()
73
74 bp := `
75 defaults {
76 name: "defaults",
77 defaults: ["missing"],
78 foo: ["defaults"],
79 }
80
81 test {
82 name: "missing_defaults",
83 defaults: ["missing"],
84 foo: ["module"],
85 }
86
87 test {
88 name: "missing_transitive_defaults",
89 defaults: ["defaults"],
90 foo: ["module"],
91 }
92 `
93
94 ctx.MockFileSystem(map[string][]byte{
95 "Android.bp": []byte(bp),
96 })
97
98 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
99 FailIfErrored(t, errs)
100 _, errs = ctx.PrepareBuildActions(config)
101 FailIfErrored(t, errs)
102
103 missingDefaults := ctx.ModuleForTests("missing_defaults", "").Output("out")
104 missingTransitiveDefaults := ctx.ModuleForTests("missing_transitive_defaults", "").Output("out")
105
106 if missingDefaults.Rule != ErrorRule {
107 t.Errorf("expected missing_defaults rule to be ErrorRule, got %#v", missingDefaults.Rule)
108 }
109
110 if g, w := missingDefaults.Args["error"], "module missing_defaults missing dependencies: missing\n"; g != w {
111 t.Errorf("want error %q, got %q", w, g)
112 }
113
114 // TODO: missing transitive defaults is currently not handled
115 _ = missingTransitiveDefaults
116}