Merge "java_sdk_library_import: Copy all prebuilt properties to child modules"
This commit is contained in:
@@ -56,7 +56,9 @@ func (t prebuiltDependencyTag) ExcludeFromApexContents() {}
|
|||||||
var _ ExcludeFromVisibilityEnforcementTag = PrebuiltDepTag
|
var _ ExcludeFromVisibilityEnforcementTag = PrebuiltDepTag
|
||||||
var _ ExcludeFromApexContentsTag = PrebuiltDepTag
|
var _ ExcludeFromApexContentsTag = PrebuiltDepTag
|
||||||
|
|
||||||
type PrebuiltProperties struct {
|
// UserSuppliedPrebuiltProperties contains the prebuilt properties that can be specified in an
|
||||||
|
// Android.bp file.
|
||||||
|
type UserSuppliedPrebuiltProperties struct {
|
||||||
// When prefer is set to true the prebuilt will be used instead of any source module with
|
// When prefer is set to true the prebuilt will be used instead of any source module with
|
||||||
// a matching name.
|
// a matching name.
|
||||||
Prefer *bool `android:"arch_variant"`
|
Prefer *bool `android:"arch_variant"`
|
||||||
@@ -70,6 +72,16 @@ type PrebuiltProperties struct {
|
|||||||
// If specified then the prefer property is ignored in favor of the value of the Soong config
|
// If specified then the prefer property is ignored in favor of the value of the Soong config
|
||||||
// variable.
|
// variable.
|
||||||
Use_source_config_var *ConfigVarProperties
|
Use_source_config_var *ConfigVarProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
// CopyUserSuppliedPropertiesFromPrebuilt copies the user supplied prebuilt properties from the
|
||||||
|
// prebuilt properties.
|
||||||
|
func (u *UserSuppliedPrebuiltProperties) CopyUserSuppliedPropertiesFromPrebuilt(p *Prebuilt) {
|
||||||
|
*u = p.properties.UserSuppliedPrebuiltProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
type PrebuiltProperties struct {
|
||||||
|
UserSuppliedPrebuiltProperties
|
||||||
|
|
||||||
SourceExists bool `blueprint:"mutated"`
|
SourceExists bool `blueprint:"mutated"`
|
||||||
UsePrebuilt bool `blueprint:"mutated"`
|
UsePrebuilt bool `blueprint:"mutated"`
|
||||||
|
@@ -2236,8 +2236,9 @@ func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl
|
|||||||
Sdk_version *string
|
Sdk_version *string
|
||||||
Libs []string
|
Libs []string
|
||||||
Jars []string
|
Jars []string
|
||||||
Prefer *bool
|
|
||||||
Compile_dex *bool
|
Compile_dex *bool
|
||||||
|
|
||||||
|
android.UserSuppliedPrebuiltProperties
|
||||||
}{}
|
}{}
|
||||||
props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
|
props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
|
||||||
props.Sdk_version = scopeProperties.Sdk_version
|
props.Sdk_version = scopeProperties.Sdk_version
|
||||||
@@ -2247,7 +2248,7 @@ func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl
|
|||||||
props.Jars = scopeProperties.Jars
|
props.Jars = scopeProperties.Jars
|
||||||
|
|
||||||
// The imports are preferred if the java_sdk_library_import is preferred.
|
// The imports are preferred if the java_sdk_library_import is preferred.
|
||||||
props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
|
props.CopyUserSuppliedPropertiesFromPrebuilt(&module.prebuilt)
|
||||||
|
|
||||||
// The imports need to be compiled to dex if the java_sdk_library_import requests it.
|
// The imports need to be compiled to dex if the java_sdk_library_import requests it.
|
||||||
compileDex := module.properties.Compile_dex
|
compileDex := module.properties.Compile_dex
|
||||||
@@ -2261,16 +2262,18 @@ func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl
|
|||||||
|
|
||||||
func (module *SdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
|
func (module *SdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
|
||||||
props := struct {
|
props := struct {
|
||||||
Name *string
|
Name *string
|
||||||
Srcs []string
|
Srcs []string
|
||||||
Prefer *bool
|
|
||||||
|
android.UserSuppliedPrebuiltProperties
|
||||||
}{}
|
}{}
|
||||||
props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope))
|
props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope))
|
||||||
props.Srcs = scopeProperties.Stub_srcs
|
props.Srcs = scopeProperties.Stub_srcs
|
||||||
mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
|
|
||||||
|
|
||||||
// The stubs source is preferred if the java_sdk_library_import is preferred.
|
// The stubs source is preferred if the java_sdk_library_import is preferred.
|
||||||
props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
|
props.CopyUserSuppliedPropertiesFromPrebuilt(&module.prebuilt)
|
||||||
|
|
||||||
|
mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the dependencies on the child module in the component deps mutator so that it
|
// Add the dependencies on the child module in the component deps mutator so that it
|
||||||
|
@@ -875,11 +875,12 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
|
func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer android.FixturePreparer) {
|
||||||
result := android.GroupFixturePreparers(
|
result := android.GroupFixturePreparers(
|
||||||
prepareForJavaTest,
|
prepareForJavaTest,
|
||||||
PrepareForTestWithJavaSdkLibraryFiles,
|
PrepareForTestWithJavaSdkLibraryFiles,
|
||||||
FixtureWithLastReleaseApis("sdklib"),
|
FixtureWithLastReleaseApis("sdklib"),
|
||||||
|
preparer,
|
||||||
).RunTestWithBp(t, `
|
).RunTestWithBp(t, `
|
||||||
java_sdk_library {
|
java_sdk_library {
|
||||||
name: "sdklib",
|
name: "sdklib",
|
||||||
@@ -893,11 +894,37 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
|
|||||||
|
|
||||||
java_sdk_library_import {
|
java_sdk_library_import {
|
||||||
name: "sdklib",
|
name: "sdklib",
|
||||||
prefer: true,
|
`+prefer+`
|
||||||
public: {
|
public: {
|
||||||
jars: ["a.jar"],
|
jars: ["a.jar"],
|
||||||
|
stub_srcs: ["a.java"],
|
||||||
|
current_api: "current.txt",
|
||||||
|
removed_api: "removed.txt",
|
||||||
|
annotations: "annotations.zip",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java_library {
|
||||||
|
name: "combined",
|
||||||
|
static_libs: [
|
||||||
|
"sdklib.stubs",
|
||||||
|
],
|
||||||
|
java_resources: [
|
||||||
|
":sdklib.stubs.source",
|
||||||
|
":sdklib{.public.api.txt}",
|
||||||
|
":sdklib{.public.removed-api.txt}",
|
||||||
|
":sdklib{.public.annotations.zip}",
|
||||||
|
],
|
||||||
|
sdk_version: "none",
|
||||||
|
system_modules: "none",
|
||||||
|
}
|
||||||
|
|
||||||
|
java_library {
|
||||||
|
name: "public",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
libs: ["sdklib"],
|
||||||
|
sdk_version: "current",
|
||||||
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{
|
CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{
|
||||||
@@ -913,9 +940,48 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
|
|||||||
CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{
|
CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{
|
||||||
`dex2oatd`,
|
`dex2oatd`,
|
||||||
`prebuilt_sdklib.stubs`,
|
`prebuilt_sdklib.stubs`,
|
||||||
|
`prebuilt_sdklib.stubs.source`,
|
||||||
`sdklib.impl`,
|
`sdklib.impl`,
|
||||||
`sdklib.xml`,
|
`sdklib.xml`,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Make sure that dependencies on child modules use the prebuilt when preferred.
|
||||||
|
CheckModuleDependencies(t, result.TestContext, "combined", "android_common", []string{
|
||||||
|
// Each use of :sdklib{...} adds a dependency onto prebuilt_sdklib.
|
||||||
|
`prebuilt_sdklib`,
|
||||||
|
`prebuilt_sdklib`,
|
||||||
|
`prebuilt_sdklib`,
|
||||||
|
`prebuilt_sdklib.stubs`,
|
||||||
|
`prebuilt_sdklib.stubs.source`,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Make sure that dependencies on sdklib that resolve to one of the child libraries use the
|
||||||
|
// prebuilt library.
|
||||||
|
public := result.ModuleForTests("public", "android_common")
|
||||||
|
rule := public.Output("javac/public.jar")
|
||||||
|
inputs := rule.Implicits.Strings()
|
||||||
|
expected := "out/soong/.intermediates/prebuilt_sdklib.stubs/android_common/combined/sdklib.stubs.jar"
|
||||||
|
if !android.InList(expected, inputs) {
|
||||||
|
t.Errorf("expected %q to contain %q", inputs, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
|
||||||
|
t.Run("prefer", func(t *testing.T) {
|
||||||
|
testJavaSdkLibraryImport_Preferred(t, "prefer: true,", android.NullFixturePreparer)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("use_source_config_var", func(t *testing.T) {
|
||||||
|
testJavaSdkLibraryImport_Preferred(t,
|
||||||
|
"use_source_config_var: {config_namespace: \"acme\", var_name: \"use_source\"},",
|
||||||
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||||
|
variables.VendorVars = map[string]map[string]string{
|
||||||
|
"acme": {
|
||||||
|
"use_source": "false",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJavaSdkLibraryEnforce(t *testing.T) {
|
func TestJavaSdkLibraryEnforce(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user