blob: 8bb784951e65b4b4476a7ffe6937923761f60048 [file] [log] [blame]
Ivan Lozano4fef93c2020-07-08 08:39:44 -04001// 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 {
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040022 // name for the generated source file. Defaults to module name (e.g. moduleNameFoo.rs is produced by default).
23 // Importantly, the inherited "stem" property for this module sets the output filename for the generated library
24 // variants only
25 Source_stem *string `android:"arch_variant"`
26
27 // crate name, used for the library variant of this source provider. See additional details in rust_library.
28 Crate_name string `android:"arch_variant"`
Ivan Lozano4fef93c2020-07-08 08:39:44 -040029}
30
31type baseSourceProvider struct {
32 Properties SourceProviderProperties
33
34 outputFile android.Path
35 subAndroidMkOnce map[subAndroidMkProvider]bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040036 subName string
Ivan Lozano4fef93c2020-07-08 08:39:44 -040037}
38
39var _ SourceProvider = (*baseSourceProvider)(nil)
40
41type SourceProvider interface {
Ivan Lozano45901ed2020-07-24 16:05:01 -040042 generateSource(ctx android.ModuleContext, deps PathDeps) android.Path
Ivan Lozano4fef93c2020-07-08 08:39:44 -040043 Srcs() android.Paths
44 sourceProviderProps() []interface{}
45 sourceProviderDeps(ctx DepsContext, deps Deps) Deps
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040046 setSubName(subName string)
Ivan Lozano4fef93c2020-07-08 08:39:44 -040047}
48
49func (sp *baseSourceProvider) Srcs() android.Paths {
50 return android.Paths{sp.outputFile}
51}
52
Ivan Lozano45901ed2020-07-24 16:05:01 -040053func (sp *baseSourceProvider) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
Ivan Lozano4fef93c2020-07-08 08:39:44 -040054 panic("baseSourceProviderModule does not implement generateSource()")
55}
56
57func (sp *baseSourceProvider) sourceProviderProps() []interface{} {
58 return []interface{}{&sp.Properties}
59}
60
61func NewSourceProvider() *baseSourceProvider {
62 return &baseSourceProvider{
63 Properties: SourceProviderProperties{},
64 }
65}
66
67func (sp *baseSourceProvider) getStem(ctx android.ModuleContext) string {
68 stem := ctx.ModuleName()
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040069 if String(sp.Properties.Source_stem) != "" {
70 stem = String(sp.Properties.Source_stem)
Ivan Lozano4fef93c2020-07-08 08:39:44 -040071 }
72 return stem
73}
74
75func (sp *baseSourceProvider) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
76 return deps
77}
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040078
79func (sp *baseSourceProvider) setSubName(subName string) {
80 sp.subName = subName
81}