Disallow shared libraries in bootclasspath_fragment contents
Bug: 177892522 Test: m nothing Change-Id: I78c8ef8664ec1eb0fe3456a2de2cb956162ca0da
This commit is contained in:
@@ -372,8 +372,12 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo
|
|||||||
ctx.VisitDirectDeps(func(module android.Module) {
|
ctx.VisitDirectDeps(func(module android.Module) {
|
||||||
tag := ctx.OtherModuleDependencyTag(module)
|
tag := ctx.OtherModuleDependencyTag(module)
|
||||||
if IsBootclasspathFragmentContentDepTag(tag) {
|
if IsBootclasspathFragmentContentDepTag(tag) {
|
||||||
|
if sdkLibrary, ok := module.(SdkLibraryDependency); ok && sdkLibrary.sharedLibrary() {
|
||||||
|
ctx.PropertyErrorf("contents", "invalid module: %s, shared libraries cannot be on the bootclasspath", ctx.OtherModuleName(module))
|
||||||
|
} else {
|
||||||
contents = append(contents, module)
|
contents = append(contents, module)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Perform hidden API processing.
|
// Perform hidden API processing.
|
||||||
|
@@ -231,7 +231,7 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
|
|||||||
java_sdk_library {
|
java_sdk_library {
|
||||||
name: "mysdklibrary",
|
name: "mysdklibrary",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
compile_dex: true,
|
shared_library: false,
|
||||||
public: {enabled: true},
|
public: {enabled: true},
|
||||||
system: {enabled: true},
|
system: {enabled: true},
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
|
|||||||
java_sdk_library {
|
java_sdk_library {
|
||||||
name: "mycoreplatform",
|
name: "mycoreplatform",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
compile_dex: true,
|
shared_library: false,
|
||||||
public: {enabled: true},
|
public: {enabled: true},
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
@@ -900,11 +900,17 @@ func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() in
|
|||||||
return componentProps
|
return componentProps
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this can be used as a shared library.
|
|
||||||
func (c *commonToSdkLibraryAndImport) sharedLibrary() bool {
|
func (c *commonToSdkLibraryAndImport) sharedLibrary() bool {
|
||||||
return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true)
|
return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the stub libraries should be compiled for dex
|
||||||
|
func (c *commonToSdkLibraryAndImport) stubLibrariesCompiledForDex() bool {
|
||||||
|
// Always compile the dex file files for the stub libraries if they will be used on the
|
||||||
|
// bootclasspath.
|
||||||
|
return !c.sharedLibrary()
|
||||||
|
}
|
||||||
|
|
||||||
// Properties related to the use of a module as an component of a java_sdk_library.
|
// Properties related to the use of a module as an component of a java_sdk_library.
|
||||||
type SdkLibraryComponentProperties struct {
|
type SdkLibraryComponentProperties struct {
|
||||||
|
|
||||||
@@ -978,6 +984,9 @@ type SdkLibraryDependency interface {
|
|||||||
// SdkApiStubDexJar returns the dex jar for the stubs. It is needed by the hiddenapi processing
|
// SdkApiStubDexJar returns the dex jar for the stubs. It is needed by the hiddenapi processing
|
||||||
// tool which processes dex files.
|
// tool which processes dex files.
|
||||||
SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) android.Path
|
SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) android.Path
|
||||||
|
|
||||||
|
// sharedLibrary returns true if this can be used as a shared library.
|
||||||
|
sharedLibrary() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type SdkLibrary struct {
|
type SdkLibrary struct {
|
||||||
@@ -1309,9 +1318,13 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext
|
|||||||
// We compile the stubs for 1.8 in line with the main android.jar stubs, and potential
|
// We compile the stubs for 1.8 in line with the main android.jar stubs, and potential
|
||||||
// interop with older developer tools that don't support 1.9.
|
// interop with older developer tools that don't support 1.9.
|
||||||
props.Java_version = proptools.StringPtr("1.8")
|
props.Java_version = proptools.StringPtr("1.8")
|
||||||
if module.dexProperties.Compile_dex != nil {
|
|
||||||
props.Compile_dex = module.dexProperties.Compile_dex
|
// The imports need to be compiled to dex if the java_sdk_library requests it.
|
||||||
|
compileDex := module.dexProperties.Compile_dex
|
||||||
|
if module.stubLibrariesCompiledForDex() {
|
||||||
|
compileDex = proptools.BoolPtr(true)
|
||||||
}
|
}
|
||||||
|
props.Compile_dex = compileDex
|
||||||
|
|
||||||
// Dist the class jar artifact for sdk builds.
|
// Dist the class jar artifact for sdk builds.
|
||||||
if !Bool(module.sdkLibraryProperties.No_dist) {
|
if !Bool(module.sdkLibraryProperties.No_dist) {
|
||||||
@@ -1969,7 +1982,11 @@ func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl
|
|||||||
props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
|
props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
|
||||||
|
|
||||||
// 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.
|
||||||
props.Compile_dex = module.properties.Compile_dex
|
compileDex := module.properties.Compile_dex
|
||||||
|
if module.stubLibrariesCompiledForDex() {
|
||||||
|
compileDex = proptools.BoolPtr(true)
|
||||||
|
}
|
||||||
|
props.Compile_dex = compileDex
|
||||||
|
|
||||||
mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary())
|
mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary())
|
||||||
}
|
}
|
||||||
|
@@ -207,21 +207,21 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
|
|||||||
java_sdk_library {
|
java_sdk_library {
|
||||||
name: "mysdklibrary",
|
name: "mysdklibrary",
|
||||||
srcs: ["Test.java"],
|
srcs: ["Test.java"],
|
||||||
compile_dex: true,
|
shared_library: false,
|
||||||
public: {enabled: true},
|
public: {enabled: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
java_sdk_library {
|
java_sdk_library {
|
||||||
name: "myothersdklibrary",
|
name: "myothersdklibrary",
|
||||||
srcs: ["Test.java"],
|
srcs: ["Test.java"],
|
||||||
compile_dex: true,
|
shared_library: false,
|
||||||
public: {enabled: true},
|
public: {enabled: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
java_sdk_library {
|
java_sdk_library {
|
||||||
name: "mycoreplatform",
|
name: "mycoreplatform",
|
||||||
srcs: ["Test.java"],
|
srcs: ["Test.java"],
|
||||||
compile_dex: true,
|
shared_library: false,
|
||||||
public: {enabled: true},
|
public: {enabled: true},
|
||||||
}
|
}
|
||||||
`),
|
`),
|
||||||
@@ -261,8 +261,7 @@ java_sdk_library_import {
|
|||||||
prefer: false,
|
prefer: false,
|
||||||
visibility: ["//visibility:public"],
|
visibility: ["//visibility:public"],
|
||||||
apex_available: ["//apex_available:platform"],
|
apex_available: ["//apex_available:platform"],
|
||||||
shared_library: true,
|
shared_library: false,
|
||||||
compile_dex: true,
|
|
||||||
public: {
|
public: {
|
||||||
jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
|
jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
|
||||||
stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
|
stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
|
||||||
@@ -277,8 +276,7 @@ java_sdk_library_import {
|
|||||||
prefer: false,
|
prefer: false,
|
||||||
visibility: ["//visibility:public"],
|
visibility: ["//visibility:public"],
|
||||||
apex_available: ["//apex_available:platform"],
|
apex_available: ["//apex_available:platform"],
|
||||||
shared_library: true,
|
shared_library: false,
|
||||||
compile_dex: true,
|
|
||||||
public: {
|
public: {
|
||||||
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
|
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
|
||||||
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
|
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
|
||||||
@@ -293,8 +291,7 @@ java_sdk_library_import {
|
|||||||
prefer: false,
|
prefer: false,
|
||||||
visibility: ["//visibility:public"],
|
visibility: ["//visibility:public"],
|
||||||
apex_available: ["//apex_available:platform"],
|
apex_available: ["//apex_available:platform"],
|
||||||
shared_library: true,
|
shared_library: false,
|
||||||
compile_dex: true,
|
|
||||||
public: {
|
public: {
|
||||||
jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
|
jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
|
||||||
stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
|
stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
|
||||||
@@ -337,8 +334,7 @@ java_sdk_library_import {
|
|||||||
sdk_member_name: "myothersdklibrary",
|
sdk_member_name: "myothersdklibrary",
|
||||||
visibility: ["//visibility:public"],
|
visibility: ["//visibility:public"],
|
||||||
apex_available: ["//apex_available:platform"],
|
apex_available: ["//apex_available:platform"],
|
||||||
shared_library: true,
|
shared_library: false,
|
||||||
compile_dex: true,
|
|
||||||
public: {
|
public: {
|
||||||
jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
|
jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
|
||||||
stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
|
stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
|
||||||
@@ -353,8 +349,7 @@ java_sdk_library_import {
|
|||||||
sdk_member_name: "mysdklibrary",
|
sdk_member_name: "mysdklibrary",
|
||||||
visibility: ["//visibility:public"],
|
visibility: ["//visibility:public"],
|
||||||
apex_available: ["//apex_available:platform"],
|
apex_available: ["//apex_available:platform"],
|
||||||
shared_library: true,
|
shared_library: false,
|
||||||
compile_dex: true,
|
|
||||||
public: {
|
public: {
|
||||||
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
|
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
|
||||||
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
|
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
|
||||||
@@ -369,8 +364,7 @@ java_sdk_library_import {
|
|||||||
sdk_member_name: "mycoreplatform",
|
sdk_member_name: "mycoreplatform",
|
||||||
visibility: ["//visibility:public"],
|
visibility: ["//visibility:public"],
|
||||||
apex_available: ["//apex_available:platform"],
|
apex_available: ["//apex_available:platform"],
|
||||||
shared_library: true,
|
shared_library: false,
|
||||||
compile_dex: true,
|
|
||||||
public: {
|
public: {
|
||||||
jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
|
jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
|
||||||
stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
|
stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
|
||||||
|
Reference in New Issue
Block a user