Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9ab9437b authored by Wei Li's avatar Wei Li Committed by Gerrit Code Review
Browse files

Merge "Add new property "exclude_files_in_output" for excluding files from the...

Merge "Add new property "exclude_files_in_output" for excluding files from the output files of Java related modules."
parents e751b535 1e73c657
Loading
Loading
Loading
Loading
+27 −16
Original line number Diff line number Diff line
@@ -72,6 +72,9 @@ type DexProperties struct {
	// This defaults to reasonable value based on module and should not be set.
	// It exists only to support ART tests.
	Uncompress_dex *bool

	// Exclude kotlinc generate files: *.kotlin_module, *.kotlin_builtins. Defaults to true.
	Exclude_kotlinc_generated_files *bool
}

type dexer struct {
@@ -94,7 +97,7 @@ var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
			`${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` +
			`$d8Template${config.D8Cmd} ${config.DexFlags} --output $outDir $d8Flags $tmpJar && ` +
			`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
			`${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`,
			`${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in`,
		CommandDeps: []string{
			"${config.D8Cmd}",
			"${config.Zip2ZipCmd}",
@@ -116,7 +119,7 @@ var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
			ExecStrategy: "${config.RED8ExecStrategy}",
			Platform:     map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
		},
	}, []string{"outDir", "d8Flags", "zipFlags", "tmpJar"}, nil)
	}, []string{"outDir", "d8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, nil)

var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
	blueprint.RuleParams{
@@ -134,7 +137,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
			`${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
			`rm -rf ${outUsageDir} && ` +
			`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
			`${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`,
			`${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in`,
		CommandDeps: []string{
			"${config.R8Cmd}",
			"${config.Zip2ZipCmd}",
@@ -165,7 +168,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
			Platform:     map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
		},
	}, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir",
		"r8Flags", "zipFlags", "tmpJar"}, []string{"implicits"})
		"r8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, []string{"implicits"})

func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
	minSdkVersion android.SdkSpec) (flags []string, deps android.Paths) {
@@ -307,6 +310,12 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi

	commonFlags, commonDeps := d.dexCommonFlags(ctx, minSdkVersion)

	// Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true.
	mergeZipsFlags := ""
	if proptools.BoolDefault(d.dexProperties.Exclude_kotlinc_generated_files, false) {
		mergeZipsFlags = "-stripFile META-INF/*.kotlin_module -stripFile **/*.kotlin_builtins"
	}

	useR8 := d.effectiveOptimizeEnabled()
	if useR8 {
		proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
@@ -328,6 +337,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
			"outUsageZip":    proguardUsageZip.String(),
			"outDir":         outDir.String(),
			"tmpJar":         tmpJar.String(),
			"mergeZipsFlags": mergeZipsFlags,
		}
		if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") {
			rule = r8RE
@@ -360,6 +370,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
				"zipFlags":       zipFlags,
				"outDir":         outDir.String(),
				"tmpJar":         tmpJar.String(),
				"mergeZipsFlags": mergeZipsFlags,
			},
		})
	}
+9 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ func TestJavaSdkLibrary(t *testing.T) {
			name: "bar",
			srcs: ["a.java", "b.java"],
			api_packages: ["bar"],
			exclude_kotlinc_generated_files: true,
		}
		java_library {
			name: "baz",
@@ -161,6 +162,14 @@ func TestJavaSdkLibrary(t *testing.T) {
		android.AssertDeepEquals(t, "qux exports (required)", []string{"fred", "quuz", "foo", "bar"}, requiredSdkLibs)
		android.AssertDeepEquals(t, "qux exports (optional)", []string{}, optionalSdkLibs)
	}

	fooDexJar := result.ModuleForTests("foo", "android_common").Rule("d8")
	// tests if kotlinc generated files are NOT excluded from output of foo.
	android.AssertStringDoesNotContain(t, "foo dex", fooDexJar.BuildParams.Args["mergeZipsFlags"], "-stripFile META-INF/*.kotlin_module")

	barDexJar := result.ModuleForTests("bar", "android_common").Rule("d8")
	// tests if kotlinc generated files are excluded from output of bar.
	android.AssertStringDoesContain(t, "bar dex", barDexJar.BuildParams.Args["mergeZipsFlags"], "-stripFile META-INF/*.kotlin_module")
}

func TestJavaSdkLibrary_UpdatableLibrary(t *testing.T) {