blob: d5c7579e899004d0c8710d6bae1836095876b1ec [file] [log] [blame]
atrostdb25ac02019-08-05 12:26:07 +01001// Copyright 2019 Google Inc. All rights reserved.
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 java
16
17import (
18 "android/soong/android"
19)
20
21func init() {
Mathew Inwood4d0c19c2019-12-09 11:32:29 +000022 android.RegisterSingletonType("platform_compat_config_singleton", platformCompatConfigSingletonFactory)
atrostdb25ac02019-08-05 12:26:07 +010023 android.RegisterModuleType("platform_compat_config", platformCompatConfigFactory)
24}
25
Mathew Inwood4d0c19c2019-12-09 11:32:29 +000026type platformCompatConfigSingleton struct {
27 metadata android.Path
28}
29
atrostdb25ac02019-08-05 12:26:07 +010030type platformCompatConfigProperties struct {
atrost87901b02019-08-29 12:48:43 +010031 Src *string `android:"path"`
atrostdb25ac02019-08-05 12:26:07 +010032}
33
34type platformCompatConfig struct {
35 android.ModuleBase
36
37 properties platformCompatConfigProperties
Colin Cross70dda7e2019-10-01 22:05:35 -070038 installDirPath android.InstallPath
atrostdb25ac02019-08-05 12:26:07 +010039 configFile android.OutputPath
Mathew Inwood0dd06f62019-12-17 11:14:42 +000040 metadataFile android.OutputPath
atrostdb25ac02019-08-05 12:26:07 +010041}
42
Mathew Inwood4d0c19c2019-12-09 11:32:29 +000043func (p *platformCompatConfig) compatConfigMetadata() android.OutputPath {
44 return p.metadataFile
45}
46
47type platformCompatConfigIntf interface {
48 compatConfigMetadata() android.OutputPath
49}
50
51var _ platformCompatConfigIntf = (*platformCompatConfig)(nil)
52
53// compat singleton rules
54func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
55
56 var compatConfigMetadata android.Paths
57
58 ctx.VisitAllModules(func(module android.Module) {
59 if c, ok := module.(platformCompatConfigIntf); ok {
60 metadata := c.compatConfigMetadata()
61 compatConfigMetadata = append(compatConfigMetadata, metadata)
62 }
63 })
64
65 if compatConfigMetadata == nil {
66 // nothing to do.
67 return
68 }
69
70 rule := android.NewRuleBuilder()
71 outputPath := android.PathForOutput(ctx, "compat_config", "merged_compat_config.xml")
72
73 rule.Command().
74 BuiltTool(ctx, "process-compat-config").
75 FlagForEachInput("--xml ", compatConfigMetadata).
76 FlagWithOutput("--merged-config ", outputPath)
77
78 rule.Build(pctx, ctx, "merged-compat-config", "Merge compat config")
79
80 p.metadata = outputPath
81}
82
Mathew Inwood653c78a2019-12-19 12:38:10 +000083func (p *platformCompatConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
84 if p.metadata != nil {
85 ctx.Strict("INTERNAL_PLATFORM_MERGED_COMPAT_CONFIG", p.metadata.String())
86 }
87}
88
atrostdb25ac02019-08-05 12:26:07 +010089func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
90 rule := android.NewRuleBuilder()
91
atrost87901b02019-08-29 12:48:43 +010092 configFileName := p.Name() + ".xml"
Mathew Inwood0dd06f62019-12-17 11:14:42 +000093 metadataFileName := p.Name() + "_meta.xml"
atrostdb25ac02019-08-05 12:26:07 +010094 p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath
Mathew Inwood0dd06f62019-12-17 11:14:42 +000095 p.metadataFile = android.PathForModuleOut(ctx, metadataFileName).OutputPath
atrostdb25ac02019-08-05 12:26:07 +010096 path := android.PathForModuleSrc(ctx, String(p.properties.Src))
97
atrostdb25ac02019-08-05 12:26:07 +010098 rule.Command().
Mathew Inwood2471c082019-12-16 12:55:26 +000099 BuiltTool(ctx, "process-compat-config").
Mathew Inwood0dd06f62019-12-17 11:14:42 +0000100 FlagWithInput("--jar ", path).
101 FlagWithOutput("--device-config ", p.configFile).
102 FlagWithOutput("--merged-config ", p.metadataFile)
atrostdb25ac02019-08-05 12:26:07 +0100103
atrost87901b02019-08-29 12:48:43 +0100104 p.installDirPath = android.PathForModuleInstall(ctx, "etc", "compatconfig")
atrostdb25ac02019-08-05 12:26:07 +0100105 rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it")
106
107}
108
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900109func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries {
110 return []android.AndroidMkEntries{android.AndroidMkEntries{
atrostdb25ac02019-08-05 12:26:07 +0100111 Class: "ETC",
112 OutputFile: android.OptionalPathForPath(p.configFile),
113 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700114 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
115 func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -0700116 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700117 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base())
118 },
atrostdb25ac02019-08-05 12:26:07 +0100119 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900120 }}
atrostdb25ac02019-08-05 12:26:07 +0100121}
122
Mathew Inwood4d0c19c2019-12-09 11:32:29 +0000123func platformCompatConfigSingletonFactory() android.Singleton {
124 return &platformCompatConfigSingleton{}
125}
126
atrostdb25ac02019-08-05 12:26:07 +0100127func platformCompatConfigFactory() android.Module {
128 module := &platformCompatConfig{}
129 module.AddProperties(&module.properties)
130 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
131 return module
132}