Inseob Kim | b554e59 | 2019-04-15 20:10:46 +0900 | [diff] [blame] | 1 | // Copyright (C) 2019 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 | "github.com/google/blueprint" |
ThiƩbaud Weksteen | fe008ad | 2024-09-17 12:06:12 +1000 | [diff] [blame^] | 19 | "github.com/google/blueprint/proptools" |
Inseob Kim | b554e59 | 2019-04-15 20:10:46 +0900 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | type dependencyTag struct { |
| 25 | blueprint.BaseDependencyTag |
| 26 | name string |
| 27 | } |
| 28 | |
| 29 | var ( |
| 30 | pctx = android.NewPackageContext("android/soong/selinux") |
| 31 | ) |
Inseob Kim | 6c6f53b | 2023-04-26 11:03:35 +0900 | [diff] [blame] | 32 | |
| 33 | // pathForModuleOut is same as android.PathForModuleOut, except that it uses DeviceName() as its |
| 34 | // intermediate directory name for system_ext/product/vendor/odm modules, to avoid rebuilding upon |
| 35 | // target change. Contents of system modules (core sepolicy) should be identical across devices, so |
| 36 | // they falls back to android.PathForModuleOut. |
| 37 | func pathForModuleOut(ctx android.ModuleContext, paths ...string) android.OutputPath { |
| 38 | if ctx.Platform() && !ctx.InstallInRecovery() { |
| 39 | return android.PathForModuleOut(ctx, paths...).OutputPath |
| 40 | } |
| 41 | |
| 42 | return android.PathForModuleOut(ctx, ctx.Config().DeviceName()).Join(ctx, paths...) |
| 43 | } |
Inseob Kim | 6cd0ddd | 2023-10-25 23:48:16 +0900 | [diff] [blame] | 44 | |
| 45 | // flagsToM4Macros converts given map to a list of M4's -D parameters to guard te files and contexts |
| 46 | // files. |
| 47 | func flagsToM4Macros(flags map[string]string) []string { |
| 48 | flagMacros := []string{} |
| 49 | for _, flag := range android.SortedKeys(flags) { |
| 50 | flagMacros = append(flagMacros, "-D target_flag_"+flag+"="+flags[flag]) |
| 51 | } |
| 52 | return flagMacros |
| 53 | } |
ThiƩbaud Weksteen | fe008ad | 2024-09-17 12:06:12 +1000 | [diff] [blame^] | 54 | |
| 55 | // boardApiLevel returns the M4 argument containing the target board API level. |
| 56 | func boardApiLevelToM4Macro(ctx android.ModuleContext, apiLevel *string) string { |
| 57 | level := proptools.StringDefault(apiLevel, "current") |
| 58 | if level == "current" { |
| 59 | level = ctx.Config().VendorApiLevel() |
| 60 | } |
| 61 | return "-D target_board_api_level=" + level |
| 62 | } |