Merge "Refactor the hiddenAPI() method for reusability" am: b71a8de0d5
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1578284 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Idc65c3755267c37f2054cbd7db053927b239846a
This commit is contained in:
@@ -4495,6 +4495,12 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkHiddenAPIIndexInputs := func(t *testing.T, ctx *android.TestContext, expectedInputs string) {
|
||||||
|
hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index")
|
||||||
|
indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index")
|
||||||
|
java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule)
|
||||||
|
}
|
||||||
|
|
||||||
t.Run("prebuilt only", func(t *testing.T) {
|
t.Run("prebuilt only", func(t *testing.T) {
|
||||||
bp := `
|
bp := `
|
||||||
prebuilt_apex {
|
prebuilt_apex {
|
||||||
@@ -4519,6 +4525,10 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
ctx := testDexpreoptWithApexes(t, bp, "", transform)
|
ctx := testDexpreoptWithApexes(t, bp, "", transform)
|
||||||
checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
|
checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
|
||||||
|
|
||||||
|
// Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index
|
||||||
|
// file.
|
||||||
|
checkHiddenAPIIndexInputs(t, ctx, ``)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("prebuilt with source library preferred", func(t *testing.T) {
|
t.Run("prebuilt with source library preferred", func(t *testing.T) {
|
||||||
@@ -4588,6 +4598,10 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
ctx := testDexpreoptWithApexes(t, bp, "", transform)
|
ctx := testDexpreoptWithApexes(t, bp, "", transform)
|
||||||
checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
|
checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
|
||||||
|
|
||||||
|
// Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index
|
||||||
|
// file.
|
||||||
|
checkHiddenAPIIndexInputs(t, ctx, ``)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("prebuilt with source apex preferred", func(t *testing.T) {
|
t.Run("prebuilt with source apex preferred", func(t *testing.T) {
|
||||||
@@ -4632,6 +4646,11 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
ctx := testDexpreoptWithApexes(t, bp, "", transform)
|
ctx := testDexpreoptWithApexes(t, bp, "", transform)
|
||||||
checkBootDexJarPath(t, ctx, ".intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar")
|
checkBootDexJarPath(t, ctx, ".intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar")
|
||||||
|
|
||||||
|
// Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file.
|
||||||
|
checkHiddenAPIIndexInputs(t, ctx, `
|
||||||
|
.intermediates/libfoo/android_common_apex10000/hiddenapi/index.csv
|
||||||
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) {
|
t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) {
|
||||||
@@ -4678,6 +4697,10 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
ctx := testDexpreoptWithApexes(t, bp, "", transform)
|
ctx := testDexpreoptWithApexes(t, bp, "", transform)
|
||||||
checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
|
checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
|
||||||
|
|
||||||
|
// Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index
|
||||||
|
// file.
|
||||||
|
checkHiddenAPIIndexInputs(t, ctx, ``)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6317,7 +6340,7 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreopt
|
|||||||
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
|
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
|
||||||
|
|
||||||
// Make sure that any changes to these dexpreopt properties are mirrored in the corresponding
|
// Make sure that any changes to these dexpreopt properties are mirrored in the corresponding
|
||||||
// product variables that are used by hiddenapi.
|
// product variables.
|
||||||
config.TestProductVariables.BootJars = dexpreoptConfig.BootJars
|
config.TestProductVariables.BootJars = dexpreoptConfig.BootJars
|
||||||
config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars
|
config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars
|
||||||
|
|
||||||
|
@@ -123,19 +123,21 @@ func (h *hiddenAPI) initHiddenAPI(ctx android.BaseModuleContext, name string) {
|
|||||||
h.annotationsOnly = strings.HasSuffix(name, "-hiddenapi")
|
h.annotationsOnly = strings.HasSuffix(name, "-hiddenapi")
|
||||||
}
|
}
|
||||||
|
|
||||||
// hiddenAPI is called by any module that could contribute to the hiddenapi processing.
|
// hiddenAPIExtractAndEncode is called by any module that could contribute to the hiddenapi
|
||||||
|
// processing.
|
||||||
//
|
//
|
||||||
// It ignores any module that has not had initHiddenApi() called on it and which is not in the boot
|
// It ignores any module that has not had initHiddenApi() called on it and which is not in the boot
|
||||||
// jar list.
|
// jar list.
|
||||||
//
|
//
|
||||||
// Otherwise, it generates ninja rules to do the following:
|
// Otherwise, it generates ninja rules to do the following:
|
||||||
// 1. Generates CSV files needed for hiddenapi processing.
|
// 1. Extract information needed for hiddenapi processing from the module and output it into CSV
|
||||||
|
// files.
|
||||||
// 2. Conditionally adds the supplied dex file to the list of files used to generate the
|
// 2. Conditionally adds the supplied dex file to the list of files used to generate the
|
||||||
// hiddenAPISingletonPathsStruct.stubsFlag file.
|
// hiddenAPISingletonPathsStruct.stubsFlag file.
|
||||||
// 3. Conditionally creates a copy of the supplied dex file into which it has encoded the hiddenapi
|
// 3. Conditionally creates a copy of the supplied dex file into which it has encoded the hiddenapi
|
||||||
// flags and returns this instead of the supplied dex jar, otherwise simply returns the supplied
|
// flags and returns this instead of the supplied dex jar, otherwise simply returns the supplied
|
||||||
// dex jar.
|
// dex jar.
|
||||||
func (h *hiddenAPI) hiddenAPI(ctx android.ModuleContext, name string, primary bool, dexJar android.OutputPath,
|
func (h *hiddenAPI) hiddenAPIExtractAndEncode(ctx android.ModuleContext, name string, primary bool, dexJar android.OutputPath,
|
||||||
implementationJar android.Path, uncompressDex bool) android.OutputPath {
|
implementationJar android.Path, uncompressDex bool) android.OutputPath {
|
||||||
|
|
||||||
if !h.active {
|
if !h.active {
|
||||||
@@ -146,13 +148,7 @@ func (h *hiddenAPI) hiddenAPI(ctx android.ModuleContext, name string, primary bo
|
|||||||
// used as a source of information for hidden API processing otherwise it will result in
|
// used as a source of information for hidden API processing otherwise it will result in
|
||||||
// duplicate entries in the files.
|
// duplicate entries in the files.
|
||||||
if primary {
|
if primary {
|
||||||
// Create ninja rules to generate various CSV files needed by hiddenapi and store the paths
|
h.hiddenAPIExtractInformation(ctx, dexJar, implementationJar)
|
||||||
// in the hiddenAPI structure.
|
|
||||||
h.hiddenAPIGenerateCSV(ctx, implementationJar)
|
|
||||||
|
|
||||||
// Save the unencoded dex jar so it can be used when generating the
|
|
||||||
// hiddenAPISingletonPathsStruct.stubFlags file.
|
|
||||||
h.bootDexJarPath = dexJar
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !h.annotationsOnly {
|
if !h.annotationsOnly {
|
||||||
@@ -168,7 +164,12 @@ func (h *hiddenAPI) hiddenAPI(ctx android.ModuleContext, name string, primary bo
|
|||||||
return dexJar
|
return dexJar
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hiddenAPI) hiddenAPIGenerateCSV(ctx android.ModuleContext, classesJar android.Path) {
|
// hiddenAPIExtractInformation generates ninja rules to extract the information from the classes
|
||||||
|
// jar, and outputs it to the appropriate module specific CSV file.
|
||||||
|
//
|
||||||
|
// It also makes the dex jar available for use when generating the
|
||||||
|
// hiddenAPISingletonPathsStruct.stubFlags.
|
||||||
|
func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJar, classesJar android.Path) {
|
||||||
stubFlagsCSV := hiddenAPISingletonPaths(ctx).stubFlags
|
stubFlagsCSV := hiddenAPISingletonPaths(ctx).stubFlags
|
||||||
|
|
||||||
flagsCSV := android.PathForModuleOut(ctx, "hiddenapi", "flags.csv")
|
flagsCSV := android.PathForModuleOut(ctx, "hiddenapi", "flags.csv")
|
||||||
@@ -207,6 +208,10 @@ func (h *hiddenAPI) hiddenAPIGenerateCSV(ctx android.ModuleContext, classesJar a
|
|||||||
FlagWithOutput("--output=", indexCSV)
|
FlagWithOutput("--output=", indexCSV)
|
||||||
rule.Build("merged-hiddenapi-index", "Merged Hidden API index")
|
rule.Build("merged-hiddenapi-index", "Merged Hidden API index")
|
||||||
h.indexCSVPath = indexCSV
|
h.indexCSVPath = indexCSV
|
||||||
|
|
||||||
|
// Save the unencoded dex jar so it can be used when generating the
|
||||||
|
// hiddenAPISingletonPathsStruct.stubFlags file.
|
||||||
|
h.bootDexJarPath = dexJar
|
||||||
}
|
}
|
||||||
|
|
||||||
var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", blueprint.RuleParams{
|
var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", blueprint.RuleParams{
|
||||||
|
@@ -76,14 +76,6 @@ func TestHiddenAPISingleton(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkRuleInputs(t *testing.T, expected string, hiddenAPIRule android.TestingBuildParams) {
|
|
||||||
actual := strings.TrimSpace(strings.Join(android.NormalizePathsForTesting(hiddenAPIRule.Implicits), "\n"))
|
|
||||||
expected = strings.TrimSpace(expected)
|
|
||||||
if actual != expected {
|
|
||||||
t.Errorf("Expected hiddenapi rule inputs:\n%s\nactual inputs:\n%s", expected, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHiddenAPIIndexSingleton(t *testing.T) {
|
func TestHiddenAPIIndexSingleton(t *testing.T) {
|
||||||
ctx, _ := testHiddenAPIBootJars(t, `
|
ctx, _ := testHiddenAPIBootJars(t, `
|
||||||
java_library {
|
java_library {
|
||||||
@@ -108,7 +100,7 @@ func TestHiddenAPIIndexSingleton(t *testing.T) {
|
|||||||
|
|
||||||
hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index")
|
hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index")
|
||||||
indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index")
|
indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index")
|
||||||
checkRuleInputs(t, `
|
CheckHiddenAPIRuleInputs(t, `
|
||||||
.intermediates/bar/android_common/hiddenapi/index.csv
|
.intermediates/bar/android_common/hiddenapi/index.csv
|
||||||
.intermediates/foo/android_common/hiddenapi/index.csv
|
.intermediates/foo/android_common/hiddenapi/index.csv
|
||||||
`,
|
`,
|
||||||
|
@@ -1805,7 +1805,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
|||||||
primary = primary && !j.IsReplacedByPrebuilt()
|
primary = primary && !j.IsReplacedByPrebuilt()
|
||||||
|
|
||||||
// Hidden API CSV generation and dex encoding
|
// Hidden API CSV generation and dex encoding
|
||||||
dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, configurationName, primary, dexOutputFile, j.implementationJarFile,
|
dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, configurationName, primary, dexOutputFile, j.implementationJarFile,
|
||||||
proptools.Bool(j.dexProperties.Uncompress_dex))
|
proptools.Bool(j.dexProperties.Uncompress_dex))
|
||||||
|
|
||||||
// merge dex jar with resources if necessary
|
// merge dex jar with resources if necessary
|
||||||
@@ -2965,7 +2965,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
primary := j.Prebuilt().UsePrebuilt()
|
primary := j.Prebuilt().UsePrebuilt()
|
||||||
|
|
||||||
// Hidden API CSV generation and dex encoding
|
// Hidden API CSV generation and dex encoding
|
||||||
dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, configurationName, primary, dexOutputFile, outputFile,
|
dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, configurationName, primary, dexOutputFile, outputFile,
|
||||||
proptools.Bool(j.dexProperties.Uncompress_dex))
|
proptools.Bool(j.dexProperties.Uncompress_dex))
|
||||||
|
|
||||||
j.dexJarFile = dexOutputFile
|
j.dexJarFile = dexOutputFile
|
||||||
|
@@ -18,6 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
@@ -237,3 +238,11 @@ func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, varia
|
|||||||
t.Errorf("expected %#q, found %#q", expected, actual)
|
t.Errorf("expected %#q, found %#q", expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckHiddenAPIRuleInputs(t *testing.T, expected string, hiddenAPIRule android.TestingBuildParams) {
|
||||||
|
actual := strings.TrimSpace(strings.Join(android.NormalizePathsForTesting(hiddenAPIRule.Implicits), "\n"))
|
||||||
|
expected = strings.TrimSpace(expected)
|
||||||
|
if actual != expected {
|
||||||
|
t.Errorf("Expected hiddenapi rule inputs:\n%s\nactual inputs:\n%s", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user