Loading java/java_test.go +33 −0 Original line number Diff line number Diff line Loading @@ -1580,6 +1580,39 @@ func TestJavaSdkLibrary(t *testing.T) { } } func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { ctx, _ := testJava(t, ` java_sdk_library { name: "sdk_lib", srcs: ["a.java"], impl_only_libs: ["foo"], stub_only_libs: ["bar"], } java_library { name: "foo", srcs: ["a.java"], sdk_version: "current", } java_library { name: "bar", srcs: ["a.java"], sdk_version: "current", } `) for _, implName := range []string{"sdk_lib", "sdk_lib.impl"} { implJavacCp := ctx.ModuleForTests(implName, "android_common").Rule("javac").Args["classpath"] if !strings.Contains(implJavacCp, "/foo.jar") || strings.Contains(implJavacCp, "/bar.jar") { t.Errorf("%v javac classpath %v does not contain foo and not bar", implName, implJavacCp) } } stubName := apiScopePublic.stubsLibraryModuleName("sdk_lib") stubsJavacCp := ctx.ModuleForTests(stubName, "android_common").Rule("javac").Args["classpath"] if strings.Contains(stubsJavacCp, "/foo.jar") || !strings.Contains(stubsJavacCp, "/bar.jar") { t.Errorf("stubs javac classpath %v does not contain bar and not foo", stubsJavacCp) } } func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { ctx, _ := testJava(t, ` java_sdk_library { Loading java/sdk_library.go +10 −0 Original line number Diff line number Diff line Loading @@ -388,6 +388,9 @@ type sdkLibraryProperties struct { // visibility property. Stubs_source_visibility []string // List of Java libraries that will be in the classpath when building the implementation lib Impl_only_libs []string `android:"arch_variant"` // List of Java libraries that will be in the classpath when building stubs Stub_only_libs []string `android:"arch_variant"` Loading Loading @@ -1137,12 +1140,16 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) Name *string Visibility []string Instrument bool Libs []string ConfigurationName *string }{ Name: proptools.StringPtr(module.implLibraryModuleName()), Visibility: visibility, // Set the instrument property to ensure it is instrumented when instrumentation is required. Instrument: true, // Set the impl_only libs. Note that the module's "Libs" get appended as well, via the // addition of &module.properties below. Libs: module.sdkLibraryProperties.Impl_only_libs, // Make the created library behave as if it had the same name as this module. ConfigurationName: moduleNamePtr, Loading Loading @@ -1565,6 +1572,9 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookCont defer javaSdkLibrariesLock.Unlock() *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) } // Add the impl_only_libs *after* we're done using the Libs prop in submodules. module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) } func (module *SdkLibrary) InitSdkLibraryProperties() { Loading Loading
java/java_test.go +33 −0 Original line number Diff line number Diff line Loading @@ -1580,6 +1580,39 @@ func TestJavaSdkLibrary(t *testing.T) { } } func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { ctx, _ := testJava(t, ` java_sdk_library { name: "sdk_lib", srcs: ["a.java"], impl_only_libs: ["foo"], stub_only_libs: ["bar"], } java_library { name: "foo", srcs: ["a.java"], sdk_version: "current", } java_library { name: "bar", srcs: ["a.java"], sdk_version: "current", } `) for _, implName := range []string{"sdk_lib", "sdk_lib.impl"} { implJavacCp := ctx.ModuleForTests(implName, "android_common").Rule("javac").Args["classpath"] if !strings.Contains(implJavacCp, "/foo.jar") || strings.Contains(implJavacCp, "/bar.jar") { t.Errorf("%v javac classpath %v does not contain foo and not bar", implName, implJavacCp) } } stubName := apiScopePublic.stubsLibraryModuleName("sdk_lib") stubsJavacCp := ctx.ModuleForTests(stubName, "android_common").Rule("javac").Args["classpath"] if strings.Contains(stubsJavacCp, "/foo.jar") || !strings.Contains(stubsJavacCp, "/bar.jar") { t.Errorf("stubs javac classpath %v does not contain bar and not foo", stubsJavacCp) } } func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { ctx, _ := testJava(t, ` java_sdk_library { Loading
java/sdk_library.go +10 −0 Original line number Diff line number Diff line Loading @@ -388,6 +388,9 @@ type sdkLibraryProperties struct { // visibility property. Stubs_source_visibility []string // List of Java libraries that will be in the classpath when building the implementation lib Impl_only_libs []string `android:"arch_variant"` // List of Java libraries that will be in the classpath when building stubs Stub_only_libs []string `android:"arch_variant"` Loading Loading @@ -1137,12 +1140,16 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) Name *string Visibility []string Instrument bool Libs []string ConfigurationName *string }{ Name: proptools.StringPtr(module.implLibraryModuleName()), Visibility: visibility, // Set the instrument property to ensure it is instrumented when instrumentation is required. Instrument: true, // Set the impl_only libs. Note that the module's "Libs" get appended as well, via the // addition of &module.properties below. Libs: module.sdkLibraryProperties.Impl_only_libs, // Make the created library behave as if it had the same name as this module. ConfigurationName: moduleNamePtr, Loading Loading @@ -1565,6 +1572,9 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookCont defer javaSdkLibrariesLock.Unlock() *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) } // Add the impl_only_libs *after* we're done using the Libs prop in submodules. module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) } func (module *SdkLibrary) InitSdkLibraryProperties() { Loading