xref: /aosp_15_r20/system/sepolicy/build/soong/selinux.go (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker// Copyright (C) 2019 The Android Open Source Project
2*e4a36f41SAndroid Build Coastguard Worker//
3*e4a36f41SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*e4a36f41SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*e4a36f41SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*e4a36f41SAndroid Build Coastguard Worker//
7*e4a36f41SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*e4a36f41SAndroid Build Coastguard Worker//
9*e4a36f41SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*e4a36f41SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*e4a36f41SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*e4a36f41SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*e4a36f41SAndroid Build Coastguard Worker// limitations under the License.
14*e4a36f41SAndroid Build Coastguard Worker
15*e4a36f41SAndroid Build Coastguard Workerpackage selinux
16*e4a36f41SAndroid Build Coastguard Worker
17*e4a36f41SAndroid Build Coastguard Workerimport (
18*e4a36f41SAndroid Build Coastguard Worker	"github.com/google/blueprint"
19*e4a36f41SAndroid Build Coastguard Worker	"github.com/google/blueprint/proptools"
20*e4a36f41SAndroid Build Coastguard Worker
21*e4a36f41SAndroid Build Coastguard Worker	"android/soong/android"
22*e4a36f41SAndroid Build Coastguard Worker)
23*e4a36f41SAndroid Build Coastguard Worker
24*e4a36f41SAndroid Build Coastguard Workertype dependencyTag struct {
25*e4a36f41SAndroid Build Coastguard Worker	blueprint.BaseDependencyTag
26*e4a36f41SAndroid Build Coastguard Worker	name string
27*e4a36f41SAndroid Build Coastguard Worker}
28*e4a36f41SAndroid Build Coastguard Worker
29*e4a36f41SAndroid Build Coastguard Workervar (
30*e4a36f41SAndroid Build Coastguard Worker	pctx = android.NewPackageContext("android/soong/selinux")
31*e4a36f41SAndroid Build Coastguard Worker)
32*e4a36f41SAndroid Build Coastguard Worker
33*e4a36f41SAndroid Build Coastguard Worker// pathForModuleOut is same as android.PathForModuleOut, except that it uses DeviceName() as its
34*e4a36f41SAndroid Build Coastguard Worker// intermediate directory name for system_ext/product/vendor/odm modules, to avoid rebuilding upon
35*e4a36f41SAndroid Build Coastguard Worker// target change. Contents of system modules (core sepolicy) should be identical across devices, so
36*e4a36f41SAndroid Build Coastguard Worker// they falls back to android.PathForModuleOut.
37*e4a36f41SAndroid Build Coastguard Workerfunc pathForModuleOut(ctx android.ModuleContext, paths ...string) android.OutputPath {
38*e4a36f41SAndroid Build Coastguard Worker	if ctx.Platform() && !ctx.InstallInRecovery() {
39*e4a36f41SAndroid Build Coastguard Worker		return android.PathForModuleOut(ctx, paths...).OutputPath
40*e4a36f41SAndroid Build Coastguard Worker	}
41*e4a36f41SAndroid Build Coastguard Worker
42*e4a36f41SAndroid Build Coastguard Worker	return android.PathForModuleOut(ctx, ctx.Config().DeviceName()).Join(ctx, paths...)
43*e4a36f41SAndroid Build Coastguard Worker}
44*e4a36f41SAndroid Build Coastguard Worker
45*e4a36f41SAndroid Build Coastguard Worker// flagsToM4Macros converts given map to a list of M4's -D parameters to guard te files and contexts
46*e4a36f41SAndroid Build Coastguard Worker// files.
47*e4a36f41SAndroid Build Coastguard Workerfunc flagsToM4Macros(flags map[string]string) []string {
48*e4a36f41SAndroid Build Coastguard Worker	flagMacros := []string{}
49*e4a36f41SAndroid Build Coastguard Worker	for _, flag := range android.SortedKeys(flags) {
50*e4a36f41SAndroid Build Coastguard Worker		flagMacros = append(flagMacros, "-D target_flag_"+flag+"="+flags[flag])
51*e4a36f41SAndroid Build Coastguard Worker	}
52*e4a36f41SAndroid Build Coastguard Worker	return flagMacros
53*e4a36f41SAndroid Build Coastguard Worker}
54*e4a36f41SAndroid Build Coastguard Worker
55*e4a36f41SAndroid Build Coastguard Worker// boardApiLevel returns the M4 argument containing the target board API level.
56*e4a36f41SAndroid Build Coastguard Workerfunc boardApiLevelToM4Macro(ctx android.ModuleContext, apiLevel *string) string {
57*e4a36f41SAndroid Build Coastguard Worker	level := proptools.StringDefault(apiLevel, "current")
58*e4a36f41SAndroid Build Coastguard Worker	if level == "current" {
59*e4a36f41SAndroid Build Coastguard Worker		level = ctx.Config().VendorApiLevel()
60*e4a36f41SAndroid Build Coastguard Worker	}
61*e4a36f41SAndroid Build Coastguard Worker	return "-D target_board_api_level=" + level
62*e4a36f41SAndroid Build Coastguard Worker}
63