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 (
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-12-09 12:32:29 +01:00
|
|
|
android.RegisterSingletonType("platform_compat_config_singleton", platformCompatConfigSingletonFactory)
|
2019-08-05 13:26:07 +02:00
|
|
|
android.RegisterModuleType("platform_compat_config", platformCompatConfigFactory)
|
|
|
|
}
|
|
|
|
|
2019-12-09 12:32:29 +01:00
|
|
|
type platformCompatConfigSingleton struct {
|
|
|
|
metadata android.Path
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-09 12:32:29 +01:00
|
|
|
func (p *platformCompatConfig) compatConfigMetadata() android.OutputPath {
|
|
|
|
return p.metadataFile
|
|
|
|
}
|
|
|
|
|
|
|
|
type platformCompatConfigIntf interface {
|
|
|
|
compatConfigMetadata() android.OutputPath
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ platformCompatConfigIntf = (*platformCompatConfig)(nil)
|
|
|
|
|
|
|
|
// compat singleton rules
|
|
|
|
func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
|
|
|
|
|
|
|
var compatConfigMetadata android.Paths
|
|
|
|
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
if c, ok := module.(platformCompatConfigIntf); ok {
|
|
|
|
metadata := c.compatConfigMetadata()
|
|
|
|
compatConfigMetadata = append(compatConfigMetadata, metadata)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if compatConfigMetadata == nil {
|
|
|
|
// nothing to do.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
outputPath := android.PathForOutput(ctx, "compat_config", "merged_compat_config.xml")
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
BuiltTool(ctx, "process-compat-config").
|
|
|
|
FlagForEachInput("--xml ", compatConfigMetadata).
|
|
|
|
FlagWithOutput("--merged-config ", outputPath)
|
|
|
|
|
|
|
|
rule.Build(pctx, ctx, "merged-compat-config", "Merge compat config")
|
|
|
|
|
|
|
|
p.metadata = outputPath
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:38:10 +01:00
|
|
|
func (p *platformCompatConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
|
|
|
|
if p.metadata != nil {
|
|
|
|
ctx.Strict("INTERNAL_PLATFORM_MERGED_COMPAT_CONFIG", p.metadata.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 13:26:07 +02:00
|
|
|
func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
|
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().
|
2019-12-16 13:55:26 +01:00
|
|
|
BuiltTool(ctx, "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")
|
2019-08-05 13:26:07 +02:00
|
|
|
rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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{
|
|
|
|
func(entries *android.AndroidMkEntries) {
|
2019-10-03 01:01:35 +02:00
|
|
|
entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().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
|
|
|
}
|
|
|
|
|
2019-12-09 12:32:29 +01:00
|
|
|
func platformCompatConfigSingletonFactory() android.Singleton {
|
|
|
|
return &platformCompatConfigSingleton{}
|
|
|
|
}
|
|
|
|
|
2019-08-05 13:26:07 +02:00
|
|
|
func platformCompatConfigFactory() android.Module {
|
|
|
|
module := &platformCompatConfig{}
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
|
|
|
|
return module
|
|
|
|
}
|