Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame^] | 1 | // Copyright 2020 The Android Open Source Project |
| 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 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | type SourceProviderProperties struct { |
| 22 | // sets name of the output |
| 23 | Stem *string `android:"arch_variant"` |
| 24 | } |
| 25 | |
| 26 | type baseSourceProvider struct { |
| 27 | Properties SourceProviderProperties |
| 28 | |
| 29 | outputFile android.Path |
| 30 | subAndroidMkOnce map[subAndroidMkProvider]bool |
| 31 | } |
| 32 | |
| 33 | var _ SourceProvider = (*baseSourceProvider)(nil) |
| 34 | |
| 35 | type SourceProvider interface { |
| 36 | generateSource(ctx android.ModuleContext) android.Path |
| 37 | Srcs() android.Paths |
| 38 | sourceProviderProps() []interface{} |
| 39 | sourceProviderDeps(ctx DepsContext, deps Deps) Deps |
| 40 | } |
| 41 | |
| 42 | func (sp *baseSourceProvider) Srcs() android.Paths { |
| 43 | return android.Paths{sp.outputFile} |
| 44 | } |
| 45 | |
| 46 | func (sp *baseSourceProvider) generateSource(ctx android.ModuleContext) android.Path { |
| 47 | panic("baseSourceProviderModule does not implement generateSource()") |
| 48 | } |
| 49 | |
| 50 | func (sp *baseSourceProvider) sourceProviderProps() []interface{} { |
| 51 | return []interface{}{&sp.Properties} |
| 52 | } |
| 53 | |
| 54 | func NewSourceProvider() *baseSourceProvider { |
| 55 | return &baseSourceProvider{ |
| 56 | Properties: SourceProviderProperties{}, |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | func (sp *baseSourceProvider) getStem(ctx android.ModuleContext) string { |
| 61 | stem := ctx.ModuleName() |
| 62 | if String(sp.Properties.Stem) != "" { |
| 63 | stem = String(sp.Properties.Stem) |
| 64 | } |
| 65 | return stem |
| 66 | } |
| 67 | |
| 68 | func (sp *baseSourceProvider) sourceProviderDeps(ctx DepsContext, deps Deps) Deps { |
| 69 | return deps |
| 70 | } |