blob: b24f61d2f2b03e4bdd2d80724798fecf404897f5 [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")
30 android.RegisterModuleType("linker_config", linkerConfigFactory)
31}
32
33type linkerConfigProperties struct {
34 // source linker configuration property file
35 Src *string `android:"path"`
36
37 // If set to true, allow module to be installed to one of the partitions.
38 // Default value is true.
39 // Installable should be marked as false for APEX configuration to avoid
40 // conflicts of configuration on /system/etc directory.
41 Installable *bool
42}
43
44type linkerConfig struct {
45 android.ModuleBase
46 properties linkerConfigProperties
47
48 outputFilePath android.OutputPath
49 installDirPath android.InstallPath
50}
51
52// Implement PrebuiltEtcModule interface to fit in APEX prebuilt list.
53var _ etc.PrebuiltEtcModule = (*linkerConfig)(nil)
54
55func (l *linkerConfig) BaseDir() string {
56 return "etc"
57}
58
59func (l *linkerConfig) SubDir() string {
60 return ""
61}
62
63func (l *linkerConfig) OutputFile() android.OutputPath {
64 return l.outputFilePath
65}
66
67func (l *linkerConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
68 inputFile := android.PathForModuleSrc(ctx, android.String(l.properties.Src))
69 l.outputFilePath = android.PathForModuleOut(ctx, "linker.config.pb").OutputPath
70 l.installDirPath = android.PathForModuleInstall(ctx, "etc")
Colin Crossf1a035e2020-11-16 17:32:30 -080071 linkerConfigRule := android.NewRuleBuilder(pctx, ctx)
Kiyoung Kim62abd122020-10-06 17:16:44 +090072 linkerConfigRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -080073 BuiltTool("conv_linker_config").
Kiyoung Kim62abd122020-10-06 17:16:44 +090074 Flag("proto").
75 FlagWithInput("-s ", inputFile).
76 FlagWithOutput("-o ", l.outputFilePath)
Colin Crossf1a035e2020-11-16 17:32:30 -080077 linkerConfigRule.Build("conv_linker_config",
Kiyoung Kim62abd122020-10-06 17:16:44 +090078 "Generate linker config protobuf "+l.outputFilePath.String())
79
80 if proptools.BoolDefault(l.properties.Installable, true) {
81 ctx.InstallFile(l.installDirPath, l.outputFilePath.Base(), l.outputFilePath)
82 }
83}
84
85// linker_config generates protobuf file from json file. This protobuf file will be used from
86// linkerconfig while generating ld.config.txt. Format of this file can be found from
87// https://android.googlesource.com/platform/system/linkerconfig/+/master/README.md
88func linkerConfigFactory() android.Module {
89 m := &linkerConfig{}
90 m.AddProperties(&m.properties)
91 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibFirst)
92 return m
93}
94
95func (l *linkerConfig) AndroidMkEntries() []android.AndroidMkEntries {
96 installable := proptools.BoolDefault(l.properties.Installable, true)
97 return []android.AndroidMkEntries{android.AndroidMkEntries{
98 Class: "ETC",
99 OutputFile: android.OptionalPathForPath(l.outputFilePath),
100 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
101 func(entries *android.AndroidMkEntries) {
102 entries.SetString("LOCAL_MODULE_PATH", l.installDirPath.ToMakePath().String())
103 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", l.outputFilePath.Base())
104 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !installable)
105 },
106 },
107 }}
108}