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