blob: 715485fd5de54ebc8e5eedfca14c213c30241728 [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
atrostdb25ac02019-08-05 12:26:07 +010083func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
84 rule := android.NewRuleBuilder()
85
atrost87901b02019-08-29 12:48:43 +010086 configFileName := p.Name() + ".xml"
Mathew Inwood0dd06f62019-12-17 11:14:42 +000087 metadataFileName := p.Name() + "_meta.xml"
atrostdb25ac02019-08-05 12:26:07 +010088 p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath
Mathew Inwood0dd06f62019-12-17 11:14:42 +000089 p.metadataFile = android.PathForModuleOut(ctx, metadataFileName).OutputPath
atrostdb25ac02019-08-05 12:26:07 +010090 path := android.PathForModuleSrc(ctx, String(p.properties.Src))
91
atrostdb25ac02019-08-05 12:26:07 +010092 rule.Command().
Mathew Inwood2471c082019-12-16 12:55:26 +000093 BuiltTool(ctx, "process-compat-config").
Mathew Inwood0dd06f62019-12-17 11:14:42 +000094 FlagWithInput("--jar ", path).
95 FlagWithOutput("--device-config ", p.configFile).
96 FlagWithOutput("--merged-config ", p.metadataFile)
atrostdb25ac02019-08-05 12:26:07 +010097
atrost87901b02019-08-29 12:48:43 +010098 p.installDirPath = android.PathForModuleInstall(ctx, "etc", "compatconfig")
atrostdb25ac02019-08-05 12:26:07 +010099 rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it")
100
101}
102
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900103func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries {
104 return []android.AndroidMkEntries{android.AndroidMkEntries{
atrostdb25ac02019-08-05 12:26:07 +0100105 Class: "ETC",
106 OutputFile: android.OptionalPathForPath(p.configFile),
107 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700108 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
109 func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -0700110 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700111 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base())
112 },
atrostdb25ac02019-08-05 12:26:07 +0100113 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900114 }}
atrostdb25ac02019-08-05 12:26:07 +0100115}
116
Mathew Inwood4d0c19c2019-12-09 11:32:29 +0000117func platformCompatConfigSingletonFactory() android.Singleton {
118 return &platformCompatConfigSingleton{}
119}
120
atrostdb25ac02019-08-05 12:26:07 +0100121func platformCompatConfigFactory() android.Module {
122 module := &platformCompatConfig{}
123 module.AddProperties(&module.properties)
124 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
125 return module
126}