Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 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 sdk |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 19 | "path/filepath" |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 20 | "strings" |
| 21 | |
| 22 | "github.com/google/blueprint/proptools" |
| 23 | |
| 24 | "android/soong/android" |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 25 | "android/soong/cc" |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 26 | "android/soong/java" |
| 27 | ) |
| 28 | |
| 29 | var pctx = android.NewPackageContext("android/soong/sdk") |
| 30 | |
| 31 | // generatedFile abstracts operations for writing contents into a file and emit a build rule |
| 32 | // for the file. |
| 33 | type generatedFile struct { |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 34 | path android.OutputPath |
| 35 | content strings.Builder |
| 36 | indentLevel int |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 37 | } |
| 38 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 39 | func newGeneratedFile(ctx android.ModuleContext, path ...string) *generatedFile { |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 40 | return &generatedFile{ |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 41 | path: android.PathForModuleOut(ctx, path...).OutputPath, |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 42 | indentLevel: 0, |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 46 | func (gf *generatedFile) Indent() { |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 47 | gf.indentLevel++ |
| 48 | } |
| 49 | |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 50 | func (gf *generatedFile) Dedent() { |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 51 | gf.indentLevel-- |
| 52 | } |
| 53 | |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 54 | func (gf *generatedFile) Printfln(format string, args ...interface{}) { |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 55 | // ninja consumes newline characters in rspfile_content. Prevent it by |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 56 | // escaping the backslash in the newline character. The extra backslash |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 57 | // is removed when the rspfile is written to the actual script file |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 58 | fmt.Fprintf(&(gf.content), strings.Repeat(" ", gf.indentLevel)+format+"\\n", args...) |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderContext, implicits android.Paths) { |
| 62 | rb := android.NewRuleBuilder() |
| 63 | // convert \\n to \n |
| 64 | rb.Command(). |
| 65 | Implicits(implicits). |
| 66 | Text("echo").Text(proptools.ShellEscape(gf.content.String())). |
| 67 | Text("| sed 's/\\\\n/\\n/g' >").Output(gf.path) |
| 68 | rb.Command(). |
| 69 | Text("chmod a+x").Output(gf.path) |
| 70 | rb.Build(pctx, ctx, gf.path.Base(), "Build "+gf.path.Base()) |
| 71 | } |
| 72 | |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 73 | func (s *sdk) javaLibs(ctx android.ModuleContext) []android.SdkAware { |
| 74 | result := []android.SdkAware{} |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 75 | ctx.VisitDirectDeps(func(m android.Module) { |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 76 | if j, ok := m.(*java.Library); ok { |
| 77 | result = append(result, j) |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 78 | } |
| 79 | }) |
| 80 | return result |
| 81 | } |
| 82 | |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 83 | // archSpecificNativeLibInfo represents an arch-specific variant of a native lib |
| 84 | type archSpecificNativeLibInfo struct { |
| 85 | name string |
| 86 | archType string |
| 87 | exportedIncludeDirs android.Paths |
| 88 | exportedSystemIncludeDirs android.Paths |
| 89 | exportedFlags []string |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 90 | exportedDeps android.Paths |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 91 | outputFile android.Path |
| 92 | } |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 93 | |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 94 | func (lib *archSpecificNativeLibInfo) signature() string { |
| 95 | return fmt.Sprintf("%v %v %v %v", |
| 96 | lib.name, |
| 97 | lib.exportedIncludeDirs.Strings(), |
| 98 | lib.exportedSystemIncludeDirs.Strings(), |
| 99 | lib.exportedFlags) |
| 100 | } |
| 101 | |
| 102 | // nativeLibInfo represents a collection of arch-specific modules having the same name |
| 103 | type nativeLibInfo struct { |
| 104 | name string |
| 105 | archVariants []archSpecificNativeLibInfo |
| 106 | // hasArchSpecificFlags is set to true if modules for each architecture all have the same |
| 107 | // include dirs, flags, etc, in which case only those of the first arch is selected. |
| 108 | hasArchSpecificFlags bool |
| 109 | } |
| 110 | |
| 111 | // nativeMemberInfos collects all cc.Modules that are member of an SDK. |
| 112 | func (s *sdk) nativeMemberInfos(ctx android.ModuleContext) []*nativeLibInfo { |
| 113 | infoMap := make(map[string]*nativeLibInfo) |
| 114 | |
| 115 | // Collect cc.Modules |
| 116 | ctx.VisitDirectDeps(func(m android.Module) { |
| 117 | ccModule, ok := m.(*cc.Module) |
| 118 | if !ok { |
| 119 | return |
| 120 | } |
| 121 | depName := ctx.OtherModuleName(m) |
| 122 | |
| 123 | if _, ok := infoMap[depName]; !ok { |
| 124 | infoMap[depName] = &nativeLibInfo{name: depName} |
| 125 | } |
| 126 | |
| 127 | info := infoMap[depName] |
| 128 | info.archVariants = append(info.archVariants, archSpecificNativeLibInfo{ |
| 129 | name: ccModule.BaseModuleName(), |
| 130 | archType: ccModule.Target().Arch.ArchType.String(), |
| 131 | exportedIncludeDirs: ccModule.ExportedIncludeDirs(), |
| 132 | exportedSystemIncludeDirs: ccModule.ExportedSystemIncludeDirs(), |
| 133 | exportedFlags: ccModule.ExportedFlags(), |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 134 | exportedDeps: ccModule.ExportedDeps(), |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 135 | outputFile: ccModule.OutputFile().Path(), |
| 136 | }) |
| 137 | }) |
| 138 | |
| 139 | // Determine if include dirs and flags for each module are different across arch-specific |
| 140 | // modules or not. And set hasArchSpecificFlags accordingly |
| 141 | for _, info := range infoMap { |
| 142 | // by default, include paths and flags are assumed to be the same across arches |
| 143 | info.hasArchSpecificFlags = false |
| 144 | oldSignature := "" |
| 145 | for _, av := range info.archVariants { |
| 146 | newSignature := av.signature() |
| 147 | if oldSignature == "" { |
| 148 | oldSignature = newSignature |
| 149 | } |
| 150 | if oldSignature != newSignature { |
| 151 | info.hasArchSpecificFlags = true |
| 152 | break |
| 153 | } |
| 154 | } |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 155 | } |
| 156 | |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 157 | var list []*nativeLibInfo |
| 158 | for _, v := range infoMap { |
| 159 | list = append(list, v) |
| 160 | } |
| 161 | return list |
| 162 | } |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 163 | |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 164 | // SDK directory structure |
| 165 | // <sdk_root>/ |
| 166 | // Android.bp : definition of a 'sdk' module is here. This is a hand-made one. |
| 167 | // <api_ver>/ : below this directory are all auto-generated |
| 168 | // Android.bp : definition of 'sdk_snapshot' module is here |
| 169 | // aidl/ |
| 170 | // frameworks/base/core/..../IFoo.aidl : an exported AIDL file |
| 171 | // java/ |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 172 | // <module_name>.jar : the stub jar for a java library 'module_name' |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 173 | // include/ |
| 174 | // bionic/libc/include/stdlib.h : an exported header file |
| 175 | // include_gen/ |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 176 | // <module_name>/com/android/.../IFoo.h : a generated header file |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 177 | // <arch>/include/ : arch-specific exported headers |
| 178 | // <arch>/include_gen/ : arch-specific generated headers |
| 179 | // <arch>/lib/ |
| 180 | // libFoo.so : a stub library |
| 181 | |
| 182 | const ( |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 183 | nativeIncludeDir = "include" |
| 184 | nativeGeneratedIncludeDir = "include_gen" |
| 185 | nativeStubDir = "lib" |
| 186 | nativeStubFileSuffix = ".so" |
| 187 | ) |
| 188 | |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 189 | // path to the stub file of a native shared library. Relative to <sdk_root>/<api_dir> |
| 190 | func nativeStubFilePathFor(lib archSpecificNativeLibInfo) string { |
| 191 | return filepath.Join(lib.archType, |
| 192 | nativeStubDir, lib.name+nativeStubFileSuffix) |
| 193 | } |
| 194 | |
| 195 | // paths to the include dirs of a native shared library. Relative to <sdk_root>/<api_dir> |
| 196 | func nativeIncludeDirPathsFor(ctx android.ModuleContext, lib archSpecificNativeLibInfo, |
| 197 | systemInclude bool, archSpecific bool) []string { |
| 198 | var result []string |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 199 | var includeDirs []android.Path |
| 200 | if !systemInclude { |
| 201 | includeDirs = lib.exportedIncludeDirs |
| 202 | } else { |
| 203 | includeDirs = lib.exportedSystemIncludeDirs |
| 204 | } |
| 205 | for _, dir := range includeDirs { |
| 206 | var path string |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 207 | if _, gen := dir.(android.WritablePath); gen { |
| 208 | path = filepath.Join(nativeGeneratedIncludeDir, lib.name) |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 209 | } else { |
| 210 | path = filepath.Join(nativeIncludeDir, dir.String()) |
| 211 | } |
| 212 | if archSpecific { |
| 213 | path = filepath.Join(lib.archType, path) |
| 214 | } |
| 215 | result = append(result, path) |
| 216 | } |
| 217 | return result |
| 218 | } |
| 219 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 220 | // A name that uniquely identifies a prebuilt SDK member for a version of SDK snapshot |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 221 | // This isn't visible to users, so could be changed in future. |
| 222 | func versionedSdkMemberName(ctx android.ModuleContext, memberName string, version string) string { |
| 223 | return ctx.ModuleName() + "_" + memberName + string(android.SdkVersionSeparator) + version |
| 224 | } |
| 225 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 226 | // buildSnapshot is the main function in this source file. It creates rules to copy |
| 227 | // the contents (header files, stub libraries, etc) into the zip file. |
| 228 | func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 229 | snapshotDir := android.PathForModuleOut(ctx, "snapshot") |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 230 | |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 231 | bp := newGeneratedFile(ctx, "snapshot", "Android.bp") |
| 232 | bp.Printfln("// This is auto-generated. DO NOT EDIT.") |
| 233 | bp.Printfln("") |
| 234 | |
| 235 | builder := &snapshotBuilder{ |
| 236 | ctx: ctx, |
| 237 | version: "current", |
| 238 | snapshotDir: snapshotDir.OutputPath, |
| 239 | androidBpFile: bp, |
| 240 | filesToZip: []android.Path{bp.path}, |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 241 | } |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 242 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 243 | // copy exported AIDL files and stub jar files |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 244 | javaLibs := s.javaLibs(ctx) |
| 245 | for _, m := range javaLibs { |
| 246 | m.BuildSnapshot(ctx, builder) |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 247 | } |
| 248 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 249 | // copy exported header files and stub *.so files |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 250 | nativeLibInfos := s.nativeMemberInfos(ctx) |
| 251 | for _, info := range nativeLibInfos { |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 252 | buildSharedNativeLibSnapshot(ctx, info, builder) |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 253 | } |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 254 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 255 | // generate Android.bp |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 256 | |
| 257 | bp.Printfln("sdk_snapshot {") |
| 258 | bp.Indent() |
| 259 | bp.Printfln("name: %q,", ctx.ModuleName()+string(android.SdkVersionSeparator)+builder.version) |
| 260 | if len(javaLibs) > 0 { |
| 261 | bp.Printfln("java_libs: [") |
| 262 | bp.Indent() |
| 263 | for _, m := range javaLibs { |
| 264 | bp.Printfln("%q,", builder.VersionedSdkMemberName(m.Name())) |
| 265 | } |
| 266 | bp.Dedent() |
| 267 | bp.Printfln("],") // java_libs |
| 268 | } |
| 269 | if len(nativeLibInfos) > 0 { |
| 270 | bp.Printfln("native_shared_libs: [") |
| 271 | bp.Indent() |
| 272 | for _, info := range nativeLibInfos { |
| 273 | bp.Printfln("%q,", builder.VersionedSdkMemberName(info.name)) |
| 274 | } |
| 275 | bp.Dedent() |
| 276 | bp.Printfln("],") // native_shared_libs |
| 277 | } |
| 278 | bp.Dedent() |
| 279 | bp.Printfln("}") // sdk_snapshot |
| 280 | bp.Printfln("") |
| 281 | |
| 282 | bp.build(pctx, ctx, nil) |
| 283 | |
| 284 | filesToZip := builder.filesToZip |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 285 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 286 | // zip them all |
| 287 | zipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath |
| 288 | rb := android.NewRuleBuilder() |
| 289 | rb.Command(). |
| 290 | BuiltTool(ctx, "soong_zip"). |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 291 | FlagWithArg("-C ", builder.snapshotDir.String()). |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 292 | FlagWithRspFileInputList("-l ", filesToZip). |
| 293 | FlagWithOutput("-o ", zipFile) |
| 294 | rb.Build(pctx, ctx, "snapshot", "Building snapshot for "+ctx.ModuleName()) |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 295 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 296 | return zipFile |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 297 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame^] | 298 | |
| 299 | func buildSharedNativeLibSnapshot(ctx android.ModuleContext, info *nativeLibInfo, builder android.SnapshotBuilder) { |
| 300 | // a function for emitting include dirs |
| 301 | printExportedDirCopyCommandsForNativeLibs := func(lib archSpecificNativeLibInfo) { |
| 302 | includeDirs := lib.exportedIncludeDirs |
| 303 | includeDirs = append(includeDirs, lib.exportedSystemIncludeDirs...) |
| 304 | if len(includeDirs) == 0 { |
| 305 | return |
| 306 | } |
| 307 | for _, dir := range includeDirs { |
| 308 | if _, gen := dir.(android.WritablePath); gen { |
| 309 | // generated headers are copied via exportedDeps. See below. |
| 310 | continue |
| 311 | } |
| 312 | targetDir := nativeIncludeDir |
| 313 | if info.hasArchSpecificFlags { |
| 314 | targetDir = filepath.Join(lib.archType, targetDir) |
| 315 | } |
| 316 | |
| 317 | // TODO(jiyong) copy headers having other suffixes |
| 318 | headers, _ := ctx.GlobWithDeps(dir.String()+"/**/*.h", nil) |
| 319 | for _, file := range headers { |
| 320 | src := android.PathForSource(ctx, file) |
| 321 | dest := filepath.Join(targetDir, file) |
| 322 | builder.CopyToSnapshot(src, dest) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | genHeaders := lib.exportedDeps |
| 327 | for _, file := range genHeaders { |
| 328 | targetDir := nativeGeneratedIncludeDir |
| 329 | if info.hasArchSpecificFlags { |
| 330 | targetDir = filepath.Join(lib.archType, targetDir) |
| 331 | } |
| 332 | dest := filepath.Join(targetDir, lib.name, file.Rel()) |
| 333 | builder.CopyToSnapshot(file, dest) |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if !info.hasArchSpecificFlags { |
| 338 | printExportedDirCopyCommandsForNativeLibs(info.archVariants[0]) |
| 339 | } |
| 340 | |
| 341 | // for each architecture |
| 342 | for _, av := range info.archVariants { |
| 343 | builder.CopyToSnapshot(av.outputFile, nativeStubFilePathFor(av)) |
| 344 | |
| 345 | if info.hasArchSpecificFlags { |
| 346 | printExportedDirCopyCommandsForNativeLibs(av) |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | bp := builder.AndroidBpFile() |
| 351 | bp.Printfln("cc_prebuilt_library_shared {") |
| 352 | bp.Indent() |
| 353 | bp.Printfln("name: %q,", builder.VersionedSdkMemberName(info.name)) |
| 354 | bp.Printfln("sdk_member_name: %q,", info.name) |
| 355 | |
| 356 | // a function for emitting include dirs |
| 357 | printExportedDirsForNativeLibs := func(lib archSpecificNativeLibInfo, systemInclude bool) { |
| 358 | includeDirs := nativeIncludeDirPathsFor(ctx, lib, systemInclude, info.hasArchSpecificFlags) |
| 359 | if len(includeDirs) == 0 { |
| 360 | return |
| 361 | } |
| 362 | if !systemInclude { |
| 363 | bp.Printfln("export_include_dirs: [") |
| 364 | } else { |
| 365 | bp.Printfln("export_system_include_dirs: [") |
| 366 | } |
| 367 | bp.Indent() |
| 368 | for _, dir := range includeDirs { |
| 369 | bp.Printfln("%q,", dir) |
| 370 | } |
| 371 | bp.Dedent() |
| 372 | bp.Printfln("],") |
| 373 | } |
| 374 | |
| 375 | if !info.hasArchSpecificFlags { |
| 376 | printExportedDirsForNativeLibs(info.archVariants[0], false /*systemInclude*/) |
| 377 | printExportedDirsForNativeLibs(info.archVariants[0], true /*systemInclude*/) |
| 378 | } |
| 379 | |
| 380 | bp.Printfln("arch: {") |
| 381 | bp.Indent() |
| 382 | for _, av := range info.archVariants { |
| 383 | bp.Printfln("%s: {", av.archType) |
| 384 | bp.Indent() |
| 385 | bp.Printfln("srcs: [%q],", nativeStubFilePathFor(av)) |
| 386 | if info.hasArchSpecificFlags { |
| 387 | // export_* properties are added inside the arch: {<arch>: {...}} block |
| 388 | printExportedDirsForNativeLibs(av, false /*systemInclude*/) |
| 389 | printExportedDirsForNativeLibs(av, true /*systemInclude*/) |
| 390 | } |
| 391 | bp.Dedent() |
| 392 | bp.Printfln("},") // <arch> |
| 393 | } |
| 394 | bp.Dedent() |
| 395 | bp.Printfln("},") // arch |
| 396 | bp.Printfln("stl: \"none\",") |
| 397 | bp.Printfln("system_shared_libs: [],") |
| 398 | bp.Dedent() |
| 399 | bp.Printfln("}") // cc_prebuilt_library_shared |
| 400 | bp.Printfln("") |
| 401 | } |
| 402 | |
| 403 | type snapshotBuilder struct { |
| 404 | ctx android.ModuleContext |
| 405 | version string |
| 406 | snapshotDir android.OutputPath |
| 407 | filesToZip android.Paths |
| 408 | androidBpFile *generatedFile |
| 409 | } |
| 410 | |
| 411 | func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) { |
| 412 | path := s.snapshotDir.Join(s.ctx, dest) |
| 413 | s.ctx.Build(pctx, android.BuildParams{ |
| 414 | Rule: android.Cp, |
| 415 | Input: src, |
| 416 | Output: path, |
| 417 | }) |
| 418 | s.filesToZip = append(s.filesToZip, path) |
| 419 | } |
| 420 | |
| 421 | func (s *snapshotBuilder) AndroidBpFile() android.GeneratedSnapshotFile { |
| 422 | return s.androidBpFile |
| 423 | } |
| 424 | |
| 425 | func (s *snapshotBuilder) VersionedSdkMemberName(unversionedName string) interface{} { |
| 426 | return versionedSdkMemberName(s.ctx, unversionedName, s.version) |
| 427 | } |