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 |
| 35 | } |
| 36 | |
| 37 | func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 38 | rule := android.NewRuleBuilder() |
| 39 | |
atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 40 | configFileName := p.Name() + ".xml" |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 41 | p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath |
| 42 | path := android.PathForModuleSrc(ctx, String(p.properties.Src)) |
| 43 | |
| 44 | // Use the empty config if the compat config file idoesn't exist (can happen if @ChangeId |
| 45 | // annotation is not used). |
atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 46 | emptyConfig := `'<?xml version="1.0" encoding="UTF-8" standalone="no"?><config/>'` |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 47 | configPath := `compat/compat_config.xml` |
| 48 | |
| 49 | rule.Command(). |
| 50 | Text(`unzip`). |
| 51 | Flag(`-l`). |
| 52 | Input(path). |
| 53 | Text(`| grep`). |
| 54 | Flag(`-q`). |
| 55 | Text(configPath). |
| 56 | Text(`; if [ "$?" = "0" ] ; then`). |
| 57 | Text(`unzip`). |
| 58 | Flag(`-qp`). |
| 59 | Input(path). |
| 60 | Text(configPath). |
| 61 | Text(`>`). |
| 62 | Output(p.configFile). |
atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 63 | Text(`; else echo `). |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 64 | Text(emptyConfig). |
atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 65 | Text(`>`). |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 66 | Output(p.configFile). |
| 67 | Text(`; fi`) |
| 68 | |
atrost | 87901b0 | 2019-08-29 12:48:43 +0100 | [diff] [blame] | 69 | p.installDirPath = android.PathForModuleInstall(ctx, "etc", "compatconfig") |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 70 | rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it") |
| 71 | |
| 72 | } |
| 73 | |
| 74 | func (p *platformCompatConfig) AndroidMkEntries() android.AndroidMkEntries { |
| 75 | return android.AndroidMkEntries{ |
| 76 | Class: "ETC", |
| 77 | OutputFile: android.OptionalPathForPath(p.configFile), |
| 78 | Include: "$(BUILD_PREBUILT)", |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 79 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 80 | func(entries *android.AndroidMkEntries) { |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 81 | entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 82 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base()) |
| 83 | }, |
atrost | db25ac0 | 2019-08-05 12:26:07 +0100 | [diff] [blame] | 84 | }, |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func platformCompatConfigFactory() android.Module { |
| 89 | module := &platformCompatConfig{} |
| 90 | module.AddProperties(&module.properties) |
| 91 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
| 92 | return module |
| 93 | } |