From db25ac07a57fe6e677f5949fedab476f782bf536 Mon Sep 17 00:00:00 2001 From: atrost Date: Mon, 5 Aug 2019 12:26:07 +0100 Subject: [PATCH] Create a module that extracts and installs compat_config. Currently it extracts from the provided jar file compat/compat_config.xml (generated by compat-changeid-annotation-processor) and installs on /system/etc/sysconfig. Future improvements: - Merge all the configs going for the system image into one, so that duplicate change ids across modules are failing the build instead of runtime. - Support uploading the config onto APEX for APEX modules. Test: flashed device locally, config files found and read by com.android.server.compat.CompatConfig. Bug: 138222363 Change-Id: I64b11fdc466f746702e7e73f612794e024de2288 --- Android.bp | 1 + java/platform_compat_config.go | 92 ++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 java/platform_compat_config.go diff --git a/Android.bp b/Android.bp index 62b0fd4c3..4e44a0d58 100644 --- a/Android.bp +++ b/Android.bp @@ -282,6 +282,7 @@ bootstrap_go_package { "java/jdeps.go", "java/java_resources.go", "java/kotlin.go", + "java/platform_compat_config.go", "java/plugin.go", "java/prebuilt_apis.go", "java/proto.go", diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go new file mode 100644 index 000000000..792edf388 --- /dev/null +++ b/java/platform_compat_config.go @@ -0,0 +1,92 @@ +// Copyright 2019 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "android/soong/android" +) + +func init() { + android.RegisterModuleType("platform_compat_config", platformCompatConfigFactory) +} + +type platformCompatConfigProperties struct { + Src *string `android:"path"` + Prefix *string +} + +type platformCompatConfig struct { + android.ModuleBase + + properties platformCompatConfigProperties + installDirPath android.OutputPath + configFile android.OutputPath +} + +func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { + rule := android.NewRuleBuilder() + + configFileName := String(p.properties.Prefix) + "_platform_compat_config.xml" + p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath + path := android.PathForModuleSrc(ctx, String(p.properties.Src)) + + // Use the empty config if the compat config file idoesn't exist (can happen if @ChangeId + // annotation is not used). + emptyConfig := `` + configPath := `compat/compat_config.xml` + + rule.Command(). + Text(`unzip`). + Flag(`-l`). + Input(path). + Text(`| grep`). + Flag(`-q`). + Text(configPath). + Text(`; if [ "$?" = "0" ] ; then`). + Text(`unzip`). + Flag(`-qp`). + Input(path). + Text(configPath). + Text(`>`). + Output(p.configFile). + Text(`; else echo '`). + Text(emptyConfig). + Text(`' >`). + Output(p.configFile). + Text(`; fi`) + + p.installDirPath = android.PathForModuleInstall(ctx, "etc", "sysconfig") + rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it") + +} + +func (p *platformCompatConfig) AndroidMkEntries() android.AndroidMkEntries { + return android.AndroidMkEntries{ + Class: "ETC", + OutputFile: android.OptionalPathForPath(p.configFile), + Include: "$(BUILD_PREBUILT)", + AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) { + entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString()) + entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base()) + }, + } +} + +func platformCompatConfigFactory() android.Module { + module := &platformCompatConfig{} + module.AddProperties(&module.properties) + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) + return module +}