Merge "add manifest_values application id property to soong" into main am: a9ead6ef2b
am: f98019df2f
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2769927 Change-Id: Ib6d65c55dff604939b406c7698609acf28711d9d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -134,6 +134,10 @@ type aapt struct {
|
|||||||
resourcesNodesDepSet *android.DepSet[*resourcesNode]
|
resourcesNodesDepSet *android.DepSet[*resourcesNode]
|
||||||
rroDirsDepSet *android.DepSet[rroDir]
|
rroDirsDepSet *android.DepSet[rroDir]
|
||||||
manifestsDepSet *android.DepSet[android.Path]
|
manifestsDepSet *android.DepSet[android.Path]
|
||||||
|
|
||||||
|
manifestValues struct {
|
||||||
|
applicationId string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type split struct {
|
type split struct {
|
||||||
@@ -380,7 +384,9 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio
|
|||||||
if len(transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
|
if len(transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
|
||||||
manifestMergerParams := ManifestMergerParams{
|
manifestMergerParams := ManifestMergerParams{
|
||||||
staticLibManifests: transitiveManifestPaths[1:],
|
staticLibManifests: transitiveManifestPaths[1:],
|
||||||
isLibrary: a.isLibrary}
|
isLibrary: a.isLibrary,
|
||||||
|
packageName: a.manifestValues.applicationId,
|
||||||
|
}
|
||||||
a.mergedManifestFile = manifestMerger(ctx, transitiveManifestPaths[0], manifestMergerParams)
|
a.mergedManifestFile = manifestMerger(ctx, transitiveManifestPaths[0], manifestMergerParams)
|
||||||
if !a.isLibrary {
|
if !a.isLibrary {
|
||||||
// Only use the merged manifest for applications. For libraries, the transitive closure of manifests
|
// Only use the merged manifest for applications. For libraries, the transitive closure of manifests
|
||||||
|
@@ -203,15 +203,21 @@ func ManifestFixer(ctx android.ModuleContext, manifest android.Path,
|
|||||||
type ManifestMergerParams struct {
|
type ManifestMergerParams struct {
|
||||||
staticLibManifests android.Paths
|
staticLibManifests android.Paths
|
||||||
isLibrary bool
|
isLibrary bool
|
||||||
|
packageName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func manifestMerger(ctx android.ModuleContext, manifest android.Path,
|
func manifestMerger(ctx android.ModuleContext, manifest android.Path,
|
||||||
params ManifestMergerParams) android.Path {
|
params ManifestMergerParams) android.Path {
|
||||||
|
|
||||||
var args string
|
var args []string
|
||||||
if !params.isLibrary {
|
if !params.isLibrary {
|
||||||
// Follow Gradle's behavior, only pass --remove-tools-declarations when merging app manifests.
|
// Follow Gradle's behavior, only pass --remove-tools-declarations when merging app manifests.
|
||||||
args = "--remove-tools-declarations"
|
args = append(args, "--remove-tools-declarations")
|
||||||
|
}
|
||||||
|
|
||||||
|
packageName := params.packageName
|
||||||
|
if packageName != "" {
|
||||||
|
args = append(args, "--property PACKAGE="+packageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
|
mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
|
||||||
@@ -223,7 +229,7 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path,
|
|||||||
Output: mergedManifest,
|
Output: mergedManifest,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"libs": android.JoinWithPrefix(params.staticLibManifests.Strings(), "--libs "),
|
"libs": android.JoinWithPrefix(params.staticLibManifests.Strings(), "--libs "),
|
||||||
"args": args,
|
"args": strings.Join(args, " "),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -15,8 +15,9 @@
|
|||||||
package java
|
package java
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestManifestMerger(t *testing.T) {
|
func TestManifestMerger(t *testing.T) {
|
||||||
@@ -101,3 +102,41 @@ func TestManifestMerger(t *testing.T) {
|
|||||||
},
|
},
|
||||||
manifestMergerRule.Implicits)
|
manifestMergerRule.Implicits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestManifestValuesApplicationIdSetsPackageName(t *testing.T) {
|
||||||
|
bp := `
|
||||||
|
android_test {
|
||||||
|
name: "test",
|
||||||
|
sdk_version: "current",
|
||||||
|
srcs: ["app/app.java"],
|
||||||
|
manifest: "test/AndroidManifest.xml",
|
||||||
|
additional_manifests: ["test/AndroidManifest2.xml"],
|
||||||
|
static_libs: ["direct"],
|
||||||
|
test_suites: ["device-tests"],
|
||||||
|
manifest_values: {
|
||||||
|
applicationId: "new_package_name"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
android_library {
|
||||||
|
name: "direct",
|
||||||
|
sdk_version: "current",
|
||||||
|
srcs: ["direct/direct.java"],
|
||||||
|
resource_dirs: ["direct/res"],
|
||||||
|
manifest: "direct/AndroidManifest.xml",
|
||||||
|
additional_manifests: ["direct/AndroidManifest2.xml"],
|
||||||
|
}
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
result := android.GroupFixturePreparers(
|
||||||
|
PrepareForTestWithJavaDefaultModules,
|
||||||
|
PrepareForTestWithOverlayBuildComponents,
|
||||||
|
).RunTestWithBp(t, bp)
|
||||||
|
|
||||||
|
manifestMergerRule := result.ModuleForTests("test", "android_common").Rule("manifestMerger")
|
||||||
|
android.AssertStringMatches(t,
|
||||||
|
"manifest merger args",
|
||||||
|
manifestMergerRule.Args["args"],
|
||||||
|
"--property PACKAGE=new_package_name")
|
||||||
|
}
|
||||||
|
24
java/app.go
24
java/app.go
@@ -308,6 +308,13 @@ func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutato
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
applicationId := a.appTestHelperAppProperties.Manifest_values.ApplicationId
|
||||||
|
if applicationId != nil {
|
||||||
|
if a.overridableAppProperties.Package_name != nil {
|
||||||
|
ctx.PropertyErrorf("manifest_values.applicationId", "property is not supported when property package_name is set.")
|
||||||
|
}
|
||||||
|
a.aapt.manifestValues.applicationId = *applicationId
|
||||||
|
}
|
||||||
a.generateAndroidBuildActions(ctx)
|
a.generateAndroidBuildActions(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1107,6 +1114,12 @@ func AndroidAppFactory() android.Module {
|
|||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A dictionary of values to be overridden in the manifest.
|
||||||
|
type Manifest_values struct {
|
||||||
|
// Overrides the value of package_name in the manifest
|
||||||
|
ApplicationId *string
|
||||||
|
}
|
||||||
|
|
||||||
type appTestProperties struct {
|
type appTestProperties struct {
|
||||||
// The name of the android_app module that the tests will run against.
|
// The name of the android_app module that the tests will run against.
|
||||||
Instrumentation_for *string
|
Instrumentation_for *string
|
||||||
@@ -1116,6 +1129,8 @@ type appTestProperties struct {
|
|||||||
|
|
||||||
// If specified, the mainline module package name in the test config is overwritten by it.
|
// If specified, the mainline module package name in the test config is overwritten by it.
|
||||||
Mainline_package_name *string
|
Mainline_package_name *string
|
||||||
|
|
||||||
|
Manifest_values Manifest_values
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidTest struct {
|
type AndroidTest struct {
|
||||||
@@ -1160,6 +1175,13 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+manifestPackageName)
|
a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+manifestPackageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
applicationId := a.appTestProperties.Manifest_values.ApplicationId
|
||||||
|
if applicationId != nil {
|
||||||
|
if a.overridableAppProperties.Package_name != nil {
|
||||||
|
ctx.PropertyErrorf("manifest_values.applicationId", "property is not supported when property package_name is set.")
|
||||||
|
}
|
||||||
|
a.aapt.manifestValues.applicationId = *applicationId
|
||||||
|
}
|
||||||
a.generateAndroidBuildActions(ctx)
|
a.generateAndroidBuildActions(ctx)
|
||||||
|
|
||||||
for _, module := range a.testProperties.Test_mainline_modules {
|
for _, module := range a.testProperties.Test_mainline_modules {
|
||||||
@@ -1264,6 +1286,8 @@ type appTestHelperAppProperties struct {
|
|||||||
|
|
||||||
// Install the test into a folder named for the module in all test suites.
|
// Install the test into a folder named for the module in all test suites.
|
||||||
Per_testcase_directory *bool
|
Per_testcase_directory *bool
|
||||||
|
|
||||||
|
Manifest_values Manifest_values
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidTestHelperApp struct {
|
type AndroidTestHelperApp struct {
|
||||||
|
Reference in New Issue
Block a user