blob: fb2924a079fa5b9b3dd179626896f9dce9edeaa8 [file] [log] [blame]
Hao Chen1c8ea5b2023-10-20 23:03:45 +00001// Copyright 2024 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
15package cc
16
17import (
Hao Chen1c8ea5b2023-10-20 23:03:45 +000018 "bytes"
19 _ "embed"
20 "fmt"
21 "path/filepath"
22 "slices"
23 "sort"
24 "strings"
25 "text/template"
26
mrziwangf95cfa62024-06-18 10:11:39 -070027 "android/soong/android"
28
Hao Chen1c8ea5b2023-10-20 23:03:45 +000029 "github.com/google/blueprint"
30 "github.com/google/blueprint/proptools"
31)
32
33const veryVerbose bool = false
34
35//go:embed cmake_main.txt
36var templateCmakeMainRaw string
37var templateCmakeMain *template.Template = parseTemplate(templateCmakeMainRaw)
38
39//go:embed cmake_module_cc.txt
40var templateCmakeModuleCcRaw string
41var templateCmakeModuleCc *template.Template = parseTemplate(templateCmakeModuleCcRaw)
42
43//go:embed cmake_module_aidl.txt
44var templateCmakeModuleAidlRaw string
45var templateCmakeModuleAidl *template.Template = parseTemplate(templateCmakeModuleAidlRaw)
46
47//go:embed cmake_ext_add_aidl_library.txt
48var cmakeExtAddAidlLibrary string
49
50//go:embed cmake_ext_append_flags.txt
51var cmakeExtAppendFlags string
52
53var defaultUnportableFlags []string = []string{
Tomasz Wasilczykcd674732024-06-25 10:30:30 -070054 "-Wno-c99-designator",
Hao Chen1c8ea5b2023-10-20 23:03:45 +000055 "-Wno-class-memaccess",
56 "-Wno-exit-time-destructors",
Tomasz Wasilczykcd674732024-06-25 10:30:30 -070057 "-Winconsistent-missing-override",
Hao Chen1c8ea5b2023-10-20 23:03:45 +000058 "-Wno-inconsistent-missing-override",
59 "-Wreorder-init-list",
60 "-Wno-reorder-init-list",
61 "-Wno-restrict",
62 "-Wno-stringop-overread",
63 "-Wno-subobject-linkage",
64}
65
66var ignoredSystemLibs []string = []string{
Tomasz Wasilczyk2493fcc2024-06-20 15:29:09 -070067 "crtbegin_dynamic",
68 "crtend_android",
69 "libc",
Hao Chen1c8ea5b2023-10-20 23:03:45 +000070 "libc++",
71 "libc++_static",
Tomasz Wasilczykbd83c742024-06-27 10:47:40 -070072 "libc++demangle",
Tomasz Wasilczyk7cec7e62024-07-01 11:31:47 -070073 "libc_musl",
74 "libc_musl_crtbegin_so",
75 "libc_musl_crtbegin_static",
76 "libc_musl_crtend",
77 "libc_musl_crtend_so",
Tomasz Wasilczyk2493fcc2024-06-20 15:29:09 -070078 "libdl",
79 "libm",
Hao Chen1c8ea5b2023-10-20 23:03:45 +000080 "prebuilt_libclang_rt.builtins",
81 "prebuilt_libclang_rt.ubsan_minimal",
82}
83
84// Mapping entry between Android's library name and the one used when building outside Android tree.
85type LibraryMappingProperty struct {
86 // Android library name.
87 Android_name string
88
89 // Library name used when building outside Android.
90 Mapped_name string
91
92 // If the make file is already present in Android source tree, specify its location.
93 Package_pregenerated string
94
95 // If the package is expected to be installed on the build host OS, specify its name.
96 Package_system string
97}
98
99type CmakeSnapshotProperties struct {
Tomasz Wasilczykd38d1402024-06-27 10:41:55 -0700100 // Host modules to add to the snapshot package. Their dependencies are pulled in automatically.
101 Modules_host []string
102
103 // System modules to add to the snapshot package. Their dependencies are pulled in automatically.
104 Modules_system []string
105
106 // Vendor modules to add to the snapshot package. Their dependencies are pulled in automatically.
107 Modules_vendor []string
108
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000109 // Host prebuilts to bundle with the snapshot. These are tools needed to build outside Android.
110 Prebuilts []string
111
112 // Global cflags to add when building outside Android.
113 Cflags []string
114
115 // Flags to skip when building outside Android.
116 Cflags_ignored []string
117
118 // Mapping between library names used in Android tree and externally.
119 Library_mapping []LibraryMappingProperty
120
121 // List of cflags that are not portable between compilers that could potentially be used to
122 // build a generated package. If left empty, it's initialized with a default list.
123 Unportable_flags []string
124
125 // Whether to include source code as part of the snapshot package.
126 Include_sources bool
127}
128
129var cmakeSnapshotSourcesProvider = blueprint.NewProvider[android.Paths]()
130
131type CmakeSnapshot struct {
132 android.ModuleBase
133
134 Properties CmakeSnapshotProperties
135
136 zipPath android.WritablePath
137}
138
139type cmakeProcessedProperties struct {
140 LibraryMapping map[string]LibraryMappingProperty
141 PregeneratedPackages []string
142 SystemPackages []string
143}
144
145type cmakeSnapshotDependencyTag struct {
146 blueprint.BaseDependencyTag
147 name string
148}
149
150var (
151 cmakeSnapshotModuleTag = cmakeSnapshotDependencyTag{name: "cmake-snapshot-module"}
152 cmakeSnapshotPrebuiltTag = cmakeSnapshotDependencyTag{name: "cmake-snapshot-prebuilt"}
153)
154
155func parseTemplate(templateContents string) *template.Template {
156 funcMap := template.FuncMap{
157 "setList": func(name string, nameSuffix string, itemPrefix string, items []string) string {
158 var list strings.Builder
159 list.WriteString("set(" + name + nameSuffix)
160 templateListBuilder(&list, itemPrefix, items)
161 return list.String()
162 },
163 "toStrings": func(files android.Paths) []string {
Colin Cross7de1db72024-06-25 14:36:24 -0700164 return files.Strings()
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000165 },
166 "concat5": func(list1 []string, list2 []string, list3 []string, list4 []string, list5 []string) []string {
167 return append(append(append(append(list1, list2...), list3...), list4...), list5...)
168 },
169 "cflagsList": func(name string, nameSuffix string, flags []string,
170 unportableFlags []string, ignoredFlags []string) string {
171 if len(unportableFlags) == 0 {
172 unportableFlags = defaultUnportableFlags
173 }
174
175 var filteredPortable []string
176 var filteredUnportable []string
177 for _, flag := range flags {
178 if slices.Contains(ignoredFlags, flag) {
179 continue
180 } else if slices.Contains(unportableFlags, flag) {
181 filteredUnportable = append(filteredUnportable, flag)
182 } else {
183 filteredPortable = append(filteredPortable, flag)
184 }
185 }
186
187 var list strings.Builder
188
189 list.WriteString("set(" + name + nameSuffix)
190 templateListBuilder(&list, "", filteredPortable)
191
192 if len(filteredUnportable) > 0 {
193 list.WriteString("\nappend_cxx_flags_if_supported(" + name + nameSuffix)
194 templateListBuilder(&list, "", filteredUnportable)
195 }
196
197 return list.String()
198 },
199 "getSources": func(m *Module) android.Paths {
200 return m.compiler.(CompiledInterface).Srcs()
201 },
202 "getModuleType": getModuleType,
203 "getCompilerProperties": func(m *Module) BaseCompilerProperties {
204 return m.compiler.baseCompilerProps()
205 },
Cole Fauste96c16a2024-06-13 14:51:14 -0700206 "getCflagsProperty": func(ctx android.ModuleContext, m *Module) []string {
207 cflags := m.compiler.baseCompilerProps().Cflags
208 return cflags.GetOrDefault(ctx, nil)
209 },
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000210 "getLinkerProperties": func(m *Module) BaseLinkerProperties {
211 return m.linker.baseLinkerProps()
212 },
213 "getExtraLibs": getExtraLibs,
214 "getIncludeDirs": getIncludeDirs,
Tomasz Wasilczyk1e831bf2024-05-10 15:15:21 -0700215 "mapLibraries": func(ctx android.ModuleContext, m *Module, libs []string, mapping map[string]LibraryMappingProperty) []string {
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000216 var mappedLibs []string
217 for _, lib := range libs {
218 mappedLib, exists := mapping[lib]
219 if exists {
220 lib = mappedLib.Mapped_name
221 } else {
Tomasz Wasilczyk1e831bf2024-05-10 15:15:21 -0700222 if !ctx.OtherModuleExists(lib) {
223 ctx.OtherModuleErrorf(m, "Dependency %s doesn't exist", lib)
224 }
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000225 lib = "android::" + lib
226 }
227 if lib == "" {
228 continue
229 }
230 mappedLibs = append(mappedLibs, lib)
231 }
232 sort.Strings(mappedLibs)
233 mappedLibs = slices.Compact(mappedLibs)
234 return mappedLibs
235 },
Tomasz Wasilczyk1e831bf2024-05-10 15:15:21 -0700236 "getAidlSources": func(m *Module) []string {
237 aidlInterface := m.compiler.baseCompilerProps().AidlInterface
238 aidlRoot := aidlInterface.AidlRoot + string(filepath.Separator)
239 if aidlInterface.AidlRoot == "" {
240 aidlRoot = ""
241 }
242 var sources []string
243 for _, src := range aidlInterface.Sources {
244 if !strings.HasPrefix(src, aidlRoot) {
245 panic(fmt.Sprintf("Aidl source '%v' doesn't start with '%v'", src, aidlRoot))
246 }
247 sources = append(sources, src[len(aidlRoot):])
248 }
249 return sources
250 },
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000251 }
252
253 return template.Must(template.New("").Delims("<<", ">>").Funcs(funcMap).Parse(templateContents))
254}
255
256func sliceWithPrefix(prefix string, slice []string) []string {
257 output := make([]string, len(slice))
258 for i, elem := range slice {
259 output[i] = prefix + elem
260 }
261 return output
262}
263
264func templateListBuilder(builder *strings.Builder, itemPrefix string, items []string) {
265 if len(items) > 0 {
266 builder.WriteString("\n")
267 for _, item := range items {
268 builder.WriteString(" " + itemPrefix + item + "\n")
269 }
270 }
271 builder.WriteString(")")
272}
273
274func executeTemplate(templ *template.Template, buffer *bytes.Buffer, data any) string {
275 buffer.Reset()
276 if err := templ.Execute(buffer, data); err != nil {
277 panic(err)
278 }
279 output := strings.TrimSpace(buffer.String())
280 buffer.Reset()
281 return output
282}
283
284func (m *CmakeSnapshot) DepsMutator(ctx android.BottomUpMutatorContext) {
Tomasz Wasilczykd38d1402024-06-27 10:41:55 -0700285 deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
286 deviceSystemVariations := append(deviceVariations, blueprint.Variation{"image", ""})
287 deviceVendorVariations := append(deviceVariations, blueprint.Variation{"image", "vendor"})
Tomasz Wasilczyk9288b512024-06-27 09:22:12 -0700288 hostVariations := ctx.Config().BuildOSTarget.Variations()
Tomasz Wasilczykd38d1402024-06-27 10:41:55 -0700289
Tomasz Wasilczykd38d1402024-06-27 10:41:55 -0700290 ctx.AddVariationDependencies(hostVariations, cmakeSnapshotModuleTag, m.Properties.Modules_host...)
291 ctx.AddVariationDependencies(deviceSystemVariations, cmakeSnapshotModuleTag, m.Properties.Modules_system...)
292 ctx.AddVariationDependencies(deviceVendorVariations, cmakeSnapshotModuleTag, m.Properties.Modules_vendor...)
Tomasz Wasilczyk2493fcc2024-06-20 15:29:09 -0700293
294 if len(m.Properties.Prebuilts) > 0 {
295 prebuilts := append(m.Properties.Prebuilts, "libc++")
Tomasz Wasilczyk9288b512024-06-27 09:22:12 -0700296 ctx.AddVariationDependencies(hostVariations, cmakeSnapshotPrebuiltTag, prebuilts...)
Tomasz Wasilczyk2493fcc2024-06-20 15:29:09 -0700297 }
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000298}
299
300func (m *CmakeSnapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
301 var templateBuffer bytes.Buffer
302 var pprop cmakeProcessedProperties
303 m.zipPath = android.PathForModuleOut(ctx, ctx.ModuleName()+".zip")
304
305 // Process Library_mapping for more efficient lookups
306 pprop.LibraryMapping = map[string]LibraryMappingProperty{}
307 for _, elem := range m.Properties.Library_mapping {
308 pprop.LibraryMapping[elem.Android_name] = elem
309
310 if elem.Package_pregenerated != "" {
311 pprop.PregeneratedPackages = append(pprop.PregeneratedPackages, elem.Package_pregenerated)
312 }
313 sort.Strings(pprop.PregeneratedPackages)
314 pprop.PregeneratedPackages = slices.Compact(pprop.PregeneratedPackages)
315
316 if elem.Package_system != "" {
317 pprop.SystemPackages = append(pprop.SystemPackages, elem.Package_system)
318 }
319 sort.Strings(pprop.SystemPackages)
320 pprop.SystemPackages = slices.Compact(pprop.SystemPackages)
321 }
322
323 // Generating CMakeLists.txt rules for all modules in dependency tree
324 moduleDirs := map[string][]string{}
325 sourceFiles := map[string]android.Path{}
326 visitedModules := map[string]bool{}
327 var pregeneratedModules []*Module
328 ctx.WalkDeps(func(dep_a android.Module, parent android.Module) bool {
329 moduleName := ctx.OtherModuleName(dep_a)
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000330 if visited := visitedModules[moduleName]; visited {
331 return false // visit only once
332 }
333 visitedModules[moduleName] = true
Tomasz Wasilczyk1e831bf2024-05-10 15:15:21 -0700334 dep, ok := dep_a.(*Module)
335 if !ok {
336 return false // not a cc module
337 }
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000338 if mapping, ok := pprop.LibraryMapping[moduleName]; ok {
339 if mapping.Package_pregenerated != "" {
340 pregeneratedModules = append(pregeneratedModules, dep)
341 }
342 return false // mapped to system or pregenerated (we'll handle these later)
343 }
344 if ctx.OtherModuleDependencyTag(dep) == cmakeSnapshotPrebuiltTag {
345 return false // we'll handle cmakeSnapshotPrebuiltTag later
346 }
347 if slices.Contains(ignoredSystemLibs, moduleName) {
348 return false // system libs built in-tree for Android
349 }
350 if dep.compiler == nil {
351 return false // unsupported module type (e.g. prebuilt)
352 }
353 isAidlModule := dep.compiler.baseCompilerProps().AidlInterface.Lang != ""
354
355 if !proptools.Bool(dep.Properties.Cmake_snapshot_supported) {
356 ctx.OtherModulePropertyErrorf(dep, "cmake_snapshot_supported",
357 "CMake snapshots not supported, despite being a dependency for %s",
358 ctx.OtherModuleName(parent))
359 return false
360 }
361
362 if veryVerbose {
363 fmt.Println("WalkDeps: " + ctx.OtherModuleName(parent) + " -> " + moduleName)
364 }
365
366 // Generate CMakeLists.txt fragment for this module
367 templateToUse := templateCmakeModuleCc
368 if isAidlModule {
369 templateToUse = templateCmakeModuleAidl
370 }
371 moduleFragment := executeTemplate(templateToUse, &templateBuffer, struct {
372 Ctx *android.ModuleContext
373 M *Module
374 Snapshot *CmakeSnapshot
375 Pprop *cmakeProcessedProperties
376 }{
377 &ctx,
378 dep,
379 m,
380 &pprop,
381 })
382 moduleDir := ctx.OtherModuleDir(dep)
383 moduleDirs[moduleDir] = append(moduleDirs[moduleDir], moduleFragment)
384
385 if m.Properties.Include_sources {
386 files, _ := android.OtherModuleProvider(ctx, dep, cmakeSnapshotSourcesProvider)
387 for _, file := range files {
388 sourceFiles[file.String()] = file
389 }
390 }
391
392 // if it's AIDL module, no need to dive into their dependencies
393 return !isAidlModule
394 })
395
396 // Enumerate sources for pregenerated modules
397 if m.Properties.Include_sources {
398 for _, dep := range pregeneratedModules {
399 if !proptools.Bool(dep.Properties.Cmake_snapshot_supported) {
400 ctx.OtherModulePropertyErrorf(dep, "cmake_snapshot_supported",
401 "Pregenerated CMake snapshots not supported, despite being requested for %s",
402 ctx.ModuleName())
403 continue
404 }
405
406 files, _ := android.OtherModuleProvider(ctx, dep, cmakeSnapshotSourcesProvider)
407 for _, file := range files {
408 sourceFiles[file.String()] = file
409 }
410 }
411 }
412
413 // Merging CMakeLists.txt contents for every module directory
414 var makefilesList android.Paths
Colin Cross7de1db72024-06-25 14:36:24 -0700415 for _, moduleDir := range android.SortedKeys(moduleDirs) {
416 fragments := moduleDirs[moduleDir]
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000417 moduleCmakePath := android.PathForModuleGen(ctx, moduleDir, "CMakeLists.txt")
418 makefilesList = append(makefilesList, moduleCmakePath)
419 sort.Strings(fragments)
420 android.WriteFileRule(ctx, moduleCmakePath, strings.Join(fragments, "\n\n\n"))
421 }
422
423 // Generating top-level CMakeLists.txt
424 mainCmakePath := android.PathForModuleGen(ctx, "CMakeLists.txt")
425 makefilesList = append(makefilesList, mainCmakePath)
426 mainContents := executeTemplate(templateCmakeMain, &templateBuffer, struct {
427 Ctx *android.ModuleContext
428 M *CmakeSnapshot
429 ModuleDirs map[string][]string
430 Pprop *cmakeProcessedProperties
431 }{
432 &ctx,
433 m,
434 moduleDirs,
435 &pprop,
436 })
437 android.WriteFileRule(ctx, mainCmakePath, mainContents)
438
439 // Generating CMake extensions
440 extPath := android.PathForModuleGen(ctx, "cmake", "AppendCxxFlagsIfSupported.cmake")
441 makefilesList = append(makefilesList, extPath)
442 android.WriteFileRuleVerbatim(ctx, extPath, cmakeExtAppendFlags)
443 extPath = android.PathForModuleGen(ctx, "cmake", "AddAidlLibrary.cmake")
444 makefilesList = append(makefilesList, extPath)
445 android.WriteFileRuleVerbatim(ctx, extPath, cmakeExtAddAidlLibrary)
446
447 // Generating the final zip file
448 zipRule := android.NewRuleBuilder(pctx, ctx)
449 zipCmd := zipRule.Command().
450 BuiltTool("soong_zip").
451 FlagWithOutput("-o ", m.zipPath)
452
453 // Packaging all sources into the zip file
454 if m.Properties.Include_sources {
455 var sourcesList android.Paths
Colin Cross7de1db72024-06-25 14:36:24 -0700456 for _, file := range android.SortedKeys(sourceFiles) {
457 path := sourceFiles[file]
458 sourcesList = append(sourcesList, path)
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000459 }
460
461 sourcesRspFile := android.PathForModuleObj(ctx, ctx.ModuleName()+"_sources.rsp")
462 zipCmd.FlagWithRspFileInputList("-r ", sourcesRspFile, sourcesList)
463 }
464
465 // Packaging all make files into the zip file
466 makefilesRspFile := android.PathForModuleObj(ctx, ctx.ModuleName()+"_makefiles.rsp")
467 zipCmd.
468 FlagWithArg("-C ", android.PathForModuleGen(ctx).OutputPath.String()).
469 FlagWithRspFileInputList("-r ", makefilesRspFile, makefilesList)
470
471 // Packaging all prebuilts into the zip file
472 if len(m.Properties.Prebuilts) > 0 {
473 var prebuiltsList android.Paths
474
475 ctx.VisitDirectDepsWithTag(cmakeSnapshotPrebuiltTag, func(dep android.Module) {
476 for _, file := range dep.FilesToInstall() {
477 prebuiltsList = append(prebuiltsList, file)
478 }
479 })
480
481 prebuiltsRspFile := android.PathForModuleObj(ctx, ctx.ModuleName()+"_prebuilts.rsp")
482 zipCmd.
483 FlagWithArg("-C ", android.PathForArbitraryOutput(ctx).String()).
484 FlagWithArg("-P ", "prebuilts").
485 FlagWithRspFileInputList("-r ", prebuiltsRspFile, prebuiltsList)
486 }
487
488 // Finish generating the final zip file
489 zipRule.Build(m.zipPath.String(), "archiving "+ctx.ModuleName())
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000490
mrziwangf95cfa62024-06-18 10:11:39 -0700491 ctx.SetOutputFiles(android.Paths{m.zipPath}, "")
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000492}
493
494func (m *CmakeSnapshot) AndroidMkEntries() []android.AndroidMkEntries {
495 return []android.AndroidMkEntries{{
496 Class: "DATA",
497 OutputFile: android.OptionalPathForPath(m.zipPath),
498 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
499 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
500 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
501 },
502 },
503 }}
504}
505
506func getModuleType(m *Module) string {
507 switch m.linker.(type) {
508 case *binaryDecorator:
509 return "executable"
510 case *libraryDecorator:
511 return "library"
512 case *testBinary:
Tomasz Wasilczykc3177e02024-06-10 14:38:45 -0700513 return "test"
Tomasz Wasilczyk6e2b8c02024-05-30 07:48:40 -0700514 case *benchmarkDecorator:
Tomasz Wasilczykc3177e02024-06-10 14:38:45 -0700515 return "test"
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000516 }
Tomasz Wasilczyk6e2b8c02024-05-30 07:48:40 -0700517 panic(fmt.Sprintf("Unexpected module type: %T", m.linker))
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000518}
519
520func getExtraLibs(m *Module) []string {
521 switch decorator := m.linker.(type) {
522 case *testBinary:
523 if decorator.testDecorator.gtest() {
Tomasz Wasilczyk6e2b8c02024-05-30 07:48:40 -0700524 return []string{
525 "libgtest",
526 "libgtest_main",
527 }
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000528 }
Tomasz Wasilczyk6e2b8c02024-05-30 07:48:40 -0700529 case *benchmarkDecorator:
530 return []string{"libgoogle-benchmark"}
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000531 }
532 return nil
533}
534
535func getIncludeDirs(ctx android.ModuleContext, m *Module) []string {
536 moduleDir := ctx.OtherModuleDir(m) + string(filepath.Separator)
537 switch decorator := m.compiler.(type) {
538 case *libraryDecorator:
Aleks Todorovc9becde2024-06-10 12:51:53 +0100539 return sliceWithPrefix(moduleDir, decorator.flagExporter.Properties.Export_include_dirs.GetOrDefault(ctx, nil))
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000540 }
541 return nil
542}
543
Tomasz Wasilczykd848dcc2024-05-10 09:16:37 -0700544func cmakeSnapshotLoadHook(ctx android.LoadHookContext) {
545 props := struct {
546 Target struct {
547 Darwin struct {
548 Enabled *bool
549 }
550 Windows struct {
551 Enabled *bool
552 }
553 }
554 }{}
555 props.Target.Darwin.Enabled = proptools.BoolPtr(false)
556 props.Target.Windows.Enabled = proptools.BoolPtr(false)
557 ctx.AppendProperties(&props)
558}
559
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000560// cmake_snapshot allows defining source packages for release outside of Android build tree.
561// As a result of cmake_snapshot module build, a zip file is generated with CMake build definitions
562// for selected source modules, their dependencies and optionally also the source code itself.
563func CmakeSnapshotFactory() android.Module {
564 module := &CmakeSnapshot{}
565 module.AddProperties(&module.Properties)
Tomasz Wasilczykd848dcc2024-05-10 09:16:37 -0700566 android.AddLoadHook(module, cmakeSnapshotLoadHook)
567 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000568 return module
569}
570
571func init() {
572 android.InitRegistrationContext.RegisterModuleType("cc_cmake_snapshot", CmakeSnapshotFactory)
573}