Merge tag 'android-15.0.0_r6' of https://android.googlesource.com/platform/build/soong into HEAD

Android 15.0.0 Release 6 (AP4A.241205.013)

Change-Id: I6593e92f1bf52c3ebcb46c13361de6baba11e5e3
Signed-off-by: micky387 <mickaelsaibi@free.fr>
diff --git a/android/namespace.go b/android/namespace.go
index ebf85a1..3b9ae3a 100644
--- a/android/namespace.go
+++ b/android/namespace.go
@@ -156,6 +156,9 @@
 			return fmt.Errorf("a namespace must be the first module in the file")
 		}
 	}
+	if (namespace.exportToKati) {
+		r.rootNamespace.visibleNamespaces = append(r.rootNamespace.visibleNamespaces, namespace)
+	}
 	r.sortedNamespaces.add(namespace)
 
 	r.namespacesByDir.Store(namespace.Path, namespace)
diff --git a/android/paths.go b/android/paths.go
index 0d94f03..28656c3 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -1169,6 +1169,31 @@
 	return ret, nil
 }
 
+// pathForSourceRelaxed creates a SourcePath from pathComponents, but does not check that it exists.
+// It differs from pathForSource in that the path is allowed to exist outside of the PathContext.
+func pathForSourceRelaxed(ctx PathContext, pathComponents ...string) (SourcePath, error) {
+	p := filepath.Join(pathComponents...)
+	ret := SourcePath{basePath{p, ""}}
+
+	abs, err := filepath.Abs(ret.String())
+	if err != nil {
+		return ret, err
+	}
+	buildroot, err := filepath.Abs(ctx.Config().outDir)
+	if err != nil {
+		return ret, err
+	}
+	if strings.HasPrefix(abs, buildroot) {
+		return ret, fmt.Errorf("source path %s is in output", abs)
+	}
+
+	if pathtools.IsGlob(ret.String()) {
+		return ret, fmt.Errorf("path may not contain a glob: %s", ret.String())
+	}
+
+	return ret, nil
+}
+
 // existsWithDependencies returns true if the path exists, and adds appropriate dependencies to rerun if the
 // path does not exist.
 func existsWithDependencies(ctx PathGlobContext, path SourcePath) (exists bool, err error) {
@@ -1241,6 +1266,31 @@
 	return path
 }
 
+// PathForSourceRelaxed joins the provided path components.  Unlike PathForSource,
+// the result is allowed to exist outside of the source dir.
+// On error, it will return a usable, but invalid SourcePath, and report a ModuleError.
+func PathForSourceRelaxed(ctx PathContext, pathComponents ...string) SourcePath {
+	path, err := pathForSourceRelaxed(ctx, pathComponents...)
+	if err != nil {
+		reportPathError(ctx, err)
+	}
+
+	if modCtx, ok := ctx.(ModuleMissingDepsPathContext); ok && ctx.Config().AllowMissingDependencies() {
+		exists, err := existsWithDependencies(modCtx, path)
+		if err != nil {
+			reportPathError(ctx, err)
+		}
+		if !exists {
+			modCtx.AddMissingDependencies([]string{path.String()})
+		}
+	} else if exists, _, err := ctx.Config().fs.Exists(path.String()); err != nil {
+		ReportPathErrorf(ctx, "%s: %s", path, err.Error())
+	} else if !exists {
+		ReportPathErrorf(ctx, "source path %s does not exist", path)
+	}
+	return path
+}
+
 // ExistentPathForSource returns an OptionalPath with the SourcePath, rooted from SrcDir, *not*
 // rooted from the module's local source directory, if the path exists, or an empty OptionalPath if
 // it doesn't exist. Dependencies are added so that the ninja file will be regenerated if the state
@@ -2063,7 +2113,7 @@
 		}
 
 		path := filepath.Clean(path)
-		if path == ".." || strings.HasPrefix(path, "../") || strings.HasPrefix(path, "/") {
+		if path == ".." || strings.HasPrefix(path, "../") || i != initialEmpty && strings.HasPrefix(path, "/") {
 			return "", fmt.Errorf("Path is outside directory: %s", path)
 		}
 
diff --git a/androidmk/androidmk/android.go b/androidmk/androidmk/android.go
index 570f36c..18c97b5 100644
--- a/androidmk/androidmk/android.go
+++ b/androidmk/androidmk/android.go
@@ -780,6 +780,13 @@
 	return fmt.Errorf("Currently LOCAL_PROTOC_FLAGS only support with value '--proto_path=$(LOCAL_PATH)/...'")
 }
 
