blob: 51ff732795d121c0a85e9e45c4d8e6fc392ec287 [file] [log] [blame]
Inseob Kimb554e592019-04-15 20:10:46 +09001// 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
15package selinux
16
17import (
18 "github.com/google/blueprint"
ThiƩbaud Weksteenfe008ad2024-09-17 12:06:12 +100019 "github.com/google/blueprint/proptools"
Inseob Kimb554e592019-04-15 20:10:46 +090020
21 "android/soong/android"
22)
23
24type dependencyTag struct {
25 blueprint.BaseDependencyTag
26 name string
27}
28
29var (
30 pctx = android.NewPackageContext("android/soong/selinux")
31)
Inseob Kim6c6f53b2023-04-26 11:03:35 +090032
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.
37func 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 Kim6cd0ddd2023-10-25 23:48:16 +090044
45// flagsToM4Macros converts given map to a list of M4's -D parameters to guard te files and contexts
46// files.
47func 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 Weksteenfe008ad2024-09-17 12:06:12 +100054
55// boardApiLevel returns the M4 argument containing the target board API level.
56func 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}