blob: b1aebac757cd15c31d7dcc7d95a322e3db417adf [file] [log] [blame]
Inseob Kim6cd0ddd2023-10-25 23:48:16 +09001// 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
15package selinux
16
17import (
18 "android/soong/android"
19)
20
21type flagsProperties struct {
22 // List of flags to be passed to M4 macro.
23 Flags []string
24}
25
26type flaggableModule interface {
27 android.Module
28 flagModuleBase() *flaggableModuleBase
29 getBuildFlags(ctx android.ModuleContext) map[string]string
30}
31
32type flaggableModuleBase struct {
33 properties flagsProperties
34}
35
36func initFlaggableModule(m flaggableModule) {
37 base := m.flagModuleBase()
38 m.AddProperties(&base.properties)
39}
40
41func (f *flaggableModuleBase) flagModuleBase() *flaggableModuleBase {
42 return f
43}
44
45// getBuildFlags returns a map from flag names to flag values.
46func (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}