Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package linkerconfig |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/etc" |
| 20 | |
| 21 | "github.com/google/blueprint/proptools" |
| 22 | ) |
| 23 | |
| 24 | var ( |
| 25 | pctx = android.NewPackageContext("android/soong/linkerconfig") |
| 26 | ) |
| 27 | |
| 28 | func init() { |
| 29 | pctx.HostBinToolVariable("conv_linker_config", "conv_linker_config") |
| 30 | android.RegisterModuleType("linker_config", linkerConfigFactory) |
| 31 | } |
| 32 | |
| 33 | type 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 | |
| 44 | type 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. |
| 53 | var _ etc.PrebuiltEtcModule = (*linkerConfig)(nil) |
| 54 | |
| 55 | func (l *linkerConfig) BaseDir() string { |
| 56 | return "etc" |
| 57 | } |
| 58 | |
| 59 | func (l *linkerConfig) SubDir() string { |
| 60 | return "" |
| 61 | } |
| 62 | |
| 63 | func (l *linkerConfig) OutputFile() android.OutputPath { |
| 64 | return l.outputFilePath |
| 65 | } |
| 66 | |
| 67 | func (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 Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame^] | 71 | linkerConfigRule := android.NewRuleBuilder(pctx, ctx) |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 72 | linkerConfigRule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame^] | 73 | BuiltTool("conv_linker_config"). |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 74 | Flag("proto"). |
| 75 | FlagWithInput("-s ", inputFile). |
| 76 | FlagWithOutput("-o ", l.outputFilePath) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame^] | 77 | linkerConfigRule.Build("conv_linker_config", |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 78 | "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 |
| 88 | func linkerConfigFactory() android.Module { |
| 89 | m := &linkerConfig{} |
| 90 | m.AddProperties(&m.properties) |
| 91 | android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibFirst) |
| 92 | return m |
| 93 | } |
| 94 | |
| 95 | func (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 | } |