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() { |
| 22 | android.RegisterModuleType("platform_compat_config", platformCompatConfigFactory) |
| 23 | } |
| 24 | |
| 25 | type platformCompatConfigProperties struct { |
atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 26 | Src *string `android:"path"` |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | type platformCompatConfig struct { |
| 30 | android.ModuleBase |
| 31 | |
| 32 | properties platformCompatConfigProperties |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 33 | installDirPath android.InstallPath |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 34 | configFile android.OutputPath |
Mathew Inwood | 0dd06f6 | 2019-12-17 11:14:42 +0000 | [diff] [blame] | 35 | metadataFile android.OutputPath |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 39 | rule := android.NewRuleBuilder() |
| 40 | |
atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 41 | configFileName := p.Name() + ".xml" |
Mathew Inwood | 0dd06f6 | 2019-12-17 11:14:42 +0000 | [diff] [blame] | 42 | metadataFileName := p.Name() + "_meta.xml" |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 43 | p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath |
Mathew Inwood | 0dd06f6 | 2019-12-17 11:14:42 +0000 | [diff] [blame] | 44 | p.metadataFile = android.PathForModuleOut(ctx, metadataFileName).OutputPath |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 45 | path := android.PathForModuleSrc(ctx, String(p.properties.Src)) |
| 46 | |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 47 | rule.Command(). |
Mathew Inwood | 2471c08 | 2019-12-16 12:55:26 +0000 | [diff] [blame] | 48 | BuiltTool(ctx, "process-compat-config"). |
Mathew Inwood | 0dd06f6 | 2019-12-17 11:14:42 +0000 | [diff] [blame] | 49 | FlagWithInput("--jar ", path). |
| 50 | FlagWithOutput("--device-config ", p.configFile). |
| 51 | FlagWithOutput("--merged-config ", p.metadataFile) |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 52 | |
atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 53 | p.installDirPath = android.PathForModuleInstall(ctx, "etc", "compatconfig") |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 54 | rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it") |
| 55 | |
| 56 | } |
| 57 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 58 | func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries { |
| 59 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 60 | Class: "ETC", |
| 61 | OutputFile: android.OptionalPathForPath(p.configFile), |
| 62 | Include: "$(BUILD_PREBUILT)", |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 63 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 64 | func(entries *android.AndroidMkEntries) { |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 65 | entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 66 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base()) |
| 67 | }, |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 68 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 69 | }} |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | func platformCompatConfigFactory() android.Module { |
| 73 | module := &platformCompatConfig{} |
| 74 | module.AddProperties(&module.properties) |
| 75 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
| 76 | return module |
| 77 | } |