2017-07-14 01:23:21 +02:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2020-11-18 17:36:47 +01:00
|
|
|
"fmt"
|
2017-07-14 01:23:21 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2019-06-15 03:51:47 +02:00
|
|
|
"reflect"
|
2020-05-26 19:13:57 +02:00
|
|
|
"regexp"
|
2017-11-02 21:28:15 +01:00
|
|
|
"strconv"
|
2017-07-14 01:23:21 +02:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-05-29 23:44:55 +02:00
|
|
|
|
2021-03-05 00:02:31 +01:00
|
|
|
"android/soong/genrule"
|
2019-11-11 02:46:36 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
2018-10-03 07:03:40 +02:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
2019-02-25 23:20:47 +01:00
|
|
|
"android/soong/dexpreopt"
|
2020-06-13 01:38:45 +02:00
|
|
|
"android/soong/python"
|
2017-07-14 01:23:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var buildDir string
|
|
|
|
|
|
|
|
func setUp() {
|
|
|
|
var err error
|
|
|
|
buildDir, err = ioutil.TempDir("", "soong_java_test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func tearDown() {
|
|
|
|
os.RemoveAll(buildDir)
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// Factory to use to create fixtures for tests in this package.
|
|
|
|
var javaFixtureFactory = android.NewFixtureFactory(
|
|
|
|
&buildDir,
|
|
|
|
genrule.PrepareForTestWithGenRuleBuildComponents,
|
|
|
|
// Get the CC build components but not default modules.
|
|
|
|
cc.PrepareForTestWithCcBuildComponents,
|
|
|
|
// Include all the default java modules.
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("java_plugin", PluginFactory)
|
|
|
|
ctx.RegisterModuleType("python_binary_host", python.PythonBinaryHostFactory)
|
|
|
|
|
|
|
|
ctx.PreDepsMutators(python.RegisterPythonPreDepsMutators)
|
|
|
|
ctx.RegisterPreSingletonType("overlay", OverlaySingletonFactory)
|
|
|
|
ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory)
|
|
|
|
}),
|
|
|
|
javaMockFS().AddToFixture(),
|
2021-03-13 23:19:17 +01:00
|
|
|
PrepareForTestWithJavaSdkLibraryFiles,
|
2021-03-08 22:48:46 +01:00
|
|
|
dexpreopt.PrepareForTestWithDexpreopt,
|
|
|
|
)
|
|
|
|
|
2017-07-14 01:23:21 +02:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
run := func() int {
|
|
|
|
setUp()
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
return m.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Exit(run())
|
|
|
|
}
|
2017-12-01 07:56:16 +01:00
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// testConfig is a legacy way of creating a test Config for testing java modules.
|
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
2019-12-14 05:41:13 +01:00
|
|
|
func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
|
2021-01-21 16:05:11 +01:00
|
|
|
return TestConfig(buildDir, env, bp, fs)
|
2017-09-30 02:58:17 +02:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// testContext is a legacy way of creating a TestContext for testing java modules.
|
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
2020-10-30 01:09:13 +01:00
|
|
|
func testContext(config android.Config) *android.TestContext {
|
2017-07-14 01:23:21 +02:00
|
|
|
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx := android.NewTestArchContext(config)
|
2021-01-20 18:13:52 +01:00
|
|
|
RegisterRequiredBuildComponentsForTest(ctx)
|
2019-11-23 00:25:03 +01:00
|
|
|
ctx.RegisterModuleType("java_plugin", PluginFactory)
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
2020-06-13 01:38:45 +02:00
|
|
|
ctx.RegisterModuleType("python_binary_host", python.PythonBinaryHostFactory)
|
2017-07-07 23:35:50 +02:00
|
|
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
2020-06-26 21:17:02 +02:00
|
|
|
ctx.PreArchMutators(android.RegisterComponentsMutator)
|
2019-12-19 12:25:19 +01:00
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
ctx.PreDepsMutators(python.RegisterPythonPreDepsMutators)
|
2019-05-11 00:16:29 +02:00
|
|
|
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
|
2021-02-24 02:43:18 +01:00
|
|
|
ctx.RegisterPreSingletonType("overlay", OverlaySingletonFactory)
|
|
|
|
ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory)
|
2018-10-03 07:03:40 +02:00
|
|
|
|
2020-07-30 17:04:17 +02:00
|
|
|
android.RegisterPrebuiltMutators(ctx)
|
|
|
|
|
2021-03-05 00:02:31 +01:00
|
|
|
genrule.RegisterGenruleBuildComponents(ctx)
|
|
|
|
|
2018-10-03 07:03:40 +02:00
|
|
|
// Register module types and mutators from cc needed for JNI testing
|
2019-12-19 17:01:36 +01:00
|
|
|
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
2018-10-03 07:03:40 +02:00
|
|
|
|
2020-10-07 03:56:10 +02:00
|
|
|
ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.TopDown("propagate_rro_enforcement", propagateRROEnforcementMutator).Parallel()
|
|
|
|
})
|
|
|
|
|
2017-12-01 07:56:16 +01:00
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// run is a legacy way of running tests of java modules.
|
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
2017-12-01 07:56:16 +01:00
|
|
|
func run(t *testing.T, ctx *android.TestContext, config android.Config) {
|
2017-12-05 22:42:45 +01:00
|
|
|
t.Helper()
|
2019-02-25 23:20:47 +01:00
|
|
|
|
2019-12-14 05:41:13 +01:00
|
|
|
pathCtx := android.PathContextForTesting(config)
|
2020-01-20 19:12:23 +01:00
|
|
|
dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
|
2019-02-25 23:20:47 +01:00
|
|
|
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx.Register()
|
2019-06-11 12:58:30 +02:00
|
|
|
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
2018-03-12 09:29:17 +01:00
|
|
|
android.FailIfErrored(t, errs)
|
2017-07-14 01:23:21 +02:00
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
2018-03-12 09:29:17 +01:00
|
|
|
android.FailIfErrored(t, errs)
|
2017-12-01 07:56:16 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// testJavaError is a legacy way of running tests of java modules that expect errors.
|
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
2019-10-29 07:44:45 +01:00
|
|
|
func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) {
|
|
|
|
t.Helper()
|
2021-03-12 22:28:15 +01:00
|
|
|
result := javaFixtureFactory.
|
|
|
|
Extend(dexpreopt.PrepareForTestWithDexpreopt).
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
|
|
|
|
RunTestWithBp(t, bp)
|
|
|
|
return result.TestContext, result.Config
|
2019-10-29 07:44:45 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// testJavaErrorWithConfig is a legacy way of running tests of java modules that expect errors.
|
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
2019-12-14 05:41:13 +01:00
|
|
|
func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config) (*android.TestContext, android.Config) {
|
2019-07-11 08:54:27 +02:00
|
|
|
t.Helper()
|
2021-03-08 22:48:46 +01:00
|
|
|
// This must be done on the supplied config and not as part of the fixture because any changes to
|
|
|
|
// the fixture's config will be ignored when RunTestWithConfig replaces it.
|
2019-12-14 05:41:13 +01:00
|
|
|
pathCtx := android.PathContextForTesting(config)
|
2020-01-20 19:12:23 +01:00
|
|
|
dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
|
2021-03-08 22:48:46 +01:00
|
|
|
result := javaFixtureFactory.
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
|
|
|
|
RunTestWithConfig(t, config)
|
|
|
|
return result.TestContext, result.Config
|
2021-02-25 16:34:13 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// runWithErrors is a legacy way of running tests of java modules that expect errors.
|
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
2021-02-25 16:34:13 +01:00
|
|
|
func runWithErrors(t *testing.T, ctx *android.TestContext, config android.Config, pattern string) {
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx.Register()
|
2019-07-11 08:54:27 +02:00
|
|
|
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
|
|
|
if len(errs) > 0 {
|
|
|
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
2021-02-25 16:34:13 +01:00
|
|
|
return
|
2019-07-11 08:54:27 +02:00
|
|
|
}
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
if len(errs) > 0 {
|
|
|
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
2021-02-25 16:34:13 +01:00
|
|
|
return
|
2019-07-11 08:54:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
|
2021-02-25 16:34:13 +01:00
|
|
|
return
|
2019-07-11 08:54:27 +02:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// testJavaWithFS runs tests using the javaFixtureFactory
|
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
|
|
|
func testJavaWithFS(t *testing.T, bp string, fs android.MockFS) (*android.TestContext, android.Config) {
|
2020-06-08 01:58:18 +02:00
|
|
|
t.Helper()
|
2021-03-08 22:48:46 +01:00
|
|
|
result := javaFixtureFactory.Extend(fs.AddToFixture()).RunTestWithBp(t, bp)
|
|
|
|
return result.TestContext, result.Config
|
2020-06-08 01:58:18 +02:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// testJava runs tests using the javaFixtureFactory
|
|
|
|
//
|
|
|
|
// Do not add any new usages of this, instead use the javaFixtureFactory directly as it makes it
|
|
|
|
// much easier to customize the test behavior.
|
|
|
|
//
|
|
|
|
// If it is necessary to customize the behavior of an existing test that uses this then please first
|
|
|
|
// convert the test to using javaFixtureFactory first and then in a following change add the
|
|
|
|
// appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify
|
|
|
|
// that it did not change the test behavior unexpectedly.
|
|
|
|
//
|
|
|
|
// deprecated
|
2019-07-17 20:15:09 +02:00
|
|
|
func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
2017-12-05 22:42:45 +01:00
|
|
|
t.Helper()
|
2021-03-08 22:48:46 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, bp)
|
|
|
|
return result.TestContext, result.Config
|
2019-10-29 07:44:45 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// testJavaWithConfig runs tests using the javaFixtureFactory
|
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
2019-12-14 05:41:13 +01:00
|
|
|
func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) {
|
2019-10-29 07:44:45 +01:00
|
|
|
t.Helper()
|
2021-03-08 22:48:46 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithConfig(t, config)
|
|
|
|
return result.TestContext, result.Config
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 04:44:24 +02:00
|
|
|
func moduleToPath(name string) string {
|
|
|
|
switch {
|
|
|
|
case name == `""`:
|
|
|
|
return name
|
2017-09-19 02:41:52 +02:00
|
|
|
case strings.HasSuffix(name, ".jar"):
|
|
|
|
return name
|
2017-10-19 22:06:22 +02:00
|
|
|
default:
|
|
|
|
return filepath.Join(buildDir, ".intermediates", name, "android_common", "turbine-combined", name+".jar")
|
2017-09-16 04:44:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:48:46 +01:00
|
|
|
// defaultModuleToPath constructs a path to the turbine generate jar for a default test module that
|
|
|
|
// is defined in PrepareForIntegrationTestWithJava
|
|
|
|
func defaultModuleToPath(name string) string {
|
|
|
|
return filepath.Join(buildDir, ".intermediates", defaultJavaDir, name, "android_common", "turbine-combined", name+".jar")
|
|
|
|
}
|
|
|
|
|
2019-12-06 16:16:24 +01:00
|
|
|
func TestJavaLinkType(t *testing.T) {
|
|
|
|
testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2020-11-17 22:44:36 +01:00
|
|
|
testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", `
|
2019-12-06 16:16:24 +01:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
sdk_version: "current",
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2020-11-17 22:44:36 +01:00
|
|
|
testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", `
|
2019-12-06 16:16:24 +01:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2017-07-14 01:23:21 +02:00
|
|
|
func TestSimple(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2017-07-14 01:23:21 +02:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2017-07-19 20:22:16 +02:00
|
|
|
libs: ["bar"],
|
|
|
|
static_libs: ["baz"],
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
2017-10-02 22:55:26 +02:00
|
|
|
`)
|
2017-07-14 01:23:21 +02:00
|
|
|
|
2017-09-16 02:36:05 +02:00
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
2017-10-19 22:06:22 +02:00
|
|
|
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
|
2017-07-14 01:23:21 +02:00
|
|
|
|
|
|
|
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
|
|
|
}
|
|
|
|
|
2017-10-18 23:44:18 +02:00
|
|
|
baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String()
|
2017-10-19 22:06:22 +02:00
|
|
|
barTurbine := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar")
|
|
|
|
bazTurbine := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "turbine-combined", "baz.jar")
|
2017-08-30 23:24:55 +02:00
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], barTurbine)
|
2017-07-14 01:23:21 +02:00
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], bazTurbine)
|
2017-08-30 23:24:55 +02:00
|
|
|
|
|
|
|
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
|
|
|
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 19:08:34 +01:00
|
|
|
func TestExportedPlugins(t *testing.T) {
|
|
|
|
type Result struct {
|
2020-11-20 03:06:03 +01:00
|
|
|
library string
|
|
|
|
processors string
|
|
|
|
disableTurbine bool
|
2019-11-26 19:08:34 +01:00
|
|
|
}
|
|
|
|
var tests = []struct {
|
|
|
|
name string
|
|
|
|
extra string
|
|
|
|
results []Result
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Exported plugin is not a direct plugin",
|
|
|
|
extra: `java_library { name: "exports", srcs: ["a.java"], exported_plugins: ["plugin"] }`,
|
|
|
|
results: []Result{{library: "exports", processors: "-proc:none"}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Exports plugin to dependee",
|
|
|
|
extra: `
|
|
|
|
java_library{name: "exports", exported_plugins: ["plugin"]}
|
|
|
|
java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
|
|
|
|
java_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]}
|
|
|
|
`,
|
|
|
|
results: []Result{
|
|
|
|
{library: "foo", processors: "-processor com.android.TestPlugin"},
|
|
|
|
{library: "bar", processors: "-processor com.android.TestPlugin"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Exports plugin to android_library",
|
|
|
|
extra: `
|
|
|
|
java_library{name: "exports", exported_plugins: ["plugin"]}
|
|
|
|
android_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
|
|
|
|
android_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]}
|
|
|
|
`,
|
|
|
|
results: []Result{
|
|
|
|
{library: "foo", processors: "-processor com.android.TestPlugin"},
|
|
|
|
{library: "bar", processors: "-processor com.android.TestPlugin"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Exports plugin is not propagated via transitive deps",
|
|
|
|
extra: `
|
|
|
|
java_library{name: "exports", exported_plugins: ["plugin"]}
|
|
|
|
java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
|
|
|
|
java_library{name: "bar", srcs: ["a.java"], static_libs: ["foo"]}
|
|
|
|
`,
|
|
|
|
results: []Result{
|
|
|
|
{library: "foo", processors: "-processor com.android.TestPlugin"},
|
|
|
|
{library: "bar", processors: "-proc:none"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Exports plugin appends to plugins",
|
|
|
|
extra: `
|
|
|
|
java_plugin{name: "plugin2", processor_class: "com.android.TestPlugin2"}
|
|
|
|
java_library{name: "exports", exported_plugins: ["plugin"]}
|
|
|
|
java_library{name: "foo", srcs: ["a.java"], libs: ["exports"], plugins: ["plugin2"]}
|
|
|
|
`,
|
|
|
|
results: []Result{
|
|
|
|
{library: "foo", processors: "-processor com.android.TestPlugin,com.android.TestPlugin2"},
|
|
|
|
},
|
|
|
|
},
|
2020-11-20 03:06:03 +01:00
|
|
|
{
|
|
|
|
name: "Exports plugin to with generates_api to dependee",
|
|
|
|
extra: `
|
|
|
|
java_library{name: "exports", exported_plugins: ["plugin_generates_api"]}
|
|
|
|
java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
|
|
|
|
java_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]}
|
|
|
|
`,
|
|
|
|
results: []Result{
|
|
|
|
{library: "foo", processors: "-processor com.android.TestPlugin", disableTurbine: true},
|
|
|
|
{library: "bar", processors: "-processor com.android.TestPlugin", disableTurbine: true},
|
|
|
|
},
|
|
|
|
},
|
2019-11-26 19:08:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, `
|
|
|
|
java_plugin {
|
|
|
|
name: "plugin",
|
|
|
|
processor_class: "com.android.TestPlugin",
|
|
|
|
}
|
2020-11-20 03:06:03 +01:00
|
|
|
java_plugin {
|
|
|
|
name: "plugin_generates_api",
|
|
|
|
generates_api: true,
|
|
|
|
processor_class: "com.android.TestPlugin",
|
|
|
|
}
|
2019-11-26 19:08:34 +01:00
|
|
|
`+test.extra)
|
|
|
|
|
|
|
|
for _, want := range test.results {
|
|
|
|
javac := ctx.ModuleForTests(want.library, "android_common").Rule("javac")
|
|
|
|
if javac.Args["processor"] != want.processors {
|
|
|
|
t.Errorf("For library %v, expected %v, found %v", want.library, want.processors, javac.Args["processor"])
|
|
|
|
}
|
2020-11-20 03:06:03 +01:00
|
|
|
turbine := ctx.ModuleForTests(want.library, "android_common").MaybeRule("turbine")
|
|
|
|
disableTurbine := turbine.BuildParams.Rule == nil
|
|
|
|
if disableTurbine != want.disableTurbine {
|
|
|
|
t.Errorf("For library %v, expected disableTurbine %v, found %v", want.library, want.disableTurbine, disableTurbine)
|
|
|
|
}
|
2019-11-26 19:08:34 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-29 07:44:45 +01:00
|
|
|
func TestSdkVersionByPartition(t *testing.T) {
|
|
|
|
testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", `
|
2019-06-25 09:26:18 +02:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
vendor: true,
|
|
|
|
}
|
2019-10-29 07:44:45 +01:00
|
|
|
`)
|
2019-06-25 09:26:18 +02:00
|
|
|
|
2019-10-29 07:44:45 +01:00
|
|
|
testJava(t, `
|
2019-06-25 09:26:18 +02:00
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-10-29 07:44:45 +01:00
|
|
|
for _, enforce := range []bool{true, false} {
|
|
|
|
bp := `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
product_specific: true,
|
|
|
|
}
|
|
|
|
`
|
2019-12-14 05:41:13 +01:00
|
|
|
|
|
|
|
config := testConfig(nil, bp, nil)
|
|
|
|
config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
|
2019-10-29 07:44:45 +01:00
|
|
|
if enforce {
|
2019-12-14 05:41:13 +01:00
|
|
|
testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config)
|
2019-10-29 07:44:45 +01:00
|
|
|
} else {
|
2019-12-14 05:41:13 +01:00
|
|
|
testJavaWithConfig(t, config)
|
2019-10-29 07:44:45 +01:00
|
|
|
}
|
2019-06-25 09:26:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:55:26 +02:00
|
|
|
func TestArchSpecific(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2017-10-02 22:55:26 +02:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
srcs: ["b.java"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
|
|
|
if len(javac.Inputs) != 2 || javac.Inputs[0].String() != "a.java" || javac.Inputs[1].String() != "b.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java", "b.java"]`, javac.Inputs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
func TestBinary(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2017-12-05 22:42:45 +01:00
|
|
|
java_library_host {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_binary_host {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
static_libs: ["foo"],
|
2020-10-10 04:00:54 +02:00
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_shared {
|
|
|
|
name: "libjni",
|
|
|
|
host_supported: true,
|
|
|
|
device_supported: false,
|
|
|
|
stl: "none",
|
2017-12-05 22:42:45 +01:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
buildOS := android.BuildOs.String()
|
|
|
|
|
|
|
|
bar := ctx.ModuleForTests("bar", buildOS+"_common")
|
|
|
|
barJar := bar.Output("bar.jar").Output.String()
|
|
|
|
barWrapper := ctx.ModuleForTests("bar", buildOS+"_x86_64")
|
|
|
|
barWrapperDeps := barWrapper.Output("bar").Implicits.Strings()
|
|
|
|
|
2020-10-10 04:00:54 +02:00
|
|
|
libjni := ctx.ModuleForTests("libjni", buildOS+"_x86_64_shared")
|
|
|
|
libjniSO := libjni.Rule("Cp").Output.String()
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
// Test that the install binary wrapper depends on the installed jar file
|
2020-10-09 19:54:15 +02:00
|
|
|
if g, w := barWrapperDeps, barJar; !android.InList(w, g) {
|
|
|
|
t.Errorf("expected binary wrapper implicits to contain %q, got %q", w, g)
|
2017-12-05 22:42:45 +01:00
|
|
|
}
|
2020-10-10 04:00:54 +02:00
|
|
|
|
|
|
|
// Test that the install binary wrapper depends on the installed JNI libraries
|
|
|
|
if g, w := barWrapperDeps, libjniSO; !android.InList(w, g) {
|
|
|
|
t.Errorf("expected binary wrapper implicits to contain %q, got %q", w, g)
|
2017-12-05 22:42:45 +01:00
|
|
|
}
|
2020-06-10 02:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
java_library {
|
|
|
|
name: "target_library",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_binary_host {
|
|
|
|
name: "host_binary",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
config := testConfig(nil, bp, nil)
|
|
|
|
config.TestProductVariables.MinimizeJavaDebugInfo = proptools.BoolPtr(true)
|
|
|
|
|
|
|
|
ctx, _ := testJavaWithConfig(t, config)
|
|
|
|
|
2020-07-28 22:27:34 +02:00
|
|
|
// first, check that the -g flag is added to target modules
|
2020-06-10 02:23:08 +02:00
|
|
|
targetLibrary := ctx.ModuleForTests("target_library", "android_common")
|
|
|
|
targetJavaFlags := targetLibrary.Module().VariablesForTests()["javacFlags"]
|
|
|
|
if !strings.Contains(targetJavaFlags, "-g:source,lines") {
|
|
|
|
t.Errorf("target library javac flags %v should contain "+
|
|
|
|
"-g:source,lines override with MinimizeJavaDebugInfo", targetJavaFlags)
|
|
|
|
}
|
2017-12-05 22:42:45 +01:00
|
|
|
|
2020-06-10 02:23:08 +02:00
|
|
|
// check that -g is not overridden for host modules
|
|
|
|
buildOS := android.BuildOs.String()
|
|
|
|
hostBinary := ctx.ModuleForTests("host_binary", buildOS+"_common")
|
|
|
|
hostJavaFlags := hostBinary.Module().VariablesForTests()["javacFlags"]
|
|
|
|
if strings.Contains(hostJavaFlags, "-g:source,lines") {
|
|
|
|
t.Errorf("java_binary_host javac flags %v should not have "+
|
|
|
|
"-g:source,lines override with MinimizeJavaDebugInfo", hostJavaFlags)
|
|
|
|
}
|
2017-12-05 22:42:45 +01:00
|
|
|
}
|
|
|
|
|
2017-07-14 01:23:21 +02:00
|
|
|
func TestPrebuilts(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2017-07-14 01:23:21 +02:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
2019-11-12 20:39:36 +01:00
|
|
|
srcs: ["a.java", ":stubs-source"],
|
2020-01-31 18:54:30 +01:00
|
|
|
libs: ["bar", "sdklib"],
|
2017-07-19 20:22:16 +02:00
|
|
|
static_libs: ["baz"],
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
java_import {
|
2017-07-14 01:23:21 +02:00
|
|
|
name: "bar",
|
2017-08-02 20:05:49 +02:00
|
|
|
jars: ["a.jar"],
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
java_import {
|
2017-07-14 01:23:21 +02:00
|
|
|
name: "baz",
|
2017-08-02 20:05:49 +02:00
|
|
|
jars: ["b.jar"],
|
2020-08-06 00:40:41 +02:00
|
|
|
sdk_version: "current",
|
|
|
|
compile_dex: true,
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
2019-02-22 03:12:14 +01:00
|
|
|
|
|
|
|
dex_import {
|
|
|
|
name: "qux",
|
|
|
|
jars: ["b.jar"],
|
|
|
|
}
|
2019-04-17 20:11:46 +02:00
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
java_sdk_library_import {
|
|
|
|
name: "sdklib",
|
|
|
|
public: {
|
|
|
|
jars: ["c.jar"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-11-12 20:39:36 +01:00
|
|
|
prebuilt_stubs_sources {
|
|
|
|
name: "stubs-source",
|
2019-12-10 14:41:51 +01:00
|
|
|
srcs: ["stubs/sources"],
|
2019-11-12 20:39:36 +01:00
|
|
|
}
|
2019-12-03 19:06:47 +01:00
|
|
|
|
|
|
|
java_test_import {
|
|
|
|
name: "test",
|
|
|
|
jars: ["a.jar"],
|
|
|
|
test_suites: ["cts"],
|
|
|
|
test_config: "AndroidTest.xml",
|
|
|
|
}
|
2017-07-14 01:23:21 +02:00
|
|
|
`)
|
|
|
|
|
2019-12-10 14:41:51 +01:00
|
|
|
fooModule := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
javac := fooModule.Rule("javac")
|
2017-10-19 22:06:22 +02:00
|
|
|
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
|
2020-08-06 00:40:41 +02:00
|
|
|
barModule := ctx.ModuleForTests("bar", "android_common")
|
|
|
|
barJar := barModule.Rule("combineJar").Output
|
|
|
|
bazModule := ctx.ModuleForTests("baz", "android_common")
|
|
|
|
bazJar := bazModule.Rule("combineJar").Output
|
2019-04-17 20:11:46 +02:00
|
|
|
sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output
|
2017-07-14 01:23:21 +02:00
|
|
|
|
2019-12-10 14:41:51 +01:00
|
|
|
fooLibrary := fooModule.Module().(*Library)
|
|
|
|
assertDeepEquals(t, "foo java sources incorrect",
|
|
|
|
[]string{"a.java"}, fooLibrary.compiledJavaSrcs.Strings())
|
2019-11-12 20:39:36 +01:00
|
|
|
|
2019-12-10 14:41:51 +01:00
|
|
|
assertDeepEquals(t, "foo java source jars incorrect",
|
|
|
|
[]string{".intermediates/stubs-source/android_common/stubs-source-stubs.srcjar"},
|
|
|
|
android.NormalizePathsForTesting(fooLibrary.compiledSrcJars))
|
2019-11-12 20:39:36 +01:00
|
|
|
|
2018-07-12 21:28:41 +02:00
|
|
|
if !strings.Contains(javac.Args["classpath"], barJar.String()) {
|
|
|
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String())
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
barDexJar := barModule.Module().(*Import).DexJarBuildPath()
|
|
|
|
if barDexJar != nil {
|
|
|
|
t.Errorf("bar dex jar build path expected to be nil, got %q", barDexJar)
|
|
|
|
}
|
|
|
|
|
2019-04-17 20:11:46 +02:00
|
|
|
if !strings.Contains(javac.Args["classpath"], sdklibStubsJar.String()) {
|
|
|
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], sdklibStubsJar.String())
|
|
|
|
}
|
|
|
|
|
2018-07-12 21:28:41 +02:00
|
|
|
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != bazJar.String() {
|
|
|
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, bazJar.String())
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
2019-02-22 03:12:14 +01:00
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
bazDexJar := bazModule.Module().(*Import).DexJarBuildPath().String()
|
|
|
|
expectedDexJar := buildDir + "/.intermediates/baz/android_common/dex/baz.jar"
|
|
|
|
if bazDexJar != expectedDexJar {
|
|
|
|
t.Errorf("baz dex jar build path expected %q, got %q", expectedDexJar, bazDexJar)
|
|
|
|
}
|
|
|
|
|
2019-02-22 03:12:14 +01:00
|
|
|
ctx.ModuleForTests("qux", "android_common").Rule("Cp")
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 14:41:51 +01:00
|
|
|
func assertDeepEquals(t *testing.T, message string, expected interface{}, actual interface{}) {
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
|
|
|
t.Errorf("%s: expected %q, found %q", message, expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-18 17:36:47 +01:00
|
|
|
func TestPrebuiltStubsSources(t *testing.T) {
|
|
|
|
test := func(t *testing.T, sourcesPath string, expectedInputs []string) {
|
|
|
|
ctx, _ := testJavaWithFS(t, fmt.Sprintf(`
|
|
|
|
prebuilt_stubs_sources {
|
|
|
|
name: "stubs-source",
|
|
|
|
srcs: ["%s"],
|
|
|
|
}`, sourcesPath), map[string][]byte{
|
|
|
|
"stubs/sources/pkg/A.java": nil,
|
|
|
|
"stubs/sources/pkg/B.java": nil,
|
|
|
|
})
|
|
|
|
|
|
|
|
zipSrc := ctx.ModuleForTests("stubs-source", "android_common").Rule("zip_src")
|
|
|
|
if expected, actual := expectedInputs, zipSrc.Inputs.Strings(); !reflect.DeepEqual(expected, actual) {
|
|
|
|
t.Errorf("mismatch of inputs to soong_zip: expected %q, actual %q", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("empty/missing directory", func(t *testing.T) {
|
|
|
|
test(t, "empty-directory", []string{})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("non-empty set of sources", func(t *testing.T) {
|
|
|
|
test(t, "stubs/sources", []string{
|
|
|
|
"stubs/sources/pkg/A.java",
|
|
|
|
"stubs/sources/pkg/B.java",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
func TestJavaSdkLibraryImport(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, `
|
2020-01-31 14:36:25 +01:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["sdklib"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo.system",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["sdklib"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo.test",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["sdklib"],
|
|
|
|
sdk_version: "test_current",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library_import {
|
|
|
|
name: "sdklib",
|
|
|
|
public: {
|
|
|
|
jars: ["a.jar"],
|
|
|
|
},
|
|
|
|
system: {
|
|
|
|
jars: ["b.jar"],
|
|
|
|
},
|
|
|
|
test: {
|
|
|
|
jars: ["c.jar"],
|
2020-05-20 17:18:00 +02:00
|
|
|
stub_srcs: ["c.java"],
|
2020-01-31 14:36:25 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
for _, scope := range []string{"", ".system", ".test"} {
|
2021-03-12 20:15:01 +01:00
|
|
|
fooModule := result.ModuleForTests("foo"+scope, "android_common")
|
2020-01-31 14:36:25 +01:00
|
|
|
javac := fooModule.Rule("javac")
|
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
sdklibStubsJar := result.ModuleForTests("sdklib.stubs"+scope, "android_common").Rule("combineJar").Output
|
|
|
|
android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], sdklibStubsJar.String())
|
2020-01-31 14:36:25 +01:00
|
|
|
}
|
2020-06-26 23:20:25 +02:00
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{
|
2020-06-26 23:20:25 +02:00
|
|
|
`prebuilt_sdklib.stubs`,
|
|
|
|
`prebuilt_sdklib.stubs.source.test`,
|
|
|
|
`prebuilt_sdklib.stubs.system`,
|
|
|
|
`prebuilt_sdklib.stubs.test`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaSdkLibraryImport_WithSource(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, `
|
2020-06-26 23:20:25 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "sdklib",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
public: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library_import {
|
|
|
|
name: "sdklib",
|
|
|
|
public: {
|
|
|
|
jars: ["a.jar"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{
|
2020-06-26 23:20:25 +02:00
|
|
|
`dex2oatd`,
|
|
|
|
`prebuilt_sdklib`,
|
|
|
|
`sdklib.impl`,
|
|
|
|
`sdklib.stubs`,
|
|
|
|
`sdklib.stubs.source`,
|
|
|
|
`sdklib.xml`,
|
|
|
|
})
|
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{
|
2020-06-26 21:17:02 +02:00
|
|
|
`prebuilt_sdklib.stubs`,
|
2020-06-26 23:20:25 +02:00
|
|
|
`sdklib.impl`,
|
|
|
|
// This should be prebuilt_sdklib.stubs but is set to sdklib.stubs because the
|
|
|
|
// dependency is added after prebuilts may have been renamed and so has to use
|
|
|
|
// the renamed name.
|
|
|
|
`sdklib.xml`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, `
|
2020-06-26 23:20:25 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "sdklib",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
public: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library_import {
|
|
|
|
name: "sdklib",
|
|
|
|
prefer: true,
|
|
|
|
public: {
|
|
|
|
jars: ["a.jar"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{
|
2020-06-26 23:20:25 +02:00
|
|
|
`dex2oatd`,
|
|
|
|
`prebuilt_sdklib`,
|
|
|
|
`sdklib.impl`,
|
2020-06-26 23:08:43 +02:00
|
|
|
`sdklib.stubs`,
|
2020-06-26 23:20:25 +02:00
|
|
|
`sdklib.stubs.source`,
|
|
|
|
`sdklib.xml`,
|
|
|
|
})
|
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{
|
2020-06-26 23:20:25 +02:00
|
|
|
`prebuilt_sdklib.stubs`,
|
|
|
|
`sdklib.impl`,
|
|
|
|
`sdklib.xml`,
|
|
|
|
})
|
2020-01-31 14:36:25 +01:00
|
|
|
}
|
|
|
|
|
2020-10-19 10:25:58 +02:00
|
|
|
func TestJavaSdkLibraryEnforce(t *testing.T) {
|
|
|
|
partitionToBpOption := func(partition string) string {
|
|
|
|
switch partition {
|
|
|
|
case "system":
|
|
|
|
return ""
|
|
|
|
case "vendor":
|
|
|
|
return "soc_specific: true,"
|
|
|
|
case "product":
|
|
|
|
return "product_specific: true,"
|
|
|
|
default:
|
|
|
|
panic("Invalid partition group name: " + partition)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type testConfigInfo struct {
|
|
|
|
libraryType string
|
|
|
|
fromPartition string
|
|
|
|
toPartition string
|
|
|
|
enforceVendorInterface bool
|
|
|
|
enforceProductInterface bool
|
|
|
|
enforceJavaSdkLibraryCheck bool
|
|
|
|
allowList []string
|
|
|
|
}
|
|
|
|
|
2021-03-12 22:28:51 +01:00
|
|
|
createPreparer := func(info testConfigInfo) android.FixturePreparer {
|
2020-10-19 10:25:58 +02:00
|
|
|
bpFileTemplate := `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["foo.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
sdk_version: "current",
|
|
|
|
%s
|
|
|
|
}
|
|
|
|
|
|
|
|
%s {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["bar.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
%s
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
bpFile := fmt.Sprintf(bpFileTemplate,
|
|
|
|
partitionToBpOption(info.fromPartition),
|
|
|
|
info.libraryType,
|
|
|
|
partitionToBpOption(info.toPartition))
|
|
|
|
|
2021-03-12 22:28:51 +01:00
|
|
|
return android.GroupFixturePreparers(
|
|
|
|
android.FixtureWithRootAndroidBp(bpFile),
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.EnforceProductPartitionInterface = proptools.BoolPtr(info.enforceProductInterface)
|
|
|
|
if info.enforceVendorInterface {
|
|
|
|
variables.DeviceVndkVersion = proptools.StringPtr("current")
|
|
|
|
}
|
|
|
|
variables.EnforceInterPartitionJavaSdkLibrary = proptools.BoolPtr(info.enforceJavaSdkLibraryCheck)
|
|
|
|
variables.InterPartitionJavaLibraryAllowList = info.allowList
|
|
|
|
}),
|
|
|
|
)
|
2020-10-19 10:25:58 +02:00
|
|
|
}
|
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest := func(t *testing.T, info testConfigInfo, expectedErrorPattern string) {
|
|
|
|
t.Run(fmt.Sprintf("%#v", info), func(t *testing.T) {
|
2021-03-12 22:28:51 +01:00
|
|
|
errorHandler := android.FixtureExpectsNoErrors
|
|
|
|
if expectedErrorPattern != "" {
|
|
|
|
errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(expectedErrorPattern)
|
2021-03-13 17:50:15 +01:00
|
|
|
}
|
2021-03-12 22:28:51 +01:00
|
|
|
javaFixtureFactory.ExtendWithErrorHandler(errorHandler).RunTest(t, createPreparer(info))
|
2021-03-13 17:50:15 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-10-19 10:25:58 +02:00
|
|
|
errorMessage := "is not allowed across the partitions"
|
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2021-01-14 03:56:56 +01:00
|
|
|
libraryType: "java_library",
|
|
|
|
fromPartition: "product",
|
|
|
|
toPartition: "system",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: true,
|
|
|
|
enforceJavaSdkLibraryCheck: false,
|
2021-03-13 17:50:15 +01:00
|
|
|
}, "")
|
2020-10-19 10:25:58 +02:00
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2021-01-14 03:56:56 +01:00
|
|
|
libraryType: "java_library",
|
|
|
|
fromPartition: "product",
|
|
|
|
toPartition: "system",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: false,
|
|
|
|
enforceJavaSdkLibraryCheck: true,
|
2021-03-13 17:50:15 +01:00
|
|
|
}, "")
|
2020-10-19 10:25:58 +02:00
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2021-01-14 03:56:56 +01:00
|
|
|
libraryType: "java_library",
|
|
|
|
fromPartition: "product",
|
|
|
|
toPartition: "system",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: true,
|
|
|
|
enforceJavaSdkLibraryCheck: true,
|
2021-03-13 17:50:15 +01:00
|
|
|
}, errorMessage)
|
2020-10-19 10:25:58 +02:00
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2021-01-14 03:56:56 +01:00
|
|
|
libraryType: "java_library",
|
|
|
|
fromPartition: "vendor",
|
|
|
|
toPartition: "system",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: true,
|
|
|
|
enforceJavaSdkLibraryCheck: true,
|
2021-03-13 17:50:15 +01:00
|
|
|
}, errorMessage)
|
2020-10-19 10:25:58 +02:00
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2020-10-19 10:25:58 +02:00
|
|
|
libraryType: "java_library",
|
|
|
|
fromPartition: "vendor",
|
|
|
|
toPartition: "system",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: true,
|
|
|
|
enforceJavaSdkLibraryCheck: true,
|
|
|
|
allowList: []string{"bar"},
|
2021-03-13 17:50:15 +01:00
|
|
|
}, "")
|
2020-10-19 10:25:58 +02:00
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2020-10-19 10:25:58 +02:00
|
|
|
libraryType: "java_library",
|
|
|
|
fromPartition: "vendor",
|
2021-01-14 03:56:56 +01:00
|
|
|
toPartition: "product",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: true,
|
|
|
|
enforceJavaSdkLibraryCheck: true,
|
2021-03-13 17:50:15 +01:00
|
|
|
}, errorMessage)
|
2021-01-14 03:56:56 +01:00
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2021-01-14 03:56:56 +01:00
|
|
|
libraryType: "java_sdk_library",
|
|
|
|
fromPartition: "product",
|
|
|
|
toPartition: "system",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: true,
|
|
|
|
enforceJavaSdkLibraryCheck: true,
|
2021-03-13 17:50:15 +01:00
|
|
|
}, "")
|
2021-01-14 03:56:56 +01:00
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2021-01-14 03:56:56 +01:00
|
|
|
libraryType: "java_sdk_library",
|
|
|
|
fromPartition: "vendor",
|
2020-10-19 10:25:58 +02:00
|
|
|
toPartition: "system",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: true,
|
|
|
|
enforceJavaSdkLibraryCheck: true,
|
2021-03-13 17:50:15 +01:00
|
|
|
}, "")
|
2021-01-14 03:56:56 +01:00
|
|
|
|
2021-03-13 17:50:15 +01:00
|
|
|
runTest(t, testConfigInfo{
|
2021-01-14 03:56:56 +01:00
|
|
|
libraryType: "java_sdk_library",
|
|
|
|
fromPartition: "vendor",
|
|
|
|
toPartition: "product",
|
|
|
|
enforceVendorInterface: true,
|
|
|
|
enforceProductInterface: true,
|
|
|
|
enforceJavaSdkLibraryCheck: true,
|
2021-03-13 17:50:15 +01:00
|
|
|
}, "")
|
2020-10-19 10:25:58 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 23:35:50 +02:00
|
|
|
func TestDefaults(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2017-07-07 23:35:50 +02:00
|
|
|
java_defaults {
|
|
|
|
name: "defaults",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
static_libs: ["baz"],
|
2019-04-17 02:16:58 +02:00
|
|
|
optimize: {enabled: false},
|
2017-07-07 23:35:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
defaults: ["defaults"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
2019-04-17 02:16:58 +02:00
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "atestOptimize",
|
|
|
|
defaults: ["defaults"],
|
|
|
|
optimize: {enabled: true},
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "atestNoOptimize",
|
|
|
|
defaults: ["defaults"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "atestDefault",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
2017-07-07 23:35:50 +02:00
|
|
|
`)
|
|
|
|
|
2017-09-16 02:36:05 +02:00
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
2017-10-19 22:06:22 +02:00
|
|
|
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
|
2017-07-07 23:35:50 +02:00
|
|
|
|
|
|
|
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
barTurbine := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar")
|
|
|
|
if !strings.Contains(javac.Args["classpath"], barTurbine) {
|
|
|
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barTurbine)
|
2017-07-07 23:35:50 +02:00
|
|
|
}
|
|
|
|
|
2017-10-18 23:44:18 +02:00
|
|
|
baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String()
|
2017-08-30 23:24:55 +02:00
|
|
|
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
|
|
|
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
|
2017-07-07 23:35:50 +02:00
|
|
|
}
|
2019-04-17 02:16:58 +02:00
|
|
|
|
|
|
|
atestOptimize := ctx.ModuleForTests("atestOptimize", "android_common").MaybeRule("r8")
|
|
|
|
if atestOptimize.Output == nil {
|
|
|
|
t.Errorf("atestOptimize should optimize APK")
|
|
|
|
}
|
|
|
|
|
|
|
|
atestNoOptimize := ctx.ModuleForTests("atestNoOptimize", "android_common").MaybeRule("d8")
|
|
|
|
if atestNoOptimize.Output == nil {
|
|
|
|
t.Errorf("atestNoOptimize should not optimize APK")
|
|
|
|
}
|
|
|
|
|
|
|
|
atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("r8")
|
|
|
|
if atestDefault.Output == nil {
|
|
|
|
t.Errorf("atestDefault should optimize APK")
|
|
|
|
}
|
2017-07-07 23:35:50 +02:00
|
|
|
}
|
|
|
|
|
2017-09-28 02:42:05 +02:00
|
|
|
func TestResources(t *testing.T) {
|
|
|
|
var table = []struct {
|
|
|
|
name string
|
|
|
|
prop string
|
|
|
|
extra string
|
|
|
|
args string
|
|
|
|
}{
|
|
|
|
{
|
2017-10-03 23:50:08 +02:00
|
|
|
// Test that a module with java_resource_dirs includes the files
|
2017-09-28 02:42:05 +02:00
|
|
|
name: "resource dirs",
|
2017-11-23 02:27:51 +01:00
|
|
|
prop: `java_resource_dirs: ["java-res"]`,
|
2018-04-10 22:07:42 +02:00
|
|
|
args: "-C java-res -f java-res/a/a -f java-res/b/b",
|
2017-09-28 02:42:05 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test that a module with java_resources includes the files
|
|
|
|
name: "resource files",
|
2018-04-10 22:07:42 +02:00
|
|
|
prop: `java_resources: ["java-res/a/a", "java-res/b/b"]`,
|
|
|
|
args: "-C . -f java-res/a/a -f java-res/b/b",
|
2017-09-28 02:42:05 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test that a module with a filegroup in java_resources includes the files with the
|
|
|
|
// path prefix
|
|
|
|
name: "resource filegroup",
|
|
|
|
prop: `java_resources: [":foo-res"]`,
|
|
|
|
extra: `
|
|
|
|
filegroup {
|
|
|
|
name: "foo-res",
|
2017-11-23 02:27:51 +01:00
|
|
|
path: "java-res",
|
2018-04-10 22:07:42 +02:00
|
|
|
srcs: ["java-res/a/a", "java-res/b/b"],
|
2017-09-28 02:42:05 +02:00
|
|
|
}`,
|
2018-04-10 22:07:42 +02:00
|
|
|
args: "-C java-res -f java-res/a/a -f java-res/b/b",
|
2017-09-28 02:42:05 +02:00
|
|
|
},
|
2018-04-10 22:07:42 +02:00
|
|
|
{
|
|
|
|
// Test that a module with wildcards in java_resource_dirs has the correct path prefixes
|
|
|
|
name: "wildcard dirs",
|
|
|
|
prop: `java_resource_dirs: ["java-res/*"]`,
|
|
|
|
args: "-C java-res/a -f java-res/a/a -C java-res/b -f java-res/b/b",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test that a module exclude_java_resource_dirs excludes the files
|
|
|
|
name: "wildcard dirs",
|
|
|
|
prop: `java_resource_dirs: ["java-res/*"], exclude_java_resource_dirs: ["java-res/b"]`,
|
|
|
|
args: "-C java-res/a -f java-res/a/a",
|
|
|
|
},
|
2018-09-13 20:26:19 +02:00
|
|
|
{
|
|
|
|
// Test wildcards in java_resources
|
|
|
|
name: "wildcard files",
|
|
|
|
prop: `java_resources: ["java-res/**/*"]`,
|
|
|
|
args: "-C . -f java-res/a/a -f java-res/b/b",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test exclude_java_resources with java_resources
|
|
|
|
name: "wildcard files with exclude",
|
|
|
|
prop: `java_resources: ["java-res/**/*"], exclude_java_resources: ["java-res/b/*"]`,
|
|
|
|
args: "-C . -f java-res/a/a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test exclude_java_resources with java_resource_dirs
|
|
|
|
name: "resource dirs with exclude files",
|
|
|
|
prop: `java_resource_dirs: ["java-res"], exclude_java_resources: ["java-res/b/b"]`,
|
|
|
|
args: "-C java-res -f java-res/a/a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test exclude_java_resource_dirs with java_resource_dirs
|
|
|
|
name: "resource dirs with exclude files",
|
|
|
|
prop: `java_resource_dirs: ["java-res", "java-res2"], exclude_java_resource_dirs: ["java-res2"]`,
|
|
|
|
args: "-C java-res -f java-res/a/a -f java-res/b/b",
|
|
|
|
},
|
2017-09-28 02:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range table {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2020-06-08 01:58:18 +02:00
|
|
|
ctx, _ := testJavaWithFS(t, `
|
2017-09-28 02:42:05 +02:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"c.java",
|
|
|
|
],
|
|
|
|
`+test.prop+`,
|
|
|
|
}
|
2020-06-08 01:58:18 +02:00
|
|
|
`+test.extra,
|
|
|
|
map[string][]byte{
|
|
|
|
"java-res/a/a": nil,
|
|
|
|
"java-res/b/b": nil,
|
|
|
|
"java-res2/a": nil,
|
|
|
|
},
|
|
|
|
)
|
2017-09-28 02:42:05 +02:00
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar")
|
2017-10-18 23:44:18 +02:00
|
|
|
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
2017-09-28 02:42:05 +02:00
|
|
|
|
|
|
|
if !inList(fooRes.Output.String(), foo.Inputs.Strings()) {
|
|
|
|
t.Errorf("foo combined jars %v does not contain %q",
|
|
|
|
foo.Inputs.Strings(), fooRes.Output.String())
|
|
|
|
}
|
|
|
|
|
2017-10-03 23:50:08 +02:00
|
|
|
if fooRes.Args["jarArgs"] != test.args {
|
|
|
|
t.Errorf("foo resource jar args %q is not %q",
|
2017-09-28 02:42:05 +02:00
|
|
|
fooRes.Args["jarArgs"], test.args)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-04 00:28:19 +02:00
|
|
|
func TestIncludeSrcs(t *testing.T) {
|
2020-06-08 01:58:18 +02:00
|
|
|
ctx, _ := testJavaWithFS(t, `
|
2019-05-04 00:28:19 +02:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"c.java",
|
|
|
|
],
|
|
|
|
include_srcs: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"c.java",
|
|
|
|
],
|
|
|
|
java_resource_dirs: ["java-res"],
|
|
|
|
include_srcs: true,
|
|
|
|
}
|
2020-06-08 01:58:18 +02:00
|
|
|
`, map[string][]byte{
|
|
|
|
"java-res/a/a": nil,
|
|
|
|
"java-res/b/b": nil,
|
|
|
|
"java-res2/a": nil,
|
|
|
|
})
|
2019-05-04 00:28:19 +02:00
|
|
|
|
|
|
|
// Test a library with include_srcs: true
|
|
|
|
foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar")
|
|
|
|
fooSrcJar := ctx.ModuleForTests("foo", "android_common").Output("foo.srcjar")
|
|
|
|
|
|
|
|
if g, w := fooSrcJar.Output.String(), foo.Inputs.Strings(); !inList(g, w) {
|
|
|
|
t.Errorf("foo combined jars %v does not contain %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := fooSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w {
|
|
|
|
t.Errorf("foo source jar args %q is not %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a library with include_srcs: true and resources
|
|
|
|
bar := ctx.ModuleForTests("bar", "android_common").Output("withres/bar.jar")
|
|
|
|
barResCombined := ctx.ModuleForTests("bar", "android_common").Output("res-combined/bar.jar")
|
|
|
|
barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
|
|
|
|
barSrcJar := ctx.ModuleForTests("bar", "android_common").Output("bar.srcjar")
|
|
|
|
|
|
|
|
if g, w := barSrcJar.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) {
|
|
|
|
t.Errorf("bar combined resource jars %v does not contain %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := barRes.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) {
|
|
|
|
t.Errorf("bar combined resource jars %v does not contain %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := barResCombined.Output.String(), bar.Inputs.Strings(); !inList(g, w) {
|
|
|
|
t.Errorf("bar combined jars %v does not contain %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := barSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w {
|
|
|
|
t.Errorf("bar source jar args %q is not %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := barRes.Args["jarArgs"], "-C java-res -f java-res/a/a -f java-res/b/b"; g != w {
|
|
|
|
t.Errorf("bar resource jar args %q is not %q", w, g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 16:41:33 +01:00
|
|
|
func TestJavaLint(t *testing.T) {
|
|
|
|
ctx, _ := testJavaWithFS(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"c.java",
|
|
|
|
],
|
|
|
|
min_sdk_version: "29",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
}
|
|
|
|
`, map[string][]byte{
|
|
|
|
"lint-baseline.xml": nil,
|
|
|
|
})
|
|
|
|
|
|
|
|
foo := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
rule := foo.Rule("lint")
|
|
|
|
|
|
|
|
if !strings.Contains(rule.RuleParams.Command, "--baseline lint-baseline.xml") {
|
|
|
|
t.Error("did not pass --baseline flag")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLintWithoutBaseline(t *testing.T) {
|
|
|
|
ctx, _ := testJavaWithFS(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"c.java",
|
|
|
|
],
|
|
|
|
min_sdk_version: "29",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
}
|
|
|
|
`, map[string][]byte{})
|
|
|
|
|
|
|
|
foo := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
rule := foo.Rule("lint")
|
|
|
|
|
|
|
|
if strings.Contains(rule.RuleParams.Command, "--baseline") {
|
|
|
|
t.Error("passed --baseline flag for non existent file")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLintRequiresCustomLintFileToExist(t *testing.T) {
|
|
|
|
config := testConfig(
|
|
|
|
nil,
|
|
|
|
`
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
],
|
|
|
|
min_sdk_version: "29",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
lint: {
|
|
|
|
baseline_filename: "mybaseline.xml",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`, map[string][]byte{
|
|
|
|
"build/soong/java/lint_defaults.txt": nil,
|
|
|
|
"prebuilts/cmdline-tools/tools/bin/lint": nil,
|
|
|
|
"prebuilts/cmdline-tools/tools/lib/lint-classpath.jar": nil,
|
|
|
|
"framework/aidl": nil,
|
|
|
|
"a.java": nil,
|
|
|
|
"AndroidManifest.xml": nil,
|
|
|
|
"build/make/target/product/security": nil,
|
|
|
|
})
|
|
|
|
config.TestAllowNonExistentPaths = false
|
|
|
|
testJavaErrorWithConfig(t,
|
|
|
|
"source path \"mybaseline.xml\" does not exist",
|
|
|
|
config,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLintUsesCorrectBpConfig(t *testing.T) {
|
|
|
|
ctx, _ := testJavaWithFS(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"c.java",
|
|
|
|
],
|
|
|
|
min_sdk_version: "29",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
lint: {
|
|
|
|
error_checks: ["SomeCheck"],
|
|
|
|
baseline_filename: "mybaseline.xml",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`, map[string][]byte{
|
|
|
|
"mybaseline.xml": nil,
|
|
|
|
})
|
|
|
|
|
|
|
|
foo := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
rule := foo.Rule("lint")
|
|
|
|
|
|
|
|
if !strings.Contains(rule.RuleParams.Command, "--baseline mybaseline.xml") {
|
|
|
|
t.Error("did not use the correct file for baseline")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 00:34:10 +02:00
|
|
|
func TestGeneratedSources(t *testing.T) {
|
2020-06-08 01:58:18 +02:00
|
|
|
ctx, _ := testJavaWithFS(t, `
|
2017-10-10 00:34:10 +02:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"a*.java",
|
|
|
|
":gen",
|
|
|
|
"b*.java",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
genrule {
|
|
|
|
name: "gen",
|
2017-11-23 02:27:51 +01:00
|
|
|
tool_files: ["java-res/a"],
|
2017-10-10 00:34:10 +02:00
|
|
|
out: ["gen.java"],
|
|
|
|
}
|
2020-06-08 01:58:18 +02:00
|
|
|
`, map[string][]byte{
|
|
|
|
"a.java": nil,
|
|
|
|
"b.java": nil,
|
|
|
|
})
|
2017-10-10 00:34:10 +02:00
|
|
|
|
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
|
|
|
genrule := ctx.ModuleForTests("gen", "").Rule("generator")
|
|
|
|
|
2017-10-21 00:07:08 +02:00
|
|
|
if filepath.Base(genrule.Output.String()) != "gen.java" {
|
|
|
|
t.Fatalf(`gen output file %v is not ".../gen.java"`, genrule.Output.String())
|
2017-10-10 00:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(javac.Inputs) != 3 ||
|
|
|
|
javac.Inputs[0].String() != "a.java" ||
|
2017-10-21 00:07:08 +02:00
|
|
|
javac.Inputs[1].String() != genrule.Output.String() ||
|
2017-10-10 00:34:10 +02:00
|
|
|
javac.Inputs[2].String() != "b.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java", ".../gen.java", "b.java"]`, javac.Inputs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 21:28:15 +01:00
|
|
|
func TestTurbine(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2017-11-02 21:28:15 +01:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2018-03-05 09:44:10 +01:00
|
|
|
sdk_version: "14",
|
2017-11-02 21:28:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
2017-12-16 05:20:39 +01:00
|
|
|
srcs: ["b.java"],
|
2017-11-02 21:28:15 +01:00
|
|
|
static_libs: ["foo"],
|
2018-03-05 09:44:10 +01:00
|
|
|
sdk_version: "14",
|
2017-11-02 21:28:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
sdk_version: "14",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
fooTurbine := ctx.ModuleForTests("foo", "android_common").Rule("turbine")
|
|
|
|
barTurbine := ctx.ModuleForTests("bar", "android_common").Rule("turbine")
|
|
|
|
barJavac := ctx.ModuleForTests("bar", "android_common").Rule("javac")
|
|
|
|
barTurbineCombined := ctx.ModuleForTests("bar", "android_common").Description("for turbine")
|
|
|
|
bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac")
|
|
|
|
|
|
|
|
if len(fooTurbine.Inputs) != 1 || fooTurbine.Inputs[0].String() != "a.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java"]`, fooTurbine.Inputs)
|
|
|
|
}
|
|
|
|
|
|
|
|
fooHeaderJar := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar")
|
|
|
|
if !strings.Contains(barTurbine.Args["classpath"], fooHeaderJar) {
|
|
|
|
t.Errorf("bar turbine classpath %v does not contain %q", barTurbine.Args["classpath"], fooHeaderJar)
|
|
|
|
}
|
|
|
|
if !strings.Contains(barJavac.Args["classpath"], fooHeaderJar) {
|
|
|
|
t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], fooHeaderJar)
|
|
|
|
}
|
|
|
|
if len(barTurbineCombined.Inputs) != 2 || barTurbineCombined.Inputs[1].String() != fooHeaderJar {
|
|
|
|
t.Errorf("bar turbine combineJar inputs %v does not contain %q", barTurbineCombined.Inputs, fooHeaderJar)
|
|
|
|
}
|
2018-04-11 14:57:30 +02:00
|
|
|
if !strings.Contains(bazJavac.Args["classpath"], "prebuilts/sdk/14/public/android.jar") {
|
2017-11-02 21:28:15 +01:00
|
|
|
t.Errorf("baz javac classpath %v does not contain %q", bazJavac.Args["classpath"],
|
2018-04-11 14:57:30 +02:00
|
|
|
"prebuilts/sdk/14/public/android.jar")
|
2017-11-02 21:28:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSharding(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2017-11-02 21:28:15 +01:00
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["a.java","b.java","c.java"],
|
|
|
|
javac_shard_size: 1
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
barHeaderJar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar")
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
barJavac := ctx.ModuleForTests("bar", "android_common").Description("javac" + strconv.Itoa(i))
|
|
|
|
if !strings.Contains(barJavac.Args["classpath"], barHeaderJar) {
|
|
|
|
t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], barHeaderJar)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 01:06:12 +01:00
|
|
|
func TestDroiddoc(t *testing.T) {
|
2020-06-08 01:58:18 +02:00
|
|
|
ctx, _ := testJavaWithFS(t, `
|
2019-12-19 11:21:09 +01:00
|
|
|
droiddoc_exported_dir {
|
Add droiddoc_template
We prefer not to use absolute paths in modules, but to reference modules
that have associated paths. This a few benefits:
* it's easier to move a module than to update all the references
* if the module doesn't exist, we treat it as a normal missing
dependency, not having to deal with the missing dependency in path.go
* implementing visibility(etc) in the future would be simpler if there
was a module attached to the reference, so we don't have to do various
path-based lookups to try and match things up.
So define a `droiddoc_template` module, which takes a path, and will run
the glob once in that module. All of the `droiddoc` modules can then
specify it through the `custom_template` property, which will pull the
necessary data.
Also fix that htmldirs should be references from the local path, the
htmldir2 argument never being specified, and complain if more than two
htmldirs are specified, or if the custom template isn't specified.
Test: m core-docs
Test: out/soong/build.ninja is nearly identical
- line numbers in comments
- adds directories to droiddoc template dependency lists, which
is more correct, since we need to rerun on added or removed
files too.
Change-Id: Iff630bddb3818b8eeed439de7e41fc7fbe7cdcb0
2018-02-26 23:33:31 +01:00
|
|
|
name: "droiddoc-templates-sdk",
|
|
|
|
path: ".",
|
|
|
|
}
|
2019-07-07 09:27:47 +02:00
|
|
|
filegroup {
|
|
|
|
name: "bar-doc-aidl-srcs",
|
|
|
|
srcs: ["bar-doc/IBar.aidl"],
|
|
|
|
path: "bar-doc",
|
|
|
|
}
|
2020-09-10 17:29:25 +02:00
|
|
|
droidstubs {
|
|
|
|
name: "bar-stubs",
|
2020-08-14 21:14:02 +02:00
|
|
|
srcs: [
|
2020-09-01 19:58:01 +02:00
|
|
|
"bar-doc/a.java",
|
2020-08-14 21:14:02 +02:00
|
|
|
],
|
2020-09-01 19:58:01 +02:00
|
|
|
exclude_srcs: [
|
|
|
|
"bar-doc/b.java"
|
|
|
|
],
|
2020-09-10 17:29:25 +02:00
|
|
|
api_levels_annotations_dirs: [
|
|
|
|
"droiddoc-templates-sdk",
|
|
|
|
],
|
|
|
|
api_levels_annotations_enabled: true,
|
|
|
|
}
|
|
|
|
droiddoc {
|
|
|
|
name: "bar-doc",
|
|
|
|
srcs: [
|
|
|
|
":bar-stubs",
|
|
|
|
"bar-doc/IFoo.aidl",
|
|
|
|
":bar-doc-aidl-srcs",
|
|
|
|
],
|
Add droiddoc_template
We prefer not to use absolute paths in modules, but to reference modules
that have associated paths. This a few benefits:
* it's easier to move a module than to update all the references
* if the module doesn't exist, we treat it as a normal missing
dependency, not having to deal with the missing dependency in path.go
* implementing visibility(etc) in the future would be simpler if there
was a module attached to the reference, so we don't have to do various
path-based lookups to try and match things up.
So define a `droiddoc_template` module, which takes a path, and will run
the glob once in that module. All of the `droiddoc` modules can then
specify it through the `custom_template` property, which will pull the
necessary data.
Also fix that htmldirs should be references from the local path, the
htmldir2 argument never being specified, and complain if more than two
htmldirs are specified, or if the custom template isn't specified.
Test: m core-docs
Test: out/soong/build.ninja is nearly identical
- line numbers in comments
- adds directories to droiddoc template dependency lists, which
is more correct, since we need to rerun on added or removed
files too.
Change-Id: Iff630bddb3818b8eeed439de7e41fc7fbe7cdcb0
2018-02-26 23:33:31 +01:00
|
|
|
custom_template: "droiddoc-templates-sdk",
|
2018-01-11 01:06:12 +01:00
|
|
|
hdf: [
|
|
|
|
"android.whichdoc offline",
|
|
|
|
],
|
|
|
|
knowntags: [
|
|
|
|
"bar-doc/known_oj_tags.txt",
|
|
|
|
],
|
|
|
|
proofread_file: "libcore-proofread.txt",
|
|
|
|
todo_file: "libcore-docs-todo.html",
|
2020-07-06 18:12:57 +02:00
|
|
|
flags: ["-offlinemode -title \"libcore\""],
|
2018-01-11 01:06:12 +01:00
|
|
|
}
|
2020-06-08 01:58:18 +02:00
|
|
|
`,
|
|
|
|
map[string][]byte{
|
|
|
|
"bar-doc/a.java": nil,
|
|
|
|
"bar-doc/b.java": nil,
|
|
|
|
})
|
2020-09-10 17:29:25 +02:00
|
|
|
barStubs := ctx.ModuleForTests("bar-stubs", "android_common")
|
|
|
|
barStubsOutputs, err := barStubs.Module().(*Droidstubs).OutputFiles("")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unexpected error %q retrieving \"bar-stubs\" output file", err)
|
|
|
|
}
|
|
|
|
if len(barStubsOutputs) != 1 {
|
|
|
|
t.Errorf("Expected one output from \"bar-stubs\" got %s", barStubsOutputs)
|
2020-07-31 00:07:22 +02:00
|
|
|
}
|
2018-01-11 01:06:12 +01:00
|
|
|
|
2020-09-10 17:29:25 +02:00
|
|
|
barStubsOutput := barStubsOutputs[0]
|
|
|
|
barDoc := ctx.ModuleForTests("bar-doc", "android_common")
|
|
|
|
javaDoc := barDoc.Rule("javadoc")
|
|
|
|
if g, w := javaDoc.Implicits.Strings(), barStubsOutput.String(); !inList(w, g) {
|
|
|
|
t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g)
|
2018-05-23 11:42:04 +02:00
|
|
|
}
|
2020-09-10 17:29:25 +02:00
|
|
|
|
|
|
|
expected := "-sourcepath " + buildDir + "/.intermediates/bar-doc/android_common/srcjars "
|
|
|
|
if !strings.Contains(javaDoc.RuleParams.Command, expected) {
|
|
|
|
t.Errorf("bar-doc command does not contain flag %q, but should\n%q", expected, javaDoc.RuleParams.Command)
|
2019-07-07 09:27:47 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 17:29:25 +02:00
|
|
|
aidl := barDoc.Rule("aidl")
|
|
|
|
if g, w := javaDoc.Implicits.Strings(), aidl.Output.String(); !inList(w, g) {
|
2019-06-15 03:51:47 +02:00
|
|
|
t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := aidl.Implicits.Strings(), []string{"bar-doc/IBar.aidl", "bar-doc/IFoo.aidl"}; !reflect.DeepEqual(w, g) {
|
|
|
|
t.Errorf("aidl inputs must be %q, but was %q", w, g)
|
2018-05-23 11:42:04 +02:00
|
|
|
}
|
2018-01-11 01:06:12 +01:00
|
|
|
}
|
|
|
|
|
2020-07-06 18:12:57 +02:00
|
|
|
func TestDroiddocArgsAndFlagsCausesError(t *testing.T) {
|
|
|
|
testJavaError(t, "flags is set. Cannot set args", `
|
|
|
|
droiddoc_exported_dir {
|
|
|
|
name: "droiddoc-templates-sdk",
|
|
|
|
path: ".",
|
|
|
|
}
|
|
|
|
filegroup {
|
|
|
|
name: "bar-doc-aidl-srcs",
|
|
|
|
srcs: ["bar-doc/IBar.aidl"],
|
|
|
|
path: "bar-doc",
|
|
|
|
}
|
2020-09-10 17:29:25 +02:00
|
|
|
droidstubs {
|
|
|
|
name: "bar-stubs",
|
2020-08-14 21:14:02 +02:00
|
|
|
srcs: [
|
2020-09-01 19:58:01 +02:00
|
|
|
"bar-doc/a.java",
|
2020-08-14 21:14:02 +02:00
|
|
|
],
|
2020-09-01 19:58:01 +02:00
|
|
|
exclude_srcs: [
|
|
|
|
"bar-doc/b.java"
|
|
|
|
],
|
2020-09-10 17:29:25 +02:00
|
|
|
api_levels_annotations_dirs: [
|
|
|
|
"droiddoc-templates-sdk",
|
|
|
|
],
|
|
|
|
api_levels_annotations_enabled: true,
|
|
|
|
}
|
|
|
|
droiddoc {
|
|
|
|
name: "bar-doc",
|
|
|
|
srcs: [
|
|
|
|
":bar-stubs",
|
|
|
|
"bar-doc/IFoo.aidl",
|
|
|
|
":bar-doc-aidl-srcs",
|
|
|
|
],
|
2020-07-06 18:12:57 +02:00
|
|
|
custom_template: "droiddoc-templates-sdk",
|
|
|
|
hdf: [
|
|
|
|
"android.whichdoc offline",
|
|
|
|
],
|
|
|
|
knowntags: [
|
|
|
|
"bar-doc/known_oj_tags.txt",
|
|
|
|
],
|
|
|
|
proofread_file: "libcore-proofread.txt",
|
|
|
|
todo_file: "libcore-docs-todo.html",
|
|
|
|
flags: ["-offlinemode -title \"libcore\""],
|
|
|
|
args: "-offlinemode -title \"libcore\"",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-08-04 18:55:13 +02:00
|
|
|
func TestDroidstubs(t *testing.T) {
|
|
|
|
ctx, _ := testJavaWithFS(t, `
|
|
|
|
droiddoc_exported_dir {
|
2020-10-26 10:57:40 +01:00
|
|
|
name: "droiddoc-templates-sdk",
|
|
|
|
path: ".",
|
2020-08-04 18:55:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
droidstubs {
|
2020-10-26 10:57:40 +01:00
|
|
|
name: "bar-stubs",
|
|
|
|
srcs: ["bar-doc/a.java"],
|
|
|
|
api_levels_annotations_dirs: ["droiddoc-templates-sdk"],
|
|
|
|
api_levels_annotations_enabled: true,
|
2020-08-04 18:55:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
droidstubs {
|
2020-10-26 10:57:40 +01:00
|
|
|
name: "bar-stubs-other",
|
|
|
|
srcs: ["bar-doc/a.java"],
|
|
|
|
high_mem: true,
|
|
|
|
api_levels_annotations_dirs: ["droiddoc-templates-sdk"],
|
|
|
|
api_levels_annotations_enabled: true,
|
|
|
|
api_levels_jar_filename: "android.other.jar",
|
2020-08-04 18:55:13 +02:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
map[string][]byte{
|
|
|
|
"bar-doc/a.java": nil,
|
|
|
|
})
|
|
|
|
testcases := []struct {
|
|
|
|
moduleName string
|
|
|
|
expectedJarFilename string
|
2020-10-26 10:57:40 +01:00
|
|
|
high_mem bool
|
2020-08-04 18:55:13 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleName: "bar-stubs",
|
|
|
|
expectedJarFilename: "android.jar",
|
2020-10-26 10:57:40 +01:00
|
|
|
high_mem: false,
|
2020-08-04 18:55:13 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleName: "bar-stubs-other",
|
|
|
|
expectedJarFilename: "android.other.jar",
|
2020-10-26 10:57:40 +01:00
|
|
|
high_mem: true,
|
2020-08-04 18:55:13 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, c := range testcases {
|
|
|
|
m := ctx.ModuleForTests(c.moduleName, "android_common")
|
|
|
|
metalava := m.Rule("metalava")
|
2020-10-26 10:57:40 +01:00
|
|
|
rp := metalava.RuleParams
|
2020-08-04 18:55:13 +02:00
|
|
|
expected := "--android-jar-pattern ./%/public/" + c.expectedJarFilename
|
2020-10-26 10:57:40 +01:00
|
|
|
if actual := rp.Command; !strings.Contains(actual, expected) {
|
2020-08-04 18:55:13 +02:00
|
|
|
t.Errorf("For %q, expected metalava argument %q, but was not found %q", c.moduleName, expected, actual)
|
|
|
|
}
|
2020-10-26 10:57:40 +01:00
|
|
|
|
|
|
|
if actual := rp.Pool != nil && strings.Contains(rp.Pool.String(), "highmem"); actual != c.high_mem {
|
|
|
|
t.Errorf("Expected %q high_mem to be %v, was %v", c.moduleName, c.high_mem, actual)
|
|
|
|
}
|
2020-08-04 18:55:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 20:44:10 +01:00
|
|
|
func TestDroidstubsWithSystemModules(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, `
|
|
|
|
droidstubs {
|
|
|
|
name: "stubs-source-system-modules",
|
|
|
|
srcs: [
|
2020-06-08 01:58:18 +02:00
|
|
|
"bar-doc/a.java",
|
2019-11-19 20:44:10 +01:00
|
|
|
],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "source-system-modules",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "source-jar",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_system_modules {
|
|
|
|
name: "source-system-modules",
|
|
|
|
libs: ["source-jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
droidstubs {
|
|
|
|
name: "stubs-prebuilt-system-modules",
|
|
|
|
srcs: [
|
2020-06-08 01:58:18 +02:00
|
|
|
"bar-doc/a.java",
|
2019-11-19 20:44:10 +01:00
|
|
|
],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "prebuilt-system-modules",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "prebuilt-jar",
|
|
|
|
jars: ["a.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_system_modules_import {
|
|
|
|
name: "prebuilt-system-modules",
|
|
|
|
libs: ["prebuilt-jar"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
checkSystemModulesUseByDroidstubs(t, ctx, "stubs-source-system-modules", "source-jar.jar")
|
|
|
|
|
|
|
|
checkSystemModulesUseByDroidstubs(t, ctx, "stubs-prebuilt-system-modules", "prebuilt-jar.jar")
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkSystemModulesUseByDroidstubs(t *testing.T, ctx *android.TestContext, moduleName string, systemJar string) {
|
|
|
|
metalavaRule := ctx.ModuleForTests(moduleName, "android_common").Rule("metalava")
|
|
|
|
var systemJars []string
|
|
|
|
for _, i := range metalavaRule.Implicits {
|
|
|
|
systemJars = append(systemJars, i.Base())
|
|
|
|
}
|
2020-04-30 09:08:37 +02:00
|
|
|
if len(systemJars) < 1 || systemJars[0] != systemJar {
|
2019-11-19 20:44:10 +01:00
|
|
|
t.Errorf("inputs of %q must be []string{%q}, but was %#v.", moduleName, systemJar, systemJars)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 18:28:08 +01:00
|
|
|
func TestJarGenrules(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2017-12-05 18:28:08 +01:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_genrule {
|
|
|
|
name: "jargen",
|
|
|
|
tool_files: ["b.java"],
|
|
|
|
cmd: "$(location b.java) $(in) $(out)",
|
|
|
|
out: ["jargen.jar"],
|
|
|
|
srcs: [":foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
static_libs: ["jargen"],
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
libs: ["jargen"],
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
foo := ctx.ModuleForTests("foo", "android_common").Output("javac/foo.jar")
|
|
|
|
jargen := ctx.ModuleForTests("jargen", "android_common").Output("jargen.jar")
|
|
|
|
bar := ctx.ModuleForTests("bar", "android_common").Output("javac/bar.jar")
|
|
|
|
baz := ctx.ModuleForTests("baz", "android_common").Output("javac/baz.jar")
|
|
|
|
barCombined := ctx.ModuleForTests("bar", "android_common").Output("combined/bar.jar")
|
|
|
|
|
2020-11-14 01:23:53 +01:00
|
|
|
if g, w := jargen.Implicits.Strings(), foo.Output.String(); !android.InList(w, g) {
|
|
|
|
t.Errorf("expected jargen inputs [%q], got %q", w, g)
|
2017-12-05 18:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bar.Args["classpath"], jargen.Output.String()) {
|
|
|
|
t.Errorf("bar classpath %v does not contain %q", bar.Args["classpath"], jargen.Output.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(baz.Args["classpath"], jargen.Output.String()) {
|
|
|
|
t.Errorf("baz classpath %v does not contain %q", baz.Args["classpath"], jargen.Output.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(barCombined.Inputs) != 2 ||
|
|
|
|
barCombined.Inputs[0].String() != bar.Output.String() ||
|
|
|
|
barCombined.Inputs[1].String() != jargen.Output.String() {
|
|
|
|
t.Errorf("bar combined jar inputs %v is not [%q, %q]",
|
|
|
|
barCombined.Inputs.Strings(), bar.Output.String(), jargen.Output.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 22:03:53 +01:00
|
|
|
func TestExcludeFileGroupInSrcs(t *testing.T) {
|
2019-07-17 20:15:09 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2018-02-09 22:03:53 +01:00
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java", ":foo-srcs"],
|
|
|
|
exclude_srcs: ["a.java", ":foo-excludes"],
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "foo-srcs",
|
|
|
|
srcs: ["java-fg/a.java", "java-fg/b.java", "java-fg/c.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "foo-excludes",
|
|
|
|
srcs: ["java-fg/a.java", "java-fg/b.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
|
|
|
|
|
|
|
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "java-fg/c.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["java-fg/c.java"]`, javac.Inputs)
|
|
|
|
}
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2019-06-11 13:31:14 +02:00
|
|
|
func TestJavaLibrary(t *testing.T) {
|
2019-12-14 05:41:13 +01:00
|
|
|
config := testConfig(nil, "", map[string][]byte{
|
2019-06-11 13:31:14 +02:00
|
|
|
"libcore/Android.bp": []byte(`
|
|
|
|
java_library {
|
|
|
|
name: "core",
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
2020-10-06 18:20:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "core-jar",
|
|
|
|
srcs: [":core{.jar}"],
|
|
|
|
}
|
|
|
|
`),
|
|
|
|
})
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx := testContext(config)
|
2020-10-06 18:20:13 +02:00
|
|
|
run(t, ctx, config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaImport(t *testing.T) {
|
|
|
|
config := testConfig(nil, "", map[string][]byte{
|
|
|
|
"libcore/Android.bp": []byte(`
|
|
|
|
java_import {
|
|
|
|
name: "core",
|
|
|
|
sdk_version: "none",
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "core-jar",
|
|
|
|
srcs: [":core{.jar}"],
|
|
|
|
}
|
|
|
|
`),
|
2019-06-11 13:31:14 +02:00
|
|
|
})
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx := testContext(config)
|
2019-06-11 13:31:14 +02:00
|
|
|
run(t, ctx, config)
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
func TestJavaSdkLibrary(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, `
|
2019-12-19 11:21:09 +01:00
|
|
|
droiddoc_exported_dir {
|
2018-04-10 06:07:10 +02:00
|
|
|
name: "droiddoc-templates-sdk",
|
|
|
|
path: ".",
|
|
|
|
}
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
}
|
|
|
|
java_sdk_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
api_packages: ["bar"],
|
|
|
|
}
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
2020-05-15 11:20:31 +02:00
|
|
|
libs: ["foo", "bar.stubs"],
|
2018-04-10 06:07:10 +02:00
|
|
|
sdk_version: "system_current",
|
|
|
|
}
|
2020-05-15 21:37:11 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "barney",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
api_only: true,
|
|
|
|
}
|
|
|
|
java_sdk_library {
|
|
|
|
name: "betty",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
shared_library: false,
|
|
|
|
}
|
2020-05-15 11:20:31 +02:00
|
|
|
java_sdk_library_import {
|
|
|
|
name: "quuz",
|
|
|
|
public: {
|
|
|
|
jars: ["c.jar"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
java_sdk_library_import {
|
|
|
|
name: "fred",
|
|
|
|
public: {
|
|
|
|
jars: ["b.jar"],
|
|
|
|
},
|
|
|
|
}
|
2020-05-15 21:37:11 +02:00
|
|
|
java_sdk_library_import {
|
|
|
|
name: "wilma",
|
|
|
|
public: {
|
|
|
|
jars: ["b.jar"],
|
|
|
|
},
|
|
|
|
shared_library: false,
|
|
|
|
}
|
2018-05-28 11:02:19 +02:00
|
|
|
java_library {
|
|
|
|
name: "qux",
|
|
|
|
srcs: ["c.java"],
|
2020-05-15 21:37:11 +02:00
|
|
|
libs: ["baz", "fred", "quuz.stubs", "wilma", "barney", "betty"],
|
2018-05-28 11:02:19 +02:00
|
|
|
sdk_version: "system_current",
|
|
|
|
}
|
2020-01-22 17:30:37 +01:00
|
|
|
java_library {
|
|
|
|
name: "baz-test",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
libs: ["foo"],
|
|
|
|
sdk_version: "test_current",
|
|
|
|
}
|
2020-01-22 18:11:15 +01:00
|
|
|
java_library {
|
|
|
|
name: "baz-29",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
libs: ["foo"],
|
|
|
|
sdk_version: "system_29",
|
|
|
|
}
|
2020-09-30 16:17:25 +02:00
|
|
|
java_library {
|
|
|
|
name: "baz-module-30",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
libs: ["foo"],
|
|
|
|
sdk_version: "module_30",
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
`)
|
|
|
|
|
|
|
|
// check the existence of the internal modules
|
2021-03-12 20:15:01 +01:00
|
|
|
result.ModuleForTests("foo", "android_common")
|
|
|
|
result.ModuleForTests(apiScopePublic.stubsLibraryModuleName("foo"), "android_common")
|
|
|
|
result.ModuleForTests(apiScopeSystem.stubsLibraryModuleName("foo"), "android_common")
|
|
|
|
result.ModuleForTests(apiScopeTest.stubsLibraryModuleName("foo"), "android_common")
|
|
|
|
result.ModuleForTests(apiScopePublic.stubsSourceModuleName("foo"), "android_common")
|
|
|
|
result.ModuleForTests(apiScopeSystem.stubsSourceModuleName("foo"), "android_common")
|
|
|
|
result.ModuleForTests(apiScopeTest.stubsSourceModuleName("foo"), "android_common")
|
|
|
|
result.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common")
|
|
|
|
result.ModuleForTests("foo.api.public.28", "")
|
|
|
|
result.ModuleForTests("foo.api.system.28", "")
|
|
|
|
result.ModuleForTests("foo.api.test.28", "")
|
|
|
|
|
|
|
|
bazJavac := result.ModuleForTests("baz", "android_common").Rule("javac")
|
2018-04-10 06:07:10 +02:00
|
|
|
// tests if baz is actually linked to the stubs lib
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertStringDoesContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.system.jar")
|
2018-04-10 06:07:10 +02:00
|
|
|
// ... and not to the impl lib
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertStringDoesNotContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.jar")
|
2018-04-10 06:07:10 +02:00
|
|
|
// test if baz is not linked to the system variant of foo
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertStringDoesNotContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.jar")
|
2018-05-28 11:02:19 +02:00
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
bazTestJavac := result.ModuleForTests("baz-test", "android_common").Rule("javac")
|
2020-01-22 17:30:37 +01:00
|
|
|
// tests if baz-test is actually linked to the test stubs lib
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertStringDoesContain(t, "baz-test javac classpath", bazTestJavac.Args["classpath"], "foo.stubs.test.jar")
|
2020-01-22 17:30:37 +01:00
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
baz29Javac := result.ModuleForTests("baz-29", "android_common").Rule("javac")
|
2020-01-22 18:11:15 +01:00
|
|
|
// tests if baz-29 is actually linked to the system 29 stubs lib
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertStringDoesContain(t, "baz-29 javac classpath", baz29Javac.Args["classpath"], "prebuilts/sdk/29/system/foo.jar")
|
2020-01-22 18:11:15 +01:00
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
bazModule30Javac := result.ModuleForTests("baz-module-30", "android_common").Rule("javac")
|
2020-09-30 16:17:25 +02:00
|
|
|
// tests if "baz-module-30" is actually linked to the module 30 stubs lib
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertStringDoesContain(t, "baz-module-30 javac classpath", bazModule30Javac.Args["classpath"], "prebuilts/sdk/30/module-lib/foo.jar")
|
2020-09-30 16:17:25 +02:00
|
|
|
|
2018-05-28 11:02:19 +02:00
|
|
|
// test if baz has exported SDK lib names foo and bar to qux
|
2021-03-12 20:15:01 +01:00
|
|
|
qux := result.ModuleForTests("qux", "android_common")
|
2018-05-28 11:02:19 +02:00
|
|
|
if quxLib, ok := qux.Module().(*Library); ok {
|
2020-10-08 13:53:58 +02:00
|
|
|
sdkLibs := quxLib.ClassLoaderContexts().UsesLibs()
|
2021-03-12 20:15:01 +01:00
|
|
|
android.AssertDeepEquals(t, "qux exports", []string{"foo", "bar", "fred", "quuz"}, sdkLibs)
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
2018-08-21 17:10:29 +02:00
|
|
|
|
2020-10-08 15:47:23 +02:00
|
|
|
func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, `
|
2020-10-08 15:47:23 +02:00
|
|
|
java_sdk_library {
|
2020-12-21 18:10:01 +01:00
|
|
|
name: "sdklib",
|
2020-10-08 15:47:23 +02:00
|
|
|
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",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2020-12-21 18:10:01 +01:00
|
|
|
for _, implName := range []string{"sdklib", "sdklib.impl"} {
|
2021-03-12 20:15:01 +01:00
|
|
|
implJavacCp := result.ModuleForTests(implName, "android_common").Rule("javac").Args["classpath"]
|
2020-10-08 15:47:23 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 18:10:01 +01:00
|
|
|
stubName := apiScopePublic.stubsLibraryModuleName("sdklib")
|
2021-03-12 20:15:01 +01:00
|
|
|
stubsJavacCp := result.ModuleForTests(stubName, "android_common").Rule("javac").Args["classpath"]
|
2020-10-08 15:47:23 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 19:13:57 +02:00
|
|
|
func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, `
|
2020-05-26 19:13:57 +02:00
|
|
|
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.
|
2021-03-12 20:15:01 +01:00
|
|
|
barLibrary := result.ModuleForTests("bar", "android_common").Rule("javac")
|
2020-05-26 19:13:57 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:39:10 +02:00
|
|
|
func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.RunTestWithBp(t, `
|
2020-05-14 16:39:10 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
public: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java", ":foo{.public.stubs.source}"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaSdkLibrary_AccessOutputFiles_MissingScope(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`"foo" does not provide api scope system`)).
|
|
|
|
RunTestWithBp(t, `
|
2020-05-14 16:39:10 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
public: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java", ":foo{.system.stubs.source}"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-06-26 23:20:25 +02:00
|
|
|
func TestJavaSdkLibrary_Deps(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, `
|
2020-06-26 23:20:25 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "sdklib",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
public: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{
|
2020-06-26 23:20:25 +02:00
|
|
|
`dex2oatd`,
|
|
|
|
`sdklib.impl`,
|
|
|
|
`sdklib.stubs`,
|
|
|
|
`sdklib.stubs.source`,
|
|
|
|
`sdklib.xml`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:39:10 +02:00
|
|
|
func TestJavaSdkLibraryImport_AccessOutputFiles(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.RunTestWithBp(t, `
|
2020-05-14 16:39:10 +02:00
|
|
|
java_sdk_library_import {
|
|
|
|
name: "foo",
|
|
|
|
public: {
|
|
|
|
jars: ["a.jar"],
|
|
|
|
stub_srcs: ["a.java"],
|
|
|
|
current_api: "api/current.txt",
|
|
|
|
removed_api: "api/removed.txt",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: [":foo{.public.stubs.source}"],
|
|
|
|
java_resources: [
|
|
|
|
":foo{.public.api.txt}",
|
|
|
|
":foo{.public.removed-api.txt}",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaSdkLibraryImport_AccessOutputFiles_Invalid(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
java_sdk_library_import {
|
|
|
|
name: "foo",
|
|
|
|
public: {
|
|
|
|
jars: ["a.jar"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
t.Run("stubs.source", func(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`stubs.source not available for api scope public`)).
|
|
|
|
RunTestWithBp(t, bp+`
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: [":foo{.public.stubs.source}"],
|
|
|
|
java_resources: [
|
|
|
|
":foo{.public.api.txt}",
|
|
|
|
":foo{.public.removed-api.txt}",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
2020-05-14 16:39:10 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("api.txt", func(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`api.txt not available for api scope public`)).
|
|
|
|
RunTestWithBp(t, bp+`
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
java_resources: [
|
|
|
|
":foo{.public.api.txt}",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
2020-05-14 16:39:10 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("removed-api.txt", func(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`removed-api.txt not available for api scope public`)).
|
|
|
|
RunTestWithBp(t, bp+`
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
java_resources: [
|
|
|
|
":foo{.public.removed-api.txt}",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
2020-05-14 16:39:10 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
func TestJavaSdkLibrary_InvalidScopes(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "foo": enabled api scope "system" depends on disabled scope "public"`)).
|
|
|
|
RunTestWithBp(t, `
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
// Explicitly disable public to test the check that ensures the set of enabled
|
|
|
|
// scopes is consistent.
|
|
|
|
public: {
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
system: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
2020-04-28 11:44:03 +02:00
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-05-12 12:50:28 +02:00
|
|
|
func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.RunTestWithBp(t, `
|
2020-05-12 12:50:28 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
system: {
|
|
|
|
enabled: true,
|
|
|
|
sdk_version: "module_current",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:00:08 +02:00
|
|
|
func TestJavaSdkLibrary_ModuleLib(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.RunTestWithBp(t, `
|
2020-06-02 14:00:08 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
system: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
module_lib: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaSdkLibrary_SystemServer(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.RunTestWithBp(t, `
|
2020-06-02 14:00:08 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
system: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
system_server: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-05-20 12:52:25 +02:00
|
|
|
func TestJavaSdkLibrary_MissingScope(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`requires api scope module-lib from foo but it only has \[\] available`)).
|
|
|
|
RunTestWithBp(t, `
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
public: {
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
}
|
2020-05-20 12:52:25 +02:00
|
|
|
|
2021-03-12 20:15:01 +01:00
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["foo"],
|
|
|
|
sdk_version: "module_current",
|
|
|
|
}
|
2020-05-20 12:52:25 +02:00
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaSdkLibrary_FallbackScope(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
javaFixtureFactory.RunTestWithBp(t, `
|
2020-05-20 12:52:25 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
system: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["foo"],
|
|
|
|
// foo does not have module-lib scope so it should fallback to system
|
|
|
|
sdk_version: "module_current",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:19:53 +02:00
|
|
|
func TestJavaSdkLibrary_DefaultToStubs(t *testing.T) {
|
2021-03-12 20:15:01 +01:00
|
|
|
result := javaFixtureFactory.RunTestWithBp(t, `
|
2020-05-27 17:19:53 +02:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
system: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
default_to_stubs: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["foo"],
|
|
|
|
// does not have sdk_version set, should fallback to module,
|
|
|
|
// which will then fallback to system because the module scope
|
|
|
|
// is not enabled.
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
// The baz library should depend on the system stubs jar.
|
2021-03-12 20:15:01 +01:00
|
|
|
bazLibrary := result.ModuleForTests("baz", "android_common").Rule("javac")
|
2020-05-27 17:19:53 +02:00
|
|
|
if expected, actual := `^-classpath .*:/[^:]*/turbine-combined/foo\.stubs.system\.jar$`, bazLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) {
|
|
|
|
t.Errorf("expected %q, found %#q", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 17:10:29 +02:00
|
|
|
var compilerFlagsTestCases = []struct {
|
|
|
|
in string
|
|
|
|
out bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
in: "a",
|
|
|
|
out: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: "-a",
|
|
|
|
out: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: "-no-jdk",
|
|
|
|
out: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: "-no-stdlib",
|
|
|
|
out: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: "-kotlin-home",
|
|
|
|
out: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: "-kotlin-home /some/path",
|
|
|
|
out: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: "-include-runtime",
|
|
|
|
out: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: "-Xintellij-plugin-root",
|
|
|
|
out: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockContext struct {
|
|
|
|
android.ModuleContext
|
|
|
|
result bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
|
|
|
|
// CheckBadCompilerFlags calls this function when the flag should be rejected
|
|
|
|
ctx.result = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCompilerFlags(t *testing.T) {
|
|
|
|
for _, testCase := range compilerFlagsTestCases {
|
|
|
|
ctx := &mockContext{result: true}
|
|
|
|
CheckKotlincFlags(ctx, []string{testCase.in})
|
|
|
|
if ctx.result != testCase.out {
|
|
|
|
t.Errorf("incorrect output:")
|
|
|
|
t.Errorf(" input: %#v", testCase.in)
|
|
|
|
t.Errorf(" expected: %#v", testCase.out)
|
|
|
|
t.Errorf(" got: %#v", ctx.result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-12 18:01:34 +01:00
|
|
|
|
|
|
|
// TODO(jungjw): Consider making this more robust by ignoring path order.
|
|
|
|
func checkPatchModuleFlag(t *testing.T, ctx *android.TestContext, moduleName string, expected string) {
|
|
|
|
variables := ctx.ModuleForTests(moduleName, "android_common").Module().VariablesForTests()
|
|
|
|
flags := strings.Split(variables["javacFlags"], " ")
|
|
|
|
got := ""
|
|
|
|
for _, flag := range flags {
|
|
|
|
keyEnd := strings.Index(flag, "=")
|
|
|
|
if keyEnd > -1 && flag[:keyEnd] == "--patch-module" {
|
|
|
|
got = flag[keyEnd+1:]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if expected != got {
|
|
|
|
t.Errorf("Unexpected patch-module flag for module %q - expected %q, but got %q", moduleName, expected, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPatchModule(t *testing.T) {
|
2019-05-02 16:32:11 +02:00
|
|
|
t.Run("Java language level 8", func(t *testing.T) {
|
2019-10-01 14:57:31 +02:00
|
|
|
// Test with legacy javac -source 1.8 -target 1.8
|
2019-10-21 15:29:58 +02:00
|
|
|
bp := `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
java_version: "1.8",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
patch_module: "java.base",
|
|
|
|
java_version: "1.8",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
patch_module: "java.base",
|
|
|
|
java_version: "1.8",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
ctx, _ := testJava(t, bp)
|
2018-12-12 18:01:34 +01:00
|
|
|
|
|
|
|
checkPatchModuleFlag(t, ctx, "foo", "")
|
|
|
|
checkPatchModuleFlag(t, ctx, "bar", "")
|
|
|
|
checkPatchModuleFlag(t, ctx, "baz", "")
|
|
|
|
})
|
|
|
|
|
2019-05-02 16:32:11 +02:00
|
|
|
t.Run("Java language level 9", func(t *testing.T) {
|
2019-10-01 14:57:31 +02:00
|
|
|
// Test with default javac -source 9 -target 9
|
2019-10-21 15:29:58 +02:00
|
|
|
bp := `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
patch_module: "java.base",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
2020-10-30 06:01:35 +01:00
|
|
|
srcs: [
|
|
|
|
"c.java",
|
|
|
|
// Tests for b/150878007
|
|
|
|
"dir/d.java",
|
|
|
|
"dir2/e.java",
|
|
|
|
"dir2/f.java",
|
|
|
|
"nested/dir/g.java"
|
|
|
|
],
|
2019-10-21 15:29:58 +02:00
|
|
|
patch_module: "java.base",
|
|
|
|
}
|
|
|
|
`
|
2019-10-01 14:57:31 +02:00
|
|
|
ctx, _ := testJava(t, bp)
|
2018-12-12 18:01:34 +01:00
|
|
|
|
|
|
|
checkPatchModuleFlag(t, ctx, "foo", "")
|
|
|
|
expected := "java.base=.:" + buildDir
|
|
|
|
checkPatchModuleFlag(t, ctx, "bar", expected)
|
2020-10-30 06:01:35 +01:00
|
|
|
expected = "java.base=" + strings.Join([]string{
|
2021-03-08 22:48:46 +01:00
|
|
|
".", buildDir, "dir", "dir2", "nested", defaultModuleToPath("ext"), defaultModuleToPath("framework")}, ":")
|
2018-12-12 18:01:34 +01:00
|
|
|
checkPatchModuleFlag(t, ctx, "baz", expected)
|
|
|
|
})
|
|
|
|
}
|
2020-01-10 18:12:18 +01:00
|
|
|
|
2019-11-19 20:44:10 +01:00
|
|
|
func TestJavaLibraryWithSystemModules(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "lib-with-source-system-modules",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "source-system-modules",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "source-jar",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_system_modules {
|
|
|
|
name: "source-system-modules",
|
|
|
|
libs: ["source-jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "lib-with-prebuilt-system-modules",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "prebuilt-system-modules",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "prebuilt-jar",
|
|
|
|
jars: ["a.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_system_modules_import {
|
|
|
|
name: "prebuilt-system-modules",
|
|
|
|
libs: ["prebuilt-jar"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
checkBootClasspathForSystemModule(t, ctx, "lib-with-source-system-modules", "/source-jar.jar")
|
|
|
|
|
|
|
|
checkBootClasspathForSystemModule(t, ctx, "lib-with-prebuilt-system-modules", "/prebuilt-jar.jar")
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkBootClasspathForSystemModule(t *testing.T, ctx *android.TestContext, moduleName string, expectedSuffix string) {
|
|
|
|
javacRule := ctx.ModuleForTests(moduleName, "android_common").Rule("javac")
|
|
|
|
bootClasspath := javacRule.Args["bootClasspath"]
|
|
|
|
if strings.HasPrefix(bootClasspath, "--system ") && strings.HasSuffix(bootClasspath, expectedSuffix) {
|
|
|
|
t.Errorf("bootclasspath of %q must start with --system and end with %q, but was %#v.", moduleName, expectedSuffix, bootClasspath)
|
|
|
|
}
|
|
|
|
}
|
2020-03-24 08:44:11 +01:00
|
|
|
|
|
|
|
func TestAidlExportIncludeDirsFromImports(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["aidl/foo/IFoo.aidl"],
|
|
|
|
libs: ["bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "bar",
|
|
|
|
jars: ["a.jar"],
|
|
|
|
aidl: {
|
|
|
|
export_include_dirs: ["aidl/bar"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command
|
|
|
|
expectedAidlFlag := "-Iaidl/bar"
|
|
|
|
if !strings.Contains(aidlCommand, expectedAidlFlag) {
|
|
|
|
t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
|
|
|
|
}
|
|
|
|
}
|
2020-06-13 01:38:45 +02:00
|
|
|
|
2021-01-05 02:33:16 +01:00
|
|
|
func TestAidlFlagsArePassedToTheAidlCompiler(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["aidl/foo/IFoo.aidl"],
|
|
|
|
aidl: { flags: ["-Werror"], },
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command
|
|
|
|
expectedAidlFlag := "-Werror"
|
|
|
|
if !strings.Contains(aidlCommand, expectedAidlFlag) {
|
|
|
|
t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
func TestDataNativeBinaries(t *testing.T) {
|
2020-07-03 22:18:24 +02:00
|
|
|
ctx, _ := testJava(t, `
|
2020-06-13 01:38:45 +02:00
|
|
|
java_test_host {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
data_native_bins: ["bin"]
|
|
|
|
}
|
|
|
|
|
|
|
|
python_binary_host {
|
|
|
|
name: "bin",
|
|
|
|
srcs: ["bin.py"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
buildOS := android.BuildOs.String()
|
|
|
|
|
|
|
|
test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
|
2020-07-03 22:18:24 +02:00
|
|
|
entries := android.AndroidMkEntriesForTest(t, ctx, test)[0]
|
2020-06-13 01:38:45 +02:00
|
|
|
expected := []string{buildDir + "/.intermediates/bin/" + buildOS + "_x86_64_PY3/bin:bin"}
|
|
|
|
actual := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
|
|
|
t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual)
|
|
|
|
}
|
|
|
|
}
|