blob: 3946a04244d82b6db095e589840c5d223d0d8b69 [file] [log] [blame]
Inseob Kim7e8bd1e2021-03-17 18:59:43 +09001// Copyright (C) 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 "fmt"
19 "os"
Inseob Kim0a707fa2021-12-09 23:35:11 +090020 "sort"
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090021 "strconv"
Inseob Kim0a707fa2021-12-09 23:35:11 +090022 "strings"
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090023
24 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
27)
28
29const (
30 // TODO: sync with Android.mk
31 MlsSens = 1
32 MlsCats = 1024
33 PolicyVers = 30
34)
35
Inseob Kim0a707fa2021-12-09 23:35:11 +090036// This order should be kept. checkpolicy syntax requires it.
37var policyConfOrder = []string{
38 "security_classes",
39 "initial_sids",
40 "access_vectors",
41 "global_macros",
42 "neverallow_macros",
43 "mls_macros",
44 "mls_decl",
45 "mls",
46 "policy_capabilities",
47 "te_macros",
Inseob Kim0a707fa2021-12-09 23:35:11 +090048 "ioctl_defines",
49 "ioctl_macros",
Inseob Kim1e796342022-06-09 11:26:35 +090050 "attributes|*.te",
Inseob Kim0a707fa2021-12-09 23:35:11 +090051 "roles_decl",
52 "roles",
53 "users",
54 "initial_sid_contexts",
55 "fs_use",
56 "genfs_contexts",
57 "port_contexts",
58}
59
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090060func init() {
61 android.RegisterModuleType("se_policy_conf", policyConfFactory)
Inseob Kimdf1a0de2021-03-17 19:05:02 +090062 android.RegisterModuleType("se_policy_cil", policyCilFactory)
Inseob Kimb9d05112021-09-27 13:13:46 +000063 android.RegisterModuleType("se_policy_binary", policyBinaryFactory)
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090064}
65
66type policyConfProperties struct {
67 // Name of the output. Default is {module_name}
68 Stem *string
69
70 // Policy files to be compiled to cil file.
71 Srcs []string `android:"path"`
72
73 // Target build variant (user / userdebug / eng). Default follows the current lunch target
74 Build_variant *string
75
76 // Whether to exclude build test or not. Default is false
77 Exclude_build_test *bool
78
79 // Whether to include asan specific policies or not. Default follows the current lunch target
80 With_asan *bool
81
82 // Whether to build CTS specific policy or not. Default is false
83 Cts *bool
84
Inseob Kim5bbcd682021-12-28 14:57:03 +090085 // Whether to build recovery specific policy or not. Default is false
86 Target_recovery *bool
87
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090088 // Whether this module is directly installable to one of the partitions. Default is true
89 Installable *bool
Inseob Kim6e384f32022-03-10 13:15:05 +090090
91 // Desired number of MLS categories. Defaults to 1024
92 Mls_cats *int64
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090093}
94
95type policyConf struct {
96 android.ModuleBase
97
98 properties policyConfProperties
99
100 installSource android.Path
101 installPath android.InstallPath
102}
103
104// se_policy_conf merges collection of policy files into a policy.conf file to be processed by
105// checkpolicy.
106func policyConfFactory() android.Module {
107 c := &policyConf{}
108 c.AddProperties(&c.properties)
109 android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon)
110 return c
111}
112
113func (c *policyConf) installable() bool {
114 return proptools.BoolDefault(c.properties.Installable, true)
115}
116
117func (c *policyConf) stem() string {
118 return proptools.StringDefault(c.properties.Stem, c.Name())
119}
120
121func (c *policyConf) buildVariant(ctx android.ModuleContext) string {
122 if variant := proptools.String(c.properties.Build_variant); variant != "" {
123 return variant
124 }
125 if ctx.Config().Eng() {
126 return "eng"
127 }
128 if ctx.Config().Debuggable() {
129 return "userdebug"
130 }
131 return "user"
132}
133
134func (c *policyConf) cts() bool {
135 return proptools.Bool(c.properties.Cts)
136}
137
Inseob Kim5bbcd682021-12-28 14:57:03 +0900138func (c *policyConf) isTargetRecovery() bool {
139 return proptools.Bool(c.properties.Target_recovery)
140}
141
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900142func (c *policyConf) withAsan(ctx android.ModuleContext) string {
143 isAsanDevice := android.InList("address", ctx.Config().SanitizeDevice())
144 return strconv.FormatBool(proptools.BoolDefault(c.properties.With_asan, isAsanDevice))
145}
146
147func (c *policyConf) sepolicySplit(ctx android.ModuleContext) string {
148 if c.cts() {
149 return "cts"
150 }
Inseob Kim5bbcd682021-12-28 14:57:03 +0900151 if c.isTargetRecovery() {
152 return "false"
153 }
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900154 return strconv.FormatBool(ctx.DeviceConfig().SepolicySplit())
155}
156
157func (c *policyConf) compatibleProperty(ctx android.ModuleContext) string {
158 if c.cts() {
159 return "cts"
160 }
Inseob Kim5bbcd682021-12-28 14:57:03 +0900161 if c.isTargetRecovery() {
162 return "false"
163 }
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900164 return "true"
165}
166
167func (c *policyConf) trebleSyspropNeverallow(ctx android.ModuleContext) string {
168 if c.cts() {
169 return "cts"
170 }
Inseob Kim5bbcd682021-12-28 14:57:03 +0900171 if c.isTargetRecovery() {
172 return "false"
173 }
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900174 return strconv.FormatBool(!ctx.DeviceConfig().BuildBrokenTrebleSyspropNeverallow())
175}
176
177func (c *policyConf) enforceSyspropOwner(ctx android.ModuleContext) string {
178 if c.cts() {
179 return "cts"
180 }
Inseob Kim5bbcd682021-12-28 14:57:03 +0900181 if c.isTargetRecovery() {
182 return "false"
183 }
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900184 return strconv.FormatBool(!ctx.DeviceConfig().BuildBrokenEnforceSyspropOwner())
185}
186
Hridya Valsarajua885dd82021-04-26 16:32:17 -0700187func (c *policyConf) enforceDebugfsRestrictions(ctx android.ModuleContext) string {
188 if c.cts() {
189 return "cts"
190 }
191 return strconv.FormatBool(ctx.DeviceConfig().BuildDebugfsRestrictionsEnabled())
192}
193
Inseob Kim6e384f32022-03-10 13:15:05 +0900194func (c *policyConf) mlsCats() int {
195 return proptools.IntDefault(c.properties.Mls_cats, MlsCats)
196}
197
Inseob Kim0a707fa2021-12-09 23:35:11 +0900198func findPolicyConfOrder(name string) int {
199 for idx, pattern := range policyConfOrder {
Inseob Kim1e796342022-06-09 11:26:35 +0900200 // We could use regexp but it seems like an overkill
201 if pattern == "attributes|*.te" && (name == "attributes" || strings.HasSuffix(name, ".te")) {
202 return idx
203 } else if pattern == name {
Inseob Kim0a707fa2021-12-09 23:35:11 +0900204 return idx
205 }
206 }
207 // name is not matched
208 return len(policyConfOrder)
209}
210
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900211func (c *policyConf) transformPolicyToConf(ctx android.ModuleContext) android.OutputPath {
Inseob Kim6c5fa542022-02-09 23:27:04 +0900212 conf := android.PathForModuleOut(ctx, c.stem()).OutputPath
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900213 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim0a707fa2021-12-09 23:35:11 +0900214
215 srcs := android.PathsForModuleSrc(ctx, c.properties.Srcs)
216 sort.SliceStable(srcs, func(x, y int) bool {
217 return findPolicyConfOrder(srcs[x].Base()) < findPolicyConfOrder(srcs[y].Base())
218 })
219
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900220 rule.Command().Tool(ctx.Config().PrebuiltBuildTool(ctx, "m4")).
221 Flag("--fatal-warnings").
222 FlagForEachArg("-D ", ctx.DeviceConfig().SepolicyM4Defs()).
223 FlagWithArg("-D mls_num_sens=", strconv.Itoa(MlsSens)).
Inseob Kim6e384f32022-03-10 13:15:05 +0900224 FlagWithArg("-D mls_num_cats=", strconv.Itoa(c.mlsCats())).
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900225 FlagWithArg("-D target_arch=", ctx.DeviceConfig().DeviceArch()).
226 FlagWithArg("-D target_with_asan=", c.withAsan(ctx)).
Inseob Kim4360c192021-03-23 20:52:53 +0900227 FlagWithArg("-D target_with_dexpreopt=", strconv.FormatBool(ctx.DeviceConfig().WithDexpreopt())).
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900228 FlagWithArg("-D target_with_native_coverage=", strconv.FormatBool(ctx.DeviceConfig().ClangCoverageEnabled() || ctx.DeviceConfig().GcovCoverageEnabled())).
229 FlagWithArg("-D target_build_variant=", c.buildVariant(ctx)).
230 FlagWithArg("-D target_full_treble=", c.sepolicySplit(ctx)).
231 FlagWithArg("-D target_compatible_property=", c.compatibleProperty(ctx)).
232 FlagWithArg("-D target_treble_sysprop_neverallow=", c.trebleSyspropNeverallow(ctx)).
233 FlagWithArg("-D target_enforce_sysprop_owner=", c.enforceSyspropOwner(ctx)).
234 FlagWithArg("-D target_exclude_build_test=", strconv.FormatBool(proptools.Bool(c.properties.Exclude_build_test))).
235 FlagWithArg("-D target_requires_insecure_execmem_for_swiftshader=", strconv.FormatBool(ctx.DeviceConfig().RequiresInsecureExecmemForSwiftshader())).
Hridya Valsarajua885dd82021-04-26 16:32:17 -0700236 FlagWithArg("-D target_enforce_debugfs_restriction=", c.enforceDebugfsRestrictions(ctx)).
Inseob Kim5bbcd682021-12-28 14:57:03 +0900237 FlagWithArg("-D target_recovery=", strconv.FormatBool(c.isTargetRecovery())).
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900238 Flag("-s").
Inseob Kim0a707fa2021-12-09 23:35:11 +0900239 Inputs(srcs).
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900240 Text("> ").Output(conf)
241
242 rule.Build("conf", "Transform policy to conf: "+ctx.ModuleName())
243 return conf
244}
245
246func (c *policyConf) DepsMutator(ctx android.BottomUpMutatorContext) {
247 // do nothing
248}
249
250func (c *policyConf) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900251 if !c.installable() {
252 c.SkipInstall()
253 }
Inseob Kim31db2742021-06-08 10:31:09 +0900254
255 c.installSource = c.transformPolicyToConf(ctx)
256 c.installPath = android.PathForModuleInstall(ctx, "etc")
257 ctx.InstallFile(c.installPath, c.stem(), c.installSource)
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900258}
259
260func (c *policyConf) AndroidMkEntries() []android.AndroidMkEntries {
261 return []android.AndroidMkEntries{android.AndroidMkEntries{
262 OutputFile: android.OptionalPathForPath(c.installSource),
263 Class: "ETC",
264 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
265 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
266 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.installable())
Colin Cross6c7f9372022-01-11 19:35:43 -0800267 entries.SetPath("LOCAL_MODULE_PATH", c.installPath)
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900268 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem())
269 },
270 },
271 }}
272}
273
274func (c *policyConf) OutputFiles(tag string) (android.Paths, error) {
275 if tag == "" {
276 return android.Paths{c.installSource}, nil
277 }
278 return nil, fmt.Errorf("Unknown tag %q", tag)
279}
280
281var _ android.OutputFileProducer = (*policyConf)(nil)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900282
283type policyCilProperties struct {
284 // Name of the output. Default is {module_name}
285 Stem *string
286
287 // Policy file to be compiled to cil file.
288 Src *string `android:"path"`
289
290 // Additional cil files to be added in the end of the output. This is to support workarounds
291 // which are not supported by the policy language.
292 Additional_cil_files []string `android:"path"`
293
294 // Cil files to be filtered out by the filter_out tool of "build_sepolicy". Used to build
295 // exported policies
296 Filter_out []string `android:"path"`
297
298 // Whether to remove line markers (denoted by ;;) out of compiled cil files. Defaults to false
299 Remove_line_marker *bool
300
301 // Whether to run secilc to check compiled policy or not. Defaults to true
302 Secilc_check *bool
303
304 // Whether to ignore neverallow when running secilc check. Defaults to
305 // SELINUX_IGNORE_NEVERALLOWS.
306 Ignore_neverallow *bool
307
308 // Whether this module is directly installable to one of the partitions. Default is true
309 Installable *bool
310}
311
312type policyCil struct {
313 android.ModuleBase
314
315 properties policyCilProperties
316
317 installSource android.Path
318 installPath android.InstallPath
319}
320
321// se_policy_cil compiles a policy.conf file to a cil file with checkpolicy, and optionally runs
322// secilc to check the output cil file. Affected by SELINUX_IGNORE_NEVERALLOWS.
323func policyCilFactory() android.Module {
324 c := &policyCil{}
325 c.AddProperties(&c.properties)
326 android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon)
327 return c
328}
329
330func (c *policyCil) Installable() bool {
331 return proptools.BoolDefault(c.properties.Installable, true)
332}
333
334func (c *policyCil) stem() string {
335 return proptools.StringDefault(c.properties.Stem, c.Name())
336}
337
338func (c *policyCil) compileConfToCil(ctx android.ModuleContext, conf android.Path) android.OutputPath {
339 cil := android.PathForModuleOut(ctx, c.stem()).OutputPath
340 rule := android.NewRuleBuilder(pctx, ctx)
Lokesh Gidra1269a172022-08-01 17:20:38 +0000341 rule.Command().BuiltTool("checkpolicy").
342 Flag("-C"). // Write CIL
343 Flag("-M"). // Enable MLS
344 FlagWithArg("-c ", strconv.Itoa(PolicyVers)).
345 FlagWithOutput("-o ", cil).
346 Input(conf)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900347
Lokesh Gidra1269a172022-08-01 17:20:38 +0000348 if len(c.properties.Additional_cil_files) > 0 {
349 rule.Command().Text("cat").
350 Inputs(android.PathsForModuleSrc(ctx, c.properties.Additional_cil_files)).
351 Text(">> ").Output(cil)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900352 }
353
354 if len(c.properties.Filter_out) > 0 {
355 rule.Command().BuiltTool("build_sepolicy").
356 Text("filter_out").
357 Flag("-f").
358 Inputs(android.PathsForModuleSrc(ctx, c.properties.Filter_out)).
359 FlagWithOutput("-t ", cil)
360 }
361
362 if proptools.Bool(c.properties.Remove_line_marker) {
363 rule.Command().Text("grep -v").
364 Text(proptools.ShellEscape(";;")).
365 Text(cil.String()).
366 Text(">").
367 Text(cil.String() + ".tmp").
368 Text("&& mv").
369 Text(cil.String() + ".tmp").
370 Text(cil.String())
371 }
372
373 if proptools.BoolDefault(c.properties.Secilc_check, true) {
374 secilcCmd := rule.Command().BuiltTool("secilc").
375 Flag("-m"). // Multiple decls
376 FlagWithArg("-M ", "true"). // Enable MLS
377 Flag("-G"). // expand and remove auto generated attributes
378 FlagWithArg("-c ", strconv.Itoa(PolicyVers)).
379 Inputs(android.PathsForModuleSrc(ctx, c.properties.Filter_out)). // Also add cil files which are filtered out
380 Text(cil.String()).
381 FlagWithArg("-o ", os.DevNull).
382 FlagWithArg("-f ", os.DevNull)
383
384 if proptools.BoolDefault(c.properties.Ignore_neverallow, ctx.Config().SelinuxIgnoreNeverallows()) {
385 secilcCmd.Flag("-N")
386 }
387 }
388
389 rule.Build("cil", "Building cil for "+ctx.ModuleName())
390 return cil
391}
392
393func (c *policyCil) GenerateAndroidBuildActions(ctx android.ModuleContext) {
394 if proptools.String(c.properties.Src) == "" {
395 ctx.PropertyErrorf("src", "must be specified")
396 return
397 }
398 conf := android.PathForModuleSrc(ctx, *c.properties.Src)
399 cil := c.compileConfToCil(ctx, conf)
400
Inseob Kim31db2742021-06-08 10:31:09 +0900401 if !c.Installable() {
402 c.SkipInstall()
403 }
404
Inseob Kim6cc75f42021-04-29 13:53:20 +0000405 if c.InstallInDebugRamdisk() {
406 // for userdebug_plat_sepolicy.cil
407 c.installPath = android.PathForModuleInstall(ctx)
408 } else {
409 c.installPath = android.PathForModuleInstall(ctx, "etc", "selinux")
410 }
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900411 c.installSource = cil
412 ctx.InstallFile(c.installPath, c.stem(), c.installSource)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900413}
414
415func (c *policyCil) AndroidMkEntries() []android.AndroidMkEntries {
416 return []android.AndroidMkEntries{android.AndroidMkEntries{
417 OutputFile: android.OptionalPathForPath(c.installSource),
418 Class: "ETC",
419 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
420 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
421 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.Installable())
Colin Cross6c7f9372022-01-11 19:35:43 -0800422 entries.SetPath("LOCAL_MODULE_PATH", c.installPath)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900423 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem())
424 },
425 },
426 }}
427}
428
429func (c *policyCil) OutputFiles(tag string) (android.Paths, error) {
430 if tag == "" {
431 return android.Paths{c.installSource}, nil
432 }
433 return nil, fmt.Errorf("Unknown tag %q", tag)
434}
435
436var _ android.OutputFileProducer = (*policyCil)(nil)
Inseob Kimb9d05112021-09-27 13:13:46 +0000437
438type policyBinaryProperties struct {
439 // Name of the output. Default is {module_name}
440 Stem *string
441
442 // Cil files to be compiled.
443 Srcs []string `android:"path"`
444
445 // Whether to ignore neverallow when running secilc check. Defaults to
446 // SELINUX_IGNORE_NEVERALLOWS.
447 Ignore_neverallow *bool
448
449 // Whether this module is directly installable to one of the partitions. Default is true
450 Installable *bool
451}
452
453type policyBinary struct {
454 android.ModuleBase
455
456 properties policyBinaryProperties
457
458 installSource android.Path
459 installPath android.InstallPath
460}
461
462// se_policy_binary compiles cil files to a binary sepolicy file with secilc. Usually sources of
463// se_policy_binary come from outputs of se_policy_cil modules.
464func policyBinaryFactory() android.Module {
465 c := &policyBinary{}
466 c.AddProperties(&c.properties)
467 android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon)
468 return c
469}
470
Inseob Kim5bbcd682021-12-28 14:57:03 +0900471func (c *policyBinary) InstallInRoot() bool {
472 return c.InstallInRecovery()
473}
474
Inseob Kimb9d05112021-09-27 13:13:46 +0000475func (c *policyBinary) Installable() bool {
476 return proptools.BoolDefault(c.properties.Installable, true)
477}
478
479func (c *policyBinary) stem() string {
480 return proptools.StringDefault(c.properties.Stem, c.Name())
481}
482
483func (c *policyBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
484 if len(c.properties.Srcs) == 0 {
485 ctx.PropertyErrorf("srcs", "must be specified")
486 return
487 }
Inseob Kim3d5f9252021-12-21 20:42:35 +0900488 bin := android.PathForModuleOut(ctx, c.stem()+"_policy")
Inseob Kimb9d05112021-09-27 13:13:46 +0000489 rule := android.NewRuleBuilder(pctx, ctx)
490 secilcCmd := rule.Command().BuiltTool("secilc").
491 Flag("-m"). // Multiple decls
492 FlagWithArg("-M ", "true"). // Enable MLS
493 Flag("-G"). // expand and remove auto generated attributes
494 FlagWithArg("-c ", strconv.Itoa(PolicyVers)).
495 Inputs(android.PathsForModuleSrc(ctx, c.properties.Srcs)).
496 FlagWithOutput("-o ", bin).
497 FlagWithArg("-f ", os.DevNull)
498
499 if proptools.BoolDefault(c.properties.Ignore_neverallow, ctx.Config().SelinuxIgnoreNeverallows()) {
500 secilcCmd.Flag("-N")
501 }
Inseob Kim3d5f9252021-12-21 20:42:35 +0900502 rule.Temporary(bin)
Inseob Kimb9d05112021-09-27 13:13:46 +0000503
Inseob Kim3d5f9252021-12-21 20:42:35 +0900504 // permissive check is performed only in user build (not debuggable).
505 if !ctx.Config().Debuggable() {
506 permissiveDomains := android.PathForModuleOut(ctx, c.stem()+"_permissive")
507 rule.Command().BuiltTool("sepolicy-analyze").
508 Input(bin).
509 Text("permissive").
510 Text(" > ").
511 Output(permissiveDomains)
512 rule.Temporary(permissiveDomains)
513
514 msg := `==========\n` +
515 `ERROR: permissive domains not allowed in user builds\n` +
516 `List of invalid domains:`
517
518 rule.Command().Text("if test").
519 FlagWithInput("-s ", permissiveDomains).
520 Text("; then echo").
521 Flag("-e").
522 Text(`"` + msg + `"`).
523 Text("&& cat ").
524 Input(permissiveDomains).
525 Text("; exit 1; fi")
526 }
527
528 out := android.PathForModuleOut(ctx, c.stem())
529 rule.Command().Text("cp").
530 Flag("-f").
531 Input(bin).
532 Output(out)
533
534 rule.DeleteTemporaryFiles()
Inseob Kimb9d05112021-09-27 13:13:46 +0000535 rule.Build("secilc", "Compiling cil files for "+ctx.ModuleName())
536
537 if !c.Installable() {
538 c.SkipInstall()
539 }
540
Inseob Kim5bbcd682021-12-28 14:57:03 +0900541 if c.InstallInRecovery() {
542 // install in root
543 c.installPath = android.PathForModuleInstall(ctx)
544 } else {
545 c.installPath = android.PathForModuleInstall(ctx, "etc", "selinux")
546 }
Inseob Kim3d5f9252021-12-21 20:42:35 +0900547 c.installSource = out
Inseob Kimb9d05112021-09-27 13:13:46 +0000548 ctx.InstallFile(c.installPath, c.stem(), c.installSource)
549}
550
551func (c *policyBinary) AndroidMkEntries() []android.AndroidMkEntries {
552 return []android.AndroidMkEntries{android.AndroidMkEntries{
553 OutputFile: android.OptionalPathForPath(c.installSource),
554 Class: "ETC",
555 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
556 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
557 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.Installable())
Colin Cross6c7f9372022-01-11 19:35:43 -0800558 entries.SetPath("LOCAL_MODULE_PATH", c.installPath)
Inseob Kimb9d05112021-09-27 13:13:46 +0000559 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem())
560 },
561 },
562 }}
563}
564
565func (c *policyBinary) OutputFiles(tag string) (android.Paths, error) {
566 if tag == "" {
567 return android.Paths{c.installSource}, nil
568 }
569 return nil, fmt.Errorf("Unknown tag %q", tag)
570}
571
572var _ android.OutputFileProducer = (*policyBinary)(nil)