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 (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
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
|
|
|
|
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"
|
2018-10-03 07:03:40 +02:00
|
|
|
"android/soong/genrule"
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
func testConfig(env map[string]string) android.Config {
|
2019-02-15 19:37:39 +01:00
|
|
|
return TestConfig(buildDir, env)
|
2017-09-30 02:58:17 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 07:56:16 +01:00
|
|
|
func testContext(config android.Config, bp string,
|
|
|
|
fs map[string][]byte) *android.TestContext {
|
2017-07-14 01:23:21 +02:00
|
|
|
|
2017-09-16 02:36:05 +02:00
|
|
|
ctx := android.NewTestArchContext()
|
2017-07-14 01:23:21 +02:00
|
|
|
ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory))
|
2019-01-18 23:27:16 +01:00
|
|
|
ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(AndroidAppCertificateFactory))
|
2018-03-28 23:58:31 +02:00
|
|
|
ctx.RegisterModuleType("android_library", android.ModuleFactoryAdaptor(AndroidLibraryFactory))
|
2018-10-03 07:03:40 +02:00
|
|
|
ctx.RegisterModuleType("android_test", android.ModuleFactoryAdaptor(AndroidTestFactory))
|
2019-01-06 07:12:12 +01:00
|
|
|
ctx.RegisterModuleType("android_test_helper_app", android.ModuleFactoryAdaptor(AndroidTestHelperAppFactory))
|
|
|
|
ctx.RegisterModuleType("java_binary", android.ModuleFactoryAdaptor(BinaryFactory))
|
2017-12-05 22:42:45 +01:00
|
|
|
ctx.RegisterModuleType("java_binary_host", android.ModuleFactoryAdaptor(BinaryHostFactory))
|
2019-03-01 22:46:24 +01:00
|
|
|
ctx.RegisterModuleType("java_device_for_host", android.ModuleFactoryAdaptor(DeviceForHostFactory))
|
|
|
|
ctx.RegisterModuleType("java_host_for_device", android.ModuleFactoryAdaptor(HostForDeviceFactory))
|
2018-06-27 02:59:05 +02:00
|
|
|
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory))
|
2017-09-16 04:44:24 +02:00
|
|
|
ctx.RegisterModuleType("java_library_host", android.ModuleFactoryAdaptor(LibraryHostFactory))
|
2019-01-06 07:12:12 +01:00
|
|
|
ctx.RegisterModuleType("java_test", android.ModuleFactoryAdaptor(TestFactory))
|
2017-08-02 20:05:49 +02:00
|
|
|
ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory))
|
2019-03-01 22:46:24 +01:00
|
|
|
ctx.RegisterModuleType("java_import_host", android.ModuleFactoryAdaptor(ImportFactoryHost))
|
2017-07-07 23:35:50 +02:00
|
|
|
ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
|
2017-09-30 02:58:17 +02:00
|
|
|
ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(SystemModulesFactory))
|
2017-12-05 18:28:08 +01:00
|
|
|
ctx.RegisterModuleType("java_genrule", android.ModuleFactoryAdaptor(genRuleFactory))
|
2019-01-22 06:37:16 +01:00
|
|
|
ctx.RegisterModuleType("java_plugin", android.ModuleFactoryAdaptor(PluginFactory))
|
2019-02-22 03:12:14 +01:00
|
|
|
ctx.RegisterModuleType("dex_import", android.ModuleFactoryAdaptor(DexImportFactory))
|
2018-04-17 23:58:42 +02:00
|
|
|
ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
|
2017-10-10 00:34:10 +02:00
|
|
|
ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(genrule.GenRuleFactory))
|
2018-01-11 01:06:12 +01:00
|
|
|
ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory))
|
|
|
|
ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory))
|
2018-08-02 00:00:28 +02:00
|
|
|
ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(ExportedDroiddocDirFactory))
|
2019-02-08 13:00:45 +01:00
|
|
|
ctx.RegisterModuleType("java_sdk_library", android.ModuleFactoryAdaptor(SdkLibraryFactory))
|
2019-03-01 00:35:54 +01:00
|
|
|
ctx.RegisterModuleType("override_android_app", android.ModuleFactoryAdaptor(OverrideAndroidAppModuleFactory))
|
2019-02-08 13:00:45 +01:00
|
|
|
ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(PrebuiltApisFactory))
|
2017-07-28 00:41:32 +02:00
|
|
|
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
|
|
|
|
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
|
2017-07-07 23:35:50 +02:00
|
|
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
2019-03-01 00:35:54 +01:00
|
|
|
ctx.PreArchMutators(android.RegisterOverridePreArchMutators)
|
2018-04-10 06:07:10 +02:00
|
|
|
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
|
2019-02-08 13:00:45 +01:00
|
|
|
ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel()
|
|
|
|
ctx.TopDown("java_sdk_library", SdkLibraryMutator).Parallel()
|
2018-04-10 06:07:10 +02:00
|
|
|
})
|
2017-11-23 01:19:37 +01:00
|
|
|
ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory))
|
2019-01-10 08:04:25 +01:00
|
|
|
ctx.RegisterPreSingletonType("sdk", android.SingletonFactoryAdaptor(sdkSingletonFactory))
|
2018-10-03 07:03:40 +02:00
|
|
|
|
|
|
|
// Register module types and mutators from cc needed for JNI testing
|
|
|
|
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
|
|
|
|
ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
|
|
|
|
ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
|
|
|
|
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("link", cc.LinkageMutator).Parallel()
|
|
|
|
ctx.BottomUp("begin", cc.BeginMutator).Parallel()
|
|
|
|
})
|
|
|
|
|
2019-02-15 19:37:39 +01:00
|
|
|
bp += GatherRequiredDepsForTest()
|
2017-09-30 02:58:17 +02:00
|
|
|
|
2017-11-23 02:27:51 +01:00
|
|
|
mockFS := map[string][]byte{
|
2018-05-12 15:29:12 +02:00
|
|
|
"Android.bp": []byte(bp),
|
|
|
|
"a.java": nil,
|
|
|
|
"b.java": nil,
|
|
|
|
"c.java": nil,
|
|
|
|
"b.kt": nil,
|
|
|
|
"a.jar": nil,
|
|
|
|
"b.jar": nil,
|
|
|
|
"java-res/a/a": nil,
|
|
|
|
"java-res/b/b": nil,
|
|
|
|
"java-res2/a": nil,
|
|
|
|
"java-fg/a.java": nil,
|
|
|
|
"java-fg/b.java": nil,
|
|
|
|
"java-fg/c.java": nil,
|
|
|
|
"api/current.txt": nil,
|
|
|
|
"api/removed.txt": nil,
|
|
|
|
"api/system-current.txt": nil,
|
|
|
|
"api/system-removed.txt": nil,
|
|
|
|
"api/test-current.txt": nil,
|
|
|
|
"api/test-removed.txt": nil,
|
2017-10-03 01:57:40 +02:00
|
|
|
|
2018-04-11 14:57:30 +02:00
|
|
|
"prebuilts/sdk/14/public/android.jar": nil,
|
|
|
|
"prebuilts/sdk/14/public/framework.aidl": nil,
|
|
|
|
"prebuilts/sdk/14/system/android.jar": nil,
|
2019-01-10 08:04:25 +01:00
|
|
|
"prebuilts/sdk/17/public/android.jar": nil,
|
|
|
|
"prebuilts/sdk/17/public/framework.aidl": nil,
|
|
|
|
"prebuilts/sdk/17/system/android.jar": nil,
|
2018-05-29 23:44:55 +02:00
|
|
|
"prebuilts/sdk/current/core/android.jar": nil,
|
2018-04-11 14:57:30 +02:00
|
|
|
"prebuilts/sdk/current/public/android.jar": nil,
|
|
|
|
"prebuilts/sdk/current/public/framework.aidl": nil,
|
|
|
|
"prebuilts/sdk/current/public/core.jar": nil,
|
|
|
|
"prebuilts/sdk/current/system/android.jar": nil,
|
|
|
|
"prebuilts/sdk/current/test/android.jar": nil,
|
2018-05-12 15:29:12 +02:00
|
|
|
"prebuilts/sdk/28/public/api/foo.txt": nil,
|
|
|
|
"prebuilts/sdk/28/system/api/foo.txt": nil,
|
|
|
|
"prebuilts/sdk/28/test/api/foo.txt": nil,
|
|
|
|
"prebuilts/sdk/28/public/api/foo-removed.txt": nil,
|
|
|
|
"prebuilts/sdk/28/system/api/foo-removed.txt": nil,
|
|
|
|
"prebuilts/sdk/28/test/api/foo-removed.txt": nil,
|
|
|
|
"prebuilts/sdk/28/public/api/bar.txt": nil,
|
|
|
|
"prebuilts/sdk/28/system/api/bar.txt": nil,
|
|
|
|
"prebuilts/sdk/28/test/api/bar.txt": nil,
|
|
|
|
"prebuilts/sdk/28/public/api/bar-removed.txt": nil,
|
|
|
|
"prebuilts/sdk/28/system/api/bar-removed.txt": nil,
|
|
|
|
"prebuilts/sdk/28/test/api/bar-removed.txt": nil,
|
2018-05-29 23:44:55 +02:00
|
|
|
"prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
|
2018-06-21 06:47:17 +02:00
|
|
|
"prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`),
|
2017-11-23 01:20:45 +01:00
|
|
|
|
|
|
|
// For framework-res, which is an implicit dependency for framework
|
|
|
|
"AndroidManifest.xml": nil,
|
|
|
|
"build/target/product/security/testkey": nil,
|
2017-12-05 22:42:45 +01:00
|
|
|
|
|
|
|
"build/soong/scripts/jar-wrapper.sh": nil,
|
2018-01-03 03:14:25 +01:00
|
|
|
|
2017-12-28 21:23:20 +01:00
|
|
|
"build/make/core/proguard.flags": nil,
|
|
|
|
"build/make/core/proguard_basic_keeps.flags": nil,
|
|
|
|
|
2018-01-03 03:14:25 +01:00
|
|
|
"jdk8/jre/lib/jce.jar": nil,
|
|
|
|
"jdk8/jre/lib/rt.jar": nil,
|
2018-05-05 03:49:16 +02:00
|
|
|
"jdk8/lib/tools.jar": nil,
|
2018-01-11 01:06:12 +01:00
|
|
|
|
|
|
|
"bar-doc/a.java": nil,
|
|
|
|
"bar-doc/b.java": nil,
|
2018-05-23 11:42:04 +02:00
|
|
|
"bar-doc/IFoo.aidl": nil,
|
2018-01-11 01:06:12 +01:00
|
|
|
"bar-doc/known_oj_tags.txt": nil,
|
|
|
|
"external/doclava/templates-sdk": nil,
|
2019-01-18 23:27:16 +01:00
|
|
|
|
|
|
|
"cert/new_cert.x509.pem": nil,
|
|
|
|
"cert/new_cert.pk8": nil,
|
2017-11-23 02:27:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range fs {
|
|
|
|
mockFS[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.MockFileSystem(mockFS)
|
2017-07-14 01:23:21 +02:00
|
|
|
|
2017-12-01 07:56:16 +01:00
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
pathCtx := android.PathContextForTesting(config, nil)
|
|
|
|
setDexpreoptTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
|
|
|
|
|
|
|
|
ctx.Register()
|
2018-05-12 15:29:12 +02:00
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp", "prebuilts/sdk/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
|
|
|
}
|
|
|
|
|
|
|
|
func testJava(t *testing.T, bp string) *android.TestContext {
|
2017-12-05 22:42:45 +01:00
|
|
|
t.Helper()
|
2017-12-01 07:56:16 +01:00
|
|
|
config := testConfig(nil)
|
|
|
|
ctx := testContext(config, bp, nil)
|
|
|
|
run(t, ctx, config)
|
2017-07-14 01:23:21 +02:00
|
|
|
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 01:23:21 +02:00
|
|
|
func TestSimple(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
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
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
if !strings.Contains(javac.Args["classpath"], barTurbine) {
|
|
|
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barTurbine)
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
if !strings.Contains(javac.Args["classpath"], bazTurbine) {
|
|
|
|
t.Errorf("foo classpath %v does not contain %q", 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:55:26 +02:00
|
|
|
func TestArchSpecific(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
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) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
java_library_host {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_binary_host {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
static_libs: ["foo"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
// Test that the install binary wrapper depends on the installed jar file
|
|
|
|
if len(barWrapperDeps) != 1 || barWrapperDeps[0] != barJar {
|
|
|
|
t.Errorf("expected binary wrapper implicits [%q], got %v",
|
|
|
|
barJar, barWrapperDeps)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-14 01:23:21 +02:00
|
|
|
func TestPrebuilts(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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"],
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
2019-02-22 03:12:14 +01:00
|
|
|
|
|
|
|
dex_import {
|
|
|
|
name: "qux",
|
|
|
|
jars: ["b.jar"],
|
|
|
|
}
|
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")
|
2018-07-12 21:28:41 +02:00
|
|
|
barJar := ctx.ModuleForTests("bar", "android_common").Rule("combineJar").Output
|
|
|
|
bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output
|
2017-07-14 01:23:21 +02: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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
ctx.ModuleForTests("qux", "android_common").Rule("Cp")
|
2017-07-14 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 23:35:50 +02:00
|
|
|
func TestDefaults(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
java_defaults {
|
|
|
|
name: "defaults",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
defaults: ["defaults"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test that a module with "include_srcs: true" includes its source files in the resources jar
|
|
|
|
name: "include sources",
|
|
|
|
prop: `include_srcs: true`,
|
2017-10-03 23:50:08 +02:00
|
|
|
args: "-C . -f a.java -f b.java -f c.java",
|
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) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"c.java",
|
|
|
|
],
|
|
|
|
`+test.prop+`,
|
|
|
|
}
|
|
|
|
`+test.extra)
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 00:34:10 +02:00
|
|
|
func TestGeneratedSources(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
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"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
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) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
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) {
|
|
|
|
ctx := testJava(t, `
|
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
|
|
|
droiddoc_template {
|
|
|
|
name: "droiddoc-templates-sdk",
|
|
|
|
path: ".",
|
|
|
|
}
|
2018-01-11 01:06:12 +01:00
|
|
|
droiddoc {
|
|
|
|
name: "bar-doc",
|
|
|
|
srcs: [
|
|
|
|
"bar-doc/*.java",
|
2018-05-23 11:42:04 +02:00
|
|
|
"bar-doc/IFoo.aidl",
|
2018-01-11 01:06:12 +01:00
|
|
|
],
|
|
|
|
exclude_srcs: [
|
|
|
|
"bar-doc/b.java"
|
|
|
|
],
|
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",
|
|
|
|
args: "-offlinemode -title \"libcore\"",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2018-02-28 19:14:25 +01:00
|
|
|
stubsJar := filepath.Join(buildDir, ".intermediates", "bar-doc", "android_common", "bar-doc-stubs.srcjar")
|
|
|
|
barDoc := ctx.ModuleForTests("bar-doc", "android_common").Output("bar-doc-stubs.srcjar")
|
2018-01-11 01:06:12 +01:00
|
|
|
if stubsJar != barDoc.Output.String() {
|
|
|
|
t.Errorf("expected stubs Jar [%q], got %q", stubsJar, barDoc.Output.String())
|
|
|
|
}
|
2018-05-23 11:42:04 +02:00
|
|
|
inputs := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc").Inputs
|
|
|
|
var javaSrcs []string
|
|
|
|
for _, i := range inputs {
|
|
|
|
javaSrcs = append(javaSrcs, i.Base())
|
|
|
|
}
|
|
|
|
if len(javaSrcs) != 2 || javaSrcs[0] != "a.java" || javaSrcs[1] != "IFoo.java" {
|
|
|
|
t.Errorf("inputs of bar-doc must be []string{\"a.java\", \"IFoo.java\", but was %#v.", javaSrcs)
|
|
|
|
}
|
2018-01-11 01:06:12 +01:00
|
|
|
}
|
|
|
|
|
2017-12-05 18:28:08 +01:00
|
|
|
func TestJarGenrules(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
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")
|
|
|
|
|
|
|
|
if len(jargen.Inputs) != 1 || jargen.Inputs[0].String() != foo.Output.String() {
|
|
|
|
t.Errorf("expected jargen inputs [%q], got %q", foo.Output.String(), jargen.Inputs.Strings())
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
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
|
|
|
|
|
|
|
func TestJavaSdkLibrary(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
droiddoc_template {
|
|
|
|
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"],
|
|
|
|
libs: ["foo", "bar"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
}
|
2018-05-28 11:02:19 +02:00
|
|
|
java_library {
|
|
|
|
name: "qux",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
libs: ["baz"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
`)
|
|
|
|
|
|
|
|
// check the existence of the internal modules
|
|
|
|
ctx.ModuleForTests("foo", "android_common")
|
|
|
|
ctx.ModuleForTests("foo"+sdkStubsLibrarySuffix, "android_common")
|
|
|
|
ctx.ModuleForTests("foo"+sdkStubsLibrarySuffix+sdkSystemApiSuffix, "android_common")
|
2018-05-12 15:29:12 +02:00
|
|
|
ctx.ModuleForTests("foo"+sdkStubsLibrarySuffix+sdkTestApiSuffix, "android_common")
|
2018-04-10 06:07:10 +02:00
|
|
|
ctx.ModuleForTests("foo"+sdkDocsSuffix, "android_common")
|
|
|
|
ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkSystemApiSuffix, "android_common")
|
2018-05-12 15:29:12 +02:00
|
|
|
ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkTestApiSuffix, "android_common")
|
2019-01-15 19:47:05 +01:00
|
|
|
ctx.ModuleForTests("foo"+sdkXmlFileSuffix, "android_arm64_armv8-a")
|
2018-05-12 15:29:12 +02:00
|
|
|
ctx.ModuleForTests("foo.api.public.28", "")
|
|
|
|
ctx.ModuleForTests("foo.api.system.28", "")
|
|
|
|
ctx.ModuleForTests("foo.api.test.28", "")
|
2018-04-10 06:07:10 +02:00
|
|
|
|
|
|
|
bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac")
|
|
|
|
// tests if baz is actually linked to the stubs lib
|
|
|
|
if !strings.Contains(bazJavac.Args["classpath"], "foo.stubs.system.jar") {
|
|
|
|
t.Errorf("baz javac classpath %v does not contain %q", bazJavac.Args["classpath"],
|
|
|
|
"foo.stubs.system.jar")
|
|
|
|
}
|
|
|
|
// ... and not to the impl lib
|
2018-10-19 06:46:09 +02:00
|
|
|
if strings.Contains(bazJavac.Args["classpath"], "foo.jar") {
|
2018-04-10 06:07:10 +02:00
|
|
|
t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"],
|
2018-10-19 06:46:09 +02:00
|
|
|
"foo.jar")
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
// test if baz is not linked to the system variant of foo
|
|
|
|
if strings.Contains(bazJavac.Args["classpath"], "foo.stubs.jar") {
|
|
|
|
t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"],
|
|
|
|
"foo.stubs.jar")
|
|
|
|
}
|
2018-05-28 11:02:19 +02:00
|
|
|
|
|
|
|
// test if baz has exported SDK lib names foo and bar to qux
|
|
|
|
qux := ctx.ModuleForTests("qux", "android_common")
|
|
|
|
if quxLib, ok := qux.Module().(*Library); ok {
|
|
|
|
sdkLibs := quxLib.ExportedSdkLibs()
|
|
|
|
if len(sdkLibs) != 2 || !android.InList("foo", sdkLibs) || !android.InList("bar", sdkLibs) {
|
|
|
|
t.Errorf("qux should export \"foo\" and \"bar\" but exports %v", sdkLibs)
|
|
|
|
}
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
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) {
|
|
|
|
bp := `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
no_standard_libs: true,
|
|
|
|
system_modules: "none",
|
|
|
|
patch_module: "java.base",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
patch_module: "java.base",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
t.Run("1.8", func(t *testing.T) {
|
|
|
|
// Test default javac 1.8
|
|
|
|
ctx := testJava(t, bp)
|
|
|
|
|
|
|
|
checkPatchModuleFlag(t, ctx, "foo", "")
|
|
|
|
checkPatchModuleFlag(t, ctx, "bar", "")
|
|
|
|
checkPatchModuleFlag(t, ctx, "baz", "")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("1.9", func(t *testing.T) {
|
|
|
|
// Test again with javac 1.9
|
|
|
|
config := testConfig(map[string]string{"EXPERIMENTAL_USE_OPENJDK9": "true"})
|
|
|
|
ctx := testContext(config, bp, nil)
|
|
|
|
run(t, ctx, config)
|
|
|
|
|
|
|
|
checkPatchModuleFlag(t, ctx, "foo", "")
|
|
|
|
expected := "java.base=.:" + buildDir
|
|
|
|
checkPatchModuleFlag(t, ctx, "bar", expected)
|
|
|
|
expected = "java.base=" + strings.Join([]string{".", buildDir, moduleToPath("ext"), moduleToPath("framework")}, ":")
|
|
|
|
checkPatchModuleFlag(t, ctx, "baz", expected)
|
|
|
|
})
|
|
|
|
}
|