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