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