+func exportCflags(ctx variableAssignmentContext) error {
+	// The Soong replacement for EXPORT_CFLAGS doesn't need the same extra escaped quotes that were present in Make
+	ctx.mkvalue = ctx.mkvalue.Clone()
+	ctx.mkvalue.ReplaceLiteral(`\"`, `"`)
+	return includeVariableNow(bpVariable{"export_cflags", bpparser.ListType}, ctx)
+}
+
 func proguardEnabled(ctx variableAssignmentContext) error {
 	val, err := makeVariableToBlueprint(ctx.file, ctx.mkvalue, bpparser.ListType)
 	if err != nil {
diff --git a/cc/cc.go b/cc/cc.go
index 96795d3..e47e3fc 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -2457,6 +2457,23 @@
 	variantNdkLibs := []string{}
 	variantLateNdkLibs := []string{}
 	if ctx.Os() == android.Android {
+		rewriteHeaderLibs := func(list []string) (newHeaderLibs []string) {
+			newHeaderLibs = []string{}
+			for _, entry := range list {
+				// Replace device_kernel_headers with generated_kernel_headers
+				// for inline kernel building
+				if entry == "device_kernel_headers" || entry == "qti_kernel_headers" {
+					if (ctx.Config().Getenv("INLINE_KERNEL_BUILDING") == "true") {
+						newHeaderLibs = append(newHeaderLibs, "generated_kernel_headers")
+						continue
+					}
+				}
+				newHeaderLibs = append(newHeaderLibs, entry)
+			}
+			return newHeaderLibs
+		}
+		deps.HeaderLibs = rewriteHeaderLibs(deps.HeaderLibs)
+
 		deps.SharedLibs, variantNdkLibs = FilterNdkLibs(c, ctx.Config(), deps.SharedLibs)
 		deps.LateSharedLibs, variantLateNdkLibs = FilterNdkLibs(c, ctx.Config(), deps.LateSharedLibs)
 		deps.ReexportSharedLibHeaders, _ = FilterNdkLibs(c, ctx.Config(), deps.ReexportSharedLibHeaders)
diff --git a/cc/library.go b/cc/library.go
index 3833b98..c4ec88c 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -197,6 +197,9 @@
 	// using -isystem for this module and any module that links against this module.
 	Export_system_include_dirs []string `android:"arch_variant,variant_prepend"`
 
+	// list of plain cc flags to be used for any module that links against this module.
+	Export_cflags []string  `android:"arch_variant"`
+
 	Target struct {
 		Vendor, Product struct {
 			// list of exported include directories, like
@@ -307,6 +310,10 @@
 	f.systemDirs = append(f.systemDirs, android.PathsForModuleSrc(ctx, f.Properties.Export_system_include_dirs)...)
 }
 
+func (f *flagExporter) exportExtraFlags(ctx ModuleContext) {
+	f.flags = append(f.flags, f.Properties.Export_cflags...)
+}
+
 // exportIncludesAsSystem registers the include directories and system include directories to be
 // exported transitively both as system include directories to modules depending on this module.
 func (f *flagExporter) exportIncludesAsSystem(ctx ModuleContext) {
@@ -1623,6 +1630,7 @@
 
 	// Export include paths and flags to be propagated up the tree.
 	library.exportIncludes(ctx)
+	library.exportExtraFlags(ctx)
 	library.reexportDirs(deps.ReexportedDirs...)
 	library.reexportSystemDirs(deps.ReexportedSystemDirs...)
 	library.reexportFlags(deps.ReexportedFlags...)
diff --git a/java/aar.go b/java/aar.go
index b5e24c4..368ad33 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -322,7 +322,7 @@
 
 	if !hasVersionName {
 		var versionName string
-		if ctx.ModuleName() == "framework-res" {
+		if ctx.ModuleName() == "framework-res" || ctx.ModuleName() == "omnirom-res" {
 			// Some builds set AppsDefaultVersionName() to include the build number ("O-123456").  aapt2 copies the
 			// version name of framework-res into app manifests as compileSdkVersionCodename, which confuses things
 			// if it contains the build number.  Use the PlatformVersionName instead.
@@ -347,6 +347,9 @@
 	if sdkDep.frameworkResModule != "" {
 		ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
 	}
+	if sdkDep.omniromResModule != "" {
+		ctx.AddVariationDependencies(nil, omniromResTag, sdkDep.omniromResModule)
+	}
 }
 
 var extractAssetsRule = pctx.AndroidStaticRule("extractAssets",
@@ -757,7 +760,7 @@
 				sharedResourcesNodeDepSets = append(sharedResourcesNodeDepSets, aarDep.ResourcesNodeDepSet())
 				sharedLibs = append(sharedLibs, exportPackage)
 			}
-		case frameworkResTag:
+		case frameworkResTag, omniromResTag:
 			if exportPackage != nil {
 				sharedLibs = append(sharedLibs, exportPackage)
 			}
@@ -1100,6 +1103,9 @@
 		if sdkDep.useModule && sdkDep.frameworkResModule != "" {
 			ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
 		}
+		if sdkDep.useModule && sdkDep.omniromResModule != "" {
+			ctx.AddVariationDependencies(nil, omniromResTag, sdkDep.omniromResModule)
+		}
 	}
 
 	ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...)
diff --git a/java/android_manifest.go b/java/android_manifest.go
index 0c77968..44b12f1 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -156,7 +156,7 @@
 		targetSdkVersion := targetSdkVersionForManifestFixer(ctx, params)
 
 		if useApiFingerprint, fingerprintTargetSdkVersion, fingerprintDeps :=
-			UseApiFingerprint(ctx); useApiFingerprint && ctx.ModuleName() != "framework-res" {
+			UseApiFingerprint(ctx); useApiFingerprint && ctx.ModuleName() != "framework-res" && ctx.ModuleName() != "omnirom-res" {
 			targetSdkVersion = fingerprintTargetSdkVersion
 			deps = append(deps, fingerprintDeps)
 		}
@@ -174,7 +174,7 @@
 		}
 
 		if useApiFingerprint, fingerprintMinSdkVersion, fingerprintDeps :=
-			UseApiFingerprint(ctx); useApiFingerprint && ctx.ModuleName() != "framework-res" {
+			UseApiFingerprint(ctx); useApiFingerprint && ctx.ModuleName() != "framework-res" && ctx.ModuleName() != "omnirom-res" {
 			minSdkVersion = fingerprintMinSdkVersion
 			deps = append(deps, fingerprintDeps)
 		}
diff --git a/java/androidmk.go b/java/androidmk.go
index a1bc904..b050445 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -368,7 +368,7 @@
 				entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", app.dexer.proguardDictionary)
 				entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", app.dexer.proguardUsageZip)
 
-				if app.Name() == "framework-res" {
+				if app.Name() == "framework-res" || app.Name() == "omnirom-res" {
 					entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)")
 					// Make base_rules.mk not put framework-res in a subdirectory called
 					// framework_res.
@@ -500,7 +500,7 @@
 			entries.SetPath("LOCAL_SOONG_AAR", a.aarFile)
 		}
 
-		if a.Name() == "framework-res" {
+		if a.Name() == "framework-res" || a.Name() == "omnirom-res" {
 			entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)")
 			// Make base_rules.mk not put framework-res in a subdirectory called
 			// framework_res.
diff --git a/java/app.go b/java/app.go
index 4ac42a7..13f1568 100644
--- a/java/app.go
+++ b/java/app.go
@@ -643,6 +643,9 @@
 	if ctx.ModuleName() == "framework-res" {
 		// framework-res.apk is installed as system/framework/framework-res.apk
 		installDir = "framework"
+	} else if ctx.ModuleName() == "omnirom-res" {
+		// omnirom-res.apk is installed as system/framework/omnirom-res.apk
+		installDir = "framework"
 	} else if a.Privileged() {
 		installDir = filepath.Join("priv-app", a.installApkName)
 	} else {
@@ -667,7 +670,7 @@
 
 	var packageResources = a.exportPackage
 
-	if ctx.ModuleName() != "framework-res" {
+	if ctx.ModuleName() != "framework-res" && ctx.ModuleName() != "omnirom-res" {
 		if a.dexProperties.resourceShrinkingEnabled(ctx) {
 			protoFile := android.PathForModuleOut(ctx, packageResources.Base()+".proto.apk")
 			aapt2Convert(ctx, protoFile, packageResources, "proto")
@@ -856,6 +859,9 @@
 	if ctx.ModuleName() == "framework-res" {
 		// framework-res.apk is installed as system/framework/framework-res.apk
 		a.installDir = android.PathForModuleInstall(ctx, "framework")
+	} else if ctx.ModuleName() == "omnirom-res" {
+		// omnirom-res.apk is installed as system/framework/omnirom-res.apk
+		a.installDir = android.PathForModuleInstall(ctx, "framework")
 	} else if a.Privileged() {
 		a.installDir = android.PathForModuleInstall(ctx, "priv-app", a.installApkName)
 	} else if ctx.InstallInTestcases() {
diff --git a/java/app_test.go b/java/app_test.go
index d7f5f0c..5ec0ad4 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -77,8 +77,11 @@
 			expectedLinkImplicits = append(expectedLinkImplicits, manifestFixer.Output.String())
 
 			frameworkRes := result.ModuleForTests("framework-res", "android_common")
+			omniromRes := result.ModuleForTests("omnirom-res", "android_common")
 			expectedLinkImplicits = append(expectedLinkImplicits,
 				frameworkRes.Output("package-res.apk").Output.String())
+			expectedLinkImplicits = append(expectedLinkImplicits,
+				omniromRes.Output("package-res.apk").Output.String())
 
 			// Test the mapping from input files to compiled output file names
 			compile := foo.Output(compiledResourceFiles[0])
diff --git a/java/java.go b/java/java.go
index 91c4d6d..c1187dc 100644
--- a/java/java.go
+++ b/java/java.go
@@ -439,6 +439,7 @@
 	bootClasspathTag        = dependencyTag{name: "bootclasspath", runtimeLinked: true}
 	systemModulesTag        = dependencyTag{name: "system modules", runtimeLinked: true}
 	frameworkResTag         = dependencyTag{name: "framework-res"}
+	omniromResTag           = dependencyTag{name: "omnirom-res"}
 	kotlinPluginTag         = dependencyTag{name: "kotlin-plugin", toolchain: true}
 	proguardRaiseTag        = dependencyTag{name: "proguard-raise"}
 	certificateTag          = dependencyTag{name: "certificate"}
@@ -506,6 +507,7 @@
 	java9Classpath []string
 
 	frameworkResModule string
+	omniromResModule   string
 
 	jars android.Paths
 	aidl android.OptionalPath
@@ -549,6 +551,10 @@
 	if sdkDep.systemModules != "" {
 		ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
 	}
+
+	if ctx.ModuleName() == "omnirom-res" {
+		ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res")
+	}
 }
 
 type deps struct {
diff --git a/java/sdk.go b/java/sdk.go
index 4537f19..1beb7d5 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -168,6 +168,7 @@
 			systemModules:      systemModules,
 			java9Classpath:     []string{module},
 			frameworkResModule: "framework-res",
+			omniromResModule:   "omnirom-res",
 			aidl:               android.OptionalPathForPath(aidl),
 		}
 	}
@@ -180,6 +181,7 @@
 			bootclasspath:      corePlatformBootclasspathLibraries(ctx),
 			classpath:          config.FrameworkLibraries,
 			frameworkResModule: "framework-res",
+			omniromResModule:   "omnirom-res",
 		}
 	case android.SdkNone:
 		systemModules := sdkContext.SystemModules()
diff --git a/java/testing.go b/java/testing.go
index 6ed6054..700314f 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -559,6 +559,11 @@
 		android_app {
 			name: "framework-res",
 			sdk_version: "core_platform",
+		}
+
+		android_app {
+			name: "omnirom-res",
+			sdk_version: "core_platform",
 		}`
 
 	systemModules := []string{
diff --git a/scripts/check_boot_jars/package_allowed_list.txt b/scripts/check_boot_jars/package_allowed_list.txt
index 1d2fc64..2f0907c 100644
--- a/scripts/check_boot_jars/package_allowed_list.txt
+++ b/scripts/check_boot_jars/package_allowed_list.txt
@@ -260,3 +260,8 @@
 # Packages used for Android in Chrome OS
 org\.chromium\.arc
 org\.chromium\.arc\..*
+
+# OmniROM adds
+omnirom\.platform
+org\.omnirom\.omnilib
+org\.omnirom\.omnilib\..*
diff --git a/scripts/gen_build_prop.py b/scripts/gen_build_prop.py
index c08a3fd..b82c8f9 100644
--- a/scripts/gen_build_prop.py
+++ b/scripts/gen_build_prop.py
@@ -41,9 +41,30 @@
 
 def get_build_keys(product_config):
   default_cert = product_config.get("DefaultAppCertificate", "")
-  if default_cert == "" or default_cert == os.path.join(TEST_KEY_DIR, "testKey"):
+  if "ROM_BUILDTYPE" in product_config:
+    return "release-keys"
+  elif default_cert == os.path.join(TEST_KEY_DIR, "testKey"):
     return "test-keys"
-  return "dev-keys"
+  else:
+    return "dev-keys"
+
+def override_config(config):
+  if "PRODUCT_BUILD_PROP_OVERRIDES" in config:
+    current_key = None
+    props_overrides = {}
+
+    for var in config["PRODUCT_BUILD_PROP_OVERRIDES"]:
+      if "=" in var:
+        current_key, value = var.split("=")
+        props_overrides[current_key] = value
+      else:
+        props_overrides[current_key] += f" {var}"
+
+    for key, value in props_overrides.items():
+      if key not in config:
+        print(f"Key \"{key}\" isn't a valid prop override", file=sys.stderr)
+        sys.exit(1)
+      config[key] = value
 
 def parse_args():
   """Parse commandline arguments."""
@@ -100,6 +121,11 @@
   if args.build_thumbprint_file:
     config["BuildThumbprint"] = args.build_thumbprint_file.read().strip()
 
+  config["OmniRomDesc"] = config["BuildDesc"]
+  config["OmniRomDevice"] = config["DeviceName"]
+
+  override_config(config)
+
   append_additional_system_props(args)
   append_additional_vendor_props(args)
   append_additional_product_props(args)
@@ -175,6 +201,8 @@
   config = args.config
   build_flags = config["BuildFlags"]
 
+  print(f"ro.build.fingerprint?={config['BuildFingerprint']}")
+
   # The ro.build.id will be set dynamically by init, by appending the unique vbmeta digest.
   if config["BoardUseVbmetaDigestInFingerprint"]:
     print(f"ro.build.legacy.id={config['BuildId']}")
@@ -193,6 +221,7 @@
       print(f"ro.build.display.id?={config['BuildId']} {config['BuildKeys']}")
   else:
     # Non-user builds should show detailed build information (See build desc above)
+    print(f"ro.build.display.id?={config['OmniRomDesc']}")
     print(f"ro.build.display.id?={config['BuildDesc']}")
   print(f"ro.build.version.incremental={config['BuildNumber']}")
   print(f"ro.build.version.sdk={config['Platform_sdk_version']}")
@@ -220,6 +249,8 @@
   # flavor (via a dedicated lunch config for example).
   print(f"ro.build.flavor={config['BuildFlavor']}")
 
+  print(f"ro.omni.device={config['OmniRomDevice']}")
+
   # These values are deprecated, use "ro.product.cpu.abilist"
   # instead (see below).
   print(f"# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,")
@@ -548,6 +579,7 @@
   # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
   variables = [
     "ADDITIONAL_PRODUCT_PROPERTIES",
+    "OMNI_PRODUCT_PROPERTIES",
     "PRODUCT_PRODUCT_PROPERTIES",
   ]
 
diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go
index 41cb5ab..46e38c9 100644
--- a/ui/build/cleanbuild.go
+++ b/ui/build/cleanbuild.go
@@ -125,6 +125,7 @@
 		hostCommonOut("obj/PACKAGING"),
 		productOut("*.img"),
 		productOut("*.zip"),
+		productOut("*.zip.md5sum"),
 		productOut("android-info.txt"),
 		productOut("misc_info.txt"),
 		productOut("apex"),
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index 5df3a95..06b1185 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -164,6 +164,7 @@
 	"BUILD_ID",
 	"OUT_DIR",
 	"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE",
+	"ROM_BUILDTYPE",
 }
 
 func Banner(make_vars map[string]string) string {
diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go
index 6c9a1eb..a532e6d 100644
--- a/ui/build/paths/config.go
+++ b/ui/build/paths/config.go
@@ -108,6 +108,8 @@
 	"tr":          Allowed,
 	"unzip":       Allowed,
 	"zip":         Allowed,
+	"nproc":          Allowed,
+	"perl":           Allowed,
 
 	// Host toolchain is removed. In-tree toolchain should be used instead.
 	// GCC also can't find cc1 with this implementation.
diff --git a/ui/build/sandbox_linux.go b/ui/build/sandbox_linux.go
index 95b71a7..4ef12d4 100644
--- a/ui/build/sandbox_linux.go
+++ b/ui/build/sandbox_linux.go
@@ -307,6 +307,10 @@
 		sandboxArgs = append(sandboxArgs, "-N")
 	}
 
+	if ccacheDir := os.Getenv("CCACHE_DIR"); ccacheDir != "" {
+		sandboxArgs = append(sandboxArgs, "-B", ccacheDir)
+	}
+
 	// Stop nsjail from parsing arguments
 	sandboxArgs = append(sandboxArgs, "--")