Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
// Copyright (C) 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package selinux
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
"github.com/google/blueprint"
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2020-03-24 15:06:40 +01:00
|
|
|
"android/soong/sysprop"
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type selinuxContextsProperties struct {
|
|
|
|
// Filenames under sepolicy directories, which will be used to generate contexts file.
|
|
|
|
Srcs []string `android:"path"`
|
|
|
|
|
2021-11-18 23:33:02 +01:00
|
|
|
// Output file name. Defaults to module name
|
|
|
|
Stem *string
|
|
|
|
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
Product_variables struct {
|
|
|
|
Debuggable struct {
|
|
|
|
Srcs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
Address_sanitize struct {
|
|
|
|
Srcs []string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Whether reqd_mask directory is included to sepolicy directories or not.
|
|
|
|
Reqd_mask *bool
|
|
|
|
|
|
|
|
// Whether the comments in generated contexts file will be removed or not.
|
|
|
|
Remove_comment *bool
|
|
|
|
|
|
|
|
// Whether the result context file is sorted with fc_sort or not.
|
|
|
|
Fc_sort *bool
|
|
|
|
|
|
|
|
// Make this module available when building for recovery
|
|
|
|
Recovery_available *bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type fileContextsProperties struct {
|
|
|
|
// flatten_apex can be used to specify additional sources of file_contexts.
|
|
|
|
// Apex paths, /system/apex/{apex_name}, will be amended to the paths of file_contexts
|
|
|
|
// entries.
|
|
|
|
Flatten_apex struct {
|
|
|
|
Srcs []string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type selinuxContextsModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
properties selinuxContextsProperties
|
|
|
|
fileContextsProperties fileContextsProperties
|
2020-03-24 15:06:40 +01:00
|
|
|
build func(ctx android.ModuleContext, inputs android.Paths) android.Path
|
|
|
|
deps func(ctx android.BottomUpMutatorContext)
|
|
|
|
outputPath android.Path
|
2019-10-02 19:36:09 +02:00
|
|
|
installPath android.InstallPath
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-03-24 15:06:40 +01:00
|
|
|
reuseContextsDepTag = dependencyTag{name: "reuseContexts"}
|
|
|
|
syspropLibraryDepTag = dependencyTag{name: "sysprop_library"}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.HostBinToolVariable("fc_sort", "fc_sort")
|
|
|
|
|
|
|
|
android.RegisterModuleType("file_contexts", fileFactory)
|
|
|
|
android.RegisterModuleType("hwservice_contexts", hwServiceFactory)
|
|
|
|
android.RegisterModuleType("property_contexts", propertyFactory)
|
|
|
|
android.RegisterModuleType("service_contexts", serviceFactory)
|
2020-07-25 22:02:29 +02:00
|
|
|
android.RegisterModuleType("keystore2_key_contexts", keystoreKeyFactory)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) InstallInRoot() bool {
|
|
|
|
return m.InRecovery()
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *selinuxContextsModule) InstallInRecovery() bool {
|
2021-01-12 05:40:27 +01:00
|
|
|
// ModuleBase.InRecovery() checks the image variant
|
|
|
|
return m.InRecovery()
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) onlyInRecovery() bool {
|
|
|
|
// ModuleBase.InstallInRecovery() checks commonProperties.Recovery property
|
|
|
|
return m.ModuleBase.InstallInRecovery()
|
2019-10-02 19:36:09 +02:00
|
|
|
}
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
func (m *selinuxContextsModule) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
if m.deps != nil {
|
|
|
|
m.deps(ctx)
|
|
|
|
}
|
2021-01-12 05:40:27 +01:00
|
|
|
|
|
|
|
if m.InRecovery() && !m.onlyInRecovery() {
|
|
|
|
ctx.AddFarVariationDependencies([]blueprint.Variation{
|
|
|
|
{Mutator: "image", Variation: android.CoreVariation},
|
|
|
|
}, reuseContextsDepTag, ctx.ModuleName())
|
|
|
|
}
|
2020-03-24 15:06:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *selinuxContextsModule) propertyContextsDeps(ctx android.BottomUpMutatorContext) {
|
|
|
|
for _, lib := range sysprop.SyspropLibraries(ctx.Config()) {
|
|
|
|
ctx.AddFarVariationDependencies([]blueprint.Variation{}, syspropLibraryDepTag, lib)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-18 23:33:02 +01:00
|
|
|
func (m *selinuxContextsModule) stem() string {
|
|
|
|
return proptools.StringDefault(m.properties.Stem, m.Name())
|
|
|
|
}
|
|
|
|
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
func (m *selinuxContextsModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-01-12 05:40:27 +01:00
|
|
|
if m.InRecovery() {
|
2019-10-02 19:36:09 +02:00
|
|
|
// Installing context files at the root of the recovery partition
|
|
|
|
m.installPath = android.PathForModuleInstall(ctx)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
} else {
|
|
|
|
m.installPath = android.PathForModuleInstall(ctx, "etc", "selinux")
|
|
|
|
}
|
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
if m.InRecovery() && !m.onlyInRecovery() {
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
dep := ctx.GetDirectDepWithTag(m.Name(), reuseContextsDepTag)
|
|
|
|
|
|
|
|
if reuseDeps, ok := dep.(*selinuxContextsModule); ok {
|
|
|
|
m.outputPath = reuseDeps.outputPath
|
2021-11-18 23:33:02 +01:00
|
|
|
ctx.InstallFile(m.installPath, m.stem(), m.outputPath)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var inputs android.Paths
|
|
|
|
|
2021-07-09 23:53:03 +02:00
|
|
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
|
|
|
depTag := ctx.OtherModuleDependencyTag(dep)
|
|
|
|
if !android.IsSourceDepTagWithOutputTag(depTag, "") {
|
|
|
|
return
|
|
|
|
}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
segroup, ok := dep.(*fileGroup)
|
|
|
|
if !ok {
|
|
|
|
ctx.ModuleErrorf("srcs dependency %q is not an selinux filegroup",
|
|
|
|
ctx.OtherModuleName(dep))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.ProductSpecific() {
|
|
|
|
inputs = append(inputs, segroup.ProductPrivateSrcs()...)
|
|
|
|
} else if ctx.SocSpecific() {
|
2021-12-08 14:45:58 +01:00
|
|
|
inputs = append(inputs, segroup.SystemVendorSrcs()...)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
inputs = append(inputs, segroup.VendorSrcs()...)
|
|
|
|
} else if ctx.DeviceSpecific() {
|
|
|
|
inputs = append(inputs, segroup.OdmSrcs()...)
|
2019-09-09 16:04:06 +02:00
|
|
|
} else if ctx.SystemExtSpecific() {
|
|
|
|
inputs = append(inputs, segroup.SystemExtPrivateSrcs()...)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
} else {
|
|
|
|
inputs = append(inputs, segroup.SystemPrivateSrcs()...)
|
2020-03-02 16:13:12 +01:00
|
|
|
inputs = append(inputs, segroup.SystemPublicSrcs()...)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if proptools.Bool(m.properties.Reqd_mask) {
|
2020-11-09 12:58:58 +01:00
|
|
|
if ctx.SocSpecific() || ctx.DeviceSpecific() {
|
|
|
|
inputs = append(inputs, segroup.VendorReqdMaskSrcs()...)
|
|
|
|
} else {
|
|
|
|
inputs = append(inputs, segroup.SystemReqdMaskSrcs()...)
|
|
|
|
}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, src := range m.properties.Srcs {
|
|
|
|
// Module sources are handled above with VisitDirectDepsWithTag
|
|
|
|
if android.SrcIsModule(src) == "" {
|
|
|
|
inputs = append(inputs, android.PathForModuleSrc(ctx, src))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
m.outputPath = m.build(ctx, inputs)
|
2021-11-18 23:33:02 +01:00
|
|
|
ctx.InstallFile(m.installPath, m.stem(), m.outputPath)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func newModule() *selinuxContextsModule {
|
|
|
|
m := &selinuxContextsModule{}
|
|
|
|
m.AddProperties(
|
|
|
|
&m.properties,
|
|
|
|
)
|
|
|
|
android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
android.AddLoadHook(m, func(ctx android.LoadHookContext) {
|
|
|
|
m.selinuxContextsHook(ctx)
|
|
|
|
})
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *selinuxContextsModule) selinuxContextsHook(ctx android.LoadHookContext) {
|
|
|
|
// TODO: clean this up to use build/soong/android/variable.go after b/79249983
|
|
|
|
var srcs []string
|
|
|
|
|
|
|
|
if ctx.Config().Debuggable() {
|
|
|
|
srcs = append(srcs, m.properties.Product_variables.Debuggable.Srcs...)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, sanitize := range ctx.Config().SanitizeDevice() {
|
|
|
|
if sanitize == "address" {
|
|
|
|
srcs = append(srcs, m.properties.Product_variables.Address_sanitize.Srcs...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m.properties.Srcs = append(m.properties.Srcs, srcs...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *selinuxContextsModule) AndroidMk() android.AndroidMkData {
|
2021-11-05 01:25:55 +01:00
|
|
|
nameSuffix := ""
|
|
|
|
if m.InRecovery() && !m.onlyInRecovery() {
|
|
|
|
nameSuffix = ".recovery"
|
|
|
|
}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
return android.AndroidMkData{
|
2021-11-05 01:25:55 +01:00
|
|
|
Class: "ETC",
|
|
|
|
OutputFile: android.OptionalPathForPath(m.outputPath),
|
|
|
|
SubName: nameSuffix,
|
|
|
|
Extra: []android.AndroidMkExtraFunc{
|
|
|
|
func(w io.Writer, outputFile android.Path) {
|
|
|
|
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", m.installPath.ToMakePath().String())
|
2021-11-18 23:33:02 +01:00
|
|
|
fmt.Fprintln(w, "LOCAL_INSTALLED_MODULE_STEM :=", m.stem())
|
2021-11-05 01:25:55 +01:00
|
|
|
},
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) ImageMutatorBegin(ctx android.BaseModuleContext) {
|
2021-11-18 23:33:02 +01:00
|
|
|
if proptools.Bool(m.properties.Recovery_available) && m.ModuleBase.InstallInRecovery() {
|
2021-01-12 05:40:27 +01:00
|
|
|
ctx.PropertyErrorf("recovery_available",
|
|
|
|
"doesn't make sense at the same time as `recovery: true`")
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
2021-01-12 05:40:27 +01:00
|
|
|
}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
|
2021-11-18 23:33:02 +01:00
|
|
|
return !m.ModuleBase.InstallInRecovery()
|
2021-01-12 05:40:27 +01:00
|
|
|
}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return false
|
|
|
|
}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return false
|
|
|
|
}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
2021-04-29 15:53:20 +02:00
|
|
|
func (m *selinuxContextsModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
|
2021-11-18 23:33:02 +01:00
|
|
|
return m.ModuleBase.InstallInRecovery() || proptools.Bool(m.properties.Recovery_available)
|
2021-01-12 05:40:27 +01:00
|
|
|
}
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) ExtraImageVariations(ctx android.BaseModuleContext) []string {
|
|
|
|
return nil
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 05:40:27 +01:00
|
|
|
func (m *selinuxContextsModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ android.ImageInterface = (*selinuxContextsModule)(nil)
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
func (m *selinuxContextsModule) buildGeneralContexts(ctx android.ModuleContext, inputs android.Paths) android.Path {
|
2021-11-18 23:33:02 +01:00
|
|
|
builtContext := android.PathForModuleGen(ctx, ctx.ModuleName()+"_m4out")
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
2020-11-17 02:58:17 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
|
|
|
rule.Command().
|
2019-06-19 19:52:50 +02:00
|
|
|
Tool(ctx.Config().PrebuiltBuildTool(ctx, "m4")).
|
|
|
|
Text("--fatal-warnings -s").
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
FlagForEachArg("-D", ctx.DeviceConfig().SepolicyM4Defs()).
|
|
|
|
Inputs(inputs).
|
2021-11-18 23:33:02 +01:00
|
|
|
FlagWithOutput("> ", builtContext)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
|
|
|
if proptools.Bool(m.properties.Remove_comment) {
|
2021-11-18 23:33:02 +01:00
|
|
|
rule.Temporary(builtContext)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
|
|
|
remove_comment_output := android.PathForModuleGen(ctx, ctx.ModuleName()+"_remove_comment")
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("sed -e 's/#.*$//' -e '/^$/d'").
|
2021-11-18 23:33:02 +01:00
|
|
|
Input(builtContext).
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
FlagWithOutput("> ", remove_comment_output)
|
|
|
|
|
2021-11-18 23:33:02 +01:00
|
|
|
builtContext = remove_comment_output
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if proptools.Bool(m.properties.Fc_sort) {
|
2021-11-18 23:33:02 +01:00
|
|
|
rule.Temporary(builtContext)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
|
|
|
sorted_output := android.PathForModuleGen(ctx, ctx.ModuleName()+"_sorted")
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Tool(ctx.Config().HostToolPath(ctx, "fc_sort")).
|
2021-11-18 23:33:02 +01:00
|
|
|
FlagWithInput("-i ", builtContext).
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
FlagWithOutput("-o ", sorted_output)
|
|
|
|
|
2021-11-18 23:33:02 +01:00
|
|
|
builtContext = sorted_output
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
2021-11-18 23:33:02 +01:00
|
|
|
ret := android.PathForModuleGen(ctx, m.stem())
|
|
|
|
rule.Temporary(builtContext)
|
|
|
|
rule.Command().Text("cp").Input(builtContext).Output(ret)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
|
|
|
rule.DeleteTemporaryFiles()
|
2021-11-18 23:33:02 +01:00
|
|
|
rule.Build("selinux_contexts", "building contexts: "+m.Name())
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
return ret
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
func (m *selinuxContextsModule) buildFileContexts(ctx android.ModuleContext, inputs android.Paths) android.Path {
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
if m.properties.Fc_sort == nil {
|
|
|
|
m.properties.Fc_sort = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:58:17 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
|
|
|
|
if ctx.Config().FlattenApex() {
|
|
|
|
for _, src := range m.fileContextsProperties.Flatten_apex.Srcs {
|
|
|
|
if m := android.SrcIsModule(src); m != "" {
|
|
|
|
ctx.ModuleErrorf(
|
|
|
|
"Module srcs dependency %q is not supported for flatten_apex.srcs", m)
|
2020-03-24 15:06:40 +01:00
|
|
|
return nil
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
for _, path := range android.PathsForModuleSrcExcludes(ctx, []string{src}, nil) {
|
|
|
|
out := android.PathForModuleGen(ctx, "flattened_apex", path.Rel())
|
|
|
|
apex_path := "/system/apex/" + strings.Replace(
|
|
|
|
strings.TrimSuffix(path.Base(), "-file_contexts"),
|
|
|
|
".", "\\\\.", -1)
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("awk '/object_r/{printf(\""+apex_path+"%s\\n\",$0)}'").
|
|
|
|
Input(path).
|
|
|
|
FlagWithOutput("> ", out)
|
|
|
|
|
|
|
|
inputs = append(inputs, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:58:17 +01:00
|
|
|
rule.Build(m.Name(), "flattened_apex_file_contexts")
|
2020-03-24 15:06:40 +01:00
|
|
|
return m.buildGeneralContexts(ctx, inputs)
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func fileFactory() android.Module {
|
|
|
|
m := newModule()
|
|
|
|
m.AddProperties(&m.fileContextsProperties)
|
|
|
|
m.build = m.buildFileContexts
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
func (m *selinuxContextsModule) buildHwServiceContexts(ctx android.ModuleContext, inputs android.Paths) android.Path {
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
if m.properties.Remove_comment == nil {
|
|
|
|
m.properties.Remove_comment = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
return m.buildGeneralContexts(ctx, inputs)
|
|
|
|
}
|
|
|
|
|
2020-12-21 05:16:44 +01:00
|
|
|
func (m *selinuxContextsModule) checkVendorPropertyNamespace(ctx android.ModuleContext, inputs android.Paths) android.Paths {
|
|
|
|
shippingApiLevel := ctx.DeviceConfig().ShippingApiLevel()
|
|
|
|
ApiLevelR := android.ApiLevelOrPanic(ctx, "R")
|
|
|
|
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
|
|
|
|
// This list is from vts_treble_sys_prop_test.
|
|
|
|
allowedPropertyPrefixes := []string{
|
|
|
|
"ctl.odm.",
|
|
|
|
"ctl.vendor.",
|
|
|
|
"ctl.start$odm.",
|
|
|
|
"ctl.start$vendor.",
|
|
|
|
"ctl.stop$odm.",
|
|
|
|
"ctl.stop$vendor.",
|
|
|
|
"init.svc.odm.",
|
|
|
|
"init.svc.vendor.",
|
|
|
|
"ro.boot.",
|
|
|
|
"ro.hardware.",
|
|
|
|
"ro.odm.",
|
|
|
|
"ro.vendor.",
|
|
|
|
"odm.",
|
|
|
|
"persist.odm.",
|
|
|
|
"persist.vendor.",
|
|
|
|
"vendor.",
|
|
|
|
}
|
|
|
|
|
|
|
|
// persist.camera is also allowed for devices launching with R or eariler
|
|
|
|
if shippingApiLevel.LessThanOrEqualTo(ApiLevelR) {
|
|
|
|
allowedPropertyPrefixes = append(allowedPropertyPrefixes, "persist.camera.")
|
|
|
|
}
|
|
|
|
|
|
|
|
var allowedContextPrefixes []string
|
|
|
|
|
|
|
|
if shippingApiLevel.GreaterThanOrEqualTo(ApiLevelR) {
|
|
|
|
// This list is from vts_treble_sys_prop_test.
|
|
|
|
allowedContextPrefixes = []string{
|
|
|
|
"vendor_",
|
|
|
|
"odm_",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var ret android.Paths
|
|
|
|
for _, input := range inputs {
|
|
|
|
cmd := rule.Command().
|
|
|
|
BuiltTool("check_prop_prefix").
|
|
|
|
FlagWithInput("--property-contexts ", input).
|
|
|
|
FlagForEachArg("--allowed-property-prefix ", proptools.ShellEscapeList(allowedPropertyPrefixes)). // contains shell special character '$'
|
|
|
|
FlagForEachArg("--allowed-context-prefix ", allowedContextPrefixes)
|
|
|
|
|
|
|
|
if !ctx.DeviceConfig().BuildBrokenVendorPropertyNamespace() {
|
|
|
|
cmd.Flag("--strict")
|
|
|
|
}
|
|
|
|
|
|
|
|
out := android.PathForModuleGen(ctx, "namespace_checked").Join(ctx, input.String())
|
|
|
|
rule.Command().Text("cp -f").Input(input).Output(out)
|
|
|
|
ret = append(ret, out)
|
|
|
|
}
|
|
|
|
rule.Build("check_namespace", "checking namespace of "+ctx.ModuleName())
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
func (m *selinuxContextsModule) buildPropertyContexts(ctx android.ModuleContext, inputs android.Paths) android.Path {
|
2020-12-21 05:16:44 +01:00
|
|
|
// vendor/odm properties are enforced for devices launching with Android Q or later. So, if
|
|
|
|
// vendor/odm, make sure that only vendor/odm properties exist.
|
|
|
|
shippingApiLevel := ctx.DeviceConfig().ShippingApiLevel()
|
|
|
|
ApiLevelQ := android.ApiLevelOrPanic(ctx, "Q")
|
|
|
|
if (ctx.SocSpecific() || ctx.DeviceSpecific()) && shippingApiLevel.GreaterThanOrEqualTo(ApiLevelQ) {
|
|
|
|
inputs = m.checkVendorPropertyNamespace(ctx, inputs)
|
|
|
|
}
|
|
|
|
|
2020-03-24 15:06:40 +01:00
|
|
|
builtCtxFile := m.buildGeneralContexts(ctx, inputs)
|
|
|
|
|
|
|
|
var apiFiles android.Paths
|
|
|
|
ctx.VisitDirectDepsWithTag(syspropLibraryDepTag, func(c android.Module) {
|
2021-01-15 10:10:29 +01:00
|
|
|
i, ok := c.(interface{ CurrentSyspropApiFile() android.OptionalPath })
|
2020-03-24 15:06:40 +01:00
|
|
|
if !ok {
|
|
|
|
panic(fmt.Errorf("unknown dependency %q for %q", ctx.OtherModuleName(c), ctx.ModuleName()))
|
|
|
|
}
|
2021-01-15 10:10:29 +01:00
|
|
|
if api := i.CurrentSyspropApiFile(); api.Valid() {
|
|
|
|
apiFiles = append(apiFiles, api.Path())
|
|
|
|
}
|
2020-03-24 15:06:40 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// check compatibility with sysprop_library
|
|
|
|
if len(apiFiles) > 0 {
|
|
|
|
out := android.PathForModuleGen(ctx, ctx.ModuleName()+"_api_checked")
|
2020-11-17 02:58:17 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2020-03-24 15:06:40 +01:00
|
|
|
|
|
|
|
msg := `\n******************************\n` +
|
|
|
|
`API of sysprop_library doesn't match with property_contexts\n` +
|
|
|
|
`Please fix the breakage and rebuild.\n` +
|
|
|
|
`******************************\n`
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("( ").
|
2020-11-17 02:58:17 +01:00
|
|
|
BuiltTool("sysprop_type_checker").
|
2020-03-24 15:06:40 +01:00
|
|
|
FlagForEachInput("--api ", apiFiles).
|
|
|
|
FlagWithInput("--context ", builtCtxFile).
|
|
|
|
Text(" || ( echo").Flag("-e").
|
|
|
|
Flag(`"` + msg + `"`).
|
|
|
|
Text("; exit 38) )")
|
|
|
|
|
|
|
|
rule.Command().Text("cp -f").Input(builtCtxFile).Output(out)
|
2020-11-17 02:58:17 +01:00
|
|
|
rule.Build("property_contexts_check_api", "checking API: "+m.Name())
|
2020-03-24 15:06:40 +01:00
|
|
|
builtCtxFile = out
|
|
|
|
}
|
|
|
|
|
|
|
|
return builtCtxFile
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func hwServiceFactory() android.Module {
|
|
|
|
m := newModule()
|
|
|
|
m.build = m.buildHwServiceContexts
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func propertyFactory() android.Module {
|
|
|
|
m := newModule()
|
2020-03-24 15:06:40 +01:00
|
|
|
m.build = m.buildPropertyContexts
|
|
|
|
m.deps = m.propertyContextsDeps
|
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I576f6f20686f6f2121204f76657274696d652121
2019-04-15 13:10:46 +02:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func serviceFactory() android.Module {
|
|
|
|
m := newModule()
|
|
|
|
m.build = m.buildGeneralContexts
|
|
|
|
return m
|
|
|
|
}
|
2020-07-25 22:02:29 +02:00
|
|
|
|
|
|
|
func keystoreKeyFactory() android.Module {
|
|
|
|
m := newModule()
|
|
|
|
m.build = m.buildGeneralContexts
|
|
|
|
return m
|
|
|
|
}
|
2021-11-18 23:33:02 +01:00
|
|
|
|
|
|
|
var _ android.OutputFileProducer = (*selinuxContextsModule)(nil)
|
|
|
|
|
|
|
|
// Implements android.OutputFileProducer
|
|
|
|
func (m *selinuxContextsModule) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
if tag == "" {
|
|
|
|
return []android.Path{m.outputPath}, nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|