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 | import ( |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 18 | "fmt" |
| 19 | "os" |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 20 | "path/filepath" |
Lazar Trsic | cdb710f | 2017-11-24 16:38:47 +0100 | [diff] [blame] | 21 | "strings" |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | ) |
| 27 | |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 28 | var ( |
Dan Albert | 97f9c96 | 2018-05-24 15:02:16 -0700 | [diff] [blame] | 29 | versionBionicHeaders = pctx.AndroidStaticRule("versionBionicHeaders", |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 30 | blueprint.RuleParams{ |
Dan Albert | d2130a9 | 2017-03-29 18:33:28 -0700 | [diff] [blame] | 31 | // The `&& touch $out` isn't really necessary, but Blueprint won't |
| 32 | // let us have only implicit outputs. |
| 33 | Command: "$versionerCmd -o $outDir $srcDir $depsPath && touch $out", |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 34 | CommandDeps: []string{"$versionerCmd"}, |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 35 | }, |
Dan Albert | d2130a9 | 2017-03-29 18:33:28 -0700 | [diff] [blame] | 36 | "depsPath", "srcDir", "outDir") |
Dan Albert | cb1b4b2 | 2018-05-24 15:06:11 -0700 | [diff] [blame] | 37 | |
| 38 | preprocessNdkHeader = pctx.AndroidStaticRule("preprocessNdkHeader", |
| 39 | blueprint.RuleParams{ |
| 40 | Command: "$preprocessor -o $out $in", |
| 41 | CommandDeps: []string{"$preprocessor"}, |
| 42 | }, |
| 43 | "preprocessor") |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | func init() { |
Logan Chien | 2f06635 | 2018-10-25 18:11:09 +0800 | [diff] [blame] | 47 | pctx.SourcePathVariable("versionerCmd", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/versioner") |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 50 | // Returns the NDK base include path for use with sdk_version current. Usable with -I. |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame^] | 51 | func getCurrentIncludePath(ctx android.ModuleContext) android.InstallPath { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 52 | return getNdkSysrootBase(ctx).Join(ctx, "usr/include") |
| 53 | } |
| 54 | |
Dan Albert | 7122205 | 2018-05-24 15:00:05 -0700 | [diff] [blame] | 55 | type headerProperties struct { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 56 | // Base directory of the headers being installed. As an example: |
| 57 | // |
| 58 | // ndk_headers { |
| 59 | // name: "foo", |
| 60 | // from: "include", |
| 61 | // to: "", |
| 62 | // srcs: ["include/foo/bar/baz.h"], |
| 63 | // } |
| 64 | // |
| 65 | // Will install $SYSROOT/usr/include/foo/bar/baz.h. If `from` were instead |
| 66 | // "include/foo", it would have installed $SYSROOT/usr/include/bar/baz.h. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 67 | From *string |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 68 | |
| 69 | // Install path within the sysroot. This is relative to usr/include. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 70 | To *string |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 71 | |
| 72 | // List of headers to install. Glob compatible. Common case is "include/**/*.h". |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 73 | Srcs []string `android:"path"` |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 74 | |
Dan Albert | 19ff8b4 | 2018-05-24 15:00:48 -0700 | [diff] [blame] | 75 | // Source paths that should be excluded from the srcs glob. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 76 | Exclude_srcs []string `android:"path"` |
Dan Albert | 19ff8b4 | 2018-05-24 15:00:48 -0700 | [diff] [blame] | 77 | |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 78 | // Path to the NOTICE file associated with the headers. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 79 | License *string `android:"path"` |
Dan Albert | 23d37e0 | 2018-11-28 08:30:10 -0800 | [diff] [blame] | 80 | |
| 81 | // True if this API is not yet ready to be shipped in the NDK. It will be |
| 82 | // available in the platform for testing, but will be excluded from the |
| 83 | // sysroot provided to the NDK proper. |
| 84 | Draft bool |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | type headerModule struct { |
| 88 | android.ModuleBase |
| 89 | |
Dan Albert | 7122205 | 2018-05-24 15:00:05 -0700 | [diff] [blame] | 90 | properties headerProperties |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 91 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 92 | installPaths android.Paths |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 93 | licensePath android.Path |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 96 | func getHeaderInstallDir(ctx android.ModuleContext, header android.Path, from string, |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame^] | 97 | to string) android.InstallPath { |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 98 | // Output path is the sysroot base + "usr/include" + to directory + directory component |
| 99 | // of the file without the leading from directory stripped. |
| 100 | // |
| 101 | // Given: |
| 102 | // sysroot base = "ndk/sysroot" |
| 103 | // from = "include/foo" |
| 104 | // to = "bar" |
| 105 | // header = "include/foo/woodly/doodly.h" |
| 106 | // output path = "ndk/sysroot/usr/include/bar/woodly/doodly.h" |
| 107 | |
| 108 | // full/platform/path/to/include/foo |
| 109 | fullFromPath := android.PathForModuleSrc(ctx, from) |
| 110 | |
| 111 | // full/platform/path/to/include/foo/woodly |
| 112 | headerDir := filepath.Dir(header.String()) |
| 113 | |
| 114 | // woodly |
| 115 | strippedHeaderDir, err := filepath.Rel(fullFromPath.String(), headerDir) |
| 116 | if err != nil { |
| 117 | ctx.ModuleErrorf("filepath.Rel(%q, %q) failed: %s", headerDir, |
| 118 | fullFromPath.String(), err) |
| 119 | } |
| 120 | |
| 121 | // full/platform/path/to/sysroot/usr/include/bar/woodly |
| 122 | installDir := getCurrentIncludePath(ctx).Join(ctx, to, strippedHeaderDir) |
| 123 | |
| 124 | // full/platform/path/to/sysroot/usr/include/bar/woodly/doodly.h |
| 125 | return installDir |
| 126 | } |
| 127 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 128 | func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 129 | if String(m.properties.License) == "" { |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 130 | ctx.PropertyErrorf("license", "field is required") |
| 131 | } |
| 132 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 133 | m.licensePath = android.PathForModuleSrc(ctx, String(m.properties.License)) |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 134 | |
Lazar Trsic | cdb710f | 2017-11-24 16:38:47 +0100 | [diff] [blame] | 135 | // When generating NDK prebuilts, skip installing MIPS headers, |
| 136 | // but keep them when doing regular platform build. |
| 137 | // Ndk_abis property is only set to true with build/soong/scripts/build-ndk-prebuilts.sh |
| 138 | // TODO: Revert this once MIPS is supported in NDK again. |
Colin Cross | 395f2cf | 2018-10-24 16:10:32 -0700 | [diff] [blame] | 139 | if ctx.Config().NdkAbis() && strings.Contains(ctx.ModuleName(), "mips") { |
Lazar Trsic | cdb710f | 2017-11-24 16:38:47 +0100 | [diff] [blame] | 140 | return |
| 141 | } |
| 142 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 143 | srcFiles := android.PathsForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 144 | for _, header := range srcFiles { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 145 | installDir := getHeaderInstallDir(ctx, header, String(m.properties.From), |
| 146 | String(m.properties.To)) |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 147 | installedPath := ctx.InstallFile(installDir, header.Base(), header) |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 148 | installPath := installDir.Join(ctx, header.Base()) |
| 149 | if installPath != installedPath { |
| 150 | panic(fmt.Sprintf( |
| 151 | "expected header install path (%q) not equal to actual install path %q", |
| 152 | installPath, installedPath)) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 153 | } |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 154 | m.installPaths = append(m.installPaths, installPath) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | if len(m.installPaths) == 0 { |
| 158 | ctx.ModuleErrorf("srcs %q matched zero files", m.properties.Srcs) |
| 159 | } |
| 160 | } |
| 161 | |
Patrice Arruda | 6ea4211 | 2019-04-03 08:43:30 -0700 | [diff] [blame] | 162 | // ndk_headers installs the sets of ndk headers defined in the srcs property |
| 163 | // to the sysroot base + "usr/include" + to directory + directory component. |
| 164 | // ndk_headers requires the license file to be specified. Example: |
| 165 | // |
| 166 | // Given: |
| 167 | // sysroot base = "ndk/sysroot" |
| 168 | // from = "include/foo" |
| 169 | // to = "bar" |
| 170 | // header = "include/foo/woodly/doodly.h" |
| 171 | // output path = "ndk/sysroot/usr/include/bar/woodly/doodly.h" |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 172 | func ndkHeadersFactory() android.Module { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 173 | module := &headerModule{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 174 | module.AddProperties(&module.properties) |
| 175 | android.InitAndroidModule(module) |
| 176 | return module |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 177 | } |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 178 | |
Dan Albert | 97f9c96 | 2018-05-24 15:02:16 -0700 | [diff] [blame] | 179 | type versionedHeaderProperties struct { |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 180 | // Base directory of the headers being installed. As an example: |
| 181 | // |
Dan Albert | 97f9c96 | 2018-05-24 15:02:16 -0700 | [diff] [blame] | 182 | // versioned_ndk_headers { |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 183 | // name: "foo", |
| 184 | // from: "include", |
| 185 | // to: "", |
| 186 | // } |
| 187 | // |
| 188 | // Will install $SYSROOT/usr/include/foo/bar/baz.h. If `from` were instead |
| 189 | // "include/foo", it would have installed $SYSROOT/usr/include/bar/baz.h. |
Nan Zhang | a5e7cb4 | 2017-11-09 22:42:32 -0800 | [diff] [blame] | 190 | From *string |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 191 | |
| 192 | // Install path within the sysroot. This is relative to usr/include. |
Nan Zhang | a5e7cb4 | 2017-11-09 22:42:32 -0800 | [diff] [blame] | 193 | To *string |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 194 | |
| 195 | // Path to the NOTICE file associated with the headers. |
Nan Zhang | a5e7cb4 | 2017-11-09 22:42:32 -0800 | [diff] [blame] | 196 | License *string |
Dan Albert | 23d37e0 | 2018-11-28 08:30:10 -0800 | [diff] [blame] | 197 | |
| 198 | // True if this API is not yet ready to be shipped in the NDK. It will be |
| 199 | // available in the platform for testing, but will be excluded from the |
| 200 | // sysroot provided to the NDK proper. |
| 201 | Draft bool |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | // Like ndk_headers, but preprocesses the headers with the bionic versioner: |
| 205 | // https://android.googlesource.com/platform/bionic/+/master/tools/versioner/README.md. |
| 206 | // |
| 207 | // Unlike ndk_headers, we don't operate on a list of sources but rather a whole directory, the |
| 208 | // module does not have the srcs property, and operates on a full directory (the `from` property). |
| 209 | // |
| 210 | // Note that this is really only built to handle bionic/libc/include. |
Dan Albert | 97f9c96 | 2018-05-24 15:02:16 -0700 | [diff] [blame] | 211 | type versionedHeaderModule struct { |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 212 | android.ModuleBase |
| 213 | |
Dan Albert | 97f9c96 | 2018-05-24 15:02:16 -0700 | [diff] [blame] | 214 | properties versionedHeaderProperties |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 215 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 216 | installPaths android.Paths |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 217 | licensePath android.Path |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Dan Albert | 97f9c96 | 2018-05-24 15:02:16 -0700 | [diff] [blame] | 220 | func (m *versionedHeaderModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Nan Zhang | a5e7cb4 | 2017-11-09 22:42:32 -0800 | [diff] [blame] | 221 | if String(m.properties.License) == "" { |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 222 | ctx.PropertyErrorf("license", "field is required") |
| 223 | } |
| 224 | |
Nan Zhang | a5e7cb4 | 2017-11-09 22:42:32 -0800 | [diff] [blame] | 225 | m.licensePath = android.PathForModuleSrc(ctx, String(m.properties.License)) |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 226 | |
Nan Zhang | a5e7cb4 | 2017-11-09 22:42:32 -0800 | [diff] [blame] | 227 | fromSrcPath := android.PathForModuleSrc(ctx, String(m.properties.From)) |
| 228 | toOutputPath := getCurrentIncludePath(ctx).Join(ctx, String(m.properties.To)) |
Dan Willemsen | 540a78c | 2018-02-26 21:50:08 -0800 | [diff] [blame] | 229 | srcFiles := ctx.GlobFiles(filepath.Join(fromSrcPath.String(), "**/*.h"), nil) |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 230 | var installPaths []android.WritablePath |
| 231 | for _, header := range srcFiles { |
Nan Zhang | a5e7cb4 | 2017-11-09 22:42:32 -0800 | [diff] [blame] | 232 | installDir := getHeaderInstallDir(ctx, header, String(m.properties.From), String(m.properties.To)) |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 233 | installPath := installDir.Join(ctx, header.Base()) |
| 234 | installPaths = append(installPaths, installPath) |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 235 | m.installPaths = append(m.installPaths, installPath) |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | if len(m.installPaths) == 0 { |
Nan Zhang | a5e7cb4 | 2017-11-09 22:42:32 -0800 | [diff] [blame] | 239 | ctx.ModuleErrorf("glob %q matched zero files", String(m.properties.From)) |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 242 | processHeadersWithVersioner(ctx, fromSrcPath, toOutputPath, srcFiles, installPaths) |
| 243 | } |
| 244 | |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 245 | func processHeadersWithVersioner(ctx android.ModuleContext, srcDir, outDir android.Path, |
| 246 | srcFiles android.Paths, installPaths []android.WritablePath) android.Path { |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 247 | // The versioner depends on a dependencies directory to simplify determining include paths |
| 248 | // when parsing headers. This directory contains architecture specific directories as well |
| 249 | // as a common directory, each of which contains symlinks to the actually directories to |
| 250 | // be included. |
| 251 | // |
| 252 | // ctx.Glob doesn't follow symlinks, so we need to do this ourselves so we correctly |
| 253 | // depend on these headers. |
| 254 | // TODO(http://b/35673191): Update the versioner to use a --sysroot. |
| 255 | depsPath := android.PathForSource(ctx, "bionic/libc/versioner-dependencies") |
| 256 | depsGlob := ctx.Glob(filepath.Join(depsPath.String(), "**/*"), nil) |
| 257 | for i, path := range depsGlob { |
| 258 | fileInfo, err := os.Lstat(path.String()) |
| 259 | if err != nil { |
| 260 | ctx.ModuleErrorf("os.Lstat(%q) failed: %s", path.String, err) |
| 261 | } |
| 262 | if fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink { |
| 263 | dest, err := os.Readlink(path.String()) |
| 264 | if err != nil { |
| 265 | ctx.ModuleErrorf("os.Readlink(%q) failed: %s", |
| 266 | path.String, err) |
| 267 | } |
| 268 | // Additional .. to account for the symlink itself. |
| 269 | depsGlob[i] = android.PathForSource( |
| 270 | ctx, filepath.Clean(filepath.Join(path.String(), "..", dest))) |
| 271 | } |
| 272 | } |
| 273 | |
Dan Albert | d2130a9 | 2017-03-29 18:33:28 -0700 | [diff] [blame] | 274 | timestampFile := android.PathForModuleOut(ctx, "versioner.timestamp") |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 275 | ctx.Build(pctx, android.BuildParams{ |
Dan Albert | 97f9c96 | 2018-05-24 15:02:16 -0700 | [diff] [blame] | 276 | Rule: versionBionicHeaders, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 277 | Description: "versioner preprocess " + srcDir.Rel(), |
Dan Albert | d2130a9 | 2017-03-29 18:33:28 -0700 | [diff] [blame] | 278 | Output: timestampFile, |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 279 | Implicits: append(srcFiles, depsGlob...), |
| 280 | ImplicitOutputs: installPaths, |
| 281 | Args: map[string]string{ |
| 282 | "depsPath": depsPath.String(), |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 283 | "srcDir": srcDir.String(), |
| 284 | "outDir": outDir.String(), |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 285 | }, |
| 286 | }) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 287 | |
| 288 | return timestampFile |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Patrice Arruda | 6ea4211 | 2019-04-03 08:43:30 -0700 | [diff] [blame] | 291 | // versioned_ndk_headers preprocesses the headers with the bionic versioner: |
| 292 | // https://android.googlesource.com/platform/bionic/+/master/tools/versioner/README.md. |
| 293 | // Unlike the ndk_headers soong module, versioned_ndk_headers operates on a |
| 294 | // directory level specified in `from` property. This is only used to process |
| 295 | // the bionic/libc/include directory. |
Dan Albert | 97f9c96 | 2018-05-24 15:02:16 -0700 | [diff] [blame] | 296 | func versionedNdkHeadersFactory() android.Module { |
| 297 | module := &versionedHeaderModule{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 298 | |
| 299 | module.AddProperties(&module.properties) |
| 300 | |
Dan Willemsen | 4f644da | 2018-10-10 17:18:08 -0700 | [diff] [blame] | 301 | android.InitAndroidModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 302 | |
| 303 | return module |
Dan Albert | 269fab8 | 2017-02-15 17:31:33 -0800 | [diff] [blame] | 304 | } |
Dan Albert | cb1b4b2 | 2018-05-24 15:06:11 -0700 | [diff] [blame] | 305 | |
| 306 | // preprocessed_ndk_header { |
| 307 | // name: "foo", |
| 308 | // preprocessor: "foo.sh", |
| 309 | // srcs: [...], |
| 310 | // to: "android", |
| 311 | // } |
| 312 | // |
| 313 | // Will invoke the preprocessor as: |
| 314 | // $preprocessor -o $SYSROOT/usr/include/android/needs_preproc.h $src |
| 315 | // For each src in srcs. |
| 316 | type preprocessedHeadersProperties struct { |
| 317 | // The preprocessor to run. Must be a program inside the source directory |
| 318 | // with no dependencies. |
| 319 | Preprocessor *string |
| 320 | |
| 321 | // Source path to the files to be preprocessed. |
| 322 | Srcs []string |
| 323 | |
| 324 | // Source paths that should be excluded from the srcs glob. |
| 325 | Exclude_srcs []string |
| 326 | |
| 327 | // Install path within the sysroot. This is relative to usr/include. |
| 328 | To *string |
| 329 | |
| 330 | // Path to the NOTICE file associated with the headers. |
| 331 | License *string |
Dan Albert | 23d37e0 | 2018-11-28 08:30:10 -0800 | [diff] [blame] | 332 | |
| 333 | // True if this API is not yet ready to be shipped in the NDK. It will be |
| 334 | // available in the platform for testing, but will be excluded from the |
| 335 | // sysroot provided to the NDK proper. |
| 336 | Draft bool |
Dan Albert | cb1b4b2 | 2018-05-24 15:06:11 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | type preprocessedHeadersModule struct { |
| 340 | android.ModuleBase |
| 341 | |
| 342 | properties preprocessedHeadersProperties |
| 343 | |
| 344 | installPaths android.Paths |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 345 | licensePath android.Path |
Dan Albert | cb1b4b2 | 2018-05-24 15:06:11 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Dan Albert | cb1b4b2 | 2018-05-24 15:06:11 -0700 | [diff] [blame] | 348 | func (m *preprocessedHeadersModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 349 | if String(m.properties.License) == "" { |
| 350 | ctx.PropertyErrorf("license", "field is required") |
| 351 | } |
| 352 | |
| 353 | preprocessor := android.PathForModuleSrc(ctx, String(m.properties.Preprocessor)) |
| 354 | m.licensePath = android.PathForModuleSrc(ctx, String(m.properties.License)) |
| 355 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 356 | srcFiles := android.PathsForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs) |
Dan Albert | cb1b4b2 | 2018-05-24 15:06:11 -0700 | [diff] [blame] | 357 | installDir := getCurrentIncludePath(ctx).Join(ctx, String(m.properties.To)) |
| 358 | for _, src := range srcFiles { |
| 359 | installPath := installDir.Join(ctx, src.Base()) |
| 360 | m.installPaths = append(m.installPaths, installPath) |
| 361 | |
| 362 | ctx.Build(pctx, android.BuildParams{ |
| 363 | Rule: preprocessNdkHeader, |
| 364 | Description: "preprocess " + src.Rel(), |
| 365 | Input: src, |
| 366 | Output: installPath, |
| 367 | Args: map[string]string{ |
| 368 | "preprocessor": preprocessor.String(), |
| 369 | }, |
| 370 | }) |
| 371 | } |
| 372 | |
| 373 | if len(m.installPaths) == 0 { |
| 374 | ctx.ModuleErrorf("srcs %q matched zero files", m.properties.Srcs) |
| 375 | } |
| 376 | } |
| 377 | |
Patrice Arruda | 6ea4211 | 2019-04-03 08:43:30 -0700 | [diff] [blame] | 378 | // preprocessed_ndk_headers preprocesses all the ndk headers listed in the srcs |
| 379 | // property by executing the command defined in the preprocessor property. |
Dan Albert | cb1b4b2 | 2018-05-24 15:06:11 -0700 | [diff] [blame] | 380 | func preprocessedNdkHeadersFactory() android.Module { |
| 381 | module := &preprocessedHeadersModule{} |
| 382 | |
| 383 | module.AddProperties(&module.properties) |
| 384 | |
Dan Willemsen | 4f644da | 2018-10-10 17:18:08 -0700 | [diff] [blame] | 385 | android.InitAndroidModule(module) |
Dan Albert | cb1b4b2 | 2018-05-24 15:06:11 -0700 | [diff] [blame] | 386 | |
| 387 | return module |
| 388 | } |