blob: fefd0e64b69fc8222ea2468e95f9e1e360135044 [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() {
22 android.RegisterModuleType("platform_compat_config", platformCompatConfigFactory)
23}
24
25type platformCompatConfigProperties struct {
atrost87901b02019-08-29 12:48:43 +010026 Src *string `android:"path"`
atrostdb25ac02019-08-05 12:26:07 +010027}
28
29type platformCompatConfig struct {
30 android.ModuleBase
31
32 properties platformCompatConfigProperties
Colin Cross70dda7e2019-10-01 22:05:35 -070033 installDirPath android.InstallPath
atrostdb25ac02019-08-05 12:26:07 +010034 configFile android.OutputPath
Mathew Inwood0dd06f62019-12-17 11:14:42 +000035 metadataFile android.OutputPath
atrostdb25ac02019-08-05 12:26:07 +010036}
37
38func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
39 rule := android.NewRuleBuilder()
40
atrost87901b02019-08-29 12:48:43 +010041 configFileName := p.Name() + ".xml"
Mathew Inwood0dd06f62019-12-17 11:14:42 +000042 metadataFileName := p.Name() + "_meta.xml"
atrostdb25ac02019-08-05 12:26:07 +010043 p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath
Mathew Inwood0dd06f62019-12-17 11:14:42 +000044 p.metadataFile = android.PathForModuleOut(ctx, metadataFileName).OutputPath
atrostdb25ac02019-08-05 12:26:07 +010045 path := android.PathForModuleSrc(ctx, String(p.properties.Src))
46
atrostdb25ac02019-08-05 12:26:07 +010047 rule.Command().
Mathew Inwood2471c082019-12-16 12:55:26 +000048 BuiltTool(ctx, "process-compat-config").
Mathew Inwood0dd06f62019-12-17 11:14:42 +000049 FlagWithInput("--jar ", path).
50 FlagWithOutput("--device-config ", p.configFile).
51 FlagWithOutput("--merged-config ", p.metadataFile)
atrostdb25ac02019-08-05 12:26:07 +010052
atrost87901b02019-08-29 12:48:43 +010053 p.installDirPath = android.PathForModuleInstall(ctx, "etc", "compatconfig")
atrostdb25ac02019-08-05 12:26:07 +010054 rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it")
55
56}
57
Jiyong Park0b0e1b92019-12-03 13:24:29 +090058func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries {
59 return []android.AndroidMkEntries{android.AndroidMkEntries{
atrostdb25ac02019-08-05 12:26:07 +010060 Class: "ETC",
61 OutputFile: android.OptionalPathForPath(p.configFile),
62 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -070063 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
64 func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -070065 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -070066 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base())
67 },
atrostdb25ac02019-08-05 12:26:07 +010068 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +090069 }}
atrostdb25ac02019-08-05 12:26:07 +010070}
71
72func platformCompatConfigFactory() android.Module {
73 module := &platformCompatConfig{}
74 module.AddProperties(&module.properties)
75 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
76 return module
77}