Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
| 15 | package cc |
| 16 | |
| 17 | // The platform needs to provide the following artifacts for the NDK: |
| 18 | // 1. Bionic headers. |
| 19 | // 2. Platform API headers. |
| 20 | // 3. NDK stub shared libraries. |
| 21 | // 4. Bionic static libraries. |
| 22 | // |
| 23 | // TODO(danalbert): All of the above need to include NOTICE files. |
| 24 | // |
| 25 | // Components 1 and 2: Headers |
| 26 | // The bionic and platform API headers are generalized into a single |
| 27 | // `ndk_headers` rule. This rule has a `from` property that indicates a base |
| 28 | // directory from which headers are to be taken, and a `to` property that |
| 29 | // indicates where in the sysroot they should reside relative to usr/include. |
| 30 | // There is also a `srcs` property that is glob compatible for specifying which |
| 31 | // headers to include. |
| 32 | // |
| 33 | // Component 3: Stub Libraries |
| 34 | // The shared libraries in the NDK are not the actual shared libraries they |
| 35 | // refer to (to prevent people from accidentally loading them), but stub |
| 36 | // libraries with dummy implementations of everything for use at build time |
| 37 | // only. |
| 38 | // |
| 39 | // Since we don't actually need to know anything about the stub libraries aside |
| 40 | // from a list of functions and globals to be exposed, we can create these for |
| 41 | // every platform level in the current tree. This is handled by the |
| 42 | // ndk_library rule. |
| 43 | // |
| 44 | // Component 4: Static Libraries |
| 45 | // The NDK only provides static libraries for bionic, not the platform APIs. |
| 46 | // Since these need to be the actual implementation, we can't build old versions |
| 47 | // in the current platform tree. As such, legacy versions are checked in |
| 48 | // prebuilt to development/ndk, and a current version is built and archived as |
| 49 | // part of the platform build. The platfrom already builds these libraries, our |
| 50 | // NDK build rules only need to archive them for retrieval so they can be added |
| 51 | // to the prebuilts. |
| 52 | // |
| 53 | // TODO(danalbert): Write `ndk_static_library` rule. |
| 54 | |
| 55 | import ( |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 56 | "android/soong/android" |
| 57 | ) |
| 58 | |
| 59 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 60 | android.RegisterModuleType("ndk_headers", ndkHeadersFactory) |
| 61 | android.RegisterModuleType("ndk_library", ndkLibraryFactory) |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 62 | android.RegisterModuleType("preprocessed_ndk_headers", preprocessedNdkHeadersFactory) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 63 | android.RegisterSingletonType("ndk", NdkSingleton) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 64 | |
| 65 | pctx.Import("android/soong/common") |
| 66 | } |
| 67 | |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 68 | func getNdkInstallBase(ctx android.PathContext) android.OutputPath { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 69 | return android.PathForOutput(ctx, "ndk") |
| 70 | } |
| 71 | |
| 72 | // Returns the main install directory for the NDK sysroot. Usable with --sysroot. |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 73 | func getNdkSysrootBase(ctx android.PathContext) android.OutputPath { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 74 | return getNdkInstallBase(ctx).Join(ctx, "sysroot") |
| 75 | } |
| 76 | |
Dan Albert | 6ab43d8 | 2017-12-13 15:05:04 -0800 | [diff] [blame^] | 77 | // The base timestamp file depends on the NDK headers and stub shared libraries, |
| 78 | // but not the static libraries. This distinction is needed because the static |
| 79 | // libraries themselves might need to depend on the base sysroot. |
| 80 | func getNdkBaseTimestampFile(ctx android.PathContext) android.WritablePath { |
| 81 | return android.PathForOutput(ctx, "ndk_base.timestamp") |
| 82 | } |
| 83 | |
| 84 | // The full timestamp file depends on the base timestamp *and* the static |
| 85 | // libraries. |
| 86 | func getNdkFullTimestampFile(ctx android.PathContext) android.WritablePath { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 87 | return android.PathForOutput(ctx, "ndk.timestamp") |
| 88 | } |
| 89 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 90 | func NdkSingleton() android.Singleton { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 91 | return &ndkSingleton{} |
| 92 | } |
| 93 | |
| 94 | type ndkSingleton struct{} |
| 95 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 96 | func (n *ndkSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Dan Albert | 6ab43d8 | 2017-12-13 15:05:04 -0800 | [diff] [blame^] | 97 | var staticLibInstallPaths android.Paths |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 98 | var installPaths android.Paths |
| 99 | var licensePaths android.Paths |
| 100 | ctx.VisitAllModules(func(module android.Module) { |
Dan Willemsen | 95f4dbb | 2017-05-05 23:26:01 -0700 | [diff] [blame] | 101 | if m, ok := module.(android.Module); ok && !m.Enabled() { |
| 102 | return |
| 103 | } |
| 104 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 105 | if m, ok := module.(*headerModule); ok { |
| 106 | installPaths = append(installPaths, m.installPaths...) |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 107 | licensePaths = append(licensePaths, m.licensePath) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 108 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 109 | |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 110 | if m, ok := module.(*preprocessedHeaderModule); ok { |
| 111 | installPaths = append(installPaths, m.installPaths...) |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 112 | licensePaths = append(licensePaths, m.licensePath) |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 113 | } |
| 114 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 115 | if m, ok := module.(*Module); ok { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 116 | if installer, ok := m.installer.(*stubDecorator); ok { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 117 | installPaths = append(installPaths, installer.installPath) |
| 118 | } |
Dan Albert | f563d25 | 2017-10-13 00:29:00 -0700 | [diff] [blame] | 119 | |
| 120 | if library, ok := m.linker.(*libraryDecorator); ok { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 121 | if library.ndkSysrootPath != nil { |
Dan Albert | 6ab43d8 | 2017-12-13 15:05:04 -0800 | [diff] [blame^] | 122 | staticLibInstallPaths = append( |
| 123 | staticLibInstallPaths, library.ndkSysrootPath) |
Dan Albert | f563d25 | 2017-10-13 00:29:00 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 126 | } |
| 127 | }) |
| 128 | |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 129 | combinedLicense := getNdkInstallBase(ctx).Join(ctx, "NOTICE") |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 130 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 131 | Rule: android.Cat, |
| 132 | Description: "combine licenses", |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 133 | Output: combinedLicense, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 134 | Inputs: licensePaths, |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 135 | }) |
| 136 | |
Dan Albert | 6ab43d8 | 2017-12-13 15:05:04 -0800 | [diff] [blame^] | 137 | baseDepPaths := append(installPaths, combinedLicense) |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 138 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 139 | // There's a dummy "ndk" rule defined in ndk/Android.mk that depends on |
| 140 | // this. `m ndk` will build the sysroots. |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 141 | ctx.Build(pctx, android.BuildParams{ |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 142 | Rule: android.Touch, |
Dan Albert | 6ab43d8 | 2017-12-13 15:05:04 -0800 | [diff] [blame^] | 143 | Output: getNdkBaseTimestampFile(ctx), |
| 144 | Implicits: baseDepPaths, |
| 145 | }) |
| 146 | |
| 147 | fullDepPaths := append(staticLibInstallPaths, getNdkBaseTimestampFile(ctx)) |
| 148 | |
| 149 | ctx.Build(pctx, android.BuildParams{ |
| 150 | Rule: android.Touch, |
| 151 | Output: getNdkFullTimestampFile(ctx), |
| 152 | Implicits: fullDepPaths, |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 153 | }) |
| 154 | } |