Inseob Kim | 6cd0ddd | 2023-10-25 23:48:16 +0900 | [diff] [blame^] | 1 | // Copyright (C) 2023 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 selinux |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | type flagsProperties struct { |
| 22 | // List of flags to be passed to M4 macro. |
| 23 | Flags []string |
| 24 | } |
| 25 | |
| 26 | type flaggableModule interface { |
| 27 | android.Module |
| 28 | flagModuleBase() *flaggableModuleBase |
| 29 | getBuildFlags(ctx android.ModuleContext) map[string]string |
| 30 | } |
| 31 | |
| 32 | type flaggableModuleBase struct { |
| 33 | properties flagsProperties |
| 34 | } |
| 35 | |
| 36 | func initFlaggableModule(m flaggableModule) { |
| 37 | base := m.flagModuleBase() |
| 38 | m.AddProperties(&base.properties) |
| 39 | } |
| 40 | |
| 41 | func (f *flaggableModuleBase) flagModuleBase() *flaggableModuleBase { |
| 42 | return f |
| 43 | } |
| 44 | |
| 45 | // getBuildFlags returns a map from flag names to flag values. |
| 46 | func (f *flaggableModuleBase) getBuildFlags(ctx android.ModuleContext) map[string]string { |
| 47 | ret := make(map[string]string) |
| 48 | for _, flag := range android.SortedUniqueStrings(f.properties.Flags) { |
| 49 | if val, ok := ctx.Config().GetBuildFlag(flag); ok { |
| 50 | ret[flag] = val |
| 51 | } |
| 52 | } |
| 53 | return ret |
| 54 | } |