Skip existence check for stub library files
Switch from `PathForModuleSrc` to `PathForSource`. The latter does not
check that the target path exists in the tree. This is necessary since
the prebuilt stub and header directories are not guaranteed to exist
when Soong analysis begins (Step 2a)
Build orchestrator will be responsible for putting these files in the
right place as part of Multi-tree ninja invocation (Step 4)
Test: go test ./cc
Change-Id: I27175a8440fca6bba21197b1e106a22b733da882
diff --git a/cc/library_stub.go b/cc/library_stub.go
index 2ebb6ef..1597a6f 100644
--- a/cc/library_stub.go
+++ b/cc/library_stub.go
@@ -81,6 +81,19 @@
return basename + multitree.GetApiImportSuffix()
}
+// Export include dirs without checking for existence.
+// The directories are not guaranteed to exist during Soong analysis.
+func (d *apiLibraryDecorator) exportIncludes(ctx ModuleContext) {
+ exporterProps := d.flagExporter.Properties
+ for _, dir := range exporterProps.Export_include_dirs {
+ d.dirs = append(d.dirs, android.PathForSource(ctx, ctx.ModuleDir(), dir))
+ }
+ // system headers
+ for _, dir := range exporterProps.Export_system_include_dirs {
+ d.systemDirs = append(d.systemDirs, android.PathForSource(ctx, ctx.ModuleDir(), dir))
+ }
+}
+
func (d *apiLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objects Objects) android.Path {
// Export headers as system include dirs if specified. Mostly for libc
if Bool(d.libraryDecorator.Properties.Llndk.Export_headers_as_system) {
@@ -91,7 +104,7 @@
}
// Flags reexported from dependencies. (e.g. vndk_prebuilt_shared)
- d.libraryDecorator.flagExporter.exportIncludes(ctx)
+ d.exportIncludes(ctx)
d.libraryDecorator.reexportDirs(deps.ReexportedDirs...)
d.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...)
d.libraryDecorator.reexportFlags(deps.ReexportedFlags...)
@@ -99,7 +112,13 @@
d.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
d.libraryDecorator.flagExporter.setProvider(ctx)
- in := android.PathForModuleSrc(ctx, *d.properties.Src)
+ if d.properties.Src == nil {
+ ctx.PropertyErrorf("src", "src is a required property")
+ }
+ // Skip the existence check of the stub prebuilt file.
+ // The file is not guaranteed to exist during Soong analysis.
+ // Build orchestrator will be responsible for creating a connected ninja graph.
+ in := android.PathForSource(ctx, ctx.ModuleDir(), *d.properties.Src)
d.unstrippedOutputFile = in
libName := d.libraryDecorator.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
diff --git a/cc/library_stub_test.go b/cc/library_stub_test.go
index cd06172..51da480 100644
--- a/cc/library_stub_test.go
+++ b/cc/library_stub_test.go
@@ -325,3 +325,41 @@
android.AssertBoolEquals(t, "original header should be used for original library", true, hasDirectDependency(t, ctx, libfoo, libfooHeader))
android.AssertBoolEquals(t, "Header from API surface should not be used for original library", false, hasDirectDependency(t, ctx, libfoo, libfooHeaderApiImport))
}
+
+func TestExportDirFromStubLibrary(t *testing.T) {
+ bp := `
+ cc_library {
+ name: "libfoo",
+ export_include_dirs: ["source_include_dir"],
+ export_system_include_dirs: ["source_system_include_dir"],
+ vendor_available: true,
+ }
+ cc_api_library {
+ name: "libfoo",
+ export_include_dirs: ["stub_include_dir"],
+ export_system_include_dirs: ["stub_system_include_dir"],
+ vendor_available: true,
+ src: "libfoo.so",
+ }
+ api_imports {
+ name: "api_imports",
+ shared_libs: [
+ "libfoo",
+ ],
+ header_libs: [],
+ }
+ // vendor binary
+ cc_binary {
+ name: "vendorbin",
+ vendor: true,
+ srcs: ["vendor.cc"],
+ shared_libs: ["libfoo"],
+ }
+ `
+ ctx := prepareForCcTest.RunTestWithBp(t, bp)
+ vendorCFlags := ctx.ModuleForTests("vendorbin", "android_vendor.29_arm64_armv8-a").Rule("cc").Args["cFlags"]
+ android.AssertStringDoesContain(t, "Vendor binary should compile using headers provided by stub", vendorCFlags, "-Istub_include_dir")
+ android.AssertStringDoesNotContain(t, "Vendor binary should not compile using headers of source", vendorCFlags, "-Isource_include_dir")
+ android.AssertStringDoesContain(t, "Vendor binary should compile using system headers provided by stub", vendorCFlags, "-isystem stub_system_include_dir")
+ android.AssertStringDoesNotContain(t, "Vendor binary should not compile using system headers of source", vendorCFlags, "-isystem source_system_include_dir")
+}