Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 4 | "encoding/json" |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 5 | "fmt" |
| 6 | "os" |
| 7 | "path/filepath" |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 8 | "reflect" |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 9 | "strings" |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 10 | |
Yu Liu | b6a15da | 2023-08-31 14:14:01 -0700 | [diff] [blame] | 11 | "android/soong/android" |
| 12 | "android/soong/android/soongconfig" |
| 13 | "android/soong/starlark_import" |
| 14 | |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 15 | "github.com/google/blueprint/proptools" |
| 16 | "go.starlark.net/starlark" |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 17 | ) |
| 18 | |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 19 | type createProductConfigFilesResult struct { |
| 20 | injectionFiles []BazelFile |
| 21 | bp2buildFiles []BazelFile |
| 22 | bp2buildTargets map[string]BazelTargets |
| 23 | } |
| 24 | |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 25 | type bazelLabel struct { |
| 26 | repo string |
| 27 | pkg string |
| 28 | target string |
| 29 | } |
| 30 | |
| 31 | func (l *bazelLabel) String() string { |
| 32 | return fmt.Sprintf("@%s//%s:%s", l.repo, l.pkg, l.target) |
| 33 | } |
| 34 | |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 35 | func createProductConfigFiles( |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 36 | ctx *CodegenContext, |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 37 | metrics CodegenMetrics) (createProductConfigFilesResult, error) { |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 38 | cfg := &ctx.config |
| 39 | targetProduct := "unknown" |
| 40 | if cfg.HasDeviceProduct() { |
| 41 | targetProduct = cfg.DeviceProduct() |
| 42 | } |
| 43 | targetBuildVariant := "user" |
| 44 | if cfg.Eng() { |
| 45 | targetBuildVariant = "eng" |
| 46 | } else if cfg.Debuggable() { |
| 47 | targetBuildVariant = "userdebug" |
| 48 | } |
| 49 | |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 50 | var res createProductConfigFilesResult |
| 51 | |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 52 | productVariablesFileName := cfg.ProductVariablesFileName |
| 53 | if !strings.HasPrefix(productVariablesFileName, "/") { |
| 54 | productVariablesFileName = filepath.Join(ctx.topDir, productVariablesFileName) |
| 55 | } |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 56 | productVariablesBytes, err := os.ReadFile(productVariablesFileName) |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 57 | if err != nil { |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 58 | return res, err |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 59 | } |
| 60 | productVariables := android.ProductVariables{} |
| 61 | err = json.Unmarshal(productVariablesBytes, &productVariables) |
| 62 | if err != nil { |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 63 | return res, err |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 66 | currentProductFolder := fmt.Sprintf("build/bazel/products/%s", targetProduct) |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 67 | if len(productVariables.PartitionVarsForBazelMigrationOnlyDoNotUse.ProductDirectory) > 0 { |
| 68 | currentProductFolder = fmt.Sprintf("%s%s", productVariables.PartitionVarsForBazelMigrationOnlyDoNotUse.ProductDirectory, targetProduct) |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 69 | } |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 70 | |
| 71 | productReplacer := strings.NewReplacer( |
| 72 | "{PRODUCT}", targetProduct, |
| 73 | "{VARIANT}", targetBuildVariant, |
| 74 | "{PRODUCT_FOLDER}", currentProductFolder) |
| 75 | |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 76 | productsForTestingMap, err := starlark_import.GetStarlarkValue[map[string]map[string]starlark.Value]("products_for_testing") |
| 77 | if err != nil { |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 78 | return res, err |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 79 | } |
| 80 | productsForTesting := android.SortedKeys(productsForTestingMap) |
| 81 | for i := range productsForTesting { |
| 82 | productsForTesting[i] = fmt.Sprintf(" \"@//build/bazel/tests/products:%s\",", productsForTesting[i]) |
| 83 | } |
| 84 | |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 85 | productLabelsToVariables := make(map[bazelLabel]*android.ProductVariables) |
| 86 | productLabelsToVariables[bazelLabel{ |
| 87 | repo: "", |
| 88 | pkg: currentProductFolder, |
| 89 | target: targetProduct, |
| 90 | }] = &productVariables |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 91 | for product, productVariablesStarlark := range productsForTestingMap { |
| 92 | productVariables, err := starlarkMapToProductVariables(productVariablesStarlark) |
| 93 | if err != nil { |
| 94 | return res, err |
| 95 | } |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 96 | productLabelsToVariables[bazelLabel{ |
| 97 | repo: "", |
| 98 | pkg: "build/bazel/tests/products", |
| 99 | target: product, |
| 100 | }] = &productVariables |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 103 | res.bp2buildTargets = make(map[string]BazelTargets) |
| 104 | res.bp2buildTargets[currentProductFolder] = append(res.bp2buildTargets[currentProductFolder], BazelTarget{ |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 105 | name: productReplacer.Replace("{PRODUCT}"), |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 106 | packageName: currentProductFolder, |
| 107 | content: productReplacer.Replace(`android_product( |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 108 | name = "{PRODUCT}", |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 109 | soong_variables = _soong_variables, |
| 110 | )`), |
| 111 | ruleClass: "android_product", |
| 112 | loads: []BazelLoad{ |
| 113 | { |
| 114 | file: ":soong.variables.bzl", |
| 115 | symbols: []BazelLoadSymbol{{ |
| 116 | symbol: "variables", |
| 117 | alias: "_soong_variables", |
| 118 | }}, |
| 119 | }, |
| 120 | { |
| 121 | file: "//build/bazel/product_config:android_product.bzl", |
| 122 | symbols: []BazelLoadSymbol{{symbol: "android_product"}}, |
| 123 | }, |
| 124 | }, |
| 125 | }) |
| 126 | createTargets(productLabelsToVariables, res.bp2buildTargets) |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 127 | |
| 128 | platformMappingContent, err := platformMappingContent( |
| 129 | productLabelsToVariables, |
| 130 | ctx.Config().Bp2buildSoongConfigDefinitions, |
| 131 | metrics.convertedModulePathMap) |
| 132 | if err != nil { |
| 133 | return res, err |
| 134 | } |
| 135 | |
| 136 | res.injectionFiles = []BazelFile{ |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 137 | newFile( |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 138 | "product_config_platforms", |
| 139 | "BUILD.bazel", |
| 140 | productReplacer.Replace(` |
| 141 | package(default_visibility = [ |
| 142 | "@//build/bazel/product_config:__subpackages__", |
| 143 | "@soong_injection//product_config_platforms:__subpackages__", |
| 144 | ]) |
Jingwen Chen | 583ab21 | 2023-05-30 09:45:23 +0000 | [diff] [blame] | 145 | |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 146 | load("@//{PRODUCT_FOLDER}:soong.variables.bzl", _soong_variables = "variables") |
Jingwen Chen | 583ab21 | 2023-05-30 09:45:23 +0000 | [diff] [blame] | 147 | load("@//build/bazel/product_config:android_product.bzl", "android_product") |
| 148 | |
Cole Faust | 319abae | 2023-06-06 15:12:49 -0700 | [diff] [blame] | 149 | # Bazel will qualify its outputs by the platform name. When switching between products, this |
| 150 | # means that soong-built files that depend on bazel-built files will suddenly get different |
| 151 | # dependency files, because the path changes, and they will be rebuilt. In order to avoid this |
| 152 | # extra rebuilding, make mixed builds always use a single platform so that the bazel artifacts |
| 153 | # are always under the same path. |
Jingwen Chen | 583ab21 | 2023-05-30 09:45:23 +0000 | [diff] [blame] | 154 | android_product( |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 155 | name = "mixed_builds_product", |
Jingwen Chen | 583ab21 | 2023-05-30 09:45:23 +0000 | [diff] [blame] | 156 | soong_variables = _soong_variables, |
Cole Faust | bc65a3f | 2023-08-01 16:38:55 +0000 | [diff] [blame] | 157 | extra_constraints = ["@//build/bazel/platforms:mixed_builds"], |
Jingwen Chen | 583ab21 | 2023-05-30 09:45:23 +0000 | [diff] [blame] | 158 | ) |
Cole Faust | 117bb74 | 2023-03-29 14:46:20 -0700 | [diff] [blame] | 159 | `)), |
| 160 | newFile( |
| 161 | "product_config_platforms", |
| 162 | "product_labels.bzl", |
| 163 | productReplacer.Replace(` |
| 164 | # This file keeps a list of all the products in the android source tree, because they're |
| 165 | # discovered as part of a preprocessing step before bazel runs. |
| 166 | # TODO: When we start generating the platforms for more than just the |
| 167 | # currently lunched product, they should all be listed here |
| 168 | product_labels = [ |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 169 | "@soong_injection//product_config_platforms:mixed_builds_product", |
| 170 | "@//{PRODUCT_FOLDER}:{PRODUCT}", |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 171 | `)+strings.Join(productsForTesting, "\n")+"\n]\n"), |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 172 | newFile( |
| 173 | "product_config_platforms", |
| 174 | "common.bazelrc", |
| 175 | productReplacer.Replace(` |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 176 | build --platform_mappings=platform_mappings |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 177 | build --platforms @//{PRODUCT_FOLDER}:{PRODUCT}_linux_x86_64 |
| 178 | build --//build/bazel/product_config:target_build_variant={VARIANT} |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 179 | |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 180 | build:android --platforms=@//{PRODUCT_FOLDER}:{PRODUCT} |
| 181 | build:linux_x86 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_x86 |
| 182 | build:linux_x86_64 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_x86_64 |
| 183 | build:linux_bionic_x86_64 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_bionic_x86_64 |
| 184 | build:linux_musl_x86 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_musl_x86 |
| 185 | build:linux_musl_x86_64 --platforms=@//{PRODUCT_FOLDER}:{PRODUCT}_linux_musl_x86_64 |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 186 | `)), |
| 187 | newFile( |
| 188 | "product_config_platforms", |
| 189 | "linux.bazelrc", |
| 190 | productReplacer.Replace(` |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 191 | build --host_platform @//{PRODUCT_FOLDER}:{PRODUCT}_linux_x86_64 |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 192 | `)), |
| 193 | newFile( |
| 194 | "product_config_platforms", |
| 195 | "darwin.bazelrc", |
| 196 | productReplacer.Replace(` |
Cole Faust | f3cf34e | 2023-09-20 17:02:40 -0700 | [diff] [blame] | 197 | build --host_platform @//{PRODUCT_FOLDER}:{PRODUCT}_darwin_x86_64 |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 198 | `)), |
| 199 | } |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 200 | res.bp2buildFiles = []BazelFile{ |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 201 | newFile( |
| 202 | "", |
| 203 | "platform_mappings", |
| 204 | platformMappingContent), |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 205 | newFile( |
| 206 | currentProductFolder, |
| 207 | "soong.variables.bzl", |
| 208 | `variables = json.decode("""`+strings.ReplaceAll(string(productVariablesBytes), "\\", "\\\\")+`""")`), |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 209 | } |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 210 | |
| 211 | return res, nil |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 212 | } |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 213 | |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 214 | func platformMappingContent( |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 215 | productLabelToVariables map[bazelLabel]*android.ProductVariables, |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 216 | soongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions, |
| 217 | convertedModulePathMap map[string]string) (string, error) { |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 218 | var result strings.Builder |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 219 | |
| 220 | mergedConvertedModulePathMap := make(map[string]string) |
| 221 | for k, v := range convertedModulePathMap { |
| 222 | mergedConvertedModulePathMap[k] = v |
| 223 | } |
| 224 | additionalModuleNamesToPackages, err := starlark_import.GetStarlarkValue[map[string]string]("additional_module_names_to_packages") |
| 225 | if err != nil { |
| 226 | return "", err |
| 227 | } |
| 228 | for k, v := range additionalModuleNamesToPackages { |
| 229 | mergedConvertedModulePathMap[k] = v |
| 230 | } |
| 231 | |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 232 | result.WriteString("platforms:\n") |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 233 | for productLabel, productVariables := range productLabelToVariables { |
| 234 | platformMappingSingleProduct(productLabel, productVariables, soongConfigDefinitions, mergedConvertedModulePathMap, &result) |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 235 | } |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 236 | return result.String(), nil |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Cole Faust | 88c8efb | 2023-07-18 11:05:16 -0700 | [diff] [blame] | 239 | var bazelPlatformSuffixes = []string{ |
| 240 | "", |
| 241 | "_darwin_arm64", |
| 242 | "_darwin_x86_64", |
| 243 | "_linux_bionic_arm64", |
| 244 | "_linux_bionic_x86_64", |
| 245 | "_linux_musl_x86", |
| 246 | "_linux_musl_x86_64", |
| 247 | "_linux_x86", |
| 248 | "_linux_x86_64", |
| 249 | "_windows_x86", |
| 250 | "_windows_x86_64", |
| 251 | } |
| 252 | |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 253 | func platformMappingSingleProduct( |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 254 | label bazelLabel, |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 255 | productVariables *android.ProductVariables, |
| 256 | soongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions, |
| 257 | convertedModulePathMap map[string]string, |
| 258 | result *strings.Builder) { |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 259 | |
Cole Faust | 95c5cf8 | 2023-08-03 13:49:27 -0700 | [diff] [blame] | 260 | platform_sdk_version := -1 |
| 261 | if productVariables.Platform_sdk_version != nil { |
| 262 | platform_sdk_version = *productVariables.Platform_sdk_version |
| 263 | } |
| 264 | |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 265 | defaultAppCertificateFilegroup := "//build/bazel/utils:empty_filegroup" |
| 266 | if proptools.String(productVariables.DefaultAppCertificate) != "" { |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 267 | defaultAppCertificateFilegroup = "@//" + filepath.Dir(proptools.String(productVariables.DefaultAppCertificate)) + ":generated_android_certificate_directory" |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 270 | for _, suffix := range bazelPlatformSuffixes { |
| 271 | result.WriteString(" ") |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 272 | result.WriteString(label.String()) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 273 | result.WriteString(suffix) |
| 274 | result.WriteString("\n") |
| 275 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:always_use_prebuilt_sdks=%t\n", proptools.Bool(productVariables.Always_use_prebuilt_sdks))) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 276 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:arc=%t\n", proptools.Bool(productVariables.Arc))) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 277 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride))) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 278 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:binder32bit=%t\n", proptools.Bool(productVariables.Binder32bit))) |
| 279 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_from_text_stub=%t\n", proptools.Bool(productVariables.Build_from_text_stub))) |
Cole Faust | ded7960 | 2023-09-05 17:48:11 -0700 | [diff] [blame] | 280 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_broken_incorrect_partition_images=%t\n", productVariables.BuildBrokenIncorrectPartitionImages)) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 281 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_id=%s\n", proptools.String(productVariables.BuildId))) |
| 282 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_version_tags=%s\n", strings.Join(productVariables.BuildVersionTags, ","))) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 283 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ","))) |
| 284 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ","))) |
| 285 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:compressed_apex=%t\n", proptools.Bool(productVariables.CompressedApex))) |
| 286 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate=%s\n", proptools.String(productVariables.DefaultAppCertificate))) |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 287 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate_filegroup=%s\n", defaultAppCertificateFilegroup)) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 288 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_abi=%s\n", strings.Join(productVariables.DeviceAbi, ","))) |
| 289 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_max_page_size_supported=%s\n", proptools.String(productVariables.DeviceMaxPageSizeSupported))) |
| 290 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_name=%s\n", proptools.String(productVariables.DeviceName))) |
Juan Yescas | 0106560 | 2023-08-09 08:34:37 -0700 | [diff] [blame] | 291 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_page_size_agnostic=%t\n", proptools.Bool(productVariables.DevicePageSizeAgnostic))) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 292 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_product=%s\n", proptools.String(productVariables.DeviceProduct))) |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 293 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_platform=%s\n", label.String())) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 294 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true))) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 295 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enforce_vintf_manifest=%t\n", proptools.Bool(productVariables.Enforce_vintf_manifest))) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 296 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_not_svelte=%t\n", proptools.Bool(productVariables.Malloc_not_svelte))) |
| 297 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_pattern_fill_contents=%t\n", proptools.Bool(productVariables.Malloc_pattern_fill_contents))) |
| 298 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_zero_contents=%t\n", proptools.Bool(productVariables.Malloc_zero_contents))) |
Yu Liu | b6a15da | 2023-08-31 14:14:01 -0700 | [diff] [blame] | 299 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_exclude_paths=%s\n", strings.Join(productVariables.MemtagHeapExcludePaths, ","))) |
| 300 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_async_include_paths=%s\n", strings.Join(productVariables.MemtagHeapAsyncIncludePaths, ","))) |
| 301 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_sync_include_paths=%s\n", strings.Join(productVariables.MemtagHeapSyncIncludePaths, ","))) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 302 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:manifest_package_name_overrides=%s\n", strings.Join(productVariables.ManifestPackageNameOverrides, ","))) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 303 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:native_coverage=%t\n", proptools.Bool(productVariables.Native_coverage))) |
Romain Jobredeaux | 3132f84 | 2023-09-15 10:06:16 -0400 | [diff] [blame] | 304 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_final=%t\n", proptools.Bool(productVariables.Platform_sdk_final))) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 305 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_name=%s\n", proptools.String(productVariables.Platform_version_name))) |
| 306 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_brand=%s\n", productVariables.ProductBrand)) |
| 307 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_manufacturer=%s\n", productVariables.ProductManufacturer)) |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 308 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_flag_default_permission=%s\n", productVariables.ReleaseAconfigFlagDefaultPermission)) |
| 309 | // Empty string can't be used as label_flag on the bazel side |
| 310 | if len(productVariables.ReleaseAconfigValueSets) > 0 { |
| 311 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_value_sets=%s\n", productVariables.ReleaseAconfigValueSets)) |
| 312 | } |
| 313 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_version=%s\n", productVariables.ReleaseVersion)) |
Cole Faust | 95c5cf8 | 2023-08-03 13:49:27 -0700 | [diff] [blame] | 314 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_version=%d\n", platform_sdk_version)) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 315 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:safestack=%t\n", proptools.Bool(productVariables.Safestack))) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 316 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:treble_linker_namespaces=%t\n", proptools.Bool(productVariables.Treble_linker_namespaces))) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 317 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:tidy_checks=%s\n", proptools.String(productVariables.TidyChecks))) |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 318 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:uml=%t\n", proptools.Bool(productVariables.Uml))) |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 319 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build=%t\n", proptools.Bool(productVariables.Unbundled_build))) |
| 320 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build_apps=%s\n", strings.Join(productVariables.Unbundled_build_apps, ","))) |
Cole Faust | 946d02c | 2023-08-03 16:08:09 -0700 | [diff] [blame] | 321 | |
| 322 | for _, override := range productVariables.CertificateOverrides { |
| 323 | parts := strings.SplitN(override, ":", 2) |
| 324 | if apexPath, ok := convertedModulePathMap[parts[0]]; ok { |
| 325 | if overrideCertPath, ok := convertedModulePathMap[parts[1]]; ok { |
| 326 | result.WriteString(fmt.Sprintf(" --%s:%s_certificate_override=%s:%s\n", apexPath, parts[0], overrideCertPath, parts[1])) |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 331 | for namespace, namespaceContents := range productVariables.VendorVars { |
| 332 | for variable, value := range namespaceContents { |
| 333 | key := namespace + "__" + variable |
| 334 | _, hasBool := soongConfigDefinitions.BoolVars[key] |
| 335 | _, hasString := soongConfigDefinitions.StringVars[key] |
| 336 | _, hasValue := soongConfigDefinitions.ValueVars[key] |
| 337 | if !hasBool && !hasString && !hasValue { |
| 338 | // Not all soong config variables are defined in Android.bp files. For example, |
| 339 | // prebuilt_bootclasspath_fragment uses soong config variables in a nonstandard |
| 340 | // way, that causes them to be present in the soong.variables file but not |
| 341 | // defined in an Android.bp file. There's also nothing stopping you from setting |
| 342 | // a variable in make that doesn't exist in soong. We only generate build |
| 343 | // settings for the ones that exist in soong, so skip all others. |
| 344 | continue |
| 345 | } |
| 346 | if hasBool && hasString || hasBool && hasValue || hasString && hasValue { |
| 347 | 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)) |
| 348 | } |
| 349 | if hasBool { |
| 350 | // Logic copied from soongConfig.Bool() |
| 351 | value = strings.ToLower(value) |
| 352 | if value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" { |
| 353 | value = "true" |
| 354 | } else { |
| 355 | value = "false" |
| 356 | } |
| 357 | } |
| 358 | result.WriteString(fmt.Sprintf(" --//build/bazel/product_config/soong_config_variables:%s=%s\n", strings.ToLower(key), value)) |
| 359 | } |
| 360 | } |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 361 | } |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | func starlarkMapToProductVariables(in map[string]starlark.Value) (android.ProductVariables, error) { |
Cole Faust | f8231dd | 2023-04-21 17:37:11 -0700 | [diff] [blame] | 365 | result := android.ProductVariables{} |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 366 | productVarsReflect := reflect.ValueOf(&result).Elem() |
| 367 | for i := 0; i < productVarsReflect.NumField(); i++ { |
| 368 | field := productVarsReflect.Field(i) |
| 369 | fieldType := productVarsReflect.Type().Field(i) |
| 370 | name := fieldType.Name |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 371 | if name == "BootJars" || name == "ApexBootJars" || name == "VendorSnapshotModules" || |
| 372 | name == "RecoverySnapshotModules" { |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 373 | // These variables have more complicated types, and we don't need them right now |
| 374 | continue |
| 375 | } |
| 376 | if _, ok := in[name]; ok { |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 377 | if name == "VendorVars" { |
| 378 | vendorVars, err := starlark_import.Unmarshal[map[string]map[string]string](in[name]) |
| 379 | if err != nil { |
| 380 | return result, err |
| 381 | } |
| 382 | field.Set(reflect.ValueOf(vendorVars)) |
| 383 | continue |
| 384 | } |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 385 | switch field.Type().Kind() { |
| 386 | case reflect.Bool: |
| 387 | val, err := starlark_import.Unmarshal[bool](in[name]) |
| 388 | if err != nil { |
| 389 | return result, err |
| 390 | } |
| 391 | field.SetBool(val) |
| 392 | case reflect.String: |
| 393 | val, err := starlark_import.Unmarshal[string](in[name]) |
| 394 | if err != nil { |
| 395 | return result, err |
| 396 | } |
| 397 | field.SetString(val) |
| 398 | case reflect.Slice: |
| 399 | if field.Type().Elem().Kind() != reflect.String { |
| 400 | return result, fmt.Errorf("slices of types other than strings are unimplemented") |
| 401 | } |
| 402 | val, err := starlark_import.UnmarshalReflect(in[name], field.Type()) |
| 403 | if err != nil { |
| 404 | return result, err |
| 405 | } |
| 406 | field.Set(val) |
| 407 | case reflect.Pointer: |
| 408 | switch field.Type().Elem().Kind() { |
| 409 | case reflect.Bool: |
| 410 | val, err := starlark_import.UnmarshalNoneable[bool](in[name]) |
| 411 | if err != nil { |
| 412 | return result, err |
| 413 | } |
| 414 | field.Set(reflect.ValueOf(val)) |
| 415 | case reflect.String: |
| 416 | val, err := starlark_import.UnmarshalNoneable[string](in[name]) |
| 417 | if err != nil { |
| 418 | return result, err |
| 419 | } |
| 420 | field.Set(reflect.ValueOf(val)) |
| 421 | case reflect.Int: |
| 422 | val, err := starlark_import.UnmarshalNoneable[int](in[name]) |
| 423 | if err != nil { |
| 424 | return result, err |
| 425 | } |
| 426 | field.Set(reflect.ValueOf(val)) |
| 427 | default: |
| 428 | return result, fmt.Errorf("pointers of types other than strings/bools are unimplemented: %s", field.Type().Elem().Kind().String()) |
| 429 | } |
| 430 | default: |
| 431 | return result, fmt.Errorf("unimplemented type: %s", field.Type().String()) |
| 432 | } |
| 433 | } |
Cole Faust | 88c8efb | 2023-07-18 11:05:16 -0700 | [diff] [blame] | 434 | } |
Cole Faust | f055db6 | 2023-07-24 15:17:03 -0700 | [diff] [blame] | 435 | |
Cole Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 436 | result.Native_coverage = proptools.BoolPtr( |
| 437 | proptools.Bool(result.GcovCoverage) || |
| 438 | proptools.Bool(result.ClangCoverage)) |
| 439 | |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 440 | return result, nil |
| 441 | } |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 442 | |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 443 | func createTargets(productLabelsToVariables map[bazelLabel]*android.ProductVariables, res map[string]BazelTargets) { |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 444 | createGeneratedAndroidCertificateDirectories(productLabelsToVariables, res) |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 445 | for label, variables := range productLabelsToVariables { |
| 446 | createSystemPartition(label, &variables.PartitionVarsForBazelMigrationOnlyDoNotUse, res) |
| 447 | } |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 450 | func createGeneratedAndroidCertificateDirectories(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) { |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 451 | var allDefaultAppCertificateDirs []string |
| 452 | for _, productVariables := range productLabelsToVariables { |
| 453 | if proptools.String(productVariables.DefaultAppCertificate) != "" { |
| 454 | d := filepath.Dir(proptools.String(productVariables.DefaultAppCertificate)) |
| 455 | if !android.InList(d, allDefaultAppCertificateDirs) { |
| 456 | allDefaultAppCertificateDirs = append(allDefaultAppCertificateDirs, d) |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | for _, dir := range allDefaultAppCertificateDirs { |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 461 | content := `filegroup( |
| 462 | name = "generated_android_certificate_directory", |
| 463 | srcs = glob([ |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 464 | "*.pk8", |
| 465 | "*.pem", |
| 466 | "*.avbpubkey", |
Cole Faust | b4cb0c8 | 2023-09-14 15:16:58 -0700 | [diff] [blame] | 467 | ]), |
| 468 | visibility = ["//visibility:public"], |
| 469 | )` |
| 470 | targets[dir] = append(targets[dir], BazelTarget{ |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 471 | name: "generated_android_certificate_directory", |
| 472 | packageName: dir, |
| 473 | content: content, |
| 474 | ruleClass: "filegroup", |
| 475 | }) |
| 476 | } |
Cole Faust | 6054cdf | 2023-09-12 10:07:07 -0700 | [diff] [blame] | 477 | } |
Cole Faust | cb193ec | 2023-09-20 16:01:18 -0700 | [diff] [blame^] | 478 | |
| 479 | func createSystemPartition(platformLabel bazelLabel, variables *android.PartitionVariables, targets map[string]BazelTargets) { |
| 480 | if !variables.PartitionQualifiedVariables["system"].BuildingImage { |
| 481 | return |
| 482 | } |
| 483 | |
| 484 | imageProps := generateImagePropDictionary(variables, "system") |
| 485 | imageProps["skip_fsck"] = "true" |
| 486 | |
| 487 | var properties strings.Builder |
| 488 | for _, prop := range android.SortedKeys(imageProps) { |
| 489 | properties.WriteString(prop) |
| 490 | properties.WriteRune('=') |
| 491 | properties.WriteString(imageProps[prop]) |
| 492 | properties.WriteRune('\n') |
| 493 | } |
| 494 | |
| 495 | targets[platformLabel.pkg] = append(targets[platformLabel.pkg], BazelTarget{ |
| 496 | name: "system_image", |
| 497 | packageName: platformLabel.pkg, |
| 498 | content: fmt.Sprintf(`partition( |
| 499 | name = "system_image", |
| 500 | base_staging_dir = "//build/bazel/bazel_sandwich:system_staging_dir", |
| 501 | base_staging_dir_file_list = "//build/bazel/bazel_sandwich:system_staging_dir_file_list", |
| 502 | root_dir = "//build/bazel/bazel_sandwich:root_staging_dir", |
| 503 | image_properties = """ |
| 504 | %s |
| 505 | """, |
| 506 | type = "system", |
| 507 | )`, properties.String()), |
| 508 | ruleClass: "partition", |
| 509 | loads: []BazelLoad{{ |
| 510 | file: "//build/bazel/rules/partitions:partition.bzl", |
| 511 | symbols: []BazelLoadSymbol{{ |
| 512 | symbol: "partition", |
| 513 | }}, |
| 514 | }}, |
| 515 | }, BazelTarget{ |
| 516 | name: "system_image_test", |
| 517 | packageName: platformLabel.pkg, |
| 518 | content: `partition_diff_test( |
| 519 | name = "system_image_test", |
| 520 | partition1 = "//build/bazel/bazel_sandwich:make_system_image", |
| 521 | partition2 = ":system_image", |
| 522 | )`, |
| 523 | ruleClass: "partition_diff_test", |
| 524 | loads: []BazelLoad{{ |
| 525 | file: "//build/bazel/rules/partitions/diff:partition_diff.bzl", |
| 526 | symbols: []BazelLoadSymbol{{ |
| 527 | symbol: "partition_diff_test", |
| 528 | }}, |
| 529 | }}, |
| 530 | }, BazelTarget{ |
| 531 | name: "run_system_image_test", |
| 532 | packageName: platformLabel.pkg, |
| 533 | content: `run_test_in_build( |
| 534 | name = "run_system_image_test", |
| 535 | test = ":system_image_test", |
| 536 | )`, |
| 537 | ruleClass: "run_test_in_build", |
| 538 | loads: []BazelLoad{{ |
| 539 | file: "//build/bazel/bazel_sandwich:run_test_in_build.bzl", |
| 540 | symbols: []BazelLoadSymbol{{ |
| 541 | symbol: "run_test_in_build", |
| 542 | }}, |
| 543 | }}, |
| 544 | }) |
| 545 | } |
| 546 | |
| 547 | var allPartitionTypes = []string{ |
| 548 | "system", |
| 549 | "vendor", |
| 550 | "cache", |
| 551 | "userdata", |
| 552 | "product", |
| 553 | "system_ext", |
| 554 | "oem", |
| 555 | "odm", |
| 556 | "vendor_dlkm", |
| 557 | "odm_dlkm", |
| 558 | "system_dlkm", |
| 559 | } |
| 560 | |
| 561 | // An equivalent of make's generate-image-prop-dictionary function |
| 562 | func generateImagePropDictionary(variables *android.PartitionVariables, partitionType string) map[string]string { |
| 563 | partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType] |
| 564 | if !ok { |
| 565 | panic("Unknown partitionType: " + partitionType) |
| 566 | } |
| 567 | ret := map[string]string{} |
| 568 | if partitionType == "system" { |
| 569 | if len(variables.PartitionQualifiedVariables["system_other"].BoardPartitionSize) > 0 { |
| 570 | ret["system_other_size"] = variables.PartitionQualifiedVariables["system_other"].BoardPartitionSize |
| 571 | } |
| 572 | if len(partitionQualifiedVariables.ProductHeadroom) > 0 { |
| 573 | ret["system_headroom"] = partitionQualifiedVariables.ProductHeadroom |
| 574 | } |
| 575 | addCommonRoFlagsToImageProps(variables, partitionType, ret) |
| 576 | } |
| 577 | // TODO: other partition-specific logic |
| 578 | if variables.TargetUserimagesUseExt2 { |
| 579 | ret["fs_type"] = "ext2" |
| 580 | } else if variables.TargetUserimagesUseExt3 { |
| 581 | ret["fs_type"] = "ext3" |
| 582 | } else if variables.TargetUserimagesUseExt4 { |
| 583 | ret["fs_type"] = "ext4" |
| 584 | } |
| 585 | |
| 586 | if !variables.TargetUserimagesSparseExtDisabled { |
| 587 | ret["extfs_sparse_flag"] = "-s" |
| 588 | } |
| 589 | if !variables.TargetUserimagesSparseErofsDisabled { |
| 590 | ret["erofs_sparse_flag"] = "-s" |
| 591 | } |
| 592 | if !variables.TargetUserimagesSparseSquashfsDisabled { |
| 593 | ret["squashfs_sparse_flag"] = "-s" |
| 594 | } |
| 595 | if !variables.TargetUserimagesSparseF2fsDisabled { |
| 596 | ret["f2fs_sparse_flag"] = "-S" |
| 597 | } |
| 598 | erofsCompressor := variables.BoardErofsCompressor |
| 599 | if len(erofsCompressor) == 0 && hasErofsPartition(variables) { |
| 600 | if len(variables.BoardErofsUseLegacyCompression) > 0 { |
| 601 | erofsCompressor = "lz4" |
| 602 | } else { |
| 603 | erofsCompressor = "lz4hc,9" |
| 604 | } |
| 605 | } |
| 606 | if len(erofsCompressor) > 0 { |
| 607 | ret["erofs_default_compressor"] = erofsCompressor |
| 608 | } |
| 609 | if len(variables.BoardErofsCompressorHints) > 0 { |
| 610 | ret["erofs_default_compress_hints"] = variables.BoardErofsCompressorHints |
| 611 | } |
| 612 | if len(variables.BoardErofsCompressorHints) > 0 { |
| 613 | ret["erofs_default_compress_hints"] = variables.BoardErofsCompressorHints |
| 614 | } |
| 615 | if len(variables.BoardErofsPclusterSize) > 0 { |
| 616 | ret["erofs_pcluster_size"] = variables.BoardErofsPclusterSize |
| 617 | } |
| 618 | if len(variables.BoardErofsShareDupBlocks) > 0 { |
| 619 | ret["erofs_share_dup_blocks"] = variables.BoardErofsShareDupBlocks |
| 620 | } |
| 621 | if len(variables.BoardErofsUseLegacyCompression) > 0 { |
| 622 | ret["erofs_use_legacy_compression"] = variables.BoardErofsUseLegacyCompression |
| 623 | } |
| 624 | if len(variables.BoardExt4ShareDupBlocks) > 0 { |
| 625 | ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks |
| 626 | } |
| 627 | if len(variables.BoardFlashLogicalBlockSize) > 0 { |
| 628 | ret["flash_logical_block_size"] = variables.BoardFlashLogicalBlockSize |
| 629 | } |
| 630 | if len(variables.BoardFlashEraseBlockSize) > 0 { |
| 631 | ret["flash_erase_block_size"] = variables.BoardFlashEraseBlockSize |
| 632 | } |
| 633 | if len(variables.BoardExt4ShareDupBlocks) > 0 { |
| 634 | ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks |
| 635 | } |
| 636 | if len(variables.BoardExt4ShareDupBlocks) > 0 { |
| 637 | ret["ext4_share_dup_blocks"] = variables.BoardExt4ShareDupBlocks |
| 638 | } |
| 639 | for _, partitionType := range allPartitionTypes { |
| 640 | if qualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType]; ok && len(qualifiedVariables.ProductVerityPartition) > 0 { |
| 641 | ret[partitionType+"_verity_block_device"] = qualifiedVariables.ProductVerityPartition |
| 642 | } |
| 643 | } |
| 644 | // TODO: Vboot |
| 645 | // TODO: AVB |
| 646 | if variables.BoardUsesRecoveryAsBoot { |
| 647 | ret["recovery_as_boot"] = "true" |
| 648 | } |
| 649 | if variables.BoardBuildGkiBootImageWithoutRamdisk { |
| 650 | ret["gki_boot_image_without_ramdisk"] = "true" |
| 651 | } |
| 652 | if variables.ProductUseDynamicPartitionSize { |
| 653 | ret["use_dynamic_partition_size"] = "true" |
| 654 | } |
| 655 | if variables.CopyImagesForTargetFilesZip { |
| 656 | ret["use_fixed_timestamp"] = "true" |
| 657 | } |
| 658 | return ret |
| 659 | } |
| 660 | |
| 661 | // Soong equivalent of make's add-common-ro-flags-to-image-props |
| 662 | func addCommonRoFlagsToImageProps(variables *android.PartitionVariables, partitionType string, ret map[string]string) { |
| 663 | partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType] |
| 664 | if !ok { |
| 665 | panic("Unknown partitionType: " + partitionType) |
| 666 | } |
| 667 | if len(partitionQualifiedVariables.BoardErofsCompressor) > 0 { |
| 668 | ret[partitionType+"_erofs_compressor"] = partitionQualifiedVariables.BoardErofsCompressor |
| 669 | } |
| 670 | if len(partitionQualifiedVariables.BoardErofsCompressHints) > 0 { |
| 671 | ret[partitionType+"_erofs_compress_hints"] = partitionQualifiedVariables.BoardErofsCompressHints |
| 672 | } |
| 673 | if len(partitionQualifiedVariables.BoardErofsPclusterSize) > 0 { |
| 674 | ret[partitionType+"_erofs_pcluster_size"] = partitionQualifiedVariables.BoardErofsPclusterSize |
| 675 | } |
| 676 | if len(partitionQualifiedVariables.BoardExtfsRsvPct) > 0 { |
| 677 | ret[partitionType+"_extfs_rsv_pct"] = partitionQualifiedVariables.BoardExtfsRsvPct |
| 678 | } |
| 679 | if len(partitionQualifiedVariables.BoardF2fsSloadCompressFlags) > 0 { |
| 680 | ret[partitionType+"_f2fs_sldc_flags"] = partitionQualifiedVariables.BoardF2fsSloadCompressFlags |
| 681 | } |
| 682 | if len(partitionQualifiedVariables.BoardFileSystemCompress) > 0 { |
| 683 | ret[partitionType+"_f2fs_compress"] = partitionQualifiedVariables.BoardFileSystemCompress |
| 684 | } |
| 685 | if len(partitionQualifiedVariables.BoardFileSystemType) > 0 { |
| 686 | ret[partitionType+"_fs_type"] = partitionQualifiedVariables.BoardFileSystemType |
| 687 | } |
| 688 | if len(partitionQualifiedVariables.BoardJournalSize) > 0 { |
| 689 | ret[partitionType+"_journal_size"] = partitionQualifiedVariables.BoardJournalSize |
| 690 | } |
| 691 | if len(partitionQualifiedVariables.BoardPartitionReservedSize) > 0 { |
| 692 | ret[partitionType+"_reserved_size"] = partitionQualifiedVariables.BoardPartitionReservedSize |
| 693 | } |
| 694 | if len(partitionQualifiedVariables.BoardPartitionSize) > 0 { |
| 695 | ret[partitionType+"_size"] = partitionQualifiedVariables.BoardPartitionSize |
| 696 | } |
| 697 | if len(partitionQualifiedVariables.BoardSquashfsBlockSize) > 0 { |
| 698 | ret[partitionType+"_squashfs_block_size"] = partitionQualifiedVariables.BoardSquashfsBlockSize |
| 699 | } |
| 700 | if len(partitionQualifiedVariables.BoardSquashfsCompressor) > 0 { |
| 701 | ret[partitionType+"_squashfs_compressor"] = partitionQualifiedVariables.BoardSquashfsCompressor |
| 702 | } |
| 703 | if len(partitionQualifiedVariables.BoardSquashfsCompressorOpt) > 0 { |
| 704 | ret[partitionType+"_squashfs_compressor_opt"] = partitionQualifiedVariables.BoardSquashfsCompressorOpt |
| 705 | } |
| 706 | if len(partitionQualifiedVariables.BoardSquashfsDisable4kAlign) > 0 { |
| 707 | ret[partitionType+"_squashfs_disable_4k_align"] = partitionQualifiedVariables.BoardSquashfsDisable4kAlign |
| 708 | } |
| 709 | if len(partitionQualifiedVariables.BoardPartitionSize) == 0 && len(partitionQualifiedVariables.BoardPartitionReservedSize) == 0 && len(partitionQualifiedVariables.ProductHeadroom) == 0 { |
| 710 | ret[partitionType+"_disable_sparse"] = "true" |
| 711 | } |
| 712 | addCommonFlagsToImageProps(variables, partitionType, ret) |
| 713 | } |
| 714 | |
| 715 | func hasErofsPartition(variables *android.PartitionVariables) bool { |
| 716 | return variables.PartitionQualifiedVariables["product"].BoardFileSystemType == "erofs" || |
| 717 | variables.PartitionQualifiedVariables["system_ext"].BoardFileSystemType == "erofs" || |
| 718 | variables.PartitionQualifiedVariables["odm"].BoardFileSystemType == "erofs" || |
| 719 | variables.PartitionQualifiedVariables["vendor"].BoardFileSystemType == "erofs" || |
| 720 | variables.PartitionQualifiedVariables["system"].BoardFileSystemType == "erofs" || |
| 721 | variables.PartitionQualifiedVariables["vendor_dlkm"].BoardFileSystemType == "erofs" || |
| 722 | variables.PartitionQualifiedVariables["odm_dlkm"].BoardFileSystemType == "erofs" || |
| 723 | variables.PartitionQualifiedVariables["system_dlkm"].BoardFileSystemType == "erofs" |
| 724 | } |
| 725 | |
| 726 | // Soong equivalent of make's add-common-flags-to-image-props |
| 727 | func addCommonFlagsToImageProps(variables *android.PartitionVariables, partitionType string, ret map[string]string) { |
| 728 | // The selinux_fc will be handled separately |
| 729 | partitionQualifiedVariables, ok := variables.PartitionQualifiedVariables[partitionType] |
| 730 | if !ok { |
| 731 | panic("Unknown partitionType: " + partitionType) |
| 732 | } |
| 733 | ret["building_"+partitionType+"_image"] = boolToMakeString(partitionQualifiedVariables.BuildingImage) |
| 734 | } |
| 735 | |
| 736 | func boolToMakeString(b bool) string { |
| 737 | if b { |
| 738 | return "true" |
| 739 | } |
| 740 | return "" |
| 741 | } |