Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame^] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
| 4 | "android/soong/android" |
| 5 | |
| 6 | "github.com/google/blueprint" |
| 7 | ) |
| 8 | |
| 9 | type nestedProps struct { |
| 10 | Nested_prop string |
| 11 | } |
| 12 | |
| 13 | type 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 | |
| 27 | type 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. |
| 35 | func (m *customModule) OutputFiles(tag string) (android.Paths, error) { |
| 36 | return android.PathsForTesting("path" + tag), nil |
| 37 | } |
| 38 | |
| 39 | func (m *customModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 40 | // nothing for now. |
| 41 | } |
| 42 | |
| 43 | func customModuleFactoryBase() android.Module { |
| 44 | module := &customModule{} |
| 45 | module.AddProperties(&module.props) |
| 46 | return module |
| 47 | } |
| 48 | |
| 49 | func customModuleFactory() android.Module { |
| 50 | m := customModuleFactoryBase() |
| 51 | android.InitAndroidModule(m) |
| 52 | return m |
| 53 | } |
| 54 | |
| 55 | type testProps struct { |
| 56 | Test_prop struct { |
| 57 | Test_string_prop string |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | type customTestModule struct { |
| 62 | android.ModuleBase |
| 63 | |
| 64 | props customProps |
| 65 | test_props testProps |
| 66 | } |
| 67 | |
| 68 | func (m *customTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 69 | // nothing for now. |
| 70 | } |
| 71 | |
| 72 | func customTestModuleFactoryBase() android.Module { |
| 73 | m := &customTestModule{} |
| 74 | m.AddProperties(&m.props) |
| 75 | m.AddProperties(&m.test_props) |
| 76 | return m |
| 77 | } |
| 78 | |
| 79 | func customTestModuleFactory() android.Module { |
| 80 | m := customTestModuleFactoryBase() |
| 81 | android.InitAndroidModule(m) |
| 82 | return m |
| 83 | } |
| 84 | |
| 85 | type customDefaultsModule struct { |
| 86 | android.ModuleBase |
| 87 | android.DefaultsModuleBase |
| 88 | } |
| 89 | |
| 90 | func customDefaultsModuleFactoryBase() android.DefaultsModule { |
| 91 | module := &customDefaultsModule{} |
| 92 | module.AddProperties(&customProps{}) |
| 93 | return module |
| 94 | } |
| 95 | |
| 96 | func customDefaultsModuleFactoryBasic() android.Module { |
| 97 | return customDefaultsModuleFactoryBase() |
| 98 | } |
| 99 | |
| 100 | func customDefaultsModuleFactory() android.Module { |
| 101 | m := customDefaultsModuleFactoryBase() |
| 102 | android.InitDefaultsModule(m) |
| 103 | return m |
| 104 | } |
| 105 | |
| 106 | type bp2buildBlueprintWrapContext struct { |
| 107 | bpCtx *blueprint.Context |
| 108 | } |
| 109 | |
| 110 | func (ctx *bp2buildBlueprintWrapContext) ModuleName(module blueprint.Module) string { |
| 111 | return ctx.bpCtx.ModuleName(module) |
| 112 | } |
| 113 | |
| 114 | func (ctx *bp2buildBlueprintWrapContext) ModuleDir(module blueprint.Module) string { |
| 115 | return ctx.bpCtx.ModuleDir(module) |
| 116 | } |
| 117 | |
| 118 | func (ctx *bp2buildBlueprintWrapContext) ModuleSubDir(module blueprint.Module) string { |
| 119 | return ctx.bpCtx.ModuleSubDir(module) |
| 120 | } |
| 121 | |
| 122 | func (ctx *bp2buildBlueprintWrapContext) ModuleType(module blueprint.Module) string { |
| 123 | return ctx.bpCtx.ModuleType(module) |
| 124 | } |
| 125 | |
| 126 | func (ctx *bp2buildBlueprintWrapContext) VisitAllModulesBlueprint(visit func(blueprint.Module)) { |
| 127 | ctx.bpCtx.VisitAllModules(visit) |
| 128 | } |
| 129 | |
| 130 | func (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 | } |