| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 | ) | 
|  | 20 |  | 
|  | 21 | func init() { | 
| Mathew Inwood | 4d0c19c | 2019-12-09 11:32:29 +0000 | [diff] [blame] | 22 | android.RegisterSingletonType("platform_compat_config_singleton", platformCompatConfigSingletonFactory) | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 23 | android.RegisterModuleType("platform_compat_config", platformCompatConfigFactory) | 
|  | 24 | } | 
|  | 25 |  | 
| Mathew Inwood | 4d0c19c | 2019-12-09 11:32:29 +0000 | [diff] [blame] | 26 | type platformCompatConfigSingleton struct { | 
|  | 27 | metadata android.Path | 
|  | 28 | } | 
|  | 29 |  | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 30 | type platformCompatConfigProperties struct { | 
| atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 31 | Src *string `android:"path"` | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 32 | } | 
|  | 33 |  | 
|  | 34 | type platformCompatConfig struct { | 
|  | 35 | android.ModuleBase | 
|  | 36 |  | 
|  | 37 | properties     platformCompatConfigProperties | 
| Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 38 | installDirPath android.InstallPath | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 39 | configFile     android.OutputPath | 
| Mathew Inwood | 0dd06f6 | 2019-12-17 11:14:42 +0000 | [diff] [blame] | 40 | metadataFile   android.OutputPath | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 41 | } | 
|  | 42 |  | 
| Mathew Inwood | 4d0c19c | 2019-12-09 11:32:29 +0000 | [diff] [blame] | 43 | func (p *platformCompatConfig) compatConfigMetadata() android.OutputPath { | 
|  | 44 | return p.metadataFile | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | type platformCompatConfigIntf interface { | 
|  | 48 | compatConfigMetadata() android.OutputPath | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | var _ platformCompatConfigIntf = (*platformCompatConfig)(nil) | 
|  | 52 |  | 
|  | 53 | // compat singleton rules | 
|  | 54 | func (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 Inwood | 653c78a | 2019-12-19 12:38:10 +0000 | [diff] [blame] | 83 | func (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 |  | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 89 | func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 90 | rule := android.NewRuleBuilder() | 
|  | 91 |  | 
| atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 92 | configFileName := p.Name() + ".xml" | 
| Mathew Inwood | 0dd06f6 | 2019-12-17 11:14:42 +0000 | [diff] [blame] | 93 | metadataFileName := p.Name() + "_meta.xml" | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 94 | p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath | 
| Mathew Inwood | 0dd06f6 | 2019-12-17 11:14:42 +0000 | [diff] [blame] | 95 | p.metadataFile = android.PathForModuleOut(ctx, metadataFileName).OutputPath | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 96 | path := android.PathForModuleSrc(ctx, String(p.properties.Src)) | 
|  | 97 |  | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 98 | rule.Command(). | 
| Mathew Inwood | 2471c08 | 2019-12-16 12:55:26 +0000 | [diff] [blame] | 99 | BuiltTool(ctx, "process-compat-config"). | 
| Mathew Inwood | 0dd06f6 | 2019-12-17 11:14:42 +0000 | [diff] [blame] | 100 | FlagWithInput("--jar ", path). | 
|  | 101 | FlagWithOutput("--device-config ", p.configFile). | 
|  | 102 | FlagWithOutput("--merged-config ", p.metadataFile) | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 103 |  | 
| atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 104 | p.installDirPath = android.PathForModuleInstall(ctx, "etc", "compatconfig") | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 105 | rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it") | 
|  | 106 |  | 
|  | 107 | } | 
|  | 108 |  | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 109 | func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries { | 
|  | 110 | return []android.AndroidMkEntries{android.AndroidMkEntries{ | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 111 | Class:      "ETC", | 
|  | 112 | OutputFile: android.OptionalPathForPath(p.configFile), | 
|  | 113 | Include:    "$(BUILD_PREBUILT)", | 
| Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 114 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ | 
|  | 115 | func(entries *android.AndroidMkEntries) { | 
| Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 116 | entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) | 
| Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 117 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base()) | 
|  | 118 | }, | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 119 | }, | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 120 | }} | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 121 | } | 
|  | 122 |  | 
| Mathew Inwood | 4d0c19c | 2019-12-09 11:32:29 +0000 | [diff] [blame] | 123 | func platformCompatConfigSingletonFactory() android.Singleton { | 
|  | 124 | return &platformCompatConfigSingleton{} | 
|  | 125 | } | 
|  | 126 |  | 
| atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 127 | func platformCompatConfigFactory() android.Module { | 
|  | 128 | module := &platformCompatConfig{} | 
|  | 129 | module.AddProperties(&module.properties) | 
|  | 130 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) | 
|  | 131 | return module | 
|  | 132 | } |