blob: 2bcf9337b3c1df8afac32e5c45f4c23c712cc686 [file] [log] [blame]
Cole Faustb85d1a12022-11-08 18:14:01 -08001package bp2build
2
3import (
Cole Faustf8231dd2023-04-21 17:37:11 -07004 "encoding/json"
Cole Faustb85d1a12022-11-08 18:14:01 -08005 "fmt"
6 "os"
7 "path/filepath"
Cole Faustf055db62023-07-24 15:17:03 -07008 "reflect"
Cole Fauste136dda2023-09-27 14:10:33 -07009 "sort"
Cole Faustb85d1a12022-11-08 18:14:01 -080010 "strings"
Cole Faustf8231dd2023-04-21 17:37:11 -070011
Yu Liub6a15da2023-08-31 14:14:01 -070012 "android/soong/android"
13 "android/soong/android/soongconfig"
14 "android/soong/starlark_import"
15
Cole Faustf8231dd2023-04-21 17:37:11 -070016 "github.com/google/blueprint/proptools"
17 "go.starlark.net/starlark"
Cole Faustb85d1a12022-11-08 18:14:01 -080018)
19
Cole Faust6054cdf2023-09-12 10:07:07 -070020type createProductConfigFilesResult struct {
21 injectionFiles []BazelFile
22 bp2buildFiles []BazelFile
23 bp2buildTargets map[string]BazelTargets
24}
25
Cole Faustcb193ec2023-09-20 16:01:18 -070026type bazelLabel struct {
27 repo string
28 pkg string
29 target string
30}
31
Cole Fauste136dda2023-09-27 14:10:33 -070032func (l *bazelLabel) Less(other *bazelLabel) bool {
33 if l.repo < other.repo {
34 return true
35 }
36 if l.repo > other.repo {
37 return false
38 }
39 if l.pkg < other.pkg {
40 return true
41 }
42 if l.pkg > other.pkg {
43 return false
44 }
45 return l.target < other.target
46}
47
Cole Faustcb193ec2023-09-20 16:01:18 -070048func (l *bazelLabel) String() string {
49 return fmt.Sprintf("@%s//%s:%s", l.repo, l.pkg, l.target)
50}
51
Cole Faust6054cdf2023-09-12 10:07:07 -070052func createProductConfigFiles(
Cole Faust946d02c2023-08-03 16:08:09 -070053 ctx *CodegenContext,
Cole Faust6054cdf2023-09-12 10:07:07 -070054 metrics CodegenMetrics) (createProductConfigFilesResult, error) {
Cole Faustb85d1a12022-11-08 18:14:01 -080055 cfg := &ctx.config
56 targetProduct := "unknown"
57 if cfg.HasDeviceProduct() {
58 targetProduct = cfg.DeviceProduct()
59 }
60 targetBuildVariant := "user"
61 if cfg.Eng() {
62 targetBuildVariant = "eng"
63 } else if cfg.Debuggable() {
64 targetBuildVariant = "userdebug"
65 }
66
Cole Faust6054cdf2023-09-12 10:07:07 -070067 var res createProductConfigFilesResult
68
Cole Faustb85d1a12022-11-08 18:14:01 -080069 productVariablesFileName := cfg.ProductVariablesFileName
70 if !strings.HasPrefix(productVariablesFileName, "/") {
71 productVariablesFileName = filepath.Join(ctx.topDir, productVariablesFileName)
72 }
Cole Faustf8231dd2023-04-21 17:37:11 -070073 productVariablesBytes, err := os.ReadFile(productVariablesFileName)
Cole Faustb85d1a12022-11-08 18:14:01 -080074 if err != nil {
Cole Faust6054cdf2023-09-12 10:07:07 -070075 return res, err
Cole Faustf8231dd2023-04-21 17:37:11 -070076 }
77 productVariables := android.ProductVariables{}
78 err = json.Unmarshal(productVariablesBytes, &productVariables)
79 if err != nil {
Cole Faust6054cdf2023-09-12 10:07:07 -070080 return res, err
Cole Faustb85d1a12022-11-08 18:14:01 -080081 }
82
Cole Faustf3cf34e2023-09-20 17:02:40 -070083 currentProductFolder := fmt.Sprintf("build/bazel/products/%s", targetProduct)
Cole Faustcb193ec2023-09-20 16:01:18 -070084 if len(productVariables.PartitionVarsForBazelMigrationOnlyDoNotUse.ProductDirectory) > 0 {
85 currentProductFolder = fmt.Sprintf("%s%s", productVariables.PartitionVarsForBazelMigrationOnlyDoNotUse.ProductDirectory, targetProduct)
Cole Faustb4cb0c82023-09-14 15:16:58 -070086 }
Cole Faustb85d1a12022-11-08 18:14:01 -080087
88 productReplacer := strings.NewReplacer(
89 "{PRODUCT}", targetProduct,
90 "{VARIANT}", targetBuildVariant,
91 "{PRODUCT_FOLDER}", currentProductFolder)
92
Cole Faust946d02c2023-08-03 16:08:09 -070093 productsForTestingMap, err := starlark_import.GetStarlarkValue[map[string]map[string]starlark.Value]("products_for_testing")
94 if err != nil {
Cole Faust6054cdf2023-09-12 10:07:07 -070095 return res, err
Cole Faust946d02c2023-08-03 16:08:09 -070096 }
97 productsForTesting := android.SortedKeys(productsForTestingMap)
98 for i := range productsForTesting {
99 productsForTesting[i] = fmt.Sprintf(" \"@//build/bazel/tests/products:%s\",", productsForTesting[i])
100 }
101
Cole Faustcb193ec2023-09-20 16:01:18 -0700102 productLabelsToVariables := make(map[bazelLabel]*android.ProductVariables)
103 productLabelsToVariables[bazelLabel{
104 repo: "",
105 pkg: currentProductFolder,
106 target: targetProduct,
107 }] = &productVariables
Cole Faust6054cdf2023-09-12 10:07:07 -0700108 for product, productVariablesStarlark := range productsForTestingMap {
109 productVariables, err := starlarkMapToProductVariables(productVariablesStarlark)
110 if err != nil {
111 return res, err
112 }
Cole Faustcb193ec2023-09-20 16:01:18 -0700113 productLabelsToVariables[bazelLabel{
114 repo: "",
115 pkg: "build/bazel/tests/products",
116 target: product,
117 }] = &productVariables
Cole Faust6054cdf2023-09-12 10:07:07 -0700118 }
119
Cole Faustb4cb0c82023-09-14 15:16:58 -0700120 res.bp2buildTargets = make(map[string]BazelTargets)
121 res.bp2buildTargets[currentProductFolder] = append(res.bp2buildTargets[currentProductFolder], BazelTarget{
Cole Faustf3cf34e2023-09-20 17:02:40 -0700122 name: productReplacer.Replace("{PRODUCT}"),
Cole Faustb4cb0c82023-09-14 15:16:58 -0700123 packageName: currentProductFolder,
124 content: productReplacer.Replace(`android_product(
Cole Faustf3cf34e2023-09-20 17:02:40 -0700125 name = "{PRODUCT}",
Cole Faustb4cb0c82023-09-14 15:16:58 -0700126 soong_variables = _soong_variables,
127)`),
128 ruleClass: "android_product",
129 loads: []BazelLoad{
130 {
131 file: ":soong.variables.bzl",
132 symbols: []BazelLoadSymbol{{
133 symbol: "variables",
134 alias: "_soong_variables",
135 }},
136 },
137 {
138 file: "//build/bazel/product_config:android_product.bzl",
139 symbols: []BazelLoadSymbol{{symbol: "android_product"}},
140 },
141 },
142 })
143 createTargets(productLabelsToVariables, res.bp2buildTargets)
Cole Faust6054cdf2023-09-12 10:07:07 -0700144
145 platformMappingContent, err := platformMappingContent(
146 productLabelsToVariables,
147 ctx.Config().Bp2buildSoongConfigDefinitions,
148 metrics.convertedModulePathMap)
149 if err != nil {
150 return res, err
151 }
152
153 res.injectionFiles = []BazelFile{
Cole Faustb85d1a12022-11-08 18:14:01 -0800154 newFile(
Cole Faustb85d1a12022-11-08 18:14:01 -0800155 "product_config_platforms",
156 "BUILD.bazel",
157 productReplacer.Replace(`
158package(default_visibility = [
159 "@//build/bazel/product_config:__subpackages__",
160 "@soong_injection//product_config_platforms:__subpackages__",
161])
Jingwen Chen583ab212023-05-30 09:45:23 +0000162
Cole Faustb4cb0c82023-09-14 15:16:58 -0700163load("@//{PRODUCT_FOLDER}:soong.variables.bzl", _soong_variables = "variables")
Jingwen Chen583ab212023-05-30 09:45:23 +0000164load("@//build/bazel/product_config:android_product.bzl", "android_product")
165
Cole Faust319abae2023-06-06 15:12:49 -0700166# Bazel will qualify its outputs by the platform name. When switching between products, this
167# means that soong-built files that depend on bazel-built files will suddenly get different
168# dependency files, because the path changes, and they will be rebuilt. In order to avoid this
169# extra rebuilding, make mixed builds always use a single platform so that the bazel artifacts
170# are always under the same path.
Jingwen Chen583ab212023-05-30 09:45:23 +0000171android_product(
Cole Faustf3cf34e2023-09-20 17:02:40 -0700172 name = "mixed_builds_product",
Jingwen Chen583ab212023-05-30 09:45:23 +0000173 soong_variables = _soong_variables,
Cole Faustbc65a3f2023-08-01 16:38:55 +0000174 extra_constraints = ["@//build/bazel/platforms:mixed_builds"],
Jingwen Chen583ab212023-05-30 09:45:23 +0000175)
Cole Faust117bb742023-03-29 14:46:20 -0700176`)),
177 newFile(
178 "product_config_platforms",
179 "product_labels.bzl",
180 productReplacer.Replace(`
181# This file keeps a list of all the products in the android source tree, because they're
182# discovered as part of a preprocessing step before bazel runs.
183# TODO: When we start generating the platforms for more than just the
184# currently lunched product, they should all be listed here
185product_labels = [
Cole Faustf3cf34e2023-09-20 17:02:40 -0700186 "@soong_injection//product_config_platforms:mixed_builds_product",
187 "@//{PRODUCT_FOLDER}:{PRODUCT}",
Cole Faust946d02c2023-08-03 16:08:09 -0700188`)+strings.Join(productsForTesting, "\n")+"\n]\n"),
Cole Faustb85d1a12022-11-08 18:14:01 -0800189 newFile(
190 "product_config_platforms",
191 "common.bazelrc",
192 productReplacer.Replace(`
Cole Faustf8231dd2023-04-21 17:37:11 -0700193build --platform_mappings=platform_mappings
Cole Faustf3cf34e2023-09-20 17:02:40 -0700194build --platforms @//{PRODUCT_FOLDER}:{PRODUCT}_linux_x86_64
195build --//build/bazel/product_config:target_build_variant={VARIANT}
Cole Faustb85d1a12022-11-08 18:14:01 -0800196
Cole Faustf3cf34e2023-09-20 17:02:40 -0700197build:android --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}
198build:linux_x86 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_x86
199build:linux_x86_64 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_x86_64
200build:linux_bionic_x86_64 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_bionic_x86_64
201build:linux_musl_x86 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_musl_x86
202build:linux_musl_x86_64 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_musl_x86_64
Cole Faustb85d1a12022-11-08 18:14:01 -0800203`)),
204 newFile(
205 "product_config_platforms",
206 "linux.bazelrc",
207 productReplacer.Replace(`
Cole Faustf3cf34e2023-09-20 17:02:40 -0700208build --host_platform @//{PRODUCT_FOLDER}:{PRODUCT}_linux_x86_64
Cole Faustb85d1a12022-11-08 18:14:01 -0800209`)),
210 newFile(
211 "product_config_platforms",
212 "darwin.bazelrc",
213 productReplacer.Replace(`
Cole Faustf3cf34e2023-09-20 17:02:40 -0700214build --host_platform @//{PRODUCT_FOLDER}:{PRODUCT}_darwin_x86_64
Cole Faustb85d1a12022-11-08 18:14:01 -0800215`)),
216 }
Cole Faust6054cdf2023-09-12 10:07:07 -0700217 res.bp2buildFiles = []BazelFile{
Cole Faustf8231dd2023-04-21 17:37:11 -0700218 newFile(
219 "",
220 "platform_mappings",
221 platformMappingContent),
Cole Faustb4cb0c82023-09-14 15:16:58 -0700222 newFile(
223 currentProductFolder,
224 "soong.variables.bzl",
225 `variables = json.decode("""`+strings.ReplaceAll(string(productVariablesBytes), "\\", "\\\\")+`""")`),
Cole Faustf8231dd2023-04-21 17:37:11 -0700226 }
Cole Faust6054cdf2023-09-12 10:07:07 -0700227
228 return res, nil
Cole Faustf8231dd2023-04-21 17:37:11 -0700229}
Cole Faustb85d1a12022-11-08 18:14:01 -0800230
Cole Faust946d02c2023-08-03 16:08:09 -0700231func platformMappingContent(
Cole Faustcb193ec2023-09-20 16:01:18 -0700232 productLabelToVariables map[bazelLabel]*android.ProductVariables,
Cole Faust946d02c2023-08-03 16:08:09 -0700233 soongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions,
234 convertedModulePathMap map[string]string) (string, error) {
Cole Faustf055db62023-07-24 15:17:03 -0700235 var result strings.Builder
Cole Faust946d02c2023-08-03 16:08:09 -0700236
237 mergedConvertedModulePathMap := make(map[string]string)
238 for k, v := range convertedModulePathMap {
239 mergedConvertedModulePathMap[k] = v
240 }
241 additionalModuleNamesToPackages, err := starlark_import.GetStarlarkValue[map[string]string]("additional_module_names_to_packages")
242 if err != nil {
243 return "", err
244 }
245 for k, v := range additionalModuleNamesToPackages {
246 mergedConvertedModulePathMap[k] = v
247 }
248
Cole Fauste136dda2023-09-27 14:10:33 -0700249 productLabels := make([]bazelLabel, 0, len(productLabelToVariables))
250 for k := range productLabelToVariables {
251 productLabels = append(productLabels, k)
252 }
253 sort.Slice(productLabels, func(i, j int) bool {
254 return productLabels[i].Less(&productLabels[j])
255 })
Cole Faustf055db62023-07-24 15:17:03 -0700256 result.WriteString("platforms:\n")
Cole Fauste136dda2023-09-27 14:10:33 -0700257 for _, productLabel := range productLabels {
258 platformMappingSingleProduct(productLabel, productLabelToVariables[productLabel], soongConfigDefinitions, mergedConvertedModulePathMap, &result)
Cole Faustf8231dd2023-04-21 17:37:11 -0700259 }
Cole Faustf055db62023-07-24 15:17:03 -0700260 return result.String(), nil
Cole Faustf8231dd2023-04-21 17:37:11 -0700261}
262
Cole Faust88c8efb2023-07-18 11:05:16 -0700263var bazelPlatformSuffixes = []string{
264 "",
265 "_darwin_arm64",
266 "_darwin_x86_64",
267 "_linux_bionic_arm64",
268 "_linux_bionic_x86_64",
269 "_linux_musl_x86",
270 "_linux_musl_x86_64",
271 "_linux_x86",
272 "_linux_x86_64",
273 "_windows_x86",
274 "_windows_x86_64",
275}
276
Cole Faust946d02c2023-08-03 16:08:09 -0700277func platformMappingSingleProduct(
Cole Faustcb193ec2023-09-20 16:01:18 -0700278 label bazelLabel,
Cole Faust946d02c2023-08-03 16:08:09 -0700279 productVariables *android.ProductVariables,
280 soongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions,
281 convertedModulePathMap map[string]string,
282 result *strings.Builder) {
Cole Faustf055db62023-07-24 15:17:03 -0700283
Cole Faust95c5cf82023-08-03 13:49:27 -0700284 platform_sdk_version := -1
285 if productVariables.Platform_sdk_version != nil {
286 platform_sdk_version = *productVariables.Platform_sdk_version
287 }
288
Cole Faust946d02c2023-08-03 16:08:09 -0700289 defaultAppCertificateFilegroup := "//build/bazel/utils:empty_filegroup"
290 if proptools.String(productVariables.DefaultAppCertificate) != "" {
Cole Faust6054cdf2023-09-12 10:07:07 -0700291 defaultAppCertificateFilegroup = "@//" + filepath.Dir(proptools.String(productVariables.DefaultAppCertificate)) + ":generated_android_certificate_directory"
Cole Faust946d02c2023-08-03 16:08:09 -0700292 }
293
Cole Faustf055db62023-07-24 15:17:03 -0700294 for _, suffix := range bazelPlatformSuffixes {
295 result.WriteString(" ")
Cole Faustcb193ec2023-09-20 16:01:18 -0700296 result.WriteString(label.String())
Cole Faustf055db62023-07-24 15:17:03 -0700297 result.WriteString(suffix)
298 result.WriteString("\n")
299 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:always_use_prebuilt_sdks=%t\n", proptools.Bool(productVariables.Always_use_prebuilt_sdks)))
Cole Faust87c0c332023-07-31 12:10:12 -0700300 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:arc=%t\n", proptools.Bool(productVariables.Arc)))
Cole Faustf055db62023-07-24 15:17:03 -0700301 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride)))
Cole Faust87c0c332023-07-31 12:10:12 -0700302 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:binder32bit=%t\n", proptools.Bool(productVariables.Binder32bit)))
303 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_from_text_stub=%t\n", proptools.Bool(productVariables.Build_from_text_stub)))
Cole Faustded79602023-09-05 17:48:11 -0700304 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_broken_incorrect_partition_images=%t\n", productVariables.BuildBrokenIncorrectPartitionImages))
Cole Faustf055db62023-07-24 15:17:03 -0700305 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_id=%s\n", proptools.String(productVariables.BuildId)))
306 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_version_tags=%s\n", strings.Join(productVariables.BuildVersionTags, ",")))
Cole Faustf055db62023-07-24 15:17:03 -0700307 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ",")))
308 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ",")))
309 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:compressed_apex=%t\n", proptools.Bool(productVariables.CompressedApex)))
310 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate=%s\n", proptools.String(productVariables.DefaultAppCertificate)))
Cole Faust946d02c2023-08-03 16:08:09 -0700311 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate_filegroup=%s\n", defaultAppCertificateFilegroup))
Cole Faustf055db62023-07-24 15:17:03 -0700312 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_abi=%s\n", strings.Join(productVariables.DeviceAbi, ",")))
313 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_max_page_size_supported=%s\n", proptools.String(productVariables.DeviceMaxPageSizeSupported)))
314 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_name=%s\n", proptools.String(productVariables.DeviceName)))
Juan Yescas01065602023-08-09 08:34:37 -0700315 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_page_size_agnostic=%t\n", proptools.Bool(productVariables.DevicePageSizeAgnostic)))
Cole Faustf055db62023-07-24 15:17:03 -0700316 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_product=%s\n", proptools.String(productVariables.DeviceProduct)))
Cole Faustcb193ec2023-09-20 16:01:18 -0700317 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_platform=%s\n", label.String()))
Cole Faustf055db62023-07-24 15:17:03 -0700318 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true)))
Cole Faust87c0c332023-07-31 12:10:12 -0700319 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enforce_vintf_manifest=%t\n", proptools.Bool(productVariables.Enforce_vintf_manifest)))
Cole Faust87c0c332023-07-31 12:10:12 -0700320 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_not_svelte=%t\n", proptools.Bool(productVariables.Malloc_not_svelte)))
321 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_pattern_fill_contents=%t\n", proptools.Bool(productVariables.Malloc_pattern_fill_contents)))
322 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_zero_contents=%t\n", proptools.Bool(productVariables.Malloc_zero_contents)))
Yu Liub6a15da2023-08-31 14:14:01 -0700323 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_exclude_paths=%s\n", strings.Join(productVariables.MemtagHeapExcludePaths, ",")))
324 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_async_include_paths=%s\n", strings.Join(productVariables.MemtagHeapAsyncIncludePaths, ",")))
325 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_sync_include_paths=%s\n", strings.Join(productVariables.MemtagHeapSyncIncludePaths, ",")))
Cole Faustf055db62023-07-24 15:17:03 -0700326 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:manifest_package_name_overrides=%s\n", strings.Join(productVariables.ManifestPackageNameOverrides, ",")))
Cole Faust87c0c332023-07-31 12:10:12 -0700327 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:native_coverage=%t\n", proptools.Bool(productVariables.Native_coverage)))
Romain Jobredeaux3132f842023-09-15 10:06:16 -0400328 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_final=%t\n", proptools.Bool(productVariables.Platform_sdk_final)))
Cole Faustb5055392023-09-27 13:44:40 -0700329 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_security_patch=%s\n", proptools.String(productVariables.Platform_security_patch)))
330 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_last_stable=%s\n", proptools.String(productVariables.Platform_version_last_stable)))
Cole Faustf055db62023-07-24 15:17:03 -0700331 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_name=%s\n", proptools.String(productVariables.Platform_version_name)))
332 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_brand=%s\n", productVariables.ProductBrand))
333 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_manufacturer=%s\n", productVariables.ProductManufacturer))
Yu Liu2cc802a2023-09-05 17:19:45 -0700334 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_flag_default_permission=%s\n", productVariables.ReleaseAconfigFlagDefaultPermission))
335 // Empty string can't be used as label_flag on the bazel side
336 if len(productVariables.ReleaseAconfigValueSets) > 0 {
337 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_value_sets=%s\n", productVariables.ReleaseAconfigValueSets))
338 }
339 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_version=%s\n", productVariables.ReleaseVersion))
Cole Faust95c5cf82023-08-03 13:49:27 -0700340 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_version=%d\n", platform_sdk_version))
Cole Faust87c0c332023-07-31 12:10:12 -0700341 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:safestack=%t\n", proptools.Bool(productVariables.Safestack)))
Cole Faust87c0c332023-07-31 12:10:12 -0700342 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:treble_linker_namespaces=%t\n", proptools.Bool(productVariables.Treble_linker_namespaces)))
Cole Faustf055db62023-07-24 15:17:03 -0700343 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:tidy_checks=%s\n", proptools.String(productVariables.TidyChecks)))
Cole Faust87c0c332023-07-31 12:10:12 -0700344 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:uml=%t\n", proptools.Bool(productVariables.Uml)))
Cole Faustf055db62023-07-24 15:17:03 -0700345 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build=%t\n", proptools.Bool(productVariables.Unbundled_build)))
346 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build_apps=%s\n", strings.Join(productVariables.Unbundled_build_apps, ",")))
Cole Faust946d02c2023-08-03 16:08:09 -0700347
348 for _, override := range productVariables.CertificateOverrides {
349 parts := strings.SplitN(override, ":", 2)
350 if apexPath, ok := convertedModulePathMap[parts[0]]; ok {
351 if overrideCertPath, ok := convertedModulePathMap[parts[1]]; ok {
352 result.WriteString(fmt.Sprintf(" --%s:%s_certificate_override=%s:%s\n", apexPath, parts[0], overrideCertPath, parts[1]))
353 }
354 }
355 }
356
Cole Fauste136dda2023-09-27 14:10:33 -0700357 for _, namespace := range android.SortedKeys(productVariables.VendorVars) {
358 for _, variable := range android.SortedKeys(productVariables.VendorVars[namespace]) {
359 value := productVariables.VendorVars[namespace][variable]
Cole Faust87c0c332023-07-31 12:10:12 -0700360 key := namespace + "__" + variable
361 _, hasBool := soongConfigDefinitions.BoolVars[key]
362 _, hasString := soongConfigDefinitions.StringVars[key]
363 _, hasValue := soongConfigDefinitions.ValueVars[key]
364 if !hasBool && !hasString && !hasValue {
365 // Not all soong config variables are defined in Android.bp files. For example,
366 // prebuilt_bootclasspath_fragment uses soong config variables in a nonstandard
367 // way, that causes them to be present in the soong.variables file but not
368 // defined in an Android.bp file. There's also nothing stopping you from setting
369 // a variable in make that doesn't exist in soong. We only generate build
370 // settings for the ones that exist in soong, so skip all others.
371 continue
372 }
373 if hasBool && hasString || hasBool && hasValue || hasString && hasValue {
374 panic(fmt.Sprintf("Soong config variable %s:%s appears to be of multiple types. bool? %t, string? %t, value? %t", namespace, variable, hasBool, hasString, hasValue))
375 }
376 if hasBool {
377 // Logic copied from soongConfig.Bool()
378 value = strings.ToLower(value)
379 if value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" {
380 value = "true"
381 } else {
382 value = "false"
383 }
384 }
385 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config/soong_config_variables:%s=%s\n", strings.ToLower(key), value))
386 }
387 }
Cole Faustf055db62023-07-24 15:17:03 -0700388 }
Cole Faustf8231dd2023-04-21 17:37:11 -0700389}
390
391func starlarkMapToProductVariables(in map[string]starlark.Value) (android.ProductVariables, error) {
Cole Faustf8231dd2023-04-21 17:37:11 -0700392 result := android.ProductVariables{}
Cole Faustf055db62023-07-24 15:17:03 -0700393 productVarsReflect := reflect.ValueOf(&result).Elem()
394 for i := 0; i < productVarsReflect.NumField(); i++ {
395 field := productVarsReflect.Field(i)
396 fieldType := productVarsReflect.Type().Field(i)
397 name := fieldType.Name
Cole Faust87c0c332023-07-31 12:10:12 -0700398 if name == "BootJars" || name == "ApexBootJars" || name == "VendorSnapshotModules" ||
399 name == "RecoverySnapshotModules" {
Cole Faustf055db62023-07-24 15:17:03 -0700400 // These variables have more complicated types, and we don't need them right now
401 continue
402 }
403 if _, ok := in[name]; ok {
Cole Faust87c0c332023-07-31 12:10:12 -0700404 if name == "VendorVars" {
405 vendorVars, err := starlark_import.Unmarshal[map[string]map[string]string](in[name])
406 if err != nil {
407 return result, err
408 }
409 field.Set(reflect.ValueOf(vendorVars))
410 continue
411 }
Cole Faustf055db62023-07-24 15:17:03 -0700412 switch field.Type().Kind() {
413 case reflect.Bool:
414 val, err := starlark_import.Unmarshal[bool](in[name])
415 if err != nil {
416 return result, err
417 }
418 field.SetBool(val)
419 case reflect.String:
420 val, err := starlark_import.Unmarshal[string](in[name])
421 if err != nil {
422 return result, err
423 }
424 field.SetString(val)
425 case reflect.Slice:
426 if field.Type().Elem().Kind() != reflect.String {
427 return result, fmt.Errorf("slices of types other than strings are unimplemented")
428 }
429 val, err := starlark_import.UnmarshalReflect(in[name], field.Type())
430 if err != nil {
431 return result, err
432 }
433 field.Set(val)
434 case reflect.Pointer:
435 switch field.Type().Elem().Kind() {
436 case reflect.Bool:
437 val, err := starlark_import.UnmarshalNoneable[bool](in[name])
438 if err != nil {
439 return result, err
440 }
441 field.Set(reflect.ValueOf(val))
442 case reflect.String:
443 val, err := starlark_import.UnmarshalNoneable[string](in[name])
444 if err != nil {
445 return result, err
446 }
447 field.Set(reflect.ValueOf(val))
448 case reflect.Int:
449 val, err := starlark_import.UnmarshalNoneable[int](in[name])
450 if err != nil {
451 return result, err
452 }
453 field.Set(reflect.ValueOf(val))
454 default:
455 return result, fmt.Errorf("pointers of types other than strings/bools are unimplemented: %s", field.Type().Elem().Kind().String())
456 }
457 default:
458 return result, fmt.Errorf("unimplemented type: %s", field.Type().String())
459 }
460 }
Cole Faust88c8efb2023-07-18 11:05:16 -0700461 }
Cole Faustf055db62023-07-24 15:17:03 -0700462
Cole Faust87c0c332023-07-31 12:10:12 -0700463 result.Native_coverage = proptools.BoolPtr(
464 proptools.Bool(result.GcovCoverage) ||
465 proptools.Bool(result.ClangCoverage))
466
Cole Faustb85d1a12022-11-08 18:14:01 -0800467 return result, nil
468}
Cole Faust6054cdf2023-09-12 10:07:07 -0700469
Cole Faustcb193ec2023-09-20 16:01:18 -0700470func createTargets(productLabelsToVariables map[bazelLabel]*android.ProductVariables, res map[string]BazelTargets) {
Cole Faustb4cb0c82023-09-14 15:16:58 -0700471 createGeneratedAndroidCertificateDirectories(productLabelsToVariables, res)
Cole Faustb5055392023-09-27 13:44:40 -0700472 createAvbKeyFilegroups(productLabelsToVariables, res)
Cole Faustcb193ec2023-09-20 16:01:18 -0700473 for label, variables := range productLabelsToVariables {
474 createSystemPartition(label, &variables.PartitionVarsForBazelMigrationOnlyDoNotUse, res)
475 }
Cole Faustb4cb0c82023-09-14 15:16:58 -0700476}
477
Cole Faustcb193ec2023-09-20 16:01:18 -0700478func createGeneratedAndroidCertificateDirectories(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) {
Cole Faust6054cdf2023-09-12 10:07:07 -0700479 var allDefaultAppCertificateDirs []string
480 for _, productVariables := range productLabelsToVariables {
481 if proptools.String(productVariables.DefaultAppCertificate) != "" {
482 d := filepath.Dir(proptools.String(productVariables.DefaultAppCertificate))
483 if !android.InList(d, allDefaultAppCertificateDirs) {
484 allDefaultAppCertificateDirs = append(allDefaultAppCertificateDirs, d)
485 }
486 }
487 }
488 for _, dir := range allDefaultAppCertificateDirs {
Cole Faustb4cb0c82023-09-14 15:16:58 -0700489 content := `filegroup(
490 name = "generated_android_certificate_directory",
491 srcs = glob([
Cole Faust6054cdf2023-09-12 10:07:07 -0700492 "*.pk8",
493 "*.pem",
494 "*.avbpubkey",
Cole Faustb4cb0c82023-09-14 15:16:58 -0700495 ]),
496 visibility = ["//visibility:public"],
497)`
498 targets[dir] = append(targets[dir], BazelTarget{
Cole Faust6054cdf2023-09-12 10:07:07 -0700499 name: "generated_android_certificate_directory",
500 packageName: dir,
501 content: content,
502 ruleClass: "filegroup",
503 })
504 }
Cole Faust6054cdf2023-09-12 10:07:07 -0700505}
Cole Faustcb193ec2023-09-20 16:01:18 -0700506
Cole Faustb5055392023-09-27 13:44:40 -0700507func createAvbKeyFilegroups(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) {
508 var allAvbKeys []string
509 for _, productVariables := range productLabelsToVariables {
510 for _, partitionVariables := range productVariables.PartitionVarsForBazelMigrationOnlyDoNotUse.PartitionQualifiedVariables {
511 if partitionVariables.BoardAvbKeyPath != "" {
512 if !android.InList(partitionVariables.BoardAvbKeyPath, allAvbKeys) {
513 allAvbKeys = append(allAvbKeys, partitionVariables.BoardAvbKeyPath)
514 }
515 }
516 }
517 }
518 for _, key := range allAvbKeys {
519 dir := filepath.Dir(key)
520 name := filepath.Base(key)
521 content := fmt.Sprintf(`filegroup(
522 name = "%s_filegroup",
523 srcs = ["%s"],
524 visibility = ["//visibility:public"],
525)`, name, name)
526 targets[dir] = append(targets[dir], BazelTarget{
527 name: name + "_filegroup",
528 packageName: dir,
529 content: content,
530 ruleClass: "filegroup",
531 })
532 }
533}
534
Cole Faustcb193ec2023-09-20 16:01:18 -0700535func createSystemPartition(platformLabel bazelLabel, variables *android.PartitionVariables, targets map[string]BazelTargets) {
536 if !variables.PartitionQualifiedVariables["system"].BuildingImage {
537 return
538 }
Cole Faustb5055392023-09-27 13:44:40 -0700539 qualifiedVariables := variables.PartitionQualifiedVariables["system"]
Cole Faustcb193ec2023-09-20 16:01:18 -0700540
541 imageProps := generateImagePropDictionary(variables, "system")
542 imageProps["skip_fsck"] = "true"
543
544 var properties strings.Builder
545 for _, prop := range android.SortedKeys(imageProps) {
546 properties.WriteString(prop)
547 properties.WriteRune('=')
548 properties.WriteString(imageProps[prop])
549 properties.WriteRune('\n')
550 }
551
Cole Faustb5055392023-09-27 13:44:40 -0700552 var extraProperties strings.Builder
553 if variables.BoardAvbEnable {
554 extraProperties.WriteString(" avb_enable = True,\n")
555 extraProperties.WriteString(fmt.Sprintf(" avb_add_hashtree_footer_args = %q,\n", qualifiedVariables.BoardAvbAddHashtreeFooterArgs))
556 keypath := qualifiedVariables.BoardAvbKeyPath
557 if keypath != "" {
558 extraProperties.WriteString(fmt.Sprintf(" avb_key = \"//%s:%s\",\n", filepath.Dir(keypath), filepath.Base(keypath)+"_filegroup"))
559 extraProperties.WriteString(fmt.Sprintf(" avb_algorithm = %q,\n", qualifiedVariables.BoardAvbAlgorithm))
560 extraProperties.WriteString(fmt.Sprintf(" avb_rollback_index = %s,\n", qualifiedVariables.BoardAvbRollbackIndex))
561 extraProperties.WriteString(fmt.Sprintf(" avb_rollback_index_location = %s,\n", qualifiedVariables.BoardAvbRollbackIndexLocation))
562 }
563 }
564
Cole Faustcb193ec2023-09-20 16:01:18 -0700565 targets[platformLabel.pkg] = append(targets[platformLabel.pkg], BazelTarget{
566 name: "system_image",
567 packageName: platformLabel.pkg,
568 content: fmt.Sprintf(`partition(
569 name = "system_image",
570 base_staging_dir = "//build/bazel/bazel_sandwich:system_staging_dir",
571 base_staging_dir_file_list = "//build/bazel/bazel_sandwich:system_staging_dir_file_list",
572 root_dir = "//build/bazel/bazel_sandwich:root_staging_dir",
Cole Faustb5055392023-09-27 13:44:40 -0700573 selinux_file_contexts = "//build/bazel/bazel_sandwich:selinux_file_contexts",
Cole Faustcb193ec2023-09-20 16:01:18 -0700574 image_properties = """
575%s
576""",
Cole Faustb5055392023-09-27 13:44:40 -0700577%s
Cole Faustcb193ec2023-09-20 16:01:18 -0700578 type = "system",
Cole Faustb5055392023-09-27 13:44:40 -0700579)`, properties.String(), extraProperties.String()),
Cole Faustcb193ec2023-09-20 16:01:18 -0700580 ruleClass: "partition",
581 loads: []BazelLoad{{
582 file: "//build/bazel/rules/partitions:partition.bzl",
583 symbols: []BazelLoadSymbol{{
584 symbol: "partition",
585 }},
586 }},
587 }, BazelTarget{
588 name: "system_image_test",
589 packageName: platformLabel.pkg,
590 content: `partition_diff_test(
591 name = "system_image_test",
592 partition1 = "//build/bazel/bazel_sandwich:make_system_image",
593 partition2 = ":system_image",
594)`,
595 ruleClass: "partition_diff_test",
596 loads: []BazelLoad{{
597 file: "//build/bazel/rules/partitions/diff:partition_diff.bzl",
598 symbols: []BazelLoadSymbol{{
599 symbol: "partition_diff_test",
600 }},
601 }},
602 }, BazelTarget{
603 name: "run_system_image_test",
604 packageName: platformLabel.pkg,
605 content: `run_test_in_build(
606 name = "run_system_image_test",
607 test = ":system_image_test",
608)`,
609 ruleClass: "run_test_in_build",
610 loads: []BazelLoad{{
611 file: "//build/bazel/bazel_sandwich:run_test_in_build.bzl",
612 symbols: []BazelLoadSymbol{{
613 symbol: "run_test_in_build",
614 }},
615 }},
616 })
617}
618
619var allPartitionTypes = []string{
620 "system",
621 "vendor",
622 "cache",
623 "userdata",
624 "product",
625 "system_ext",
626 "oem",
627 "odm",
628 "vendor_dlkm",
629 "odm_dlkm",
630 "system_dlkm",
631}
632
633// An equivalent of make's generate-image-prop-dictionary function
634func generateImagePropDictionary(variables *android.PartitionVariables, partitionType string) map[string]string {
635 partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]
636 if !ok {
637 panic("Unknown partitionType: " + partitionType)
638 }
639 ret := map[string]string{}
640 if partitionType == "system" {
641 if len(variables.PartitionQualifiedVariables["system_other"].BoardPartitionSize) > 0 {
642 ret["system_other_size"] = variables.PartitionQualifiedVariables["system_other"].BoardPartitionSize
643 }
644 if len(partitionQualifiedVariables.ProductHeadroom) > 0 {
645 ret["system_headroom"] = partitionQualifiedVariables.ProductHeadroom
646 }
647 addCommonRoFlagsToImageProps(variables, partitionType, ret)
648 }
649 // TODO: other partition-specific logic
650 if variables.TargetUserimagesUseExt2 {
651 ret["fs_type"] = "ext2"
652 } else if variables.TargetUserimagesUseExt3 {
653 ret["fs_type"] = "ext3"
654 } else if variables.TargetUserimagesUseExt4 {
655 ret["fs_type"] = "ext4"
656 }
657
658 if !variables.TargetUserimagesSparseExtDisabled {
659 ret["extfs_sparse_flag"] = "-s"
660 }
661 if !variables.TargetUserimagesSparseErofsDisabled {
662 ret["erofs_sparse_flag"] = "-s"
663 }
664 if !variables.TargetUserimagesSparseSquashfsDisabled {
665 ret["squashfs_sparse_flag"] = "-s"
666 }
667 if !variables.TargetUserimagesSparseF2fsDisabled {
668 ret["f2fs_sparse_flag"] = "-S"
669 }
670 erofsCompressor := variables.BoardErofsCompressor
671 if len(erofsCompressor) == 0 && hasErofsPartition(variables) {
672 if len(variables.BoardErofsUseLegacyCompression) > 0 {
673 erofsCompressor = "lz4"
674 } else {
675 erofsCompressor = "lz4hc,9"
676 }
677 }
678 if len(erofsCompressor) > 0 {
679 ret["erofs_default_compressor"] = erofsCompressor
680 }
681 if len(variables.BoardErofsCompressorHints) > 0 {
682 ret["erofs_default_compress_hints"] = variables.BoardErofsCompressorHints
683 }
684 if len(variables.BoardErofsCompressorHints) > 0 {
685 ret["erofs_default_compress_hints"] = variables.BoardErofsCompressorHints
686 }
687 if len(variables.BoardErofsPclusterSize) > 0 {
688 ret["erofs_pcluster_size"] = variables.BoardErofsPclusterSize
689 }
690 if len(variables.BoardErofsShareDupBlocks) > 0 {
691 ret["erofs_share_dup_blocks"] = variables.BoardErofsShareDupBlocks
692 }
693 if len(variables.BoardErofsUseLegacyCompression) > 0 {
694 ret["erofs_use_legacy_compression"] = variables.BoardErofsUseLegacyCompression
695 }
696 if len(variables.BoardExt4ShareDupBlocks) > 0 {
697 ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks
698 }
699 if len(variables.BoardFlashLogicalBlockSize) > 0 {
700 ret["flash_logical_block_size"] = variables.BoardFlashLogicalBlockSize
701 }
702 if len(variables.BoardFlashEraseBlockSize) > 0 {
703 ret["flash_erase_block_size"] = variables.BoardFlashEraseBlockSize
704 }
705 if len(variables.BoardExt4ShareDupBlocks) > 0 {
706 ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks
707 }
708 if len(variables.BoardExt4ShareDupBlocks) > 0 {
709 ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks
710 }
711 for _, partitionType := range allPartitionTypes {
712 if qualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]; ok && len(qualifiedVariables.ProductVerityPartition) > 0 {
713 ret[partitionType+"_verity_block_device"] = qualifiedVariables.ProductVerityPartition
714 }
715 }
716 // TODO: Vboot
717 // TODO: AVB
718 if variables.BoardUsesRecoveryAsBoot {
719 ret["recovery_as_boot"] = "true"
720 }
721 if variables.BoardBuildGkiBootImageWithoutRamdisk {
722 ret["gki_boot_image_without_ramdisk"] = "true"
723 }
724 if variables.ProductUseDynamicPartitionSize {
725 ret["use_dynamic_partition_size"] = "true"
726 }
727 if variables.CopyImagesForTargetFilesZip {
728 ret["use_fixed_timestamp"] = "true"
729 }
730 return ret
731}
732
733// Soong equivalent of make's add-common-ro-flags-to-image-props
734func addCommonRoFlagsToImageProps(variables *android.PartitionVariables, partitionType string, ret map[string]string) {
735 partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]
736 if !ok {
737 panic("Unknown partitionType: " + partitionType)
738 }
739 if len(partitionQualifiedVariables.BoardErofsCompressor) > 0 {
740 ret[partitionType+"_erofs_compressor"] = partitionQualifiedVariables.BoardErofsCompressor
741 }
742 if len(partitionQualifiedVariables.BoardErofsCompressHints) > 0 {
743 ret[partitionType+"_erofs_compress_hints"] = partitionQualifiedVariables.BoardErofsCompressHints
744 }
745 if len(partitionQualifiedVariables.BoardErofsPclusterSize) > 0 {
746 ret[partitionType+"_erofs_pcluster_size"] = partitionQualifiedVariables.BoardErofsPclusterSize
747 }
748 if len(partitionQualifiedVariables.BoardExtfsRsvPct) > 0 {
749 ret[partitionType+"_extfs_rsv_pct"] = partitionQualifiedVariables.BoardExtfsRsvPct
750 }
751 if len(partitionQualifiedVariables.BoardF2fsSloadCompressFlags) > 0 {
752 ret[partitionType+"_f2fs_sldc_flags"] = partitionQualifiedVariables.BoardF2fsSloadCompressFlags
753 }
754 if len(partitionQualifiedVariables.BoardFileSystemCompress) > 0 {
755 ret[partitionType+"_f2fs_compress"] = partitionQualifiedVariables.BoardFileSystemCompress
756 }
757 if len(partitionQualifiedVariables.BoardFileSystemType) > 0 {
758 ret[partitionType+"_fs_type"] = partitionQualifiedVariables.BoardFileSystemType
759 }
760 if len(partitionQualifiedVariables.BoardJournalSize) > 0 {
761 ret[partitionType+"_journal_size"] = partitionQualifiedVariables.BoardJournalSize
762 }
763 if len(partitionQualifiedVariables.BoardPartitionReservedSize) > 0 {
764 ret[partitionType+"_reserved_size"] = partitionQualifiedVariables.BoardPartitionReservedSize
765 }
766 if len(partitionQualifiedVariables.BoardPartitionSize) > 0 {
767 ret[partitionType+"_size"] = partitionQualifiedVariables.BoardPartitionSize
768 }
769 if len(partitionQualifiedVariables.BoardSquashfsBlockSize) > 0 {
770 ret[partitionType+"_squashfs_block_size"] = partitionQualifiedVariables.BoardSquashfsBlockSize
771 }
772 if len(partitionQualifiedVariables.BoardSquashfsCompressor) > 0 {
773 ret[partitionType+"_squashfs_compressor"] = partitionQualifiedVariables.BoardSquashfsCompressor
774 }
775 if len(partitionQualifiedVariables.BoardSquashfsCompressorOpt) > 0 {
776 ret[partitionType+"_squashfs_compressor_opt"] = partitionQualifiedVariables.BoardSquashfsCompressorOpt
777 }
778 if len(partitionQualifiedVariables.BoardSquashfsDisable4kAlign) > 0 {
779 ret[partitionType+"_squashfs_disable_4k_align"] = partitionQualifiedVariables.BoardSquashfsDisable4kAlign
780 }
781 if len(partitionQualifiedVariables.BoardPartitionSize) == 0 && len(partitionQualifiedVariables.BoardPartitionReservedSize) == 0 && len(partitionQualifiedVariables.ProductHeadroom) == 0 {
782 ret[partitionType+"_disable_sparse"] = "true"
783 }
784 addCommonFlagsToImageProps(variables, partitionType, ret)
785}
786
787func hasErofsPartition(variables *android.PartitionVariables) bool {
788 return variables.PartitionQualifiedVariables["product"].BoardFileSystemType == "erofs" ||
789 variables.PartitionQualifiedVariables["system_ext"].BoardFileSystemType == "erofs" ||
790 variables.PartitionQualifiedVariables["odm"].BoardFileSystemType == "erofs" ||
791 variables.PartitionQualifiedVariables["vendor"].BoardFileSystemType == "erofs" ||
792 variables.PartitionQualifiedVariables["system"].BoardFileSystemType == "erofs" ||
793 variables.PartitionQualifiedVariables["vendor_dlkm"].BoardFileSystemType == "erofs" ||
794 variables.PartitionQualifiedVariables["odm_dlkm"].BoardFileSystemType == "erofs" ||
795 variables.PartitionQualifiedVariables["system_dlkm"].BoardFileSystemType == "erofs"
796}
797
798// Soong equivalent of make's add-common-flags-to-image-props
799func addCommonFlagsToImageProps(variables *android.PartitionVariables, partitionType string, ret map[string]string) {
800 // The selinux_fc will be handled separately
801 partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]
802 if !ok {
803 panic("Unknown partitionType: " + partitionType)
804 }
805 ret["building_"+partitionType+"_image"] = boolToMakeString(partitionQualifiedVariables.BuildingImage)
806}
807
808func boolToMakeString(b bool) string {
809 if b {
810 return "true"
811 }
812 return ""
813}