From b3454ab24de620f367d6b8b77f0de2ce978b2d5f Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 28 Sep 2016 17:34:58 -0700 Subject: [PATCH] Add export_generated_headers Similar to export_shared_library_headers, this will export headers imported from a gensrcs or genrule. Bug: 31742855 Test: Add export_generated_headers, ensure it's in out/soong/Android-*.mk Change-Id: Ieadefd007ece8b249f011a258a9c5b27f5d3f594 --- cc/cc.go | 57 ++++++++++++++++++++++++++++++++++------------------ cc/linker.go | 5 +++++ 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index d04f84331..66c47c1fe 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -64,6 +64,8 @@ type Deps struct { GeneratedSources []string GeneratedHeaders []string + ReexportGeneratedHeaders []string + CrtBegin, CrtEnd string } @@ -193,21 +195,22 @@ type dependencyTag struct { } var ( - sharedDepTag = dependencyTag{name: "shared", library: true} - sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true} - lateSharedDepTag = dependencyTag{name: "late shared", library: true} - staticDepTag = dependencyTag{name: "static", library: true} - staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true} - lateStaticDepTag = dependencyTag{name: "late static", library: true} - wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true} - genSourceDepTag = dependencyTag{name: "gen source"} - genHeaderDepTag = dependencyTag{name: "gen header"} - objDepTag = dependencyTag{name: "obj"} - crtBeginDepTag = dependencyTag{name: "crtbegin"} - crtEndDepTag = dependencyTag{name: "crtend"} - reuseObjTag = dependencyTag{name: "reuse objects"} - ndkStubDepTag = dependencyTag{name: "ndk stub", library: true} - ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true} + sharedDepTag = dependencyTag{name: "shared", library: true} + sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true} + lateSharedDepTag = dependencyTag{name: "late shared", library: true} + staticDepTag = dependencyTag{name: "static", library: true} + staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true} + lateStaticDepTag = dependencyTag{name: "late static", library: true} + wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true} + genSourceDepTag = dependencyTag{name: "gen source"} + genHeaderDepTag = dependencyTag{name: "gen header"} + genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true} + objDepTag = dependencyTag{name: "obj"} + crtBeginDepTag = dependencyTag{name: "crtbegin"} + crtEndDepTag = dependencyTag{name: "crtend"} + reuseObjTag = dependencyTag{name: "reuse objects"} + ndkStubDepTag = dependencyTag{name: "ndk stub", library: true} + ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true} ) // Module contains the properties and members used by all C/C++ module types, and implements @@ -503,6 +506,12 @@ func (c *Module) deps(ctx BaseModuleContext) Deps { } } + for _, gen := range deps.ReexportGeneratedHeaders { + if !inList(gen, deps.GeneratedHeaders) { + ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen) + } + } + return deps } @@ -594,7 +603,14 @@ func (c *Module) depsMutator(actx android.BottomUpMutatorContext) { deps.LateSharedLibs...) actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...) - actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...) + + for _, gen := range deps.GeneratedHeaders { + depTag := genHeaderDepTag + if inList(gen, deps.ReexportGeneratedHeaders) { + depTag = genHeaderExportDepTag + } + actx.AddDependency(c, depTag, gen) + } actx.AddDependency(c, objDepTag, deps.ObjFiles...) @@ -736,12 +752,15 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { } else { ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name) } - case genHeaderDepTag: + case genHeaderDepTag, genHeaderExportDepTag: if genRule, ok := m.(genrule.SourceFileGenerator); ok { depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, genRule.GeneratedSourceFiles()...) - depPaths.Flags = append(depPaths.Flags, - includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()})) + flags := includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()}) + depPaths.Flags = append(depPaths.Flags, flags) + if tag == genHeaderExportDepTag { + depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags) + } } else { ctx.ModuleErrorf("module %q is not a genrule", name) } diff --git a/cc/linker.go b/cc/linker.go index 4ee38dcc7..2c4c25059 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -67,6 +67,10 @@ type BaseLinkerProperties struct { // present in static_libs. Export_static_lib_headers []string `android:"arch_variant"` + // list of generated headers to re-export include directories from. Entries must be + // present in generated_headers. + Export_generated_headers []string `android:"arch_variant"` + // don't link in crt_begin and crt_end. This flag should only be necessary for // compiling crt or libc. Nocrt *bool `android:"arch_variant"` @@ -107,6 +111,7 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...) deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...) + deps.ReexportGeneratedHeaders = append(deps.ReexportGeneratedHeaders, linker.Properties.Export_generated_headers...) if ctx.ModuleName() != "libcompiler_rt-extras" { deps.LateStaticLibs = append(deps.LateStaticLibs, "libcompiler_rt-extras")