Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 18 | "path/filepath" |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 19 | "strings" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0d99045 | 2021-08-11 16:46:13 +0000 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 22 | "android/soong/bazel" |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func init() { |
Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 26 | RegisterPrebuiltBuildComponents(android.InitRegistrationContext) |
| 27 | } |
| 28 | |
| 29 | func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) { |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 30 | ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory) |
Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 31 | ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) |
| 32 | ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 33 | ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory) |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 34 | ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory) |
Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 35 | ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | type prebuiltLinkerInterface interface { |
| 39 | Name(string) string |
| 40 | prebuilt() *android.Prebuilt |
| 41 | } |
| 42 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 43 | type prebuiltLinkerProperties struct { |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 44 | // a prebuilt library or binary. Can reference a genrule module that generates an executable file. |
| 45 | Srcs []string `android:"path,arch_variant"` |
| 46 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 47 | Sanitized Sanitized `android:"arch_variant"` |
| 48 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 49 | // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined |
| 50 | // symbols, etc), default true. |
| 51 | Check_elf_files *bool |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 52 | |
| 53 | // Optionally provide an import library if this is a Windows PE DLL prebuilt. |
| 54 | // This is needed only if this library is linked by other modules in build time. |
| 55 | // Only makes sense for the Windows target. |
| 56 | Windows_import_lib *string `android:"path,arch_variant"` |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 59 | type prebuiltLinker struct { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 60 | android.Prebuilt |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 61 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 62 | properties prebuiltLinkerProperties |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 65 | func (p *prebuiltLinker) prebuilt() *android.Prebuilt { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 66 | return &p.Prebuilt |
| 67 | } |
| 68 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 69 | func (p *prebuiltLinker) PrebuiltSrcs() []string { |
| 70 | return p.properties.Srcs |
| 71 | } |
| 72 | |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 73 | type prebuiltLibraryInterface interface { |
| 74 | libraryInterface |
| 75 | prebuiltLinkerInterface |
| 76 | disablePrebuilt() |
| 77 | } |
| 78 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 79 | type prebuiltLibraryLinker struct { |
| 80 | *libraryDecorator |
| 81 | prebuiltLinker |
| 82 | } |
| 83 | |
| 84 | var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 85 | var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 86 | |
Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 87 | func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {} |
| 88 | |
| 89 | func (p *prebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Logan Chien | c7f797e | 2019-01-14 15:35:08 +0800 | [diff] [blame] | 90 | return p.libraryDecorator.linkerDeps(ctx, deps) |
Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | func (p *prebuiltLibraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 1ab10a7 | 2018-09-04 11:02:37 -0700 | [diff] [blame] | 94 | return flags |
Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | func (p *prebuiltLibraryLinker) linkerProps() []interface{} { |
| 98 | return p.libraryDecorator.linkerProps() |
| 99 | } |
| 100 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 101 | func (p *prebuiltLibraryLinker) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 102 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Paul Duffin | f5ea9e1 | 2020-02-21 10:57:00 +0000 | [diff] [blame] | 103 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 104 | p.libraryDecorator.flagExporter.exportIncludes(ctx) |
| 105 | p.libraryDecorator.flagExporter.reexportDirs(deps.ReexportedDirs...) |
| 106 | p.libraryDecorator.flagExporter.reexportSystemDirs(deps.ReexportedSystemDirs...) |
| 107 | p.libraryDecorator.flagExporter.reexportFlags(deps.ReexportedFlags...) |
| 108 | p.libraryDecorator.flagExporter.reexportDeps(deps.ReexportedDeps...) |
| 109 | p.libraryDecorator.flagExporter.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...) |
| 110 | |
| 111 | p.libraryDecorator.flagExporter.setProvider(ctx) |
Paul Duffin | f5ea9e1 | 2020-02-21 10:57:00 +0000 | [diff] [blame] | 112 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 113 | // TODO(ccross): verify shared library dependencies |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 114 | srcs := p.prebuiltSrcs(ctx) |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 115 | if len(srcs) > 0 { |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 116 | if len(srcs) > 1 { |
| 117 | ctx.PropertyErrorf("srcs", "multiple prebuilt source files") |
| 118 | return nil |
| 119 | } |
| 120 | |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 121 | p.libraryDecorator.exportVersioningMacroIfNeeded(ctx) |
| 122 | |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 123 | in := android.PathForModuleSrc(ctx, srcs[0]) |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 124 | |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 125 | if p.static() { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 126 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() |
| 127 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ |
| 128 | StaticLibrary: in, |
| 129 | |
| 130 | TransitiveStaticLibrariesForOrdering: depSet, |
| 131 | }) |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 132 | return in |
| 133 | } |
| 134 | |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 135 | if p.shared() { |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 136 | p.unstrippedOutputFile = in |
Colin Cross | 0fd6a41 | 2019-08-16 14:22:10 -0700 | [diff] [blame] | 137 | libName := p.libraryDecorator.getLibName(ctx) + flags.Toolchain.ShlibSuffix() |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 138 | outputFile := android.PathForModuleOut(ctx, libName) |
| 139 | var implicits android.Paths |
| 140 | |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 141 | if p.stripper.NeedsStrip(ctx) { |
| 142 | stripFlags := flagsToStripFlags(flags) |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 143 | stripped := android.PathForModuleOut(ctx, "stripped", libName) |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 144 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags) |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 145 | in = stripped |
| 146 | } |
| 147 | |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 148 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 149 | // depending on a table of contents file instead of the library itself. |
| 150 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 151 | p.tocFile = android.OptionalPathForPath(tocFile) |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 152 | TransformSharedObjectToToc(ctx, outputFile, tocFile) |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 153 | |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 154 | if ctx.Windows() && p.properties.Windows_import_lib != nil { |
| 155 | // Consumers of this library actually links to the import library in build |
| 156 | // time and dynamically links to the DLL in run time. i.e. |
| 157 | // a.exe <-- static link --> foo.lib <-- dynamic link --> foo.dll |
| 158 | importLibSrc := android.PathForModuleSrc(ctx, String(p.properties.Windows_import_lib)) |
| 159 | importLibName := p.libraryDecorator.getLibName(ctx) + ".lib" |
| 160 | importLibOutputFile := android.PathForModuleOut(ctx, importLibName) |
| 161 | implicits = append(implicits, importLibOutputFile) |
| 162 | |
| 163 | ctx.Build(pctx, android.BuildParams{ |
| 164 | Rule: android.Cp, |
| 165 | Description: "prebuilt import library", |
| 166 | Input: importLibSrc, |
| 167 | Output: importLibOutputFile, |
| 168 | Args: map[string]string{ |
| 169 | "cpFlags": "-L", |
| 170 | }, |
| 171 | }) |
| 172 | } |
| 173 | |
| 174 | ctx.Build(pctx, android.BuildParams{ |
| 175 | Rule: android.Cp, |
| 176 | Description: "prebuilt shared library", |
| 177 | Implicits: implicits, |
| 178 | Input: in, |
| 179 | Output: outputFile, |
| 180 | Args: map[string]string{ |
| 181 | "cpFlags": "-L", |
| 182 | }, |
| 183 | }) |
| 184 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 185 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
Liz Kammer | ef6dfea | 2021-06-08 15:37:09 -0400 | [diff] [blame] | 186 | SharedLibrary: outputFile, |
| 187 | Target: ctx.Target(), |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 188 | |
| 189 | TableOfContents: p.tocFile, |
| 190 | }) |
| 191 | |
Martin Stjernholm | 5bdf2d5 | 2022-02-06 22:07:45 +0000 | [diff] [blame] | 192 | // TODO(b/220898484): Mainline module sdk prebuilts of stub libraries use a stub |
| 193 | // library as their source and must not be installed, but libclang_rt.* libraries |
| 194 | // have stubs because they are LLNDK libraries, but use an implementation library |
| 195 | // as their source and need to be installed. This discrepancy should be resolved |
| 196 | // without the prefix hack below. |
| 197 | if p.hasStubsVariants() && !p.buildStubs() && !ctx.Host() && |
| 198 | !strings.HasPrefix(ctx.baseModuleName(), "libclang_rt.") { |
| 199 | ctx.Module().MakeUninstallable() |
| 200 | } |
| 201 | |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 202 | return outputFile |
| 203 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Colin Cross | 649d817 | 2020-12-10 12:30:21 -0800 | [diff] [blame] | 206 | if p.header() { |
| 207 | ctx.SetProvider(HeaderLibraryInfoProvider, HeaderLibraryInfo{}) |
| 208 | |
Martin Stjernholm | d51cb5c | 2021-11-30 18:49:03 +0000 | [diff] [blame] | 209 | // Need to return an output path so that the AndroidMk logic doesn't skip |
| 210 | // the prebuilt header. For compatibility, in case Android.mk files use a |
| 211 | // header lib in LOCAL_STATIC_LIBRARIES, create an empty ar file as |
| 212 | // placeholder, just like non-prebuilt header modules do in linkStatic(). |
| 213 | ph := android.PathForModuleOut(ctx, ctx.ModuleName()+staticLibraryExtension) |
| 214 | transformObjToStaticLib(ctx, nil, nil, builderFlags{}, ph, nil, nil) |
| 215 | return ph |
Colin Cross | 649d817 | 2020-12-10 12:30:21 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 218 | return nil |
| 219 | } |
| 220 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 221 | func (p *prebuiltLibraryLinker) prebuiltSrcs(ctx android.BaseModuleContext) []string { |
| 222 | sanitize := ctx.Module().(*Module).sanitize |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 223 | srcs := p.properties.Srcs |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 224 | srcs = append(srcs, srcsForSanitizer(sanitize, p.properties.Sanitized)...) |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 225 | if p.static() { |
| 226 | srcs = append(srcs, p.libraryDecorator.StaticProperties.Static.Srcs...) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 227 | srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.StaticProperties.Static.Sanitized)...) |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 228 | } |
| 229 | if p.shared() { |
| 230 | srcs = append(srcs, p.libraryDecorator.SharedProperties.Shared.Srcs...) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 231 | srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.SharedProperties.Shared.Sanitized)...) |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 232 | } |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 233 | return srcs |
| 234 | } |
| 235 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 236 | func (p *prebuiltLibraryLinker) shared() bool { |
| 237 | return p.libraryDecorator.shared() |
| 238 | } |
| 239 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 240 | func (p *prebuiltLibraryLinker) nativeCoverage() bool { |
| 241 | return false |
| 242 | } |
| 243 | |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 244 | func (p *prebuiltLibraryLinker) disablePrebuilt() { |
| 245 | p.properties.Srcs = nil |
| 246 | } |
| 247 | |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 248 | // Implements versionedInterface |
| 249 | func (p *prebuiltLibraryLinker) implementationModuleName(name string) string { |
Paul Duffin | 9804da0 | 2021-10-26 10:42:42 +0100 | [diff] [blame] | 250 | return android.RemoveOptionalPrebuiltPrefix(name) |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 251 | } |
| 252 | |
Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 253 | func NewPrebuiltLibrary(hod android.HostOrDeviceSupported, srcsProperty string) (*Module, *libraryDecorator) { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 254 | module, library := NewLibrary(hod) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 255 | module.compiler = nil |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 256 | module.bazelable = true |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 257 | |
| 258 | prebuilt := &prebuiltLibraryLinker{ |
| 259 | libraryDecorator: library, |
| 260 | } |
| 261 | module.linker = prebuilt |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 262 | module.library = prebuilt |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 263 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 264 | module.AddProperties(&prebuilt.properties) |
| 265 | |
Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 266 | if srcsProperty == "" { |
| 267 | android.InitPrebuiltModuleWithoutSrcs(module) |
| 268 | } else { |
| 269 | srcsSupplier := func(ctx android.BaseModuleContext, _ android.Module) []string { |
| 270 | return prebuilt.prebuiltSrcs(ctx) |
| 271 | } |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 272 | |
Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 273 | android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, srcsProperty) |
| 274 | } |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 275 | |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 276 | // Prebuilt libraries can be used in SDKs. |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 277 | android.InitSdkAwareModule(module) |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 278 | return module, library |
| 279 | } |
| 280 | |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 281 | // cc_prebuilt_library installs a precompiled shared library that are |
| 282 | // listed in the srcs property in the device's directory. |
| 283 | func PrebuiltLibraryFactory() android.Module { |
Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 284 | module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported, "srcs") |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 285 | |
| 286 | // Prebuilt shared libraries can be included in APEXes |
| 287 | android.InitApexModule(module) |
| 288 | |
| 289 | return module.Init() |
| 290 | } |
| 291 | |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 292 | // cc_prebuilt_library_shared installs a precompiled shared library that are |
| 293 | // listed in the srcs property in the device's directory. |
| 294 | func PrebuiltSharedLibraryFactory() android.Module { |
| 295 | module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported) |
| 296 | return module.Init() |
| 297 | } |
| 298 | |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 299 | // cc_prebuilt_test_library_shared installs a precompiled shared library |
| 300 | // to be used as a data dependency of a test-related module (such as cc_test, or |
| 301 | // cc_test_library). |
| 302 | func PrebuiltSharedTestLibraryFactory() android.Module { |
Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 303 | module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported, "srcs") |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 304 | library.BuildOnlyShared() |
| 305 | library.baseInstaller = NewTestInstaller() |
| 306 | return module.Init() |
| 307 | } |
| 308 | |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 309 | func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 310 | module, library := NewPrebuiltLibrary(hod, "srcs") |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 311 | library.BuildOnlyShared() |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 312 | module.bazelable = true |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c3b97c3 | 2021-10-05 13:43:23 -0400 | [diff] [blame] | 313 | module.bazelHandler = &prebuiltSharedLibraryBazelHandler{module: module, library: library} |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 314 | |
| 315 | // Prebuilt shared libraries can be included in APEXes |
| 316 | android.InitApexModule(module) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 317 | |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 318 | return module, library |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 321 | // cc_prebuilt_library_static installs a precompiled static library that are |
| 322 | // listed in the srcs property in the device's directory. |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 323 | func PrebuiltStaticLibraryFactory() android.Module { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 324 | module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported) |
| 325 | return module.Init() |
| 326 | } |
| 327 | |
| 328 | func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 329 | module, library := NewPrebuiltLibrary(hod, "srcs") |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 330 | library.BuildOnlyStatic() |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 331 | module.bazelable = true |
Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 332 | module.bazelHandler = &prebuiltStaticLibraryBazelHandler{module: module, library: library} |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 333 | return module, library |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 336 | type bazelPrebuiltLibraryStaticAttributes struct { |
| 337 | Static_library bazel.LabelAttribute |
| 338 | Export_includes bazel.StringListAttribute |
| 339 | Export_system_includes bazel.StringListAttribute |
| 340 | } |
| 341 | |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 342 | // TODO(b/228623543): The below is not entirely true until the bug is fixed. For now, both targets are always generated |
| 343 | // Implements bp2build for cc_prebuilt_library modules. This will generate: |
| 344 | // * Only a prebuilt_library_static if the shared.enabled property is set to false across all variants. |
| 345 | // * Only a prebuilt_library_shared if the static.enabled property is set to false across all variants |
| 346 | // * Both a prebuilt_library_static and prebuilt_library_shared if the aforementioned properties are not false across |
| 347 | // all variants |
| 348 | // |
| 349 | // In all cases, prebuilt_library_static target names will be appended with "_bp2build_cc_library_static". |
| 350 | func prebuiltLibraryBp2Build(ctx android.TopDownMutatorContext, module *Module) { |
| 351 | prebuiltLibraryStaticBp2Build(ctx, module, true) |
| 352 | prebuiltLibrarySharedBp2Build(ctx, module) |
| 353 | } |
| 354 | |
| 355 | func prebuiltLibraryStaticBp2Build(ctx android.TopDownMutatorContext, module *Module, fullBuild bool) { |
| 356 | prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module, true) |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 357 | exportedIncludes := Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx, module) |
| 358 | |
| 359 | attrs := &bazelPrebuiltLibraryStaticAttributes{ |
| 360 | Static_library: prebuiltAttrs.Src, |
| 361 | Export_includes: exportedIncludes.Includes, |
| 362 | Export_system_includes: exportedIncludes.SystemIncludes, |
| 363 | } |
| 364 | |
| 365 | props := bazel.BazelTargetModuleProperties{ |
| 366 | Rule_class: "prebuilt_library_static", |
Liz Kammer | 2b376bc | 2022-01-12 12:00:49 -0500 | [diff] [blame] | 367 | Bzl_load_location: "//build/bazel/rules/cc:prebuilt_library_static.bzl", |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | name := android.RemoveOptionalPrebuiltPrefix(module.Name()) |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 371 | if fullBuild { |
| 372 | name += "_bp2build_cc_library_static" |
| 373 | } |
| 374 | ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name}, attrs, prebuiltAttrs.Enabled) |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 375 | } |
| 376 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 377 | type bazelPrebuiltLibrarySharedAttributes struct { |
| 378 | Shared_library bazel.LabelAttribute |
| 379 | } |
| 380 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 381 | func prebuiltLibrarySharedBp2Build(ctx android.TopDownMutatorContext, module *Module) { |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 382 | prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module, false) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 383 | |
| 384 | attrs := &bazelPrebuiltLibrarySharedAttributes{ |
| 385 | Shared_library: prebuiltAttrs.Src, |
| 386 | } |
| 387 | |
| 388 | props := bazel.BazelTargetModuleProperties{ |
| 389 | Rule_class: "prebuilt_library_shared", |
Liz Kammer | 2b376bc | 2022-01-12 12:00:49 -0500 | [diff] [blame] | 390 | Bzl_load_location: "//build/bazel/rules/cc:prebuilt_library_shared.bzl", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | name := android.RemoveOptionalPrebuiltPrefix(module.Name()) |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 394 | ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name}, attrs, prebuiltAttrs.Enabled) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 395 | } |
| 396 | |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 397 | type prebuiltObjectProperties struct { |
| 398 | Srcs []string `android:"path,arch_variant"` |
| 399 | } |
| 400 | |
| 401 | type prebuiltObjectLinker struct { |
| 402 | android.Prebuilt |
| 403 | objectLinker |
| 404 | |
| 405 | properties prebuiltObjectProperties |
| 406 | } |
| 407 | |
Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 408 | type prebuiltStaticLibraryBazelHandler struct { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0d99045 | 2021-08-11 16:46:13 +0000 | [diff] [blame] | 409 | android.BazelHandler |
Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 410 | |
| 411 | module *Module |
| 412 | library *libraryDecorator |
| 413 | } |
| 414 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0d99045 | 2021-08-11 16:46:13 +0000 | [diff] [blame] | 415 | func (h *prebuiltStaticLibraryBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool { |
Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 416 | bazelCtx := ctx.Config().BazelContext |
Chris Parsons | 787fb36 | 2021-10-14 18:43:51 -0400 | [diff] [blame] | 417 | ccInfo, ok, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx)) |
Liz Kammer | fe23bf3 | 2021-04-09 16:17:05 -0400 | [diff] [blame] | 418 | if err != nil { |
| 419 | ctx.ModuleErrorf("Error getting Bazel CcInfo: %s", err) |
| 420 | } |
Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 421 | if !ok { |
| 422 | return false |
| 423 | } |
Liz Kammer | fe23bf3 | 2021-04-09 16:17:05 -0400 | [diff] [blame] | 424 | staticLibs := ccInfo.CcStaticLibraryFiles |
Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 425 | if len(staticLibs) > 1 { |
| 426 | ctx.ModuleErrorf("expected 1 static library from bazel target %q, got %s", label, staticLibs) |
| 427 | return false |
| 428 | } |
| 429 | |
| 430 | // TODO(b/184543518): cc_prebuilt_library_static may have properties for re-exporting flags |
| 431 | |
| 432 | // TODO(eakammer):Add stub-related flags if this library is a stub library. |
| 433 | // h.library.exportVersioningMacroIfNeeded(ctx) |
| 434 | |
| 435 | // Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise |
| 436 | // validation will fail. For now, set this to an empty list. |
| 437 | // TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation. |
| 438 | h.library.collectedSnapshotHeaders = android.Paths{} |
| 439 | |
| 440 | if len(staticLibs) == 0 { |
| 441 | h.module.outputFile = android.OptionalPath{} |
| 442 | return true |
| 443 | } |
| 444 | |
| 445 | out := android.PathForBazelOut(ctx, staticLibs[0]) |
| 446 | h.module.outputFile = android.OptionalPathForPath(out) |
| 447 | |
| 448 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(out).Build() |
| 449 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ |
| 450 | StaticLibrary: out, |
| 451 | |
| 452 | TransitiveStaticLibrariesForOrdering: depSet, |
| 453 | }) |
| 454 | |
| 455 | return true |
| 456 | } |
| 457 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c3b97c3 | 2021-10-05 13:43:23 -0400 | [diff] [blame] | 458 | type prebuiltSharedLibraryBazelHandler struct { |
| 459 | android.BazelHandler |
| 460 | |
| 461 | module *Module |
| 462 | library *libraryDecorator |
| 463 | } |
| 464 | |
| 465 | func (h *prebuiltSharedLibraryBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool { |
| 466 | bazelCtx := ctx.Config().BazelContext |
| 467 | ccInfo, ok, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx)) |
| 468 | if err != nil { |
| 469 | ctx.ModuleErrorf("Error getting Bazel CcInfo for %s: %s", label, err) |
| 470 | } |
| 471 | if !ok { |
| 472 | return false |
| 473 | } |
| 474 | sharedLibs := ccInfo.CcSharedLibraryFiles |
| 475 | if len(sharedLibs) != 1 { |
| 476 | ctx.ModuleErrorf("expected 1 shared library from bazel target %s, got %q", label, sharedLibs) |
| 477 | return false |
| 478 | } |
| 479 | |
| 480 | // TODO(b/184543518): cc_prebuilt_library_shared may have properties for re-exporting flags |
| 481 | |
| 482 | // TODO(eakammer):Add stub-related flags if this library is a stub library. |
| 483 | // h.library.exportVersioningMacroIfNeeded(ctx) |
| 484 | |
| 485 | // Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise |
| 486 | // validation will fail. For now, set this to an empty list. |
| 487 | // TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation. |
| 488 | h.library.collectedSnapshotHeaders = android.Paths{} |
| 489 | |
| 490 | if len(sharedLibs) == 0 { |
| 491 | h.module.outputFile = android.OptionalPath{} |
| 492 | return true |
| 493 | } |
| 494 | |
| 495 | out := android.PathForBazelOut(ctx, sharedLibs[0]) |
| 496 | h.module.outputFile = android.OptionalPathForPath(out) |
| 497 | |
| 498 | // FIXME(b/214600441): We don't yet strip prebuilt shared libraries |
| 499 | h.library.unstrippedOutputFile = out |
| 500 | |
| 501 | var toc android.Path |
| 502 | if len(ccInfo.TocFile) > 0 { |
| 503 | toc = android.PathForBazelOut(ctx, ccInfo.TocFile) |
| 504 | } else { |
| 505 | toc = out // Just reuse `out` so ninja still gets an input but won't matter |
| 506 | } |
| 507 | |
| 508 | info := SharedLibraryInfo{ |
| 509 | SharedLibrary: out, |
| 510 | TableOfContents: android.OptionalPathForPath(toc), |
| 511 | Target: ctx.Target(), |
| 512 | } |
| 513 | ctx.SetProvider(SharedLibraryInfoProvider, info) |
| 514 | |
| 515 | h.library.setFlagExporterInfoFromCcInfo(ctx, ccInfo) |
| 516 | h.module.maybeUnhideFromMake() |
| 517 | |
| 518 | return true |
| 519 | } |
| 520 | |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 521 | func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt { |
| 522 | return &p.Prebuilt |
| 523 | } |
| 524 | |
| 525 | var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil) |
| 526 | |
| 527 | func (p *prebuiltObjectLinker) link(ctx ModuleContext, |
| 528 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 529 | if len(p.properties.Srcs) > 0 { |
Colin Cross | ee02aed | 2022-04-15 15:16:02 -0700 | [diff] [blame] | 530 | // Copy objects to a name matching the final installed name |
| 531 | in := p.Prebuilt.SingleSourcePath(ctx) |
| 532 | outputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".o") |
| 533 | ctx.Build(pctx, android.BuildParams{ |
| 534 | Rule: android.CpExecutable, |
| 535 | Description: "prebuilt", |
| 536 | Output: outputFile, |
| 537 | Input: in, |
| 538 | }) |
| 539 | return outputFile |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 540 | } |
| 541 | return nil |
| 542 | } |
| 543 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 544 | func (p *prebuiltObjectLinker) object() bool { |
| 545 | return true |
| 546 | } |
| 547 | |
Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 548 | func NewPrebuiltObject(hod android.HostOrDeviceSupported) *Module { |
| 549 | module := newObject(hod) |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 550 | prebuilt := &prebuiltObjectLinker{ |
| 551 | objectLinker: objectLinker{ |
| 552 | baseLinker: NewBaseLinker(nil), |
| 553 | }, |
| 554 | } |
| 555 | module.linker = prebuilt |
| 556 | module.AddProperties(&prebuilt.properties) |
| 557 | android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) |
| 558 | android.InitSdkAwareModule(module) |
| 559 | return module |
| 560 | } |
| 561 | |
| 562 | func prebuiltObjectFactory() android.Module { |
Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 563 | module := NewPrebuiltObject(android.HostAndDeviceSupported) |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 564 | return module.Init() |
| 565 | } |
| 566 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 567 | type prebuiltBinaryLinker struct { |
| 568 | *binaryDecorator |
| 569 | prebuiltLinker |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 570 | |
| 571 | toolPath android.OptionalPath |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil) |
| 575 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 576 | func (p *prebuiltBinaryLinker) hostToolPath() android.OptionalPath { |
| 577 | return p.toolPath |
| 578 | } |
| 579 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 580 | func (p *prebuiltBinaryLinker) link(ctx ModuleContext, |
| 581 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 582 | // TODO(ccross): verify shared library dependencies |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 583 | if len(p.properties.Srcs) > 0 { |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 584 | fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix() |
| 585 | in := p.Prebuilt.SingleSourcePath(ctx) |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 586 | outputFile := android.PathForModuleOut(ctx, fileName) |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 587 | p.unstrippedOutputFile = in |
| 588 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 589 | if ctx.Host() { |
| 590 | // Host binaries are symlinked to their prebuilt source locations. That |
| 591 | // way they are executed directly from there so the linker resolves their |
| 592 | // shared library dependencies relative to that location (using |
| 593 | // $ORIGIN/../lib(64):$ORIGIN/lib(64) as RUNPATH). This way the prebuilt |
| 594 | // repository can supply the expected versions of the shared libraries |
| 595 | // without interference from what is in the out tree. |
Colin Cross | 94921e7 | 2017-08-08 16:20:15 -0700 | [diff] [blame] | 596 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 597 | // These shared lib paths may point to copies of the libs in |
| 598 | // .intermediates, which isn't where the binary will load them from, but |
| 599 | // it's fine for dependency tracking. If a library dependency is updated, |
| 600 | // the symlink will get a new timestamp, along with any installed symlinks |
| 601 | // handled in make. |
| 602 | sharedLibPaths := deps.EarlySharedLibs |
| 603 | sharedLibPaths = append(sharedLibPaths, deps.SharedLibs...) |
| 604 | sharedLibPaths = append(sharedLibPaths, deps.LateSharedLibs...) |
| 605 | |
Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 606 | var fromPath = in.String() |
| 607 | if !filepath.IsAbs(fromPath) { |
| 608 | fromPath = "$$PWD/" + fromPath |
| 609 | } |
| 610 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 611 | ctx.Build(pctx, android.BuildParams{ |
| 612 | Rule: android.Symlink, |
| 613 | Output: outputFile, |
| 614 | Input: in, |
| 615 | Implicits: sharedLibPaths, |
| 616 | Args: map[string]string{ |
Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 617 | "fromPath": fromPath, |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 618 | }, |
| 619 | }) |
| 620 | |
| 621 | p.toolPath = android.OptionalPathForPath(outputFile) |
| 622 | } else { |
| 623 | if p.stripper.NeedsStrip(ctx) { |
| 624 | stripped := android.PathForModuleOut(ctx, "stripped", fileName) |
| 625 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, flagsToStripFlags(flags)) |
| 626 | in = stripped |
| 627 | } |
| 628 | |
| 629 | // Copy binaries to a name matching the final installed name |
| 630 | ctx.Build(pctx, android.BuildParams{ |
| 631 | Rule: android.CpExecutable, |
| 632 | Description: "prebuilt", |
| 633 | Output: outputFile, |
| 634 | Input: in, |
| 635 | }) |
| 636 | } |
Colin Cross | 94921e7 | 2017-08-08 16:20:15 -0700 | [diff] [blame] | 637 | |
| 638 | return outputFile |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | return nil |
| 642 | } |
| 643 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 644 | func (p *prebuiltBinaryLinker) binary() bool { |
| 645 | return true |
| 646 | } |
| 647 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 648 | // cc_prebuilt_binary installs a precompiled executable in srcs property in the |
| 649 | // device's directory. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 650 | func prebuiltBinaryFactory() android.Module { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 651 | module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported) |
| 652 | return module.Init() |
| 653 | } |
| 654 | |
| 655 | func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { |
Liz Kammer | bdc922f | 2021-12-14 14:21:21 -0500 | [diff] [blame] | 656 | module, binary := newBinary(hod, false) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 657 | module.compiler = nil |
| 658 | |
| 659 | prebuilt := &prebuiltBinaryLinker{ |
| 660 | binaryDecorator: binary, |
| 661 | } |
| 662 | module.linker = prebuilt |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 663 | module.installer = prebuilt |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 664 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 665 | module.AddProperties(&prebuilt.properties) |
| 666 | |
| 667 | android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 668 | return module, binary |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 669 | } |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 670 | |
| 671 | type Sanitized struct { |
| 672 | None struct { |
| 673 | Srcs []string `android:"path,arch_variant"` |
| 674 | } `android:"arch_variant"` |
| 675 | Address struct { |
| 676 | Srcs []string `android:"path,arch_variant"` |
| 677 | } `android:"arch_variant"` |
| 678 | Hwaddress struct { |
| 679 | Srcs []string `android:"path,arch_variant"` |
| 680 | } `android:"arch_variant"` |
| 681 | } |
| 682 | |
| 683 | func srcsForSanitizer(sanitize *sanitize, sanitized Sanitized) []string { |
| 684 | if sanitize == nil { |
| 685 | return nil |
| 686 | } |
| 687 | if Bool(sanitize.Properties.Sanitize.Address) && sanitized.Address.Srcs != nil { |
| 688 | return sanitized.Address.Srcs |
| 689 | } |
| 690 | if Bool(sanitize.Properties.Sanitize.Hwaddress) && sanitized.Hwaddress.Srcs != nil { |
| 691 | return sanitized.Hwaddress.Srcs |
| 692 | } |
| 693 | return sanitized.None.Srcs |
| 694 | } |