Allow NDK static libraries to use the NDK sysroot.

Building a static library for the NDK only requires that the NDK
headers be available. Currently, A module with both
`static_ndk_lib: true` and `sdk_version: something` will have a cyclic
dependency since it both needs the NDK and is in the NDK. Create two
NDK timestamp files: one for the isolated parts of the NDK (headers
and stub libraries), and another for the full sysroot with the static
libraries.

Test: set static_ndk_lib on compiler-rt-extras, make ndk
Bug: None
Change-Id: Iab50ffa0e4cbf4cd164f376e15281030c7aad984
This commit is contained in:
Dan Albert
2017-12-13 15:05:04 -08:00
parent 281f22b3f2
commit 6ab43d8597
2 changed files with 25 additions and 6 deletions

View File

@@ -522,7 +522,7 @@ func ndkPathDeps(ctx ModuleContext) android.Paths {
if ctx.useSdk() { if ctx.useSdk() {
// The NDK sysroot timestamp file depends on all the NDK sysroot files // The NDK sysroot timestamp file depends on all the NDK sysroot files
// (headers and libraries). // (headers and libraries).
return android.Paths{getNdkSysrootTimestampFile(ctx)} return android.Paths{getNdkBaseTimestampFile(ctx)}
} }
return nil return nil
} }

View File

@@ -74,7 +74,16 @@ func getNdkSysrootBase(ctx android.PathContext) android.OutputPath {
return getNdkInstallBase(ctx).Join(ctx, "sysroot") return getNdkInstallBase(ctx).Join(ctx, "sysroot")
} }
func getNdkSysrootTimestampFile(ctx android.PathContext) android.WritablePath { // The base timestamp file depends on the NDK headers and stub shared libraries,
// but not the static libraries. This distinction is needed because the static
// libraries themselves might need to depend on the base sysroot.
func getNdkBaseTimestampFile(ctx android.PathContext) android.WritablePath {
return android.PathForOutput(ctx, "ndk_base.timestamp")
}
// The full timestamp file depends on the base timestamp *and* the static
// libraries.
func getNdkFullTimestampFile(ctx android.PathContext) android.WritablePath {
return android.PathForOutput(ctx, "ndk.timestamp") return android.PathForOutput(ctx, "ndk.timestamp")
} }
@@ -85,6 +94,7 @@ func NdkSingleton() android.Singleton {
type ndkSingleton struct{} type ndkSingleton struct{}
func (n *ndkSingleton) GenerateBuildActions(ctx android.SingletonContext) { func (n *ndkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
var staticLibInstallPaths android.Paths
var installPaths android.Paths var installPaths android.Paths
var licensePaths android.Paths var licensePaths android.Paths
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
@@ -109,7 +119,8 @@ func (n *ndkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
if library, ok := m.linker.(*libraryDecorator); ok { if library, ok := m.linker.(*libraryDecorator); ok {
if library.ndkSysrootPath != nil { if library.ndkSysrootPath != nil {
installPaths = append(installPaths, library.ndkSysrootPath) staticLibInstallPaths = append(
staticLibInstallPaths, library.ndkSysrootPath)
} }
} }
} }
@@ -123,13 +134,21 @@ func (n *ndkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Inputs: licensePaths, Inputs: licensePaths,
}) })
depPaths := append(installPaths, combinedLicense) baseDepPaths := append(installPaths, combinedLicense)
// There's a dummy "ndk" rule defined in ndk/Android.mk that depends on // There's a dummy "ndk" rule defined in ndk/Android.mk that depends on
// this. `m ndk` will build the sysroots. // this. `m ndk` will build the sysroots.
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: android.Touch, Rule: android.Touch,
Output: getNdkSysrootTimestampFile(ctx), Output: getNdkBaseTimestampFile(ctx),
Implicits: depPaths, Implicits: baseDepPaths,
})
fullDepPaths := append(staticLibInstallPaths, getNdkBaseTimestampFile(ctx))
ctx.Build(pctx, android.BuildParams{
Rule: android.Touch,
Output: getNdkFullTimestampFile(ctx),
Implicits: fullDepPaths,
}) })
} }