2019-08-05 13:26:07 +02:00
|
|
|
// Copyright 2019 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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 java
|
|
|
|
|
|
|
|
import (
|
2021-03-11 19:43:31 +01:00
|
|
|
"path/filepath"
|
|
|
|
|
2019-08-05 13:26:07 +02:00
|
|
|
"android/soong/android"
|
2021-03-11 19:43:31 +01:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
2019-12-19 15:27:08 +01:00
|
|
|
"fmt"
|
2019-08-05 13:26:07 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-03-09 03:59:25 +01:00
|
|
|
registerPlatformCompatConfigBuildComponents(android.InitRegistrationContext)
|
2021-03-11 19:43:31 +01:00
|
|
|
|
2022-07-20 16:18:24 +02:00
|
|
|
android.RegisterSdkMemberType(CompatConfigSdkMemberType)
|
|
|
|
}
|
|
|
|
|
|
|
|
var CompatConfigSdkMemberType = &compatConfigMemberType{
|
|
|
|
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "compat_configs",
|
|
|
|
SupportsSdk: true,
|
|
|
|
},
|
2019-12-19 15:27:08 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 03:59:25 +01:00
|
|
|
func registerPlatformCompatConfigBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterSingletonType("platform_compat_config_singleton", platformCompatConfigSingletonFactory)
|
|
|
|
ctx.RegisterModuleType("platform_compat_config", PlatformCompatConfigFactory)
|
2021-03-16 16:06:54 +01:00
|
|
|
ctx.RegisterModuleType("prebuilt_platform_compat_config", prebuiltCompatConfigFactory)
|
2021-03-09 03:59:25 +01:00
|
|
|
ctx.RegisterModuleType("global_compat_config", globalCompatConfigFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
var PrepareForTestWithPlatformCompatConfig = android.FixtureRegisterWithContext(registerPlatformCompatConfigBuildComponents)
|
|
|
|
|
2019-12-19 15:27:08 +01:00
|
|
|
func platformCompatConfigPath(ctx android.PathContext) android.OutputPath {
|
|
|
|
return android.PathForOutput(ctx, "compat_config", "merged_compat_config.xml")
|
2019-08-05 13:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type platformCompatConfigProperties struct {
|
2019-08-29 13:48:43 +02:00
|
|
|
Src *string `android:"path"`
|
2019-08-05 13:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type platformCompatConfig struct {
|
|
|
|
android.ModuleBase
|
2021-03-11 19:43:31 +01:00
|
|
|
android.SdkBase
|
2019-08-05 13:26:07 +02:00
|
|
|
|
|
|
|
properties platformCompatConfigProperties
|
2019-10-02 07:05:35 +02:00
|
|
|
installDirPath android.InstallPath
|
2019-08-05 13:26:07 +02:00
|
|
|
configFile android.OutputPath
|
2019-12-17 12:14:42 +01:00
|
|
|
metadataFile android.OutputPath
|
2019-08-05 13:26:07 +02:00
|
|
|
}
|
|
|
|
|
2021-03-16 11:12:49 +01:00
|
|
|
func (p *platformCompatConfig) compatConfigMetadata() android.Path {
|
2019-12-09 12:32:29 +01:00
|
|
|
return p.metadataFile
|
|
|
|
}
|
|
|
|
|
2020-01-27 18:01:16 +01:00
|
|
|
func (p *platformCompatConfig) CompatConfig() android.OutputPath {
|
|
|
|
return p.configFile
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *platformCompatConfig) SubDir() string {
|
|
|
|
return "compatconfig"
|
|
|
|
}
|
|
|
|
|
2021-03-16 11:12:49 +01:00
|
|
|
type platformCompatConfigMetadataProvider interface {
|
|
|
|
compatConfigMetadata() android.Path
|
|
|
|
}
|
|
|
|
|
2020-01-27 18:01:16 +01:00
|
|
|
type PlatformCompatConfigIntf interface {
|
|
|
|
android.Module
|
|
|
|
|
|
|
|
CompatConfig() android.OutputPath
|
|
|
|
// Sub dir under etc dir.
|
|
|
|
SubDir() string
|
2019-12-09 12:32:29 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 18:01:16 +01:00
|
|
|
var _ PlatformCompatConfigIntf = (*platformCompatConfig)(nil)
|
2021-03-16 11:12:49 +01:00
|
|
|
var _ platformCompatConfigMetadataProvider = (*platformCompatConfig)(nil)
|
2019-12-09 12:32:29 +01:00
|
|
|
|
2019-08-05 13:26:07 +02:00
|
|
|
func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2020-11-17 02:32:30 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2019-08-05 13:26:07 +02:00
|
|
|
|
2019-08-29 13:48:43 +02:00
|
|
|
configFileName := p.Name() + ".xml"
|
2019-12-17 12:14:42 +01:00
|
|
|
metadataFileName := p.Name() + "_meta.xml"
|
2019-08-05 13:26:07 +02:00
|
|
|
p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath
|
2019-12-17 12:14:42 +01:00
|
|
|
p.metadataFile = android.PathForModuleOut(ctx, metadataFileName).OutputPath
|
2019-08-05 13:26:07 +02:00
|
|
|
path := android.PathForModuleSrc(ctx, String(p.properties.Src))
|
|
|
|
|
|
|
|
rule.Command().
|
2020-11-17 02:32:30 +01:00
|
|
|
BuiltTool("process-compat-config").
|
2019-12-17 12:14:42 +01:00
|
|
|
FlagWithInput("--jar ", path).
|
|
|
|
FlagWithOutput("--device-config ", p.configFile).
|
|
|
|
FlagWithOutput("--merged-config ", p.metadataFile)
|
2019-08-05 13:26:07 +02:00
|
|
|
|
2019-08-29 13:48:43 +02:00
|
|
|
p.installDirPath = android.PathForModuleInstall(ctx, "etc", "compatconfig")
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build(configFileName, "Extract compat/compat_config.xml and install it")
|
2019-08-05 13:26:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-03 05:24:29 +01:00
|
|
|
func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
2019-08-05 13:26:07 +02:00
|
|
|
Class: "ETC",
|
|
|
|
OutputFile: android.OptionalPathForPath(p.configFile),
|
|
|
|
Include: "$(BUILD_PREBUILT)",
|
2019-08-28 02:33:16 +02:00
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
2020-07-03 22:18:24 +02:00
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2021-11-12 03:59:15 +01:00
|
|
|
entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
|
2019-08-28 02:33:16 +02:00
|
|
|
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base())
|
|
|
|
},
|
2019-08-05 13:26:07 +02:00
|
|
|
},
|
2019-12-03 05:24:29 +01:00
|
|
|
}}
|
2019-08-05 13:26:07 +02:00
|
|
|
}
|
|
|
|
|
2020-01-27 18:01:16 +01:00
|
|
|
func PlatformCompatConfigFactory() android.Module {
|
2019-08-05 13:26:07 +02:00
|
|
|
module := &platformCompatConfig{}
|
|
|
|
module.AddProperties(&module.properties)
|
2021-03-11 19:43:31 +01:00
|
|
|
android.InitSdkAwareModule(module)
|
2021-03-15 20:49:14 +01:00
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
2019-08-05 13:26:07 +02:00
|
|
|
return module
|
|
|
|
}
|
2019-12-19 15:27:08 +01:00
|
|
|
|
2021-03-11 19:43:31 +01:00
|
|
|
type compatConfigMemberType struct {
|
|
|
|
android.SdkMemberTypeBase
|
|
|
|
}
|
|
|
|
|
2021-07-14 11:29:36 +02:00
|
|
|
func (b *compatConfigMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
|
|
|
|
ctx.AddVariationDependencies(nil, dependencyTag, names...)
|
2021-03-11 19:43:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *compatConfigMemberType) IsInstance(module android.Module) bool {
|
|
|
|
_, ok := module.(*platformCompatConfig)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *compatConfigMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_platform_compat_config")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *compatConfigMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
|
|
|
return &compatConfigSdkMemberProperties{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type compatConfigSdkMemberProperties struct {
|
|
|
|
android.SdkMemberPropertiesBase
|
|
|
|
|
|
|
|
Metadata android.Path
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *compatConfigSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
|
|
|
module := variant.(*platformCompatConfig)
|
|
|
|
b.Metadata = module.metadataFile
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *compatConfigSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
|
|
|
builder := ctx.SnapshotBuilder()
|
|
|
|
if b.Metadata != nil {
|
|
|
|
snapshotRelativePath := filepath.Join("compat_configs", ctx.Name(), b.Metadata.Base())
|
|
|
|
builder.CopyToSnapshot(b.Metadata, snapshotRelativePath)
|
|
|
|
propertySet.AddProperty("metadata", snapshotRelativePath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ android.SdkMemberType = (*compatConfigMemberType)(nil)
|
|
|
|
|
2021-03-16 16:06:54 +01:00
|
|
|
// A prebuilt version of the platform compat config module.
|
|
|
|
type prebuiltCompatConfigModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.SdkBase
|
|
|
|
prebuilt android.Prebuilt
|
|
|
|
|
|
|
|
properties prebuiltCompatConfigProperties
|
|
|
|
|
|
|
|
metadataFile android.Path
|
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltCompatConfigProperties struct {
|
|
|
|
Metadata *string `android:"path"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *prebuiltCompatConfigModule) Prebuilt() *android.Prebuilt {
|
|
|
|
return &module.prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *prebuiltCompatConfigModule) Name() string {
|
|
|
|
return module.prebuilt.Name(module.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *prebuiltCompatConfigModule) compatConfigMetadata() android.Path {
|
|
|
|
return module.metadataFile
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ platformCompatConfigMetadataProvider = (*prebuiltCompatConfigModule)(nil)
|
|
|
|
|
|
|
|
func (module *prebuiltCompatConfigModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
module.metadataFile = module.prebuilt.SingleSourcePath(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A prebuilt version of platform_compat_config that provides the metadata.
|
|
|
|
func prebuiltCompatConfigFactory() android.Module {
|
|
|
|
m := &prebuiltCompatConfigModule{}
|
|
|
|
m.AddProperties(&m.properties)
|
|
|
|
android.InitSingleSourcePrebuiltModule(m, &m.properties, "Metadata")
|
|
|
|
android.InitSdkAwareModule(m)
|
|
|
|
android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-15 19:18:22 +01:00
|
|
|
// compat singleton rules
|
|
|
|
type platformCompatConfigSingleton struct {
|
|
|
|
metadata android.Path
|
|
|
|
}
|
|
|
|
|
2021-03-24 13:08:53 +01:00
|
|
|
// isModulePreferredByCompatConfig checks to see whether the module is preferred for use by
|
|
|
|
// platform compat config.
|
|
|
|
func isModulePreferredByCompatConfig(module android.Module) bool {
|
|
|
|
// A versioned prebuilt_platform_compat_config, i.e. foo-platform-compat-config@current should be
|
|
|
|
// ignored.
|
2021-04-28 01:39:52 +02:00
|
|
|
if android.IsModuleInVersionedSdk(module) {
|
|
|
|
return false
|
2021-03-24 13:08:53 +01:00
|
|
|
}
|
|
|
|
|
2021-04-02 11:35:24 +02:00
|
|
|
return android.IsModulePreferred(module)
|
2021-03-24 13:08:53 +01:00
|
|
|
}
|
|
|
|
|
2021-03-15 19:18:22 +01:00
|
|
|
func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
|
|
|
|
|
|
|
var compatConfigMetadata android.Paths
|
|
|
|
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
2021-03-24 13:08:53 +01:00
|
|
|
if !module.Enabled() {
|
|
|
|
return
|
|
|
|
}
|
2021-03-16 11:12:49 +01:00
|
|
|
if c, ok := module.(platformCompatConfigMetadataProvider); ok {
|
2021-03-24 13:08:53 +01:00
|
|
|
if !isModulePreferredByCompatConfig(module) {
|
|
|
|
return
|
|
|
|
}
|
2021-03-15 19:18:22 +01:00
|
|
|
metadata := c.compatConfigMetadata()
|
|
|
|
compatConfigMetadata = append(compatConfigMetadata, metadata)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if compatConfigMetadata == nil {
|
|
|
|
// nothing to do.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
outputPath := platformCompatConfigPath(ctx)
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
BuiltTool("process-compat-config").
|
|
|
|
FlagForEachInput("--xml ", compatConfigMetadata).
|
|
|
|
FlagWithOutput("--merged-config ", outputPath)
|
|
|
|
|
|
|
|
rule.Build("merged-compat-config", "Merge compat config")
|
|
|
|
|
|
|
|
p.metadata = outputPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *platformCompatConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
|
|
|
|
if p.metadata != nil {
|
|
|
|
ctx.Strict("INTERNAL_PLATFORM_MERGED_COMPAT_CONFIG", p.metadata.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func platformCompatConfigSingletonFactory() android.Singleton {
|
|
|
|
return &platformCompatConfigSingleton{}
|
|
|
|
}
|
|
|
|
|
2022-08-16 19:27:33 +02:00
|
|
|
// ============== merged_compat_config =================
|
2019-12-19 15:27:08 +01:00
|
|
|
type globalCompatConfigProperties struct {
|
|
|
|
// name of the file into which the metadata will be copied.
|
|
|
|
Filename *string
|
|
|
|
}
|
|
|
|
|
|
|
|
type globalCompatConfig struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
properties globalCompatConfigProperties
|
|
|
|
|
|
|
|
outputFilePath android.OutputPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *globalCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
filename := String(c.properties.Filename)
|
|
|
|
|
|
|
|
inputPath := platformCompatConfigPath(ctx)
|
|
|
|
c.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
|
|
|
|
|
|
|
|
// This ensures that outputFilePath has the correct name for others to
|
|
|
|
// use, as the source file may have a different name.
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Output: c.outputFilePath,
|
|
|
|
Input: inputPath,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *globalCompatConfig) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "":
|
|
|
|
return android.Paths{h.outputFilePath}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// global_compat_config provides access to the merged compat config xml file generated by the build.
|
|
|
|
func globalCompatConfigFactory() android.Module {
|
|
|
|
module := &globalCompatConfig{}
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
|
|
|
|
return module
|
|
|
|
}
|