java_sdk_library: Only expose impl jars when they are built am: daaa332827

Change-Id: I18f5be5e66fca6c1185b5c3f92d790a2fee8b3c2
This commit is contained in:
Paul Duffin
2020-05-26 21:49:02 +00:00
committed by Automerger Merge Worker
2 changed files with 38 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"regexp"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@@ -1261,6 +1262,31 @@ func TestJavaSdkLibrary(t *testing.T) {
} }
} }
func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) {
ctx, _ := testJava(t, `
java_sdk_library {
name: "foo",
srcs: ["a.java"],
api_only: true,
public: {
enabled: true,
},
}
java_library {
name: "bar",
srcs: ["b.java"],
libs: ["foo"],
}
`)
// The bar library should depend on the stubs jar.
barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac")
if expected, actual := `^-classpath .*:/[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) {
t.Errorf("expected %q, found %#q", expected, actual)
}
}
func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) { func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) {
testJava(t, ` testJava(t, `
java_sdk_library { java_sdk_library {

View File

@@ -1295,15 +1295,18 @@ func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) and
func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths { func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
// Check any special cases for java_sdk_library. // Only provide access to the implementation library if it is actually built.
// if module.requiresRuntimeImplementationLibrary() {
// Only allow access to the implementation library in the following condition: // Check any special cases for java_sdk_library.
// * No sdk_version specified on the referencing module. //
if sdkVersion.kind == sdkPrivate { // Only allow access to the implementation library in the following condition:
if headerJars { // * No sdk_version specified on the referencing module.
return module.HeaderJars() if sdkVersion.kind == sdkPrivate {
} else { if headerJars {
return module.ImplementationJars() return module.HeaderJars()
} else {
return module.ImplementationJars()
}
} }
} }