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
15package selinux
16
17import (
18	"github.com/google/blueprint"
19
20	"android/soong/android"
21)
22
23type dependencyTag struct {
24	blueprint.BaseDependencyTag
25	name string
26}
27
28var (
29	pctx = android.NewPackageContext("android/soong/selinux")
30)
31
32// pathForModuleOut is same as android.PathForModuleOut, except that it uses DeviceName() as its
33// intermediate directory name for system_ext/product/vendor/odm modules, to avoid rebuilding upon
34// target change. Contents of system modules (core sepolicy) should be identical across devices, so
35// they falls back to android.PathForModuleOut.
36func pathForModuleOut(ctx android.ModuleContext, paths ...string) android.OutputPath {
37	if ctx.Platform() && !ctx.InstallInRecovery() {
38		return android.PathForModuleOut(ctx, paths...).OutputPath
39	}
40
41	return android.PathForModuleOut(ctx, ctx.Config().DeviceName()).Join(ctx, paths...)
42}
43
44// flagsToM4Macros converts given map to a list of M4's -D parameters to guard te files and contexts
45// files.
46func flagsToM4Macros(flags map[string]string) []string {
47	flagMacros := []string{}
48	for _, flag := range android.SortedKeys(flags) {
49		flagMacros = append(flagMacros, "-D target_flag_"+flag+"="+flags[flag])
50	}
51	return flagMacros
52}
53