blob: a40716ab1936f638e0d8d41454d54eb9c8c4d2a2 [file] [log] [blame]
Inseob Kimb554e592019-04-15 20:10:46 +09001// 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 "fmt"
19 "io"
20 "strings"
21
Inseob Kimcd616492020-03-24 23:06:40 +090022 "github.com/google/blueprint"
Inseob Kimb554e592019-04-15 20:10:46 +090023 "github.com/google/blueprint/proptools"
24
25 "android/soong/android"
Inseob Kimcd616492020-03-24 23:06:40 +090026 "android/soong/sysprop"
Inseob Kimb554e592019-04-15 20:10:46 +090027)
28
Inseob Kimb554e592019-04-15 20:10:46 +090029type selinuxContextsProperties struct {
30 // Filenames under sepolicy directories, which will be used to generate contexts file.
31 Srcs []string `android:"path"`
32
Yuntao Xu42e732c2021-11-18 22:33:02 +000033 // Output file name. Defaults to module name
34 Stem *string
35
Inseob Kimb554e592019-04-15 20:10:46 +090036 Product_variables struct {
37 Debuggable struct {
38 Srcs []string
39 }
40
41 Address_sanitize struct {
42 Srcs []string
43 }
44 }
45
46 // Whether reqd_mask directory is included to sepolicy directories or not.
47 Reqd_mask *bool
48
49 // Whether the comments in generated contexts file will be removed or not.
50 Remove_comment *bool
51
52 // Whether the result context file is sorted with fc_sort or not.
53 Fc_sort *bool
54
55 // Make this module available when building for recovery
56 Recovery_available *bool
Inseob Kimb554e592019-04-15 20:10:46 +090057}
58
59type fileContextsProperties struct {
60 // flatten_apex can be used to specify additional sources of file_contexts.
61 // Apex paths, /system/apex/{apex_name}, will be amended to the paths of file_contexts
62 // entries.
63 Flatten_apex struct {
64 Srcs []string
65 }
66}
67
68type selinuxContextsModule struct {
69 android.ModuleBase
70
71 properties selinuxContextsProperties
72 fileContextsProperties fileContextsProperties
Inseob Kimcd616492020-03-24 23:06:40 +090073 build func(ctx android.ModuleContext, inputs android.Paths) android.Path
74 deps func(ctx android.BottomUpMutatorContext)
75 outputPath android.Path
Colin Cross040f1512019-10-02 10:36:09 -070076 installPath android.InstallPath
Inseob Kimb554e592019-04-15 20:10:46 +090077}
78
79var (
Inseob Kimcd616492020-03-24 23:06:40 +090080 reuseContextsDepTag = dependencyTag{name: "reuseContexts"}
81 syspropLibraryDepTag = dependencyTag{name: "sysprop_library"}
Inseob Kimb554e592019-04-15 20:10:46 +090082)
83
84func init() {
85 pctx.HostBinToolVariable("fc_sort", "fc_sort")
86
87 android.RegisterModuleType("file_contexts", fileFactory)
88 android.RegisterModuleType("hwservice_contexts", hwServiceFactory)
89 android.RegisterModuleType("property_contexts", propertyFactory)
90 android.RegisterModuleType("service_contexts", serviceFactory)
Janis Danisevskisc40681f2020-07-25 13:02:29 -070091 android.RegisterModuleType("keystore2_key_contexts", keystoreKeyFactory)
Inseob Kimb554e592019-04-15 20:10:46 +090092}
93
Colin Cross040f1512019-10-02 10:36:09 -070094func (m *selinuxContextsModule) InstallInRoot() bool {
Inseob Kimfa6fe472021-01-12 13:40:27 +090095 return m.InRecovery()
96}
97
98func (m *selinuxContextsModule) InstallInRecovery() bool {
99 // ModuleBase.InRecovery() checks the image variant
100 return m.InRecovery()
101}
102
103func (m *selinuxContextsModule) onlyInRecovery() bool {
104 // ModuleBase.InstallInRecovery() checks commonProperties.Recovery property
105 return m.ModuleBase.InstallInRecovery()
Colin Cross040f1512019-10-02 10:36:09 -0700106}
107
Inseob Kimcd616492020-03-24 23:06:40 +0900108func (m *selinuxContextsModule) DepsMutator(ctx android.BottomUpMutatorContext) {
109 if m.deps != nil {
110 m.deps(ctx)
111 }
Inseob Kimfa6fe472021-01-12 13:40:27 +0900112
113 if m.InRecovery() && !m.onlyInRecovery() {
114 ctx.AddFarVariationDependencies([]blueprint.Variation{
115 {Mutator: "image", Variation: android.CoreVariation},
116 }, reuseContextsDepTag, ctx.ModuleName())
117 }
Inseob Kimcd616492020-03-24 23:06:40 +0900118}
119
120func (m *selinuxContextsModule) propertyContextsDeps(ctx android.BottomUpMutatorContext) {
121 for _, lib := range sysprop.SyspropLibraries(ctx.Config()) {
122 ctx.AddFarVariationDependencies([]blueprint.Variation{}, syspropLibraryDepTag, lib)
123 }
124}
125
Yuntao Xu42e732c2021-11-18 22:33:02 +0000126func (m *selinuxContextsModule) stem() string {
127 return proptools.StringDefault(m.properties.Stem, m.Name())
128}
129
Inseob Kimb554e592019-04-15 20:10:46 +0900130func (m *selinuxContextsModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Inseob Kimfa6fe472021-01-12 13:40:27 +0900131 if m.InRecovery() {
Colin Cross040f1512019-10-02 10:36:09 -0700132 // Installing context files at the root of the recovery partition
133 m.installPath = android.PathForModuleInstall(ctx)
Inseob Kimb554e592019-04-15 20:10:46 +0900134 } else {
135 m.installPath = android.PathForModuleInstall(ctx, "etc", "selinux")
136 }
137
Inseob Kimfa6fe472021-01-12 13:40:27 +0900138 if m.InRecovery() && !m.onlyInRecovery() {
Inseob Kimb554e592019-04-15 20:10:46 +0900139 dep := ctx.GetDirectDepWithTag(m.Name(), reuseContextsDepTag)
140
141 if reuseDeps, ok := dep.(*selinuxContextsModule); ok {
142 m.outputPath = reuseDeps.outputPath
Yuntao Xu42e732c2021-11-18 22:33:02 +0000143 ctx.InstallFile(m.installPath, m.stem(), m.outputPath)
Inseob Kimb554e592019-04-15 20:10:46 +0900144 return
145 }
146 }
147
148 var inputs android.Paths
149
Paul Duffin532bde12021-07-09 22:53:03 +0100150 ctx.VisitDirectDeps(func(dep android.Module) {
151 depTag := ctx.OtherModuleDependencyTag(dep)
152 if !android.IsSourceDepTagWithOutputTag(depTag, "") {
153 return
154 }
Inseob Kimb554e592019-04-15 20:10:46 +0900155 segroup, ok := dep.(*fileGroup)
156 if !ok {
157 ctx.ModuleErrorf("srcs dependency %q is not an selinux filegroup",
158 ctx.OtherModuleName(dep))
159 return
160 }
161
162 if ctx.ProductSpecific() {
163 inputs = append(inputs, segroup.ProductPrivateSrcs()...)
164 } else if ctx.SocSpecific() {
Inseob Kim7174ffe2021-12-08 22:45:58 +0900165 inputs = append(inputs, segroup.SystemVendorSrcs()...)
Inseob Kimb554e592019-04-15 20:10:46 +0900166 inputs = append(inputs, segroup.VendorSrcs()...)
167 } else if ctx.DeviceSpecific() {
168 inputs = append(inputs, segroup.OdmSrcs()...)
Bowgo Tsai86a048d2019-09-09 22:04:06 +0800169 } else if ctx.SystemExtSpecific() {
170 inputs = append(inputs, segroup.SystemExtPrivateSrcs()...)
Inseob Kimb554e592019-04-15 20:10:46 +0900171 } else {
172 inputs = append(inputs, segroup.SystemPrivateSrcs()...)
Felix342b58a2020-03-02 16:13:12 +0100173 inputs = append(inputs, segroup.SystemPublicSrcs()...)
Inseob Kimb554e592019-04-15 20:10:46 +0900174 }
175
176 if proptools.Bool(m.properties.Reqd_mask) {
Inseob Kim8ada8a72020-11-09 20:58:58 +0900177 if ctx.SocSpecific() || ctx.DeviceSpecific() {
178 inputs = append(inputs, segroup.VendorReqdMaskSrcs()...)
179 } else {
180 inputs = append(inputs, segroup.SystemReqdMaskSrcs()...)
181 }
Inseob Kimb554e592019-04-15 20:10:46 +0900182 }
183 })
184
185 for _, src := range m.properties.Srcs {
186 // Module sources are handled above with VisitDirectDepsWithTag
187 if android.SrcIsModule(src) == "" {
188 inputs = append(inputs, android.PathForModuleSrc(ctx, src))
189 }
190 }
191
Inseob Kimcd616492020-03-24 23:06:40 +0900192 m.outputPath = m.build(ctx, inputs)
Yuntao Xu42e732c2021-11-18 22:33:02 +0000193 ctx.InstallFile(m.installPath, m.stem(), m.outputPath)
Inseob Kimb554e592019-04-15 20:10:46 +0900194}
195
196func newModule() *selinuxContextsModule {
197 m := &selinuxContextsModule{}
198 m.AddProperties(
199 &m.properties,
200 )
201 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
202 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
203 m.selinuxContextsHook(ctx)
204 })
205 return m
206}
207
208func (m *selinuxContextsModule) selinuxContextsHook(ctx android.LoadHookContext) {
209 // TODO: clean this up to use build/soong/android/variable.go after b/79249983
210 var srcs []string
211
212 if ctx.Config().Debuggable() {
213 srcs = append(srcs, m.properties.Product_variables.Debuggable.Srcs...)
214 }
215
216 for _, sanitize := range ctx.Config().SanitizeDevice() {
217 if sanitize == "address" {
218 srcs = append(srcs, m.properties.Product_variables.Address_sanitize.Srcs...)
219 break
220 }
221 }
222
223 m.properties.Srcs = append(m.properties.Srcs, srcs...)
224}
225
226func (m *selinuxContextsModule) AndroidMk() android.AndroidMkData {
Colin Crossf82aed02021-11-04 17:25:55 -0700227 nameSuffix := ""
228 if m.InRecovery() && !m.onlyInRecovery() {
229 nameSuffix = ".recovery"
230 }
Inseob Kimb554e592019-04-15 20:10:46 +0900231 return android.AndroidMkData{
Colin Crossf82aed02021-11-04 17:25:55 -0700232 Class: "ETC",
233 OutputFile: android.OptionalPathForPath(m.outputPath),
234 SubName: nameSuffix,
235 Extra: []android.AndroidMkExtraFunc{
236 func(w io.Writer, outputFile android.Path) {
237 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", m.installPath.ToMakePath().String())
Yuntao Xu42e732c2021-11-18 22:33:02 +0000238 fmt.Fprintln(w, "LOCAL_INSTALLED_MODULE_STEM :=", m.stem())
Colin Crossf82aed02021-11-04 17:25:55 -0700239 },
Inseob Kimb554e592019-04-15 20:10:46 +0900240 },
241 }
242}
243
Inseob Kimfa6fe472021-01-12 13:40:27 +0900244func (m *selinuxContextsModule) ImageMutatorBegin(ctx android.BaseModuleContext) {
Yuntao Xu42e732c2021-11-18 22:33:02 +0000245 if proptools.Bool(m.properties.Recovery_available) && m.ModuleBase.InstallInRecovery() {
Inseob Kimfa6fe472021-01-12 13:40:27 +0900246 ctx.PropertyErrorf("recovery_available",
247 "doesn't make sense at the same time as `recovery: true`")
Inseob Kimb554e592019-04-15 20:10:46 +0900248 }
249}
250
Inseob Kimfa6fe472021-01-12 13:40:27 +0900251func (m *selinuxContextsModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Yuntao Xu42e732c2021-11-18 22:33:02 +0000252 return !m.ModuleBase.InstallInRecovery()
Inseob Kimfa6fe472021-01-12 13:40:27 +0900253}
254
255func (m *selinuxContextsModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
256 return false
257}
258
259func (m *selinuxContextsModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
260 return false
261}
262
Inseob Kim6cc75f42021-04-29 13:53:20 +0000263func (m *selinuxContextsModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
264 return false
265}
266
Inseob Kimfa6fe472021-01-12 13:40:27 +0900267func (m *selinuxContextsModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
Yuntao Xu42e732c2021-11-18 22:33:02 +0000268 return m.ModuleBase.InstallInRecovery() || proptools.Bool(m.properties.Recovery_available)
Inseob Kimfa6fe472021-01-12 13:40:27 +0900269}
270
271func (m *selinuxContextsModule) ExtraImageVariations(ctx android.BaseModuleContext) []string {
272 return nil
273}
274
275func (m *selinuxContextsModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
276}
277
278var _ android.ImageInterface = (*selinuxContextsModule)(nil)
279
Inseob Kimcd616492020-03-24 23:06:40 +0900280func (m *selinuxContextsModule) buildGeneralContexts(ctx android.ModuleContext, inputs android.Paths) android.Path {
Yuntao Xu42e732c2021-11-18 22:33:02 +0000281 builtContext := android.PathForModuleGen(ctx, ctx.ModuleName()+"_m4out")
Inseob Kimb554e592019-04-15 20:10:46 +0900282
Colin Cross242c8bc2020-11-16 17:58:17 -0800283 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kimb554e592019-04-15 20:10:46 +0900284
285 rule.Command().
Dan Willemsen3c3e59b2019-06-19 10:52:50 -0700286 Tool(ctx.Config().PrebuiltBuildTool(ctx, "m4")).
287 Text("--fatal-warnings -s").
Inseob Kimb554e592019-04-15 20:10:46 +0900288 FlagForEachArg("-D", ctx.DeviceConfig().SepolicyM4Defs()).
289 Inputs(inputs).
Yuntao Xu42e732c2021-11-18 22:33:02 +0000290 FlagWithOutput("> ", builtContext)
Inseob Kimb554e592019-04-15 20:10:46 +0900291
292 if proptools.Bool(m.properties.Remove_comment) {
Yuntao Xu42e732c2021-11-18 22:33:02 +0000293 rule.Temporary(builtContext)
Inseob Kimb554e592019-04-15 20:10:46 +0900294
295 remove_comment_output := android.PathForModuleGen(ctx, ctx.ModuleName()+"_remove_comment")
296
297 rule.Command().
298 Text("sed -e 's/#.*$//' -e '/^$/d'").
Yuntao Xu42e732c2021-11-18 22:33:02 +0000299 Input(builtContext).
Inseob Kimb554e592019-04-15 20:10:46 +0900300 FlagWithOutput("> ", remove_comment_output)
301
Yuntao Xu42e732c2021-11-18 22:33:02 +0000302 builtContext = remove_comment_output
Inseob Kimb554e592019-04-15 20:10:46 +0900303 }
304
305 if proptools.Bool(m.properties.Fc_sort) {
Yuntao Xu42e732c2021-11-18 22:33:02 +0000306 rule.Temporary(builtContext)
Inseob Kimb554e592019-04-15 20:10:46 +0900307
308 sorted_output := android.PathForModuleGen(ctx, ctx.ModuleName()+"_sorted")
309
310 rule.Command().
311 Tool(ctx.Config().HostToolPath(ctx, "fc_sort")).
Yuntao Xu42e732c2021-11-18 22:33:02 +0000312 FlagWithInput("-i ", builtContext).
Inseob Kimb554e592019-04-15 20:10:46 +0900313 FlagWithOutput("-o ", sorted_output)
314
Yuntao Xu42e732c2021-11-18 22:33:02 +0000315 builtContext = sorted_output
Inseob Kimb554e592019-04-15 20:10:46 +0900316 }
317
Yuntao Xu42e732c2021-11-18 22:33:02 +0000318 ret := android.PathForModuleGen(ctx, m.stem())
319 rule.Temporary(builtContext)
320 rule.Command().Text("cp").Input(builtContext).Output(ret)
Inseob Kimb554e592019-04-15 20:10:46 +0900321
322 rule.DeleteTemporaryFiles()
Yuntao Xu42e732c2021-11-18 22:33:02 +0000323 rule.Build("selinux_contexts", "building contexts: "+m.Name())
Inseob Kimb554e592019-04-15 20:10:46 +0900324
Inseob Kimcd616492020-03-24 23:06:40 +0900325 return ret
Inseob Kimb554e592019-04-15 20:10:46 +0900326}
327
Inseob Kimcd616492020-03-24 23:06:40 +0900328func (m *selinuxContextsModule) buildFileContexts(ctx android.ModuleContext, inputs android.Paths) android.Path {
Inseob Kimb554e592019-04-15 20:10:46 +0900329 if m.properties.Fc_sort == nil {
330 m.properties.Fc_sort = proptools.BoolPtr(true)
331 }
332
Colin Cross242c8bc2020-11-16 17:58:17 -0800333 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kimb554e592019-04-15 20:10:46 +0900334
335 if ctx.Config().FlattenApex() {
336 for _, src := range m.fileContextsProperties.Flatten_apex.Srcs {
337 if m := android.SrcIsModule(src); m != "" {
338 ctx.ModuleErrorf(
339 "Module srcs dependency %q is not supported for flatten_apex.srcs", m)
Inseob Kimcd616492020-03-24 23:06:40 +0900340 return nil
Inseob Kimb554e592019-04-15 20:10:46 +0900341 }
342 for _, path := range android.PathsForModuleSrcExcludes(ctx, []string{src}, nil) {
343 out := android.PathForModuleGen(ctx, "flattened_apex", path.Rel())
344 apex_path := "/system/apex/" + strings.Replace(
345 strings.TrimSuffix(path.Base(), "-file_contexts"),
346 ".", "\\\\.", -1)
347
348 rule.Command().
349 Text("awk '/object_r/{printf(\""+apex_path+"%s\\n\",$0)}'").
350 Input(path).
351 FlagWithOutput("> ", out)
352
353 inputs = append(inputs, out)
354 }
355 }
356 }
357
Colin Cross242c8bc2020-11-16 17:58:17 -0800358 rule.Build(m.Name(), "flattened_apex_file_contexts")
Inseob Kimcd616492020-03-24 23:06:40 +0900359 return m.buildGeneralContexts(ctx, inputs)
Inseob Kimb554e592019-04-15 20:10:46 +0900360}
361
362func fileFactory() android.Module {
363 m := newModule()
364 m.AddProperties(&m.fileContextsProperties)
365 m.build = m.buildFileContexts
366 return m
367}
368
Inseob Kimcd616492020-03-24 23:06:40 +0900369func (m *selinuxContextsModule) buildHwServiceContexts(ctx android.ModuleContext, inputs android.Paths) android.Path {
Inseob Kimb554e592019-04-15 20:10:46 +0900370 if m.properties.Remove_comment == nil {
371 m.properties.Remove_comment = proptools.BoolPtr(true)
372 }
373
Inseob Kimcd616492020-03-24 23:06:40 +0900374 return m.buildGeneralContexts(ctx, inputs)
375}
376
Inseob Kim2bcc0452020-12-21 13:16:44 +0900377func (m *selinuxContextsModule) checkVendorPropertyNamespace(ctx android.ModuleContext, inputs android.Paths) android.Paths {
378 shippingApiLevel := ctx.DeviceConfig().ShippingApiLevel()
379 ApiLevelR := android.ApiLevelOrPanic(ctx, "R")
380
381 rule := android.NewRuleBuilder(pctx, ctx)
382
383 // This list is from vts_treble_sys_prop_test.
384 allowedPropertyPrefixes := []string{
385 "ctl.odm.",
386 "ctl.vendor.",
387 "ctl.start$odm.",
388 "ctl.start$vendor.",
389 "ctl.stop$odm.",
390 "ctl.stop$vendor.",
391 "init.svc.odm.",
392 "init.svc.vendor.",
393 "ro.boot.",
394 "ro.hardware.",
395 "ro.odm.",
396 "ro.vendor.",
397 "odm.",
398 "persist.odm.",
399 "persist.vendor.",
400 "vendor.",
401 }
402
403 // persist.camera is also allowed for devices launching with R or eariler
404 if shippingApiLevel.LessThanOrEqualTo(ApiLevelR) {
405 allowedPropertyPrefixes = append(allowedPropertyPrefixes, "persist.camera.")
406 }
407
408 var allowedContextPrefixes []string
409
410 if shippingApiLevel.GreaterThanOrEqualTo(ApiLevelR) {
411 // This list is from vts_treble_sys_prop_test.
412 allowedContextPrefixes = []string{
413 "vendor_",
414 "odm_",
415 }
416 }
417
418 var ret android.Paths
419 for _, input := range inputs {
420 cmd := rule.Command().
421 BuiltTool("check_prop_prefix").
422 FlagWithInput("--property-contexts ", input).
423 FlagForEachArg("--allowed-property-prefix ", proptools.ShellEscapeList(allowedPropertyPrefixes)). // contains shell special character '$'
424 FlagForEachArg("--allowed-context-prefix ", allowedContextPrefixes)
425
426 if !ctx.DeviceConfig().BuildBrokenVendorPropertyNamespace() {
427 cmd.Flag("--strict")
428 }
429
430 out := android.PathForModuleGen(ctx, "namespace_checked").Join(ctx, input.String())
431 rule.Command().Text("cp -f").Input(input).Output(out)
432 ret = append(ret, out)
433 }
434 rule.Build("check_namespace", "checking namespace of "+ctx.ModuleName())
435 return ret
436}
437
Inseob Kimcd616492020-03-24 23:06:40 +0900438func (m *selinuxContextsModule) buildPropertyContexts(ctx android.ModuleContext, inputs android.Paths) android.Path {
Inseob Kim2bcc0452020-12-21 13:16:44 +0900439 // vendor/odm properties are enforced for devices launching with Android Q or later. So, if
440 // vendor/odm, make sure that only vendor/odm properties exist.
441 shippingApiLevel := ctx.DeviceConfig().ShippingApiLevel()
442 ApiLevelQ := android.ApiLevelOrPanic(ctx, "Q")
443 if (ctx.SocSpecific() || ctx.DeviceSpecific()) && shippingApiLevel.GreaterThanOrEqualTo(ApiLevelQ) {
444 inputs = m.checkVendorPropertyNamespace(ctx, inputs)
445 }
446
Inseob Kimcd616492020-03-24 23:06:40 +0900447 builtCtxFile := m.buildGeneralContexts(ctx, inputs)
448
449 var apiFiles android.Paths
450 ctx.VisitDirectDepsWithTag(syspropLibraryDepTag, func(c android.Module) {
Inseob Kim3a3539a2021-01-15 18:10:29 +0900451 i, ok := c.(interface{ CurrentSyspropApiFile() android.OptionalPath })
Inseob Kimcd616492020-03-24 23:06:40 +0900452 if !ok {
453 panic(fmt.Errorf("unknown dependency %q for %q", ctx.OtherModuleName(c), ctx.ModuleName()))
454 }
Inseob Kim3a3539a2021-01-15 18:10:29 +0900455 if api := i.CurrentSyspropApiFile(); api.Valid() {
456 apiFiles = append(apiFiles, api.Path())
457 }
Inseob Kimcd616492020-03-24 23:06:40 +0900458 })
459
460 // check compatibility with sysprop_library
461 if len(apiFiles) > 0 {
462 out := android.PathForModuleGen(ctx, ctx.ModuleName()+"_api_checked")
Colin Cross242c8bc2020-11-16 17:58:17 -0800463 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kimcd616492020-03-24 23:06:40 +0900464
465 msg := `\n******************************\n` +
466 `API of sysprop_library doesn't match with property_contexts\n` +
467 `Please fix the breakage and rebuild.\n` +
468 `******************************\n`
469
470 rule.Command().
471 Text("( ").
Colin Cross242c8bc2020-11-16 17:58:17 -0800472 BuiltTool("sysprop_type_checker").
Inseob Kimcd616492020-03-24 23:06:40 +0900473 FlagForEachInput("--api ", apiFiles).
474 FlagWithInput("--context ", builtCtxFile).
475 Text(" || ( echo").Flag("-e").
476 Flag(`"` + msg + `"`).
477 Text("; exit 38) )")
478
479 rule.Command().Text("cp -f").Input(builtCtxFile).Output(out)
Colin Cross242c8bc2020-11-16 17:58:17 -0800480 rule.Build("property_contexts_check_api", "checking API: "+m.Name())
Inseob Kimcd616492020-03-24 23:06:40 +0900481 builtCtxFile = out
482 }
483
484 return builtCtxFile
Inseob Kimb554e592019-04-15 20:10:46 +0900485}
486
487func hwServiceFactory() android.Module {
488 m := newModule()
489 m.build = m.buildHwServiceContexts
490 return m
491}
492
493func propertyFactory() android.Module {
494 m := newModule()
Inseob Kimcd616492020-03-24 23:06:40 +0900495 m.build = m.buildPropertyContexts
496 m.deps = m.propertyContextsDeps
Inseob Kimb554e592019-04-15 20:10:46 +0900497 return m
498}
499
500func serviceFactory() android.Module {
501 m := newModule()
502 m.build = m.buildGeneralContexts
503 return m
504}
Janis Danisevskisc40681f2020-07-25 13:02:29 -0700505
506func keystoreKeyFactory() android.Module {
507 m := newModule()
508 m.build = m.buildGeneralContexts
509 return m
510}
Yuntao Xu42e732c2021-11-18 22:33:02 +0000511
512var _ android.OutputFileProducer = (*selinuxContextsModule)(nil)
513
514// Implements android.OutputFileProducer
515func (m *selinuxContextsModule) OutputFiles(tag string) (android.Paths, error) {
516 if tag == "" {
517 return []android.Path{m.outputPath}, nil
518 }
519 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
520}