1// Copyright 2015 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 15package cc 16 17import ( 18 "github.com/google/blueprint/proptools" 19 20 "fmt" 21 "io" 22 "path/filepath" 23 "strings" 24 25 "android/soong/android" 26 "android/soong/multitree" 27) 28 29var ( 30 NativeBridgeSuffix = ".native_bridge" 31 ProductSuffix = ".product" 32 VendorSuffix = ".vendor" 33 RamdiskSuffix = ".ramdisk" 34 VendorRamdiskSuffix = ".vendor_ramdisk" 35 RecoverySuffix = ".recovery" 36 sdkSuffix = ".sdk" 37) 38 39type AndroidMkContext interface { 40 BaseModuleName() string 41 Target() android.Target 42 subAndroidMk(*android.AndroidMkEntries, interface{}) 43 Arch() android.Arch 44 Os() android.OsType 45 Host() bool 46 UseVndk() bool 47 VndkVersion() string 48 static() bool 49 InRamdisk() bool 50 InVendorRamdisk() bool 51 InRecovery() bool 52 NotInPlatform() bool 53} 54 55type subAndroidMkProvider interface { 56 AndroidMkEntries(AndroidMkContext, *android.AndroidMkEntries) 57} 58 59func (c *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) { 60 if c.subAndroidMkOnce == nil { 61 c.subAndroidMkOnce = make(map[subAndroidMkProvider]bool) 62 } 63 if androidmk, ok := obj.(subAndroidMkProvider); ok { 64 if !c.subAndroidMkOnce[androidmk] { 65 c.subAndroidMkOnce[androidmk] = true 66 androidmk.AndroidMkEntries(c, entries) 67 } 68 } 69} 70 71func (c *Module) AndroidMkEntries() []android.AndroidMkEntries { 72 if c.hideApexVariantFromMake || c.Properties.HideFromMake { 73 return []android.AndroidMkEntries{{ 74 Disabled: true, 75 }} 76 } 77 78 entries := android.AndroidMkEntries{ 79 OutputFile: c.outputFile, 80 // TODO(jiyong): add the APEXes providing shared libs to the required 81 // modules Currently, adding c.Properties.ApexesProvidingSharedLibs is 82 // causing multiple ART APEXes (com.android.art and com.android.art.debug) 83 // to be installed. And this is breaking some older devices (like marlin) 84 // where system.img is small. 85 Required: c.Properties.AndroidMkRuntimeLibs, 86 Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk", 87 88 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 89 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 90 if len(c.Properties.Logtags) > 0 { 91 entries.AddStrings("LOCAL_LOGTAGS_FILES", c.Properties.Logtags...) 92 } 93 // Note: Pass the exact value of AndroidMkSystemSharedLibs to the Make 94 // world, even if it is an empty list. In the Make world, 95 // LOCAL_SYSTEM_SHARED_LIBRARIES defaults to "none", which is expanded 96 // to the default list of system shared libs by the build system. 97 // Soong computes the exact list of system shared libs, so we have to 98 // override the default value when the list of libs is actually empty. 99 entries.SetString("LOCAL_SYSTEM_SHARED_LIBRARIES", strings.Join(c.Properties.AndroidMkSystemSharedLibs, " ")) 100 if len(c.Properties.AndroidMkSharedLibs) > 0 { 101 entries.AddStrings("LOCAL_SHARED_LIBRARIES", c.Properties.AndroidMkSharedLibs...) 102 } 103 if len(c.Properties.AndroidMkStaticLibs) > 0 { 104 entries.AddStrings("LOCAL_STATIC_LIBRARIES", c.Properties.AndroidMkStaticLibs...) 105 } 106 if len(c.Properties.AndroidMkWholeStaticLibs) > 0 { 107 entries.AddStrings("LOCAL_WHOLE_STATIC_LIBRARIES", c.Properties.AndroidMkWholeStaticLibs...) 108 } 109 if len(c.Properties.AndroidMkHeaderLibs) > 0 { 110 entries.AddStrings("LOCAL_HEADER_LIBRARIES", c.Properties.AndroidMkHeaderLibs...) 111 } 112 if len(c.Properties.AndroidMkRuntimeLibs) > 0 { 113 entries.AddStrings("LOCAL_RUNTIME_LIBRARIES", c.Properties.AndroidMkRuntimeLibs...) 114 } 115 entries.SetString("LOCAL_SOONG_LINK_TYPE", c.makeLinkType) 116 if c.UseVndk() { 117 entries.SetBool("LOCAL_USE_VNDK", true) 118 if c.IsVndk() && !c.static() { 119 entries.SetString("LOCAL_SOONG_VNDK_VERSION", c.VndkVersion()) 120 // VNDK libraries available to vendor are not installed because 121 // they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go) 122 if !c.IsVndkExt() { 123 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 124 } 125 } 126 } 127 if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake { 128 // Make the SDK variant uninstallable so that there are not two rules to install 129 // to the same location. 130 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 131 // Add the unsuffixed name to SOONG_SDK_VARIANT_MODULES so that Make can rewrite 132 // dependencies to the .sdk suffix when building a module that uses the SDK. 133 entries.SetString("SOONG_SDK_VARIANT_MODULES", 134 "$(SOONG_SDK_VARIANT_MODULES) $(patsubst %.sdk,%,$(LOCAL_MODULE))") 135 } 136 }, 137 }, 138 ExtraFooters: []android.AndroidMkExtraFootersFunc{ 139 func(w io.Writer, name, prefix, moduleDir string) { 140 if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake && 141 c.CcLibraryInterface() && c.Shared() { 142 // Using the SDK variant as a JNI library needs a copy of the .so that 143 // is not named .sdk.so so that it can be packaged into the APK with 144 // the right name. 145 fmt.Fprintln(w, "$(eval $(call copy-one-file,", 146 "$(LOCAL_BUILT_MODULE),", 147 "$(patsubst %.sdk.so,%.so,$(LOCAL_BUILT_MODULE))))") 148 } 149 }, 150 }, 151 } 152 153 for _, feature := range c.features { 154 c.subAndroidMk(&entries, feature) 155 } 156 157 c.subAndroidMk(&entries, c.compiler) 158 c.subAndroidMk(&entries, c.linker) 159 if c.sanitize != nil { 160 c.subAndroidMk(&entries, c.sanitize) 161 } 162 c.subAndroidMk(&entries, c.installer) 163 164 entries.SubName += c.Properties.SubName 165 166 return []android.AndroidMkEntries{entries} 167} 168 169func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *android.AndroidMkEntries) { 170 if len(extraTestConfigs) > 0 { 171 entries.ExtraEntries = append(entries.ExtraEntries, 172 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 173 entries.AddStrings("LOCAL_EXTRA_FULL_TEST_CONFIGS", extraTestConfigs.Strings()...) 174 }) 175 } 176} 177 178func AndroidMkWriteTestData(data []android.DataPath, entries *android.AndroidMkEntries) { 179 testFiles := android.AndroidMkDataPaths(data) 180 if len(testFiles) > 0 { 181 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 182 entries.AddStrings("LOCAL_TEST_DATA", testFiles...) 183 }) 184 } 185} 186 187func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string { 188 if ctx.Target().NativeBridge == android.NativeBridgeEnabled { 189 var result []string 190 for _, override := range overrides { 191 result = append(result, override+NativeBridgeSuffix) 192 } 193 return result 194 } 195 196 return overrides 197} 198 199func (library *libraryDecorator) androidMkWriteExportedFlags(entries *android.AndroidMkEntries) { 200 var exportedFlags []string 201 var includeDirs android.Paths 202 var systemIncludeDirs android.Paths 203 var exportedDeps android.Paths 204 205 if library.flagExporterInfo != nil { 206 exportedFlags = library.flagExporterInfo.Flags 207 includeDirs = library.flagExporterInfo.IncludeDirs 208 systemIncludeDirs = library.flagExporterInfo.SystemIncludeDirs 209 exportedDeps = library.flagExporterInfo.Deps 210 } else { 211 exportedFlags = library.flagExporter.flags 212 includeDirs = library.flagExporter.dirs 213 systemIncludeDirs = library.flagExporter.systemDirs 214 exportedDeps = library.flagExporter.deps 215 } 216 for _, dir := range includeDirs { 217 exportedFlags = append(exportedFlags, "-I"+dir.String()) 218 } 219 for _, dir := range systemIncludeDirs { 220 exportedFlags = append(exportedFlags, "-isystem "+dir.String()) 221 } 222 if len(exportedFlags) > 0 { 223 entries.AddStrings("LOCAL_EXPORT_CFLAGS", exportedFlags...) 224 } 225 if len(exportedDeps) > 0 { 226 entries.AddStrings("LOCAL_EXPORT_C_INCLUDE_DEPS", exportedDeps.Strings()...) 227 } 228} 229 230func (library *libraryDecorator) androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries *android.AndroidMkEntries) { 231 if !library.static() { 232 entries.AddPaths("LOCAL_ADDITIONAL_DEPENDENCIES", library.sAbiDiff) 233 } 234} 235 236// TODO(ccross): remove this once apex/androidmk.go is converted to AndroidMkEntries 237func (library *libraryDecorator) androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) { 238 if !library.static() { 239 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", strings.Join(library.sAbiDiff.Strings(), " ")) 240 } 241} 242 243func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 244 if library.static() { 245 entries.Class = "STATIC_LIBRARIES" 246 } else if library.shared() { 247 entries.Class = "SHARED_LIBRARIES" 248 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 249 entries.SetString("LOCAL_SOONG_TOC", library.toc().String()) 250 if !library.buildStubs() && library.unstrippedOutputFile != nil { 251 entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", library.unstrippedOutputFile.String()) 252 } 253 if len(library.Properties.Overrides) > 0 { 254 entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, library.Properties.Overrides), " ")) 255 } 256 if len(library.postInstallCmds) > 0 { 257 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(library.postInstallCmds, "&& ")) 258 } 259 }) 260 } else if library.header() { 261 entries.Class = "HEADER_LIBRARIES" 262 } 263 264 if library.distFile != nil { 265 entries.DistFiles = android.MakeDefaultDistFiles(library.distFile) 266 } 267 268 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 269 library.androidMkWriteExportedFlags(entries) 270 library.androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries) 271 272 if entries.OutputFile.Valid() { 273 _, _, ext := android.SplitFileExt(entries.OutputFile.Path().Base()) 274 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext) 275 } 276 277 if library.coverageOutputFile.Valid() { 278 entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", library.coverageOutputFile.String()) 279 } 280 281 if library.useCoreVariant { 282 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 283 entries.SetBool("LOCAL_NO_NOTICE_FILE", true) 284 entries.SetBool("LOCAL_VNDK_DEPEND_ON_CORE_VARIANT", true) 285 } 286 if library.checkSameCoreVariant { 287 entries.SetBool("LOCAL_CHECK_SAME_VNDK_VARIANTS", true) 288 } 289 }) 290 291 if library.shared() && !library.buildStubs() { 292 ctx.subAndroidMk(entries, library.baseInstaller) 293 } else { 294 if library.buildStubs() && library.stubsVersion() != "" { 295 entries.SubName = "." + library.stubsVersion() 296 } 297 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 298 // library.makeUninstallable() depends on this to bypass HideFromMake() for 299 // static libraries. 300 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 301 if library.buildStubs() { 302 entries.SetBool("LOCAL_NO_NOTICE_FILE", true) 303 } 304 }) 305 } 306 // If a library providing a stub is included in an APEX, the private APIs of the library 307 // is accessible only inside the APEX. From outside of the APEX, clients can only use the 308 // public APIs via the stub. To enforce this, the (latest version of the) stub gets the 309 // name of the library. The impl library instead gets the `.bootstrap` suffix to so that 310 // they can be exceptionally used directly when APEXes are not available (e.g. during the 311 // very early stage in the boot process). 312 if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.NotInPlatform() && 313 !ctx.InRamdisk() && !ctx.InVendorRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && !ctx.static() { 314 if library.buildStubs() && library.isLatestStubVersion() { 315 entries.SubName = "" 316 } 317 if !library.buildStubs() { 318 entries.SubName = ".bootstrap" 319 } 320 } 321} 322 323func (object *objectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 324 entries.Class = "STATIC_LIBRARIES" 325 entries.ExtraFooters = append(entries.ExtraFooters, 326 func(w io.Writer, name, prefix, moduleDir string) { 327 out := entries.OutputFile.Path() 328 varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName) 329 330 fmt.Fprintf(w, "\n%s := %s\n", varname, out.String()) 331 fmt.Fprintln(w, ".KATI_READONLY: "+varname) 332 }) 333} 334 335func (test *testDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 336 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 337 if len(test.InstallerProperties.Test_suites) > 0 { 338 entries.AddCompatibilityTestSuites(test.InstallerProperties.Test_suites...) 339 } 340 }) 341} 342 343func (binary *binaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 344 ctx.subAndroidMk(entries, binary.baseInstaller) 345 346 entries.Class = "EXECUTABLES" 347 entries.DistFiles = binary.distFiles 348 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 349 entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", binary.unstrippedOutputFile.String()) 350 if len(binary.symlinks) > 0 { 351 entries.AddStrings("LOCAL_MODULE_SYMLINKS", binary.symlinks...) 352 } 353 354 if binary.coverageOutputFile.Valid() { 355 entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", binary.coverageOutputFile.String()) 356 } 357 358 if len(binary.Properties.Overrides) > 0 { 359 entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, binary.Properties.Overrides), " ")) 360 } 361 if len(binary.postInstallCmds) > 0 { 362 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(binary.postInstallCmds, "&& ")) 363 } 364 }) 365} 366 367func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 368 ctx.subAndroidMk(entries, benchmark.binaryDecorator) 369 entries.Class = "NATIVE_TESTS" 370 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 371 if len(benchmark.Properties.Test_suites) > 0 { 372 entries.AddCompatibilityTestSuites(benchmark.Properties.Test_suites...) 373 } 374 if benchmark.testConfig != nil { 375 entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String()) 376 } 377 entries.SetBool("LOCAL_NATIVE_BENCHMARK", true) 378 if !BoolDefault(benchmark.Properties.Auto_gen_config, true) { 379 entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true) 380 } 381 }) 382 dataPaths := []android.DataPath{} 383 for _, srcPath := range benchmark.data { 384 dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath}) 385 } 386 AndroidMkWriteTestData(dataPaths, entries) 387} 388 389func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 390 ctx.subAndroidMk(entries, test.binaryDecorator) 391 ctx.subAndroidMk(entries, test.testDecorator) 392 393 entries.Class = "NATIVE_TESTS" 394 if Bool(test.Properties.Test_per_src) { 395 entries.SubName = "_" + String(test.binaryDecorator.Properties.Stem) 396 } 397 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 398 if test.testConfig != nil { 399 entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String()) 400 } 401 if !BoolDefault(test.Properties.Auto_gen_config, true) { 402 entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true) 403 } 404 entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", test.Properties.Test_mainline_modules...) 405 406 entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(test.Properties.Per_testcase_directory)) 407 if len(test.Properties.Data_bins) > 0 { 408 entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...) 409 } 410 411 test.Properties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries) 412 }) 413 414 AndroidMkWriteTestData(test.data, entries) 415 androidMkWriteExtraTestConfigs(test.extraTestConfigs, entries) 416} 417 418func (fuzz *fuzzBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 419 ctx.subAndroidMk(entries, fuzz.binaryDecorator) 420 421 var fuzzFiles []string 422 for _, d := range fuzz.fuzzPackagedModule.Corpus { 423 fuzzFiles = append(fuzzFiles, 424 filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base()) 425 } 426 427 for _, d := range fuzz.fuzzPackagedModule.Data { 428 fuzzFiles = append(fuzzFiles, 429 filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel()) 430 } 431 432 if fuzz.fuzzPackagedModule.Dictionary != nil { 433 fuzzFiles = append(fuzzFiles, 434 filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base()) 435 } 436 437 if fuzz.fuzzPackagedModule.Config != nil { 438 fuzzFiles = append(fuzzFiles, 439 filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json") 440 } 441 442 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 443 entries.SetBool("LOCAL_IS_FUZZ_TARGET", true) 444 if len(fuzzFiles) > 0 { 445 entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...) 446 } 447 if fuzz.installedSharedDeps != nil { 448 entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...) 449 } 450 }) 451} 452 453func (test *testLibrary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 454 ctx.subAndroidMk(entries, test.libraryDecorator) 455 ctx.subAndroidMk(entries, test.testDecorator) 456} 457 458func (installer *baseInstaller) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 459 if installer.path == (android.InstallPath{}) { 460 return 461 } 462 463 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 464 path, file := filepath.Split(installer.path.String()) 465 stem, suffix, _ := android.SplitFileExt(file) 466 entries.SetString("LOCAL_MODULE_SUFFIX", suffix) 467 entries.SetString("LOCAL_MODULE_PATH", path) 468 entries.SetString("LOCAL_MODULE_STEM", stem) 469 }) 470} 471 472func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 473 entries.SubName = ndkLibrarySuffix + "." + c.apiLevel.String() 474 entries.Class = "SHARED_LIBRARIES" 475 476 if !c.buildStubs() { 477 entries.Disabled = true 478 return 479 } 480 481 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 482 path, file := filepath.Split(c.installPath.String()) 483 stem, suffix, _ := android.SplitFileExt(file) 484 entries.SetString("LOCAL_MODULE_SUFFIX", suffix) 485 entries.SetString("LOCAL_MODULE_PATH", path) 486 entries.SetString("LOCAL_MODULE_STEM", stem) 487 entries.SetBool("LOCAL_NO_NOTICE_FILE", true) 488 if c.parsedCoverageXmlPath.String() != "" { 489 entries.SetString("SOONG_NDK_API_XML", "$(SOONG_NDK_API_XML) "+c.parsedCoverageXmlPath.String()) 490 } 491 }) 492} 493 494func (c *vndkPrebuiltLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 495 entries.Class = "SHARED_LIBRARIES" 496 497 entries.SubName = c.androidMkSuffix 498 499 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 500 c.libraryDecorator.androidMkWriteExportedFlags(entries) 501 502 // Specifying stem is to pass check_elf_files when vendor modules link against vndk prebuilt. 503 // We can't use install path because VNDKs are not installed. Instead, Srcs is directly used. 504 _, file := filepath.Split(c.properties.Srcs[0]) 505 stem, suffix, ext := android.SplitFileExt(file) 506 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext) 507 entries.SetString("LOCAL_MODULE_SUFFIX", suffix) 508 entries.SetString("LOCAL_MODULE_STEM", stem) 509 510 if c.tocFile.Valid() { 511 entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String()) 512 } 513 514 // VNDK libraries available to vendor are not installed because 515 // they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go) 516 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 517 }) 518} 519 520func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 521 // Each vendor snapshot is exported to androidMk only when BOARD_VNDK_VERSION != current 522 // and the version of the prebuilt is same as BOARD_VNDK_VERSION. 523 if c.shared() { 524 entries.Class = "SHARED_LIBRARIES" 525 } else if c.static() { 526 entries.Class = "STATIC_LIBRARIES" 527 } else if c.header() { 528 entries.Class = "HEADER_LIBRARIES" 529 } 530 531 entries.SubName = "" 532 533 if c.isSanitizerEnabled(cfi) { 534 entries.SubName += ".cfi" 535 } else if c.isSanitizerEnabled(Hwasan) { 536 entries.SubName += ".hwasan" 537 } 538 539 entries.SubName += c.baseProperties.Androidmk_suffix 540 541 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 542 c.libraryDecorator.androidMkWriteExportedFlags(entries) 543 544 if c.shared() || c.static() { 545 src := c.path.String() 546 // For static libraries which aren't installed, directly use Src to extract filename. 547 // This is safe: generated snapshot modules have a real path as Src, not a module 548 if c.static() { 549 src = proptools.String(c.properties.Src) 550 } 551 path, file := filepath.Split(src) 552 stem, suffix, ext := android.SplitFileExt(file) 553 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext) 554 entries.SetString("LOCAL_MODULE_SUFFIX", suffix) 555 entries.SetString("LOCAL_MODULE_STEM", stem) 556 if c.shared() { 557 entries.SetString("LOCAL_MODULE_PATH", path) 558 } 559 if c.tocFile.Valid() { 560 entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String()) 561 } 562 563 if c.shared() && len(c.Properties.Overrides) > 0 { 564 entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, c.Properties.Overrides), " ")) 565 } 566 } 567 568 if !c.shared() { // static or header 569 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 570 } 571 }) 572} 573 574func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 575 entries.Class = "EXECUTABLES" 576 entries.SubName = c.baseProperties.Androidmk_suffix 577} 578 579func (c *snapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 580 entries.Class = "STATIC_LIBRARIES" 581 entries.SubName = c.baseProperties.Androidmk_suffix 582 583 entries.ExtraFooters = append(entries.ExtraFooters, 584 func(w io.Writer, name, prefix, moduleDir string) { 585 out := entries.OutputFile.Path() 586 varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName) 587 588 fmt.Fprintf(w, "\n%s := %s\n", varname, out.String()) 589 fmt.Fprintln(w, ".KATI_READONLY: "+varname) 590 }) 591} 592 593func (c *ndkPrebuiltStlLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 594 entries.Class = "SHARED_LIBRARIES" 595} 596 597func (p *prebuiltLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 598 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 599 if p.properties.Check_elf_files != nil { 600 entries.SetBool("LOCAL_CHECK_ELF_FILES", *p.properties.Check_elf_files) 601 } else { 602 // soong_cc_rust_prebuilt.mk does not include check_elf_file.mk by default 603 // because cc_library_shared and cc_binary use soong_cc_rust_prebuilt.mk as well. 604 // In order to turn on prebuilt ABI checker, set `LOCAL_CHECK_ELF_FILES` to 605 // true if `p.properties.Check_elf_files` is not specified. 606 entries.SetBool("LOCAL_CHECK_ELF_FILES", true) 607 } 608 }) 609} 610 611func (p *prebuiltLibraryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 612 ctx.subAndroidMk(entries, p.libraryDecorator) 613 if p.shared() { 614 ctx.subAndroidMk(entries, &p.prebuiltLinker) 615 androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries) 616 } 617} 618 619func (p *prebuiltBinaryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 620 ctx.subAndroidMk(entries, p.binaryDecorator) 621 ctx.subAndroidMk(entries, &p.prebuiltLinker) 622 androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries) 623} 624 625func (a *apiLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 626 entries.Class = "SHARED_LIBRARIES" 627 entries.SubName += multitree.GetApiImportSuffix() 628 629 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 630 a.libraryDecorator.androidMkWriteExportedFlags(entries) 631 src := *a.properties.Src 632 path, file := filepath.Split(src) 633 stem, suffix, ext := android.SplitFileExt(file) 634 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext) 635 entries.SetString("LOCAL_MODULE_SUFFIX", suffix) 636 entries.SetString("LOCAL_MODULE_STEM", stem) 637 entries.SetString("LOCAL_MODULE_PATH", path) 638 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 639 entries.SetString("LOCAL_SOONG_TOC", a.toc().String()) 640 }) 641} 642 643func (a *apiHeadersDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { 644 entries.Class = "HEADER_LIBRARIES" 645 entries.SubName += multitree.GetApiImportSuffix() 646 647 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 648 a.libraryDecorator.androidMkWriteExportedFlags(entries) 649 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 650 }) 651} 652 653func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, entries *android.AndroidMkEntries) { 654 allow := linker.Properties.Allow_undefined_symbols 655 if allow != nil { 656 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 657 entries.SetBool("LOCAL_ALLOW_UNDEFINED_SYMBOLS", *allow) 658 }) 659 } 660} 661