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 15package rust 16 17import ( 18 "android/soong/android" 19) 20 21type SourceProviderProperties struct { 22 // sets name of the output 23 Stem *string `android:"arch_variant"` 24} 25 26type baseSourceProvider struct { 27 Properties SourceProviderProperties 28 29 outputFile android.Path 30 subAndroidMkOnce map[subAndroidMkProvider]bool 31} 32 33var _ SourceProvider = (*baseSourceProvider)(nil) 34 35type SourceProvider interface { 36 generateSource(ctx android.ModuleContext, deps PathDeps) android.Path 37 Srcs() android.Paths 38 sourceProviderProps() []interface{} 39 sourceProviderDeps(ctx DepsContext, deps Deps) Deps 40} 41 42func (sp *baseSourceProvider) Srcs() android.Paths { 43 return android.Paths{sp.outputFile} 44} 45 46func (sp *baseSourceProvider) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path { 47 panic("baseSourceProviderModule does not implement generateSource()") 48} 49 50func (sp *baseSourceProvider) sourceProviderProps() []interface{} { 51 return []interface{}{&sp.Properties} 52} 53 54func NewSourceProvider() *baseSourceProvider { 55 return &baseSourceProvider{ 56 Properties: SourceProviderProperties{}, 57 } 58} 59 60func (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 68func (sp *baseSourceProvider) sourceProviderDeps(ctx DepsContext, deps Deps) Deps { 69 return deps 70} 71