Add new property "exclude_kotlinc_generated_files" for excluding files generated by kotlinc from the output files of Java related modules.
Bug: 204888276
Test: m service-permission
Change-Id: I9f6113834826358b0e3af22ed1dd63a43c255452
Merged-In: I9f6113834826358b0e3af22ed1dd63a43c255452
(cherry picked from commit 1e73c6573e
)
This commit is contained in:
19
java/dex.go
19
java/dex.go
@@ -69,6 +69,9 @@ type DexProperties struct {
|
|||||||
// This defaults to reasonable value based on module and should not be set.
|
// This defaults to reasonable value based on module and should not be set.
|
||||||
// It exists only to support ART tests.
|
// It exists only to support ART tests.
|
||||||
Uncompress_dex *bool
|
Uncompress_dex *bool
|
||||||
|
|
||||||
|
// Exclude kotlinc generate files: *.kotlin_module, *.kotlin_builtins. Defaults to false.
|
||||||
|
Exclude_kotlinc_generated_files *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type dexer struct {
|
type dexer struct {
|
||||||
@@ -89,7 +92,7 @@ var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
|
|||||||
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
||||||
`$d8Template${config.D8Cmd} ${config.DexFlags} --output $outDir $d8Flags $in && ` +
|
`$d8Template${config.D8Cmd} ${config.DexFlags} --output $outDir $d8Flags $in && ` +
|
||||||
`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
|
`$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{
|
CommandDeps: []string{
|
||||||
"${config.D8Cmd}",
|
"${config.D8Cmd}",
|
||||||
"${config.SoongZipCmd}",
|
"${config.SoongZipCmd}",
|
||||||
@@ -110,7 +113,7 @@ var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
|
|||||||
ExecStrategy: "${config.RED8ExecStrategy}",
|
ExecStrategy: "${config.RED8ExecStrategy}",
|
||||||
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
|
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
|
||||||
},
|
},
|
||||||
}, []string{"outDir", "d8Flags", "zipFlags"}, nil)
|
}, []string{"outDir", "d8Flags", "zipFlags", "mergeZipsFlags"}, nil)
|
||||||
|
|
||||||
var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
|
var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
@@ -126,7 +129,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
|
|||||||
`${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
|
`${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
|
||||||
`rm -rf ${outUsageDir} && ` +
|
`rm -rf ${outUsageDir} && ` +
|
||||||
`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
|
`$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{
|
CommandDeps: []string{
|
||||||
"${config.R8Cmd}",
|
"${config.R8Cmd}",
|
||||||
"${config.SoongZipCmd}",
|
"${config.SoongZipCmd}",
|
||||||
@@ -156,7 +159,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
|
|||||||
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
|
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
|
||||||
},
|
},
|
||||||
}, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir",
|
}, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir",
|
||||||
"r8Flags", "zipFlags"}, []string{"implicits"})
|
"r8Flags", "zipFlags", "mergeZipsFlags"}, []string{"implicits"})
|
||||||
|
|
||||||
func (d *dexer) dexCommonFlags(ctx android.ModuleContext, minSdkVersion android.SdkSpec) []string {
|
func (d *dexer) dexCommonFlags(ctx android.ModuleContext, minSdkVersion android.SdkSpec) []string {
|
||||||
flags := d.dexProperties.Dxflags
|
flags := d.dexProperties.Dxflags
|
||||||
@@ -281,6 +284,12 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
|
|
||||||
commonFlags := d.dexCommonFlags(ctx, minSdkVersion)
|
commonFlags := 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()
|
useR8 := d.effectiveOptimizeEnabled()
|
||||||
if useR8 {
|
if useR8 {
|
||||||
proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
|
proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
|
||||||
@@ -300,6 +309,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
"outUsage": proguardUsage.String(),
|
"outUsage": proguardUsage.String(),
|
||||||
"outUsageZip": proguardUsageZip.String(),
|
"outUsageZip": proguardUsageZip.String(),
|
||||||
"outDir": outDir.String(),
|
"outDir": outDir.String(),
|
||||||
|
"mergeZipsFlags": mergeZipsFlags,
|
||||||
}
|
}
|
||||||
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") {
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") {
|
||||||
rule = r8RE
|
rule = r8RE
|
||||||
@@ -330,6 +340,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
"d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
|
"d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
|
||||||
"zipFlags": zipFlags,
|
"zipFlags": zipFlags,
|
||||||
"outDir": outDir.String(),
|
"outDir": outDir.String(),
|
||||||
|
"mergeZipsFlags": mergeZipsFlags,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,7 @@ func TestJavaSdkLibrary(t *testing.T) {
|
|||||||
name: "bar",
|
name: "bar",
|
||||||
srcs: ["a.java", "b.java"],
|
srcs: ["a.java", "b.java"],
|
||||||
api_packages: ["bar"],
|
api_packages: ["bar"],
|
||||||
|
exclude_kotlinc_generated_files: true,
|
||||||
}
|
}
|
||||||
java_library {
|
java_library {
|
||||||
name: "baz",
|
name: "baz",
|
||||||
@@ -159,6 +160,14 @@ func TestJavaSdkLibrary(t *testing.T) {
|
|||||||
sdkLibs := quxLib.ClassLoaderContexts().UsesLibs()
|
sdkLibs := quxLib.ClassLoaderContexts().UsesLibs()
|
||||||
android.AssertDeepEquals(t, "qux exports", []string{"foo", "bar", "fred", "quuz"}, sdkLibs)
|
android.AssertDeepEquals(t, "qux exports", []string{"foo", "bar", "fred", "quuz"}, sdkLibs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_StubOrImplOnlyLibs(t *testing.T) {
|
func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user