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