blob: 0ed7409b70ad1a95ab7bcb623dece1bf93c25f93 [file] [log] [blame]
Kiyoung Kim62abd122020-10-06 17:16:44 +09001// Copyright (C) 2020 The Android Open Source Project
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 linkerconfig
16
17import (
18 "android/soong/android"
19 "android/soong/etc"
20
21 "github.com/google/blueprint/proptools"
22)
23
24var (
25 pctx = android.NewPackageContext("android/soong/linkerconfig")
26)
27
28func init() {
29 pctx.HostBinToolVariable("conv_linker_config", "conv_linker_config")
Paul Duffin2a2fb662021-03-29 01:14:55 +010030 registerLinkerConfigBuildComponent(android.InitRegistrationContext)
31}
32
33func registerLinkerConfigBuildComponent(ctx android.RegistrationContext) {
34 ctx.RegisterModuleType("linker_config", linkerConfigFactory)
Kiyoung Kim62abd122020-10-06 17:16:44 +090035}
36
37type linkerConfigProperties struct {
38 // source linker configuration property file
39 Src *string `android:"path"`
40
41 // If set to true, allow module to be installed to one of the partitions.
42 // Default value is true.
43 // Installable should be marked as false for APEX configuration to avoid
44 // conflicts of configuration on /system/etc directory.
45 Installable *bool
46}
47
48type linkerConfig struct {
49 android.ModuleBase
50 properties linkerConfigProperties
51
52 outputFilePath android.OutputPath
53 installDirPath android.InstallPath
54}
55
56// Implement PrebuiltEtcModule interface to fit in APEX prebuilt list.
57var _ etc.PrebuiltEtcModule = (*linkerConfig)(nil)
58
59func (l *linkerConfig) BaseDir() string {
60 return "etc"
61}
62
63func (l *linkerConfig) SubDir() string {
64 return ""
65}
66
67func (l *linkerConfig) OutputFile() android.OutputPath {
68 return l.outputFilePath
69}
70
71func (l *linkerConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
72 inputFile := android.PathForModuleSrc(ctx, android.String(l.properties.Src))
73 l.outputFilePath = android.PathForModuleOut(ctx, "linker.config.pb").OutputPath
74 l.installDirPath = android.PathForModuleInstall(ctx, "etc")
Colin Crossf1a035e2020-11-16 17:32:30 -080075 linkerConfigRule := android.NewRuleBuilder(pctx, ctx)
Kiyoung Kim62abd122020-10-06 17:16:44 +090076 linkerConfigRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -080077 BuiltTool("conv_linker_config").
Kiyoung Kim62abd122020-10-06 17:16:44 +090078 Flag("proto").
79 FlagWithInput("-s ", inputFile).
80 FlagWithOutput("-o ", l.outputFilePath)
Colin Crossf1a035e2020-11-16 17:32:30 -080081 linkerConfigRule.Build("conv_linker_config",
Kiyoung Kim62abd122020-10-06 17:16:44 +090082 "Generate linker config protobuf "+l.outputFilePath.String())
83
Jooyung Hanc6a91ec2021-04-15 04:41:13 +090084 if !proptools.BoolDefault(l.properties.Installable, true) {
85 l.SkipInstall()
Kiyoung Kim62abd122020-10-06 17:16:44 +090086 }
Jooyung Hanc6a91ec2021-04-15 04:41:13 +090087 ctx.InstallFile(l.installDirPath, l.outputFilePath.Base(), l.outputFilePath)
Kiyoung Kim62abd122020-10-06 17:16:44 +090088}
89
90// linker_config generates protobuf file from json file. This protobuf file will be used from
91// linkerconfig while generating ld.config.txt. Format of this file can be found from
92// https://android.googlesource.com/platform/system/linkerconfig/+/master/README.md
93func linkerConfigFactory() android.Module {
94 m := &linkerConfig{}
95 m.AddProperties(&m.properties)
96 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibFirst)
97 return m
98}
99
100func (l *linkerConfig) AndroidMkEntries() []android.AndroidMkEntries {
101 installable := proptools.BoolDefault(l.properties.Installable, true)
102 return []android.AndroidMkEntries{android.AndroidMkEntries{
103 Class: "ETC",
104 OutputFile: android.OptionalPathForPath(l.outputFilePath),
105 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700106 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Kiyoung Kim62abd122020-10-06 17:16:44 +0900107 entries.SetString("LOCAL_MODULE_PATH", l.installDirPath.ToMakePath().String())
108 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", l.outputFilePath.Base())
109 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !installable)
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +0900110 entries.SetString("LINKER_CONFIG_PATH_"+l.Name(), l.OutputFile().String())
Kiyoung Kim62abd122020-10-06 17:16:44 +0900111 },
112 },
113 }}
114}