From 2a6e9d0b01c13172b13d649c6551355a96d65fe1 Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Tue, 31 Mar 2020 16:05:34 +0100 Subject: [PATCH] Fix missing NOTICE targets for static libs that aren't available to platform. The NOTICE file generation depends on the NOTICE targets for all static library dependencies. If such a dependency didn't have //apex_available:platform it didn't get any AndroidMk entry and hence no NOTICE target via soong_cc_prebuilt.mk. If it was then depended upon by a binary or library that is accessible to platform, the NOTICE dependency failed. Normally such a dependency is invalid, but there are corner cases where binaries go neither into platform nor any APEX module, and they can legitimately have such dependencies (cf. b/152241137). With this CL requests to skip installation of such a static libraries are ignored so that they get AndroidMk entries, which will always have LOCAL_UNINSTALLABLE_MODULE set. Test: "m simpleperf_ndk" with https://r.android.com/1273016, which removes //apex_available:platform from libs that simpleperf_ndk depends on statically. Bug: 152241137 Bug: 149217815 Change-Id: If36e85dd16ade56d4ec1d6744811df5a15b6242c Merged-In: If36e85dd16ade56d4ec1d6744811df5a15b6242c --- cc/androidmk.go | 4 ++++ cc/cc.go | 9 +++++++++ cc/installer.go | 4 ++++ cc/library.go | 12 ++++++++++++ cc/prebuilt.go | 5 +++++ 5 files changed, 34 insertions(+) diff --git a/cc/androidmk.go b/cc/androidmk.go index ef695b003..1c90aaf79 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -248,6 +248,10 @@ func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries entries.SubName = "." + library.stubsVersion() } entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) { + // Note library.skipInstall() has a special case to get here for static + // libraries that otherwise would have skipped installation and hence not + // have executed AndroidMkEntries at all. The reason is to ensure they get + // a NOTICE file make target which other libraries might depend on. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) if library.buildStubs() { entries.SetBool("LOCAL_NO_NOTICE_FILE", true) diff --git a/cc/cc.go b/cc/cc.go index cb71c3bd8..e4a42a0e1 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -377,6 +377,7 @@ type installer interface { inSanitizerDir() bool hostToolPath() android.OptionalPath relativeInstallPath() string + skipInstall(mod *Module) } type xref interface { @@ -2588,6 +2589,14 @@ func (c *Module) InstallInRecovery() bool { return c.InRecovery() } +func (c *Module) SkipInstall() { + if c.installer == nil { + c.ModuleBase.SkipInstall() + return + } + c.installer.skipInstall(c) +} + func (c *Module) HostToolPath() android.OptionalPath { if c.installer == nil { return android.OptionalPath{} diff --git a/cc/installer.go b/cc/installer.go index 2f55ac57b..13a411915 100644 --- a/cc/installer.go +++ b/cc/installer.go @@ -101,3 +101,7 @@ func (installer *baseInstaller) hostToolPath() android.OptionalPath { func (installer *baseInstaller) relativeInstallPath() string { return String(installer.Properties.Relative_install_path) } + +func (installer *baseInstaller) skipInstall(mod *Module) { + mod.ModuleBase.SkipInstall() +} diff --git a/cc/library.go b/cc/library.go index c7488ee30..34b27a401 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1303,6 +1303,18 @@ func (library *libraryDecorator) availableFor(what string) bool { return android.CheckAvailableForApex(what, list) } +func (library *libraryDecorator) skipInstall(mod *Module) { + if library.static() && library.buildStatic() && !library.buildStubs() { + // If we're asked to skip installation of a static library (in particular + // when it's not //apex_available:platform) we still want an AndroidMk entry + // for it to ensure we get the relevant NOTICE file targets (cf. + // notice_files.mk) that other libraries might depend on. AndroidMkEntries + // always sets LOCAL_UNINSTALLABLE_MODULE for these entries. + return + } + mod.ModuleBase.SkipInstall() +} + var versioningMacroNamesListKey = android.NewOnceKey("versioningMacroNamesList") func versioningMacroNamesList(config android.Config) *map[string]string { diff --git a/cc/prebuilt.go b/cc/prebuilt.go index b0cf4890e..4f77d41c8 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -134,6 +134,10 @@ func (p *prebuiltLibraryLinker) disablePrebuilt() { p.properties.Srcs = nil } +func (p *prebuiltLibraryLinker) skipInstall(mod *Module) { + mod.ModuleBase.SkipInstall() +} + func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { module, library := NewLibrary(hod) module.compiler = nil @@ -142,6 +146,7 @@ func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDec libraryDecorator: library, } module.linker = prebuilt + module.installer = prebuilt module.AddProperties(&prebuilt.properties)