Inseob Kim | 1c056b1 | 2021-04-30 00:11:43 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package selinux |
| 16 | |
| 17 | import ( |
Inseob Kim | 1c056b1 | 2021-04-30 00:11:43 +0900 | [diff] [blame] | 18 | "github.com/google/blueprint/proptools" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | android.RegisterModuleType("sepolicy_vers", sepolicyVersFactory) |
| 25 | } |
| 26 | |
| 27 | // sepolicy_vers prints sepolicy version string to {partition}/etc/selinux. |
| 28 | func sepolicyVersFactory() android.Module { |
| 29 | v := &sepolicyVers{} |
| 30 | v.AddProperties(&v.properties) |
| 31 | android.InitAndroidArchModule(v, android.DeviceSupported, android.MultilibCommon) |
| 32 | return v |
| 33 | } |
| 34 | |
| 35 | type sepolicyVers struct { |
| 36 | android.ModuleBase |
| 37 | properties sepolicyVersProperties |
| 38 | installSource android.Path |
| 39 | installPath android.InstallPath |
| 40 | } |
| 41 | |
| 42 | type sepolicyVersProperties struct { |
| 43 | // Version to output. Can be "platform" for PLATFORM_SEPOLICY_VERSION, "vendor" for |
| 44 | // BOARD_SEPOLICY_VERS |
| 45 | Version *string |
| 46 | |
| 47 | // Output file name. Defaults to module name if unspecified. |
| 48 | Stem *string |
| 49 | |
| 50 | // Whether this module is directly installable to one of the partitions. Default is true |
| 51 | Installable *bool |
| 52 | } |
| 53 | |
| 54 | func (v *sepolicyVers) installable() bool { |
| 55 | return proptools.BoolDefault(v.properties.Installable, true) |
| 56 | } |
| 57 | |
| 58 | func (v *sepolicyVers) stem() string { |
| 59 | return proptools.StringDefault(v.properties.Stem, v.Name()) |
| 60 | } |
| 61 | |
| 62 | func (v *sepolicyVers) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 63 | // do nothing |
| 64 | } |
| 65 | |
| 66 | func (v *sepolicyVers) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 67 | var ver string |
| 68 | switch proptools.String(v.properties.Version) { |
| 69 | case "platform": |
| 70 | ver = ctx.DeviceConfig().PlatformSepolicyVersion() |
| 71 | case "vendor": |
| 72 | ver = ctx.DeviceConfig().BoardSepolicyVers() |
| 73 | default: |
| 74 | ctx.PropertyErrorf("version", `should be either "platform" or "vendor"`) |
| 75 | } |
| 76 | |
| 77 | out := android.PathForModuleGen(ctx, v.stem()) |
| 78 | |
| 79 | rule := android.NewRuleBuilder(pctx, ctx) |
| 80 | rule.Command().Text("echo").Text(ver).Text(">").Output(out) |
| 81 | rule.Build("sepolicy_vers", v.Name()) |
| 82 | |
Inseob Kim | 1c056b1 | 2021-04-30 00:11:43 +0900 | [diff] [blame] | 83 | if !v.installable() { |
| 84 | v.SkipInstall() |
| 85 | } |
Inseob Kim | 31db274 | 2021-06-08 10:31:09 +0900 | [diff] [blame] | 86 | |
| 87 | v.installPath = android.PathForModuleInstall(ctx, "etc", "selinux") |
| 88 | v.installSource = out |
| 89 | ctx.InstallFile(v.installPath, v.stem(), v.installSource) |
mrziwang | dc268a7 | 2024-06-06 14:42:10 -0700 | [diff] [blame^] | 90 | |
| 91 | ctx.SetOutputFiles(android.Paths{v.installSource}, "") |
Inseob Kim | 1c056b1 | 2021-04-30 00:11:43 +0900 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | func (v *sepolicyVers) AndroidMkEntries() []android.AndroidMkEntries { |
| 95 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 96 | Class: "ETC", |
| 97 | OutputFile: android.OptionalPathForPath(v.installSource), |
| 98 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 99 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | 6c7f937 | 2022-01-11 19:35:43 -0800 | [diff] [blame] | 100 | entries.SetPath("LOCAL_MODULE_PATH", v.installPath) |
Inseob Kim | 1c056b1 | 2021-04-30 00:11:43 +0900 | [diff] [blame] | 101 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", v.stem()) |
| 102 | }, |
| 103 | }, |
| 104 | }} |
| 105 | } |