blob: ba607ef53ea44c9bdc393bc70cf7f6879ff2cc78 [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) {
Colin Cross0e991752019-06-10 15:41:28 -070061 bp := `
62 defaults {
63 name: "defaults",
64 defaults: ["missing"],
65 foo: ["defaults"],
66 }
67
68 test {
69 name: "missing_defaults",
70 defaults: ["missing"],
71 foo: ["module"],
72 }
73
74 test {
75 name: "missing_transitive_defaults",
76 defaults: ["defaults"],
77 foo: ["module"],
78 }
79 `
80
Colin Cross98be1bb2019-12-13 20:41:13 -080081 config := TestConfig(buildDir, nil, bp, nil)
82 config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
83
84 ctx := NewTestContext()
85 ctx.SetAllowMissingDependencies(true)
86
87 ctx.RegisterModuleType("test", defaultsTestModuleFactory)
88 ctx.RegisterModuleType("defaults", defaultsTestDefaultsFactory)
89
90 ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
91
92 ctx.Register(config)
Colin Cross0e991752019-06-10 15:41:28 -070093
94 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
95 FailIfErrored(t, errs)
96 _, errs = ctx.PrepareBuildActions(config)
97 FailIfErrored(t, errs)
98
99 missingDefaults := ctx.ModuleForTests("missing_defaults", "").Output("out")
100 missingTransitiveDefaults := ctx.ModuleForTests("missing_transitive_defaults", "").Output("out")
101
102 if missingDefaults.Rule != ErrorRule {
103 t.Errorf("expected missing_defaults rule to be ErrorRule, got %#v", missingDefaults.Rule)
104 }
105
106 if g, w := missingDefaults.Args["error"], "module missing_defaults missing dependencies: missing\n"; g != w {
107 t.Errorf("want error %q, got %q", w, g)
108 }
109
110 // TODO: missing transitive defaults is currently not handled
111 _ = missingTransitiveDefaults
112}