blob: 3e004534e2ccb5a169ed92a0416bd132cc240ccd [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
Romain Jobredeaux9c06ef32023-08-21 18:05:29 -0400294 // TODO: b/301598690 - commas can't be escaped in a string-list passed in a platform mapping,
295 // so commas are switched for ":" here, and must be back-substituted into commas
296 // wherever the AAPTCharacteristics product config variable is used.
297 AAPTConfig := []string{}
298 for _, conf := range productVariables.AAPTConfig {
299 AAPTConfig = append(AAPTConfig, strings.Replace(conf, ",", ":", -1))
300 }
301
Cole Faustf055db62023-07-24 15:17:03 -0700302 for _, suffix := range bazelPlatformSuffixes {
303 result.WriteString(" ")
Cole Faustcb193ec2023-09-20 16:01:18 -0700304 result.WriteString(label.String())
Cole Faustf055db62023-07-24 15:17:03 -0700305 result.WriteString(suffix)
306 result.WriteString("\n")
Romain Jobredeaux9c06ef32023-08-21 18:05:29 -0400307 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:aapt_characteristics=%s\n", proptools.String(productVariables.AAPTCharacteristics)))
308 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:aapt_config=%s\n", strings.Join(AAPTConfig, ",")))
309 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:aapt_preferred_config=%s\n", proptools.String(productVariables.AAPTPreferredConfig)))
Cole Faustf055db62023-07-24 15:17:03 -0700310 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 -0700311 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:arc=%t\n", proptools.Bool(productVariables.Arc)))
Cole Faustf055db62023-07-24 15:17:03 -0700312 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 -0700313 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:binder32bit=%t\n", proptools.Bool(productVariables.Binder32bit)))
314 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 -0700315 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_broken_incorrect_partition_images=%t\n", productVariables.BuildBrokenIncorrectPartitionImages))
Cole Faustf055db62023-07-24 15:17:03 -0700316 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_id=%s\n", proptools.String(productVariables.BuildId)))
317 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_version_tags=%s\n", strings.Join(productVariables.BuildVersionTags, ",")))
Cole Faustf055db62023-07-24 15:17:03 -0700318 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ",")))
319 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ",")))
320 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:compressed_apex=%t\n", proptools.Bool(productVariables.CompressedApex)))
321 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate=%s\n", proptools.String(productVariables.DefaultAppCertificate)))
Cole Faust946d02c2023-08-03 16:08:09 -0700322 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate_filegroup=%s\n", defaultAppCertificateFilegroup))
Cole Faustf055db62023-07-24 15:17:03 -0700323 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_abi=%s\n", strings.Join(productVariables.DeviceAbi, ",")))
324 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_max_page_size_supported=%s\n", proptools.String(productVariables.DeviceMaxPageSizeSupported)))
325 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_name=%s\n", proptools.String(productVariables.DeviceName)))
Juan Yescas01065602023-08-09 08:34:37 -0700326 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 -0700327 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_product=%s\n", proptools.String(productVariables.DeviceProduct)))
Cole Faustcb193ec2023-09-20 16:01:18 -0700328 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_platform=%s\n", label.String()))
Cole Faustf055db62023-07-24 15:17:03 -0700329 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true)))
Cole Faust87c0c332023-07-31 12:10:12 -0700330 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 -0700331 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_not_svelte=%t\n", proptools.Bool(productVariables.Malloc_not_svelte)))
332 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_pattern_fill_contents=%t\n", proptools.Bool(productVariables.Malloc_pattern_fill_contents)))
333 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 -0700334 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_exclude_paths=%s\n", strings.Join(productVariables.MemtagHeapExcludePaths, ",")))
335 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_async_include_paths=%s\n", strings.Join(productVariables.MemtagHeapAsyncIncludePaths, ",")))
336 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 -0700337 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 -0700338 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:native_coverage=%t\n", proptools.Bool(productVariables.Native_coverage)))
Romain Jobredeaux3132f842023-09-15 10:06:16 -0400339 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 -0700340 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_security_patch=%s\n", proptools.String(productVariables.Platform_security_patch)))
341 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 -0700342 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_name=%s\n", proptools.String(productVariables.Platform_version_name)))
343 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_brand=%s\n", productVariables.ProductBrand))
344 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_manufacturer=%s\n", productVariables.ProductManufacturer))
Yu Liu2cc802a2023-09-05 17:19:45 -0700345 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_flag_default_permission=%s\n", productVariables.ReleaseAconfigFlagDefaultPermission))
346 // Empty string can't be used as label_flag on the bazel side
347 if len(productVariables.ReleaseAconfigValueSets) > 0 {
348 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_value_sets=%s\n", productVariables.ReleaseAconfigValueSets))
349 }
350 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_version=%s\n", productVariables.ReleaseVersion))
Cole Faust95c5cf82023-08-03 13:49:27 -0700351 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_version=%d\n", platform_sdk_version))
Cole Faust87c0c332023-07-31 12:10:12 -0700352 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:safestack=%t\n", proptools.Bool(productVariables.Safestack)))
Cole Faust87c0c332023-07-31 12:10:12 -0700353 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 -0700354 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:tidy_checks=%s\n", proptools.String(productVariables.TidyChecks)))
Cole Faust87c0c332023-07-31 12:10:12 -0700355 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:uml=%t\n", proptools.Bool(productVariables.Uml)))
Cole Faustf055db62023-07-24 15:17:03 -0700356 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build=%t\n", proptools.Bool(productVariables.Unbundled_build)))
357 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 -0700358
359 for _, override := range productVariables.CertificateOverrides {
360 parts := strings.SplitN(override, ":", 2)
361 if apexPath, ok := convertedModulePathMap[parts[0]]; ok {
362 if overrideCertPath, ok := convertedModulePathMap[parts[1]]; ok {
363 result.WriteString(fmt.Sprintf(" --%s:%s_certificate_override=%s:%s\n", apexPath, parts[0], overrideCertPath, parts[1]))
364 }
365 }
366 }
367
Cole Fauste136dda2023-09-27 14:10:33 -0700368 for _, namespace := range android.SortedKeys(productVariables.VendorVars) {
369 for _, variable := range android.SortedKeys(productVariables.VendorVars[namespace]) {
370 value := productVariables.VendorVars[namespace][variable]
Cole Faust87c0c332023-07-31 12:10:12 -0700371 key := namespace + "__" + variable
372 _, hasBool := soongConfigDefinitions.BoolVars[key]
373 _, hasString := soongConfigDefinitions.StringVars[key]
374 _, hasValue := soongConfigDefinitions.ValueVars[key]
375 if !hasBool && !hasString && !hasValue {
376 // Not all soong config variables are defined in Android.bp files. For example,
377 // prebuilt_bootclasspath_fragment uses soong config variables in a nonstandard
378 // way, that causes them to be present in the soong.variables file but not
379 // defined in an Android.bp file. There's also nothing stopping you from setting
380 // a variable in make that doesn't exist in soong. We only generate build
381 // settings for the ones that exist in soong, so skip all others.
382 continue
383 }
384 if hasBool && hasString || hasBool && hasValue || hasString && hasValue {
385 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))
386 }
387 if hasBool {
388 // Logic copied from soongConfig.Bool()
389 value = strings.ToLower(value)
390 if value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" {
391 value = "true"
392 } else {
393 value = "false"
394 }
395 }
396 result.WriteString(fmt.Sprintf(" --//build/bazel/product_config/soong_config_variables:%s=%s\n", strings.ToLower(key), value))
397 }
398 }
Cole Faustf055db62023-07-24 15:17:03 -0700399 }
Cole Faustf8231dd2023-04-21 17:37:11 -0700400}
401
402func starlarkMapToProductVariables(in map[string]starlark.Value) (android.ProductVariables, error) {
Cole Faustf8231dd2023-04-21 17:37:11 -0700403 result := android.ProductVariables{}
Cole Faustf055db62023-07-24 15:17:03 -0700404 productVarsReflect := reflect.ValueOf(&result).Elem()
405 for i := 0; i < productVarsReflect.NumField(); i++ {
406 field := productVarsReflect.Field(i)
407 fieldType := productVarsReflect.Type().Field(i)
408 name := fieldType.Name
Cole Faust87c0c332023-07-31 12:10:12 -0700409 if name == "BootJars" || name == "ApexBootJars" || name == "VendorSnapshotModules" ||
410 name == "RecoverySnapshotModules" {
Cole Faustf055db62023-07-24 15:17:03 -0700411 // These variables have more complicated types, and we don't need them right now
412 continue
413 }
414 if _, ok := in[name]; ok {
Cole Faust87c0c332023-07-31 12:10:12 -0700415 if name == "VendorVars" {
416 vendorVars, err := starlark_import.Unmarshal[map[string]map[string]string](in[name])
417 if err != nil {
418 return result, err
419 }
420 field.Set(reflect.ValueOf(vendorVars))
421 continue
422 }
Cole Faustf055db62023-07-24 15:17:03 -0700423 switch field.Type().Kind() {
424 case reflect.Bool:
425 val, err := starlark_import.Unmarshal[bool](in[name])
426 if err != nil {
427 return result, err
428 }
429 field.SetBool(val)
430 case reflect.String:
431 val, err := starlark_import.Unmarshal[string](in[name])
432 if err != nil {
433 return result, err
434 }
435 field.SetString(val)
436 case reflect.Slice:
437 if field.Type().Elem().Kind() != reflect.String {
438 return result, fmt.Errorf("slices of types other than strings are unimplemented")
439 }
440 val, err := starlark_import.UnmarshalReflect(in[name], field.Type())
441 if err != nil {
442 return result, err
443 }
444 field.Set(val)
445 case reflect.Pointer:
446 switch field.Type().Elem().Kind() {
447 case reflect.Bool:
448 val, err := starlark_import.UnmarshalNoneable[bool](in[name])
449 if err != nil {
450 return result, err
451 }
452 field.Set(reflect.ValueOf(val))
453 case reflect.String:
454 val, err := starlark_import.UnmarshalNoneable[string](in[name])
455 if err != nil {
456 return result, err
457 }
458 field.Set(reflect.ValueOf(val))
459 case reflect.Int:
460 val, err := starlark_import.UnmarshalNoneable[int](in[name])
461 if err != nil {
462 return result, err
463 }
464 field.Set(reflect.ValueOf(val))
465 default:
466 return result, fmt.Errorf("pointers of types other than strings/bools are unimplemented: %s", field.Type().Elem().Kind().String())
467 }
468 default:
469 return result, fmt.Errorf("unimplemented type: %s", field.Type().String())
470 }
471 }
Cole Faust88c8efb2023-07-18 11:05:16 -0700472 }
Cole Faustf055db62023-07-24 15:17:03 -0700473
Cole Faust87c0c332023-07-31 12:10:12 -0700474 result.Native_coverage = proptools.BoolPtr(
475 proptools.Bool(result.GcovCoverage) ||
476 proptools.Bool(result.ClangCoverage))
477
Cole Faustb85d1a12022-11-08 18:14:01 -0800478 return result, nil
479}
Cole Faust6054cdf2023-09-12 10:07:07 -0700480
Cole Faustcb193ec2023-09-20 16:01:18 -0700481func createTargets(productLabelsToVariables map[bazelLabel]*android.ProductVariables, res map[string]BazelTargets) {
Cole Faustb4cb0c82023-09-14 15:16:58 -0700482 createGeneratedAndroidCertificateDirectories(productLabelsToVariables, res)
Cole Faustb5055392023-09-27 13:44:40 -0700483 createAvbKeyFilegroups(productLabelsToVariables, res)
Cole Faustcb193ec2023-09-20 16:01:18 -0700484 for label, variables := range productLabelsToVariables {
485 createSystemPartition(label, &variables.PartitionVarsForBazelMigrationOnlyDoNotUse, res)
486 }
Cole Faustb4cb0c82023-09-14 15:16:58 -0700487}
488
Cole Faustcb193ec2023-09-20 16:01:18 -0700489func createGeneratedAndroidCertificateDirectories(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) {
Cole Faust6054cdf2023-09-12 10:07:07 -0700490 var allDefaultAppCertificateDirs []string
491 for _, productVariables := range productLabelsToVariables {
492 if proptools.String(productVariables.DefaultAppCertificate) != "" {
493 d := filepath.Dir(proptools.String(productVariables.DefaultAppCertificate))
494 if !android.InList(d, allDefaultAppCertificateDirs) {
495 allDefaultAppCertificateDirs = append(allDefaultAppCertificateDirs, d)
496 }
497 }
498 }
499 for _, dir := range allDefaultAppCertificateDirs {
Cole Faustb4cb0c82023-09-14 15:16:58 -0700500 content := `filegroup(
501 name = "generated_android_certificate_directory",
502 srcs = glob([
Cole Faust6054cdf2023-09-12 10:07:07 -0700503 "*.pk8",
504 "*.pem",
505 "*.avbpubkey",
Cole Faustb4cb0c82023-09-14 15:16:58 -0700506 ]),
507 visibility = ["//visibility:public"],
508)`
509 targets[dir] = append(targets[dir], BazelTarget{
Cole Faust6054cdf2023-09-12 10:07:07 -0700510 name: "generated_android_certificate_directory",
511 packageName: dir,
512 content: content,
513 ruleClass: "filegroup",
514 })
515 }
Cole Faust6054cdf2023-09-12 10:07:07 -0700516}
Cole Faustcb193ec2023-09-20 16:01:18 -0700517
Cole Faustb5055392023-09-27 13:44:40 -0700518func createAvbKeyFilegroups(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) {
519 var allAvbKeys []string
520 for _, productVariables := range productLabelsToVariables {
521 for _, partitionVariables := range productVariables.PartitionVarsForBazelMigrationOnlyDoNotUse.PartitionQualifiedVariables {
522 if partitionVariables.BoardAvbKeyPath != "" {
523 if !android.InList(partitionVariables.BoardAvbKeyPath, allAvbKeys) {
524 allAvbKeys = append(allAvbKeys, partitionVariables.BoardAvbKeyPath)
525 }
526 }
527 }
528 }
529 for _, key := range allAvbKeys {
530 dir := filepath.Dir(key)
531 name := filepath.Base(key)
532 content := fmt.Sprintf(`filegroup(
533 name = "%s_filegroup",
534 srcs = ["%s"],
535 visibility = ["//visibility:public"],
536)`, name, name)
537 targets[dir] = append(targets[dir], BazelTarget{
538 name: name + "_filegroup",
539 packageName: dir,
540 content: content,
541 ruleClass: "filegroup",
542 })
543 }
544}
545
Cole Faustcb193ec2023-09-20 16:01:18 -0700546func createSystemPartition(platformLabel bazelLabel, variables *android.PartitionVariables, targets map[string]BazelTargets) {
547 if !variables.PartitionQualifiedVariables["system"].BuildingImage {
548 return
549 }
Cole Faustb5055392023-09-27 13:44:40 -0700550 qualifiedVariables := variables.PartitionQualifiedVariables["system"]
Cole Faustcb193ec2023-09-20 16:01:18 -0700551
552 imageProps := generateImagePropDictionary(variables, "system")
553 imageProps["skip_fsck"] = "true"
554
555 var properties strings.Builder
556 for _, prop := range android.SortedKeys(imageProps) {
557 properties.WriteString(prop)
558 properties.WriteRune('=')
559 properties.WriteString(imageProps[prop])
560 properties.WriteRune('\n')
561 }
562
Cole Faustb5055392023-09-27 13:44:40 -0700563 var extraProperties strings.Builder
564 if variables.BoardAvbEnable {
565 extraProperties.WriteString(" avb_enable = True,\n")
566 extraProperties.WriteString(fmt.Sprintf(" avb_add_hashtree_footer_args = %q,\n", qualifiedVariables.BoardAvbAddHashtreeFooterArgs))
567 keypath := qualifiedVariables.BoardAvbKeyPath
568 if keypath != "" {
569 extraProperties.WriteString(fmt.Sprintf(" avb_key = \"//%s:%s\",\n", filepath.Dir(keypath), filepath.Base(keypath)+"_filegroup"))
570 extraProperties.WriteString(fmt.Sprintf(" avb_algorithm = %q,\n", qualifiedVariables.BoardAvbAlgorithm))
571 extraProperties.WriteString(fmt.Sprintf(" avb_rollback_index = %s,\n", qualifiedVariables.BoardAvbRollbackIndex))
572 extraProperties.WriteString(fmt.Sprintf(" avb_rollback_index_location = %s,\n", qualifiedVariables.BoardAvbRollbackIndexLocation))
573 }
574 }
575
Cole Faustcb193ec2023-09-20 16:01:18 -0700576 targets[platformLabel.pkg] = append(targets[platformLabel.pkg], BazelTarget{
577 name: "system_image",
578 packageName: platformLabel.pkg,
579 content: fmt.Sprintf(`partition(
580 name = "system_image",
581 base_staging_dir = "//build/bazel/bazel_sandwich:system_staging_dir",
582 base_staging_dir_file_list = "//build/bazel/bazel_sandwich:system_staging_dir_file_list",
583 root_dir = "//build/bazel/bazel_sandwich:root_staging_dir",
Cole Faustb5055392023-09-27 13:44:40 -0700584 selinux_file_contexts = "//build/bazel/bazel_sandwich:selinux_file_contexts",
Cole Faustcb193ec2023-09-20 16:01:18 -0700585 image_properties = """
586%s
587""",
Cole Faustb5055392023-09-27 13:44:40 -0700588%s
Cole Faustcb193ec2023-09-20 16:01:18 -0700589 type = "system",
Cole Faustb5055392023-09-27 13:44:40 -0700590)`, properties.String(), extraProperties.String()),
Cole Faustcb193ec2023-09-20 16:01:18 -0700591 ruleClass: "partition",
592 loads: []BazelLoad{{
593 file: "//build/bazel/rules/partitions:partition.bzl",
594 symbols: []BazelLoadSymbol{{
595 symbol: "partition",
596 }},
597 }},
598 }, BazelTarget{
599 name: "system_image_test",
600 packageName: platformLabel.pkg,
601 content: `partition_diff_test(
602 name = "system_image_test",
603 partition1 = "//build/bazel/bazel_sandwich:make_system_image",
604 partition2 = ":system_image",
605)`,
606 ruleClass: "partition_diff_test",
607 loads: []BazelLoad{{
608 file: "//build/bazel/rules/partitions/diff:partition_diff.bzl",
609 symbols: []BazelLoadSymbol{{
610 symbol: "partition_diff_test",
611 }},
612 }},
613 }, BazelTarget{
614 name: "run_system_image_test",
615 packageName: platformLabel.pkg,
616 content: `run_test_in_build(
617 name = "run_system_image_test",
618 test = ":system_image_test",
619)`,
620 ruleClass: "run_test_in_build",
621 loads: []BazelLoad{{
622 file: "//build/bazel/bazel_sandwich:run_test_in_build.bzl",
623 symbols: []BazelLoadSymbol{{
624 symbol: "run_test_in_build",
625 }},
626 }},
627 })
628}
629
630var allPartitionTypes = []string{
631 "system",
632 "vendor",
633 "cache",
634 "userdata",
635 "product",
636 "system_ext",
637 "oem",
638 "odm",
639 "vendor_dlkm",
640 "odm_dlkm",
641 "system_dlkm",
642}
643
644// An equivalent of make's generate-image-prop-dictionary function
645func generateImagePropDictionary(variables *android.PartitionVariables, partitionType string) map[string]string {
646 partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]
647 if !ok {
648 panic("Unknown partitionType: " + partitionType)
649 }
650 ret := map[string]string{}
651 if partitionType == "system" {
652 if len(variables.PartitionQualifiedVariables["system_other"].BoardPartitionSize) > 0 {
653 ret["system_other_size"] = variables.PartitionQualifiedVariables["system_other"].BoardPartitionSize
654 }
655 if len(partitionQualifiedVariables.ProductHeadroom) > 0 {
656 ret["system_headroom"] = partitionQualifiedVariables.ProductHeadroom
657 }
658 addCommonRoFlagsToImageProps(variables, partitionType, ret)
659 }
660 // TODO: other partition-specific logic
661 if variables.TargetUserimagesUseExt2 {
662 ret["fs_type"] = "ext2"
663 } else if variables.TargetUserimagesUseExt3 {
664 ret["fs_type"] = "ext3"
665 } else if variables.TargetUserimagesUseExt4 {
666 ret["fs_type"] = "ext4"
667 }
668
669 if !variables.TargetUserimagesSparseExtDisabled {
670 ret["extfs_sparse_flag"] = "-s"
671 }
672 if !variables.TargetUserimagesSparseErofsDisabled {
673 ret["erofs_sparse_flag"] = "-s"
674 }
675 if !variables.TargetUserimagesSparseSquashfsDisabled {
676 ret["squashfs_sparse_flag"] = "-s"
677 }
678 if !variables.TargetUserimagesSparseF2fsDisabled {
679 ret["f2fs_sparse_flag"] = "-S"
680 }
681 erofsCompressor := variables.BoardErofsCompressor
682 if len(erofsCompressor) == 0 && hasErofsPartition(variables) {
683 if len(variables.BoardErofsUseLegacyCompression) > 0 {
684 erofsCompressor = "lz4"
685 } else {
686 erofsCompressor = "lz4hc,9"
687 }
688 }
689 if len(erofsCompressor) > 0 {
690 ret["erofs_default_compressor"] = erofsCompressor
691 }
692 if len(variables.BoardErofsCompressorHints) > 0 {
693 ret["erofs_default_compress_hints"] = variables.BoardErofsCompressorHints
694 }
695 if len(variables.BoardErofsCompressorHints) > 0 {
696 ret["erofs_default_compress_hints"] = variables.BoardErofsCompressorHints
697 }
698 if len(variables.BoardErofsPclusterSize) > 0 {
699 ret["erofs_pcluster_size"] = variables.BoardErofsPclusterSize
700 }
701 if len(variables.BoardErofsShareDupBlocks) > 0 {
702 ret["erofs_share_dup_blocks"] = variables.BoardErofsShareDupBlocks
703 }
704 if len(variables.BoardErofsUseLegacyCompression) > 0 {
705 ret["erofs_use_legacy_compression"] = variables.BoardErofsUseLegacyCompression
706 }
707 if len(variables.BoardExt4ShareDupBlocks) > 0 {
708 ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks
709 }
710 if len(variables.BoardFlashLogicalBlockSize) > 0 {
711 ret["flash_logical_block_size"] = variables.BoardFlashLogicalBlockSize
712 }
713 if len(variables.BoardFlashEraseBlockSize) > 0 {
714 ret["flash_erase_block_size"] = variables.BoardFlashEraseBlockSize
715 }
716 if len(variables.BoardExt4ShareDupBlocks) > 0 {
717 ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks
718 }
719 if len(variables.BoardExt4ShareDupBlocks) > 0 {
720 ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks
721 }
722 for _, partitionType := range allPartitionTypes {
723 if qualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]; ok && len(qualifiedVariables.ProductVerityPartition) > 0 {
724 ret[partitionType+"_verity_block_device"] = qualifiedVariables.ProductVerityPartition
725 }
726 }
727 // TODO: Vboot
728 // TODO: AVB
729 if variables.BoardUsesRecoveryAsBoot {
730 ret["recovery_as_boot"] = "true"
731 }
732 if variables.BoardBuildGkiBootImageWithoutRamdisk {
733 ret["gki_boot_image_without_ramdisk"] = "true"
734 }
735 if variables.ProductUseDynamicPartitionSize {
736 ret["use_dynamic_partition_size"] = "true"
737 }
738 if variables.CopyImagesForTargetFilesZip {
739 ret["use_fixed_timestamp"] = "true"
740 }
741 return ret
742}
743
744// Soong equivalent of make's add-common-ro-flags-to-image-props
745func addCommonRoFlagsToImageProps(variables *android.PartitionVariables, partitionType string, ret map[string]string) {
746 partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]
747 if !ok {
748 panic("Unknown partitionType: " + partitionType)
749 }
750 if len(partitionQualifiedVariables.BoardErofsCompressor) > 0 {
751 ret[partitionType+"_erofs_compressor"] = partitionQualifiedVariables.BoardErofsCompressor
752 }
753 if len(partitionQualifiedVariables.BoardErofsCompressHints) > 0 {
754 ret[partitionType+"_erofs_compress_hints"] = partitionQualifiedVariables.BoardErofsCompressHints
755 }
756 if len(partitionQualifiedVariables.BoardErofsPclusterSize) > 0 {
757 ret[partitionType+"_erofs_pcluster_size"] = partitionQualifiedVariables.BoardErofsPclusterSize
758 }
759 if len(partitionQualifiedVariables.BoardExtfsRsvPct) > 0 {
760 ret[partitionType+"_extfs_rsv_pct"] = partitionQualifiedVariables.BoardExtfsRsvPct
761 }
762 if len(partitionQualifiedVariables.BoardF2fsSloadCompressFlags) > 0 {
763 ret[partitionType+"_f2fs_sldc_flags"] = partitionQualifiedVariables.BoardF2fsSloadCompressFlags
764 }
765 if len(partitionQualifiedVariables.BoardFileSystemCompress) > 0 {
766 ret[partitionType+"_f2fs_compress"] = partitionQualifiedVariables.BoardFileSystemCompress
767 }
768 if len(partitionQualifiedVariables.BoardFileSystemType) > 0 {
769 ret[partitionType+"_fs_type"] = partitionQualifiedVariables.BoardFileSystemType
770 }
771 if len(partitionQualifiedVariables.BoardJournalSize) > 0 {
772 ret[partitionType+"_journal_size"] = partitionQualifiedVariables.BoardJournalSize
773 }
774 if len(partitionQualifiedVariables.BoardPartitionReservedSize) > 0 {
775 ret[partitionType+"_reserved_size"] = partitionQualifiedVariables.BoardPartitionReservedSize
776 }
777 if len(partitionQualifiedVariables.BoardPartitionSize) > 0 {
778 ret[partitionType+"_size"] = partitionQualifiedVariables.BoardPartitionSize
779 }
780 if len(partitionQualifiedVariables.BoardSquashfsBlockSize) > 0 {
781 ret[partitionType+"_squashfs_block_size"] = partitionQualifiedVariables.BoardSquashfsBlockSize
782 }
783 if len(partitionQualifiedVariables.BoardSquashfsCompressor) > 0 {
784 ret[partitionType+"_squashfs_compressor"] = partitionQualifiedVariables.BoardSquashfsCompressor
785 }
786 if len(partitionQualifiedVariables.BoardSquashfsCompressorOpt) > 0 {
787 ret[partitionType+"_squashfs_compressor_opt"] = partitionQualifiedVariables.BoardSquashfsCompressorOpt
788 }
789 if len(partitionQualifiedVariables.BoardSquashfsDisable4kAlign) > 0 {
790 ret[partitionType+"_squashfs_disable_4k_align"] = partitionQualifiedVariables.BoardSquashfsDisable4kAlign
791 }
792 if len(partitionQualifiedVariables.BoardPartitionSize) == 0 && len(partitionQualifiedVariables.BoardPartitionReservedSize) == 0 && len(partitionQualifiedVariables.ProductHeadroom) == 0 {
793 ret[partitionType+"_disable_sparse"] = "true"
794 }
795 addCommonFlagsToImageProps(variables, partitionType, ret)
796}
797
798func hasErofsPartition(variables *android.PartitionVariables) bool {
799 return variables.PartitionQualifiedVariables["product"].BoardFileSystemType == "erofs" ||
800 variables.PartitionQualifiedVariables["system_ext"].BoardFileSystemType == "erofs" ||
801 variables.PartitionQualifiedVariables["odm"].BoardFileSystemType == "erofs" ||
802 variables.PartitionQualifiedVariables["vendor"].BoardFileSystemType == "erofs" ||
803 variables.PartitionQualifiedVariables["system"].BoardFileSystemType == "erofs" ||
804 variables.PartitionQualifiedVariables["vendor_dlkm"].BoardFileSystemType == "erofs" ||
805 variables.PartitionQualifiedVariables["odm_dlkm"].BoardFileSystemType == "erofs" ||
806 variables.PartitionQualifiedVariables["system_dlkm"].BoardFileSystemType == "erofs"
807}
808
809// Soong equivalent of make's add-common-flags-to-image-props
810func addCommonFlagsToImageProps(variables *android.PartitionVariables, partitionType string, ret map[string]string) {
811 // The selinux_fc will be handled separately
812 partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]
813 if !ok {
814 panic("Unknown partitionType: " + partitionType)
815 }
816 ret["building_"+partitionType+"_image"] = boolToMakeString(partitionQualifiedVariables.BuildingImage)
817}
818
819func boolToMakeString(b bool) string {
820 if b {
821 return "true"
822 }
823 return ""
824}