xref: /aosp_15_r20/system/sepolicy/build/soong/bug_map.go (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker// Copyright 2021 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/proptools"
19*e4a36f41SAndroid Build Coastguard Worker
20*e4a36f41SAndroid Build Coastguard Worker	"android/soong/android"
21*e4a36f41SAndroid Build Coastguard Worker)
22*e4a36f41SAndroid Build Coastguard Worker
23*e4a36f41SAndroid Build Coastguard Workerfunc init() {
24*e4a36f41SAndroid Build Coastguard Worker	android.RegisterModuleType("se_bug_map", bugMapFactory)
25*e4a36f41SAndroid Build Coastguard Worker}
26*e4a36f41SAndroid Build Coastguard Worker
27*e4a36f41SAndroid Build Coastguard Worker// se_bug_map collects and installs selinux denial bug tracking information to be loaded by auditd.
28*e4a36f41SAndroid Build Coastguard Workerfunc bugMapFactory() android.Module {
29*e4a36f41SAndroid Build Coastguard Worker	c := &bugMap{}
30*e4a36f41SAndroid Build Coastguard Worker	c.AddProperties(&c.properties)
31*e4a36f41SAndroid Build Coastguard Worker	android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon)
32*e4a36f41SAndroid Build Coastguard Worker	return c
33*e4a36f41SAndroid Build Coastguard Worker}
34*e4a36f41SAndroid Build Coastguard Worker
35*e4a36f41SAndroid Build Coastguard Workertype bugMap struct {
36*e4a36f41SAndroid Build Coastguard Worker	android.ModuleBase
37*e4a36f41SAndroid Build Coastguard Worker	properties    bugMapProperties
38*e4a36f41SAndroid Build Coastguard Worker	installSource android.Path
39*e4a36f41SAndroid Build Coastguard Worker	installPath   android.InstallPath
40*e4a36f41SAndroid Build Coastguard Worker}
41*e4a36f41SAndroid Build Coastguard Worker
42*e4a36f41SAndroid Build Coastguard Workertype bugMapProperties struct {
43*e4a36f41SAndroid Build Coastguard Worker	// List of source files or se_build_files modules.
44*e4a36f41SAndroid Build Coastguard Worker	Srcs []string `android:"path"`
45*e4a36f41SAndroid Build Coastguard Worker
46*e4a36f41SAndroid Build Coastguard Worker	// Output file name. Defaults to module name if unspecified.
47*e4a36f41SAndroid Build Coastguard Worker	Stem *string
48*e4a36f41SAndroid Build Coastguard Worker}
49*e4a36f41SAndroid Build Coastguard Worker
50*e4a36f41SAndroid Build Coastguard Workerfunc (b *bugMap) stem() string {
51*e4a36f41SAndroid Build Coastguard Worker	return proptools.StringDefault(b.properties.Stem, b.Name())
52*e4a36f41SAndroid Build Coastguard Worker}
53*e4a36f41SAndroid Build Coastguard Worker
54*e4a36f41SAndroid Build Coastguard Workerfunc (b *bugMap) expandSeSources(ctx android.ModuleContext) android.Paths {
55*e4a36f41SAndroid Build Coastguard Worker	return android.PathsForModuleSrc(ctx, b.properties.Srcs)
56*e4a36f41SAndroid Build Coastguard Worker}
57*e4a36f41SAndroid Build Coastguard Worker
58*e4a36f41SAndroid Build Coastguard Workerfunc (b *bugMap) GenerateAndroidBuildActions(ctx android.ModuleContext) {
59*e4a36f41SAndroid Build Coastguard Worker	if !b.SocSpecific() && !b.SystemExtSpecific() && !b.Platform() {
60*e4a36f41SAndroid Build Coastguard Worker		ctx.ModuleErrorf("Selinux bug_map can only be installed in system, system_ext and vendor partitions")
61*e4a36f41SAndroid Build Coastguard Worker	}
62*e4a36f41SAndroid Build Coastguard Worker
63*e4a36f41SAndroid Build Coastguard Worker	srcPaths := b.expandSeSources(ctx)
64*e4a36f41SAndroid Build Coastguard Worker	out := android.PathForModuleGen(ctx, b.Name())
65*e4a36f41SAndroid Build Coastguard Worker	ctx.Build(pctx, android.BuildParams{
66*e4a36f41SAndroid Build Coastguard Worker		Rule:        android.Cat,
67*e4a36f41SAndroid Build Coastguard Worker		Inputs:      srcPaths,
68*e4a36f41SAndroid Build Coastguard Worker		Output:      out,
69*e4a36f41SAndroid Build Coastguard Worker		Description: "Combining bug_map for " + b.Name(),
70*e4a36f41SAndroid Build Coastguard Worker	})
71*e4a36f41SAndroid Build Coastguard Worker
72*e4a36f41SAndroid Build Coastguard Worker	b.installPath = android.PathForModuleInstall(ctx, "etc", "selinux")
73*e4a36f41SAndroid Build Coastguard Worker	b.installSource = out
74*e4a36f41SAndroid Build Coastguard Worker	ctx.InstallFile(b.installPath, b.stem(), b.installSource)
75*e4a36f41SAndroid Build Coastguard Worker}
76*e4a36f41SAndroid Build Coastguard Worker
77*e4a36f41SAndroid Build Coastguard Workerfunc (b *bugMap) AndroidMkEntries() []android.AndroidMkEntries {
78*e4a36f41SAndroid Build Coastguard Worker	return []android.AndroidMkEntries{android.AndroidMkEntries{
79*e4a36f41SAndroid Build Coastguard Worker		Class:      "ETC",
80*e4a36f41SAndroid Build Coastguard Worker		OutputFile: android.OptionalPathForPath(b.installSource),
81*e4a36f41SAndroid Build Coastguard Worker		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
82*e4a36f41SAndroid Build Coastguard Worker			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
83*e4a36f41SAndroid Build Coastguard Worker				entries.SetPath("LOCAL_MODULE_PATH", b.installPath)
84*e4a36f41SAndroid Build Coastguard Worker				entries.SetString("LOCAL_INSTALLED_MODULE_STEM", b.stem())
85*e4a36f41SAndroid Build Coastguard Worker			},
86*e4a36f41SAndroid Build Coastguard Worker		},
87*e4a36f41SAndroid Build Coastguard Worker	}}
88*e4a36f41SAndroid Build Coastguard Worker}
89