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