blob: 160412de8a8384b9875a160721e7ed52e553b7b9 [file] [log] [blame]
Liz Kammer2dd9ca42020-11-25 16:06:39 -08001package bp2build
2
3import (
4 "android/soong/android"
5
6 "github.com/google/blueprint"
7)
8
9type nestedProps struct {
10 Nested_prop string
11}
12
13type customProps struct {
14 Bool_prop bool
15 Bool_ptr_prop *bool
16 // Ensure that properties tagged `blueprint:mutated` are omitted
17 Int_prop int `blueprint:"mutated"`
18 Int64_ptr_prop *int64
19 String_prop string
20 String_ptr_prop *string
21 String_list_prop []string
22
23 Nested_props nestedProps
24 Nested_props_ptr *nestedProps
25}
26
27type customModule struct {
28 android.ModuleBase
29
30 props customProps
31}
32
33// OutputFiles is needed because some instances of this module use dist with a
34// tag property which requires the module implements OutputFileProducer.
35func (m *customModule) OutputFiles(tag string) (android.Paths, error) {
36 return android.PathsForTesting("path" + tag), nil
37}
38
39func (m *customModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
40 // nothing for now.
41}
42
43func customModuleFactoryBase() android.Module {
44 module := &customModule{}
45 module.AddProperties(&module.props)
46 return module
47}
48
49func customModuleFactory() android.Module {
50 m := customModuleFactoryBase()
51 android.InitAndroidModule(m)
52 return m
53}
54
55type testProps struct {
56 Test_prop struct {
57 Test_string_prop string
58 }
59}
60
61type customTestModule struct {
62 android.ModuleBase
63
64 props customProps
65 test_props testProps
66}
67
68func (m *customTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
69 // nothing for now.
70}
71
72func customTestModuleFactoryBase() android.Module {
73 m := &customTestModule{}
74 m.AddProperties(&m.props)
75 m.AddProperties(&m.test_props)
76 return m
77}
78
79func customTestModuleFactory() android.Module {
80 m := customTestModuleFactoryBase()
81 android.InitAndroidModule(m)
82 return m
83}
84
85type customDefaultsModule struct {
86 android.ModuleBase
87 android.DefaultsModuleBase
88}
89
90func customDefaultsModuleFactoryBase() android.DefaultsModule {
91 module := &customDefaultsModule{}
92 module.AddProperties(&customProps{})
93 return module
94}
95
96func customDefaultsModuleFactoryBasic() android.Module {
97 return customDefaultsModuleFactoryBase()
98}
99
100func customDefaultsModuleFactory() android.Module {
101 m := customDefaultsModuleFactoryBase()
102 android.InitDefaultsModule(m)
103 return m
104}
105
106type bp2buildBlueprintWrapContext struct {
107 bpCtx *blueprint.Context
108}
109
110func (ctx *bp2buildBlueprintWrapContext) ModuleName(module blueprint.Module) string {
111 return ctx.bpCtx.ModuleName(module)
112}
113
114func (ctx *bp2buildBlueprintWrapContext) ModuleDir(module blueprint.Module) string {
115 return ctx.bpCtx.ModuleDir(module)
116}
117
118func (ctx *bp2buildBlueprintWrapContext) ModuleSubDir(module blueprint.Module) string {
119 return ctx.bpCtx.ModuleSubDir(module)
120}
121
122func (ctx *bp2buildBlueprintWrapContext) ModuleType(module blueprint.Module) string {
123 return ctx.bpCtx.ModuleType(module)
124}
125
126func (ctx *bp2buildBlueprintWrapContext) VisitAllModulesBlueprint(visit func(blueprint.Module)) {
127 ctx.bpCtx.VisitAllModules(visit)
128}
129
130func (ctx *bp2buildBlueprintWrapContext) VisitDirectDeps(module android.Module, visit func(android.Module)) {
131 ctx.bpCtx.VisitDirectDeps(module, func(m blueprint.Module) {
132 if aModule, ok := m.(android.Module); ok {
133 visit(aModule)
134 }
135 })
136}