2017-07-14 07:23:21 +08: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 (
|
|
|
|
"android/soong/android"
|
2017-09-28 08:42:05 +08:00
|
|
|
"android/soong/genrule"
|
2017-07-14 07:23:21 +08:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-08-31 05:14:52 +08:00
|
|
|
"reflect"
|
2017-11-03 04:28:15 +08:00
|
|
|
"strconv"
|
2017-07-14 07:23:21 +08:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
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 14:56:16 +08:00
|
|
|
|
|
|
|
func testConfig(env map[string]string) android.Config {
|
2018-01-03 10:14:25 +08:00
|
|
|
if env == nil {
|
|
|
|
env = make(map[string]string)
|
|
|
|
}
|
|
|
|
if env["ANDROID_JAVA8_HOME"] == "" {
|
|
|
|
env["ANDROID_JAVA8_HOME"] = "jdk8"
|
|
|
|
}
|
2018-01-15 14:05:10 +08:00
|
|
|
config := android.TestArchConfig(buildDir, env)
|
|
|
|
config.ProductVariables.DeviceSystemSdkVersions = &[]string{"14", "15"}
|
|
|
|
return config
|
2017-12-01 14:56:16 +08:00
|
|
|
|
2017-09-30 08:58:17 +08:00
|
|
|
}
|
|
|
|
|
2017-12-01 14:56:16 +08:00
|
|
|
func testContext(config android.Config, bp string,
|
|
|
|
fs map[string][]byte) *android.TestContext {
|
2017-07-14 07:23:21 +08:00
|
|
|
|
2017-09-16 08:36:05 +08:00
|
|
|
ctx := android.NewTestArchContext()
|
2017-07-14 07:23:21 +08:00
|
|
|
ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory))
|
2017-12-06 05:42:45 +08:00
|
|
|
ctx.RegisterModuleType("java_binary_host", android.ModuleFactoryAdaptor(BinaryHostFactory))
|
2017-10-03 09:10:21 +08:00
|
|
|
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory(true)))
|
2017-09-16 10:44:24 +08:00
|
|
|
ctx.RegisterModuleType("java_library_host", android.ModuleFactoryAdaptor(LibraryHostFactory))
|
2017-08-03 02:05:49 +08:00
|
|
|
ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory))
|
2017-07-08 05:35:50 +08:00
|
|
|
ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
|
2017-09-30 08:58:17 +08:00
|
|
|
ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(SystemModulesFactory))
|
2017-12-06 01:28:08 +08:00
|
|
|
ctx.RegisterModuleType("java_genrule", android.ModuleFactoryAdaptor(genRuleFactory))
|
2017-09-28 08:42:05 +08:00
|
|
|
ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(genrule.FileGroupFactory))
|
2017-10-10 06:34:10 +08:00
|
|
|
ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(genrule.GenRuleFactory))
|
2018-01-11 08:06:12 +08:00
|
|
|
ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory))
|
|
|
|
ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory))
|
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-27 06:33:31 +08:00
|
|
|
ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(DroiddocTemplateFactory))
|
2017-07-28 06:41:32 +08:00
|
|
|
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
|
|
|
|
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
|
2017-07-08 05:35:50 +08:00
|
|
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
2017-11-23 08:19:37 +08:00
|
|
|
ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory))
|
2017-07-14 07:23:21 +08:00
|
|
|
ctx.Register()
|
|
|
|
|
2017-09-16 08:36:05 +08:00
|
|
|
extraModules := []string{
|
|
|
|
"core-oj",
|
|
|
|
"core-libart",
|
|
|
|
"framework",
|
|
|
|
"ext",
|
|
|
|
"okhttp",
|
2017-09-16 10:44:24 +08:00
|
|
|
"android_stubs_current",
|
|
|
|
"android_system_stubs_current",
|
|
|
|
"android_test_stubs_current",
|
2017-08-16 04:34:18 +08:00
|
|
|
"kotlin-stdlib",
|
2017-09-16 08:36:05 +08:00
|
|
|
}
|
2017-07-14 07:23:21 +08:00
|
|
|
|
|
|
|
for _, extra := range extraModules {
|
|
|
|
bp += fmt.Sprintf(`
|
|
|
|
java_library {
|
|
|
|
name: "%s",
|
2017-08-31 05:24:55 +08:00
|
|
|
srcs: ["a.java"],
|
2017-08-30 07:02:06 +08:00
|
|
|
no_standard_libs: true,
|
2017-09-30 08:58:17 +08:00
|
|
|
system_modules: "core-system-modules",
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
|
|
|
`, extra)
|
|
|
|
}
|
|
|
|
|
2017-11-23 08:20:45 +08:00
|
|
|
bp += `
|
|
|
|
android_app {
|
|
|
|
name: "framework-res",
|
|
|
|
no_framework_libs: true,
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2017-12-01 14:56:16 +08:00
|
|
|
systemModules := []string{
|
|
|
|
"core-system-modules",
|
|
|
|
"android_stubs_current_system_modules",
|
|
|
|
"android_system_stubs_current_system_modules",
|
|
|
|
"android_test_stubs_current_system_modules",
|
|
|
|
}
|
2017-09-30 08:58:17 +08:00
|
|
|
|
2017-12-01 14:56:16 +08:00
|
|
|
for _, extra := range systemModules {
|
|
|
|
bp += fmt.Sprintf(`
|
2017-09-30 08:58:17 +08:00
|
|
|
java_system_modules {
|
|
|
|
name: "%s",
|
|
|
|
}
|
|
|
|
`, extra)
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:27:51 +08:00
|
|
|
mockFS := map[string][]byte{
|
2018-02-10 05:03:53 +08: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": nil,
|
|
|
|
"java-res/b": nil,
|
|
|
|
"java-res2/a": nil,
|
|
|
|
"java-fg/a.java": nil,
|
|
|
|
"java-fg/b.java": nil,
|
|
|
|
"java-fg/c.java": nil,
|
2017-10-03 07:57:40 +08:00
|
|
|
|
2017-10-21 05:00:31 +08:00
|
|
|
"prebuilts/sdk/14/android.jar": nil,
|
|
|
|
"prebuilts/sdk/14/framework.aidl": nil,
|
|
|
|
"prebuilts/sdk/current/android.jar": nil,
|
|
|
|
"prebuilts/sdk/current/framework.aidl": nil,
|
2018-01-30 23:20:13 +08:00
|
|
|
"prebuilts/sdk/current/core.jar": nil,
|
2017-10-21 05:00:31 +08:00
|
|
|
"prebuilts/sdk/system_current/android.jar": nil,
|
|
|
|
"prebuilts/sdk/system_current/framework.aidl": nil,
|
2017-10-17 15:34:51 +08:00
|
|
|
"prebuilts/sdk/system_14/android.jar": nil,
|
|
|
|
"prebuilts/sdk/system_14/framework.aidl": nil,
|
2017-10-21 05:00:31 +08:00
|
|
|
"prebuilts/sdk/test_current/android.jar": nil,
|
|
|
|
"prebuilts/sdk/test_current/framework.aidl": nil,
|
2017-11-23 08:20:45 +08:00
|
|
|
|
|
|
|
// For framework-res, which is an implicit dependency for framework
|
|
|
|
"AndroidManifest.xml": nil,
|
|
|
|
"build/target/product/security/testkey": nil,
|
2017-12-06 05:42:45 +08:00
|
|
|
|
|
|
|
"build/soong/scripts/jar-wrapper.sh": nil,
|
2018-01-03 10:14:25 +08:00
|
|
|
|
2017-12-29 04:23:20 +08:00
|
|
|
"build/make/core/proguard.flags": nil,
|
|
|
|
"build/make/core/proguard_basic_keeps.flags": nil,
|
|
|
|
|
2018-01-03 10:14:25 +08:00
|
|
|
"jdk8/jre/lib/jce.jar": nil,
|
|
|
|
"jdk8/jre/lib/rt.jar": nil,
|
2018-01-11 08:06:12 +08:00
|
|
|
|
|
|
|
"bar-doc/a.java": nil,
|
|
|
|
"bar-doc/b.java": nil,
|
|
|
|
"bar-doc/known_oj_tags.txt": nil,
|
|
|
|
"external/doclava/templates-sdk": nil,
|
2018-03-08 21:21:55 +08:00
|
|
|
|
|
|
|
"external/kotlinc/jarjar-rules.txt": nil,
|
2017-11-23 09:27:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range fs {
|
|
|
|
mockFS[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.MockFileSystem(mockFS)
|
2017-07-14 07:23:21 +08:00
|
|
|
|
2017-12-01 14:56:16 +08:00
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(t *testing.T, ctx *android.TestContext, config android.Config) {
|
2017-12-06 05:42:45 +08:00
|
|
|
t.Helper()
|
2017-08-09 08:46:01 +08:00
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
2018-03-12 16:29:17 +08:00
|
|
|
android.FailIfErrored(t, errs)
|
2017-07-14 07:23:21 +08:00
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
2018-03-12 16:29:17 +08:00
|
|
|
android.FailIfErrored(t, errs)
|
2017-12-01 14:56:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func testJava(t *testing.T, bp string) *android.TestContext {
|
2017-12-06 05:42:45 +08:00
|
|
|
t.Helper()
|
2017-12-01 14:56:16 +08:00
|
|
|
config := testConfig(nil)
|
|
|
|
ctx := testContext(config, bp, nil)
|
|
|
|
run(t, ctx, config)
|
2017-07-14 07:23:21 +08:00
|
|
|
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
2017-09-16 10:44:24 +08:00
|
|
|
func moduleToPath(name string) string {
|
|
|
|
switch {
|
|
|
|
case name == `""`:
|
|
|
|
return name
|
2017-09-19 08:41:52 +08:00
|
|
|
case strings.HasSuffix(name, ".jar"):
|
|
|
|
return name
|
2017-10-20 04:06:22 +08:00
|
|
|
case name == "android_stubs_current" || name == "android_system_stubs_current" ||
|
|
|
|
name == "android_test_stubs_current":
|
2017-10-19 05:44:18 +08:00
|
|
|
return filepath.Join(buildDir, ".intermediates", name, "android_common", "javac", name+".jar")
|
2017-10-20 04:06:22 +08:00
|
|
|
default:
|
|
|
|
return filepath.Join(buildDir, ".intermediates", name, "android_common", "turbine-combined", name+".jar")
|
2017-09-16 10:44:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 07:23:21 +08:00
|
|
|
func TestSimple(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2017-07-20 02:22:16 +08:00
|
|
|
libs: ["bar"],
|
|
|
|
static_libs: ["baz"],
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
2017-10-03 04:55:26 +08:00
|
|
|
`)
|
2017-07-14 07:23:21 +08:00
|
|
|
|
2017-09-16 08:36:05 +08:00
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
2017-10-20 04:06:22 +08:00
|
|
|
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
|
2017-07-14 07:23:21 +08:00
|
|
|
|
|
|
|
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
|
|
|
}
|
|
|
|
|
2017-10-19 05:44:18 +08:00
|
|
|
baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String()
|
2017-10-20 04:06:22 +08: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-31 05:24:55 +08:00
|
|
|
|
2017-10-20 04:06:22 +08:00
|
|
|
if !strings.Contains(javac.Args["classpath"], barTurbine) {
|
|
|
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barTurbine)
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
|
|
|
|
2017-10-20 04:06:22 +08:00
|
|
|
if !strings.Contains(javac.Args["classpath"], bazTurbine) {
|
|
|
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bazTurbine)
|
2017-08-31 05:24:55 +08: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 07:23:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 04:55:26 +08: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-06 05:42:45 +08: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-09-16 10:44:24 +08:00
|
|
|
var classpathTestcases = []struct {
|
|
|
|
name string
|
2017-10-04 11:57:01 +08:00
|
|
|
moduleType string
|
2017-09-16 10:44:24 +08:00
|
|
|
host android.OsClass
|
|
|
|
properties string
|
|
|
|
bootclasspath []string
|
2017-09-30 08:58:17 +08:00
|
|
|
system string
|
2017-09-16 10:44:24 +08:00
|
|
|
classpath []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "default",
|
|
|
|
bootclasspath: []string{"core-oj", "core-libart"},
|
2017-09-30 08:58:17 +08:00
|
|
|
system: "core-system-modules",
|
2017-09-16 10:44:24 +08:00
|
|
|
classpath: []string{"ext", "framework", "okhttp"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "blank sdk version",
|
|
|
|
properties: `sdk_version: "",`,
|
|
|
|
bootclasspath: []string{"core-oj", "core-libart"},
|
2017-09-30 08:58:17 +08:00
|
|
|
system: "core-system-modules",
|
2017-09-16 10:44:24 +08:00
|
|
|
classpath: []string{"ext", "framework", "okhttp"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "sdk v14",
|
|
|
|
properties: `sdk_version: "14",`,
|
2017-09-19 08:41:52 +08:00
|
|
|
bootclasspath: []string{`""`},
|
2017-09-30 08:58:17 +08:00
|
|
|
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
|
2017-09-19 08:41:52 +08:00
|
|
|
classpath: []string{"prebuilts/sdk/14/android.jar"},
|
2017-09-16 10:44:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "current",
|
|
|
|
properties: `sdk_version: "current",`,
|
2017-10-21 05:00:31 +08:00
|
|
|
bootclasspath: []string{`""`},
|
|
|
|
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
|
|
|
|
classpath: []string{"prebuilts/sdk/current/android.jar"},
|
2017-09-16 10:44:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "system_current",
|
|
|
|
properties: `sdk_version: "system_current",`,
|
2017-10-21 05:00:31 +08:00
|
|
|
bootclasspath: []string{`""`},
|
|
|
|
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
|
|
|
|
classpath: []string{"prebuilts/sdk/system_current/android.jar"},
|
2017-09-16 10:44:24 +08:00
|
|
|
},
|
2017-10-17 15:34:51 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
name: "system_14",
|
|
|
|
properties: `sdk_version: "system_14",`,
|
|
|
|
bootclasspath: []string{`""`},
|
|
|
|
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
|
|
|
|
classpath: []string{"prebuilts/sdk/system_14/android.jar"},
|
|
|
|
},
|
2017-09-16 10:44:24 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
name: "test_current",
|
|
|
|
properties: `sdk_version: "test_current",`,
|
2017-10-21 05:00:31 +08:00
|
|
|
bootclasspath: []string{`""`},
|
|
|
|
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
|
|
|
|
classpath: []string{"prebuilts/sdk/test_current/android.jar"},
|
2017-09-16 10:44:24 +08:00
|
|
|
},
|
2018-01-30 23:20:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
name: "core_current",
|
|
|
|
properties: `sdk_version: "core_current",`,
|
|
|
|
bootclasspath: []string{`""`},
|
|
|
|
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
|
|
|
|
classpath: []string{"prebuilts/sdk/current/core.jar"},
|
|
|
|
},
|
2017-09-16 10:44:24 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
name: "nostdlib",
|
2017-09-30 08:58:17 +08:00
|
|
|
properties: `no_standard_libs: true, system_modules: "none"`,
|
|
|
|
system: "none",
|
|
|
|
bootclasspath: []string{`""`},
|
|
|
|
classpath: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "nostdlib system_modules",
|
|
|
|
properties: `no_standard_libs: true, system_modules: "core-system-modules"`,
|
|
|
|
system: "core-system-modules",
|
2017-09-16 10:44:24 +08:00
|
|
|
bootclasspath: []string{`""`},
|
|
|
|
classpath: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
2018-01-03 10:14:25 +08:00
|
|
|
name: "host default",
|
|
|
|
moduleType: "java_library_host",
|
|
|
|
properties: ``,
|
|
|
|
host: android.Host,
|
|
|
|
bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
|
|
|
|
classpath: []string{},
|
2017-09-16 10:44:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "host nostdlib",
|
2017-10-04 11:57:01 +08:00
|
|
|
moduleType: "java_library_host",
|
2017-09-16 10:44:24 +08:00
|
|
|
host: android.Host,
|
|
|
|
properties: `no_standard_libs: true`,
|
|
|
|
classpath: []string{},
|
|
|
|
},
|
2017-10-04 11:57:01 +08:00
|
|
|
{
|
|
|
|
|
2018-01-03 10:14:25 +08:00
|
|
|
name: "host supported default",
|
|
|
|
host: android.Host,
|
|
|
|
properties: `host_supported: true,`,
|
|
|
|
classpath: []string{},
|
|
|
|
bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
|
2017-10-04 11:57:01 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "host supported nostdlib",
|
|
|
|
host: android.Host,
|
2017-09-30 08:58:17 +08:00
|
|
|
properties: `host_supported: true, no_standard_libs: true, system_modules: "none"`,
|
2017-10-04 11:57:01 +08:00
|
|
|
classpath: []string{},
|
|
|
|
},
|
2017-09-16 10:44:24 +08:00
|
|
|
}
|
2017-07-14 07:23:21 +08:00
|
|
|
|
2017-09-16 10:44:24 +08:00
|
|
|
func TestClasspath(t *testing.T) {
|
|
|
|
for _, testcase := range classpathTestcases {
|
|
|
|
t.Run(testcase.name, func(t *testing.T) {
|
2017-10-04 11:57:01 +08:00
|
|
|
moduleType := "java_library"
|
|
|
|
if testcase.moduleType != "" {
|
|
|
|
moduleType = testcase.moduleType
|
2017-09-16 10:44:24 +08:00
|
|
|
}
|
2017-09-30 08:58:17 +08:00
|
|
|
|
|
|
|
bp := moduleType + ` {
|
2017-09-16 10:44:24 +08:00
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2017-09-30 08:58:17 +08:00
|
|
|
` + testcase.properties + `
|
|
|
|
}`
|
|
|
|
|
|
|
|
variant := "android_common"
|
|
|
|
if testcase.host == android.Host {
|
|
|
|
variant = android.BuildOs.String() + "_common"
|
2017-09-16 10:44:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
convertModulesToPaths := func(cp []string) []string {
|
|
|
|
ret := make([]string, len(cp))
|
|
|
|
for i, e := range cp {
|
|
|
|
ret[i] = moduleToPath(e)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
2017-07-14 07:23:21 +08:00
|
|
|
|
2017-09-16 10:44:24 +08:00
|
|
|
bootclasspath := convertModulesToPaths(testcase.bootclasspath)
|
|
|
|
classpath := convertModulesToPaths(testcase.classpath)
|
2017-07-14 07:23:21 +08:00
|
|
|
|
2017-09-16 10:44:24 +08:00
|
|
|
bc := strings.Join(bootclasspath, ":")
|
2017-09-30 08:58:17 +08:00
|
|
|
if bc != "" {
|
|
|
|
bc = "-bootclasspath " + bc
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
2017-09-16 10:44:24 +08:00
|
|
|
|
|
|
|
c := strings.Join(classpath, ":")
|
2017-09-30 08:58:17 +08:00
|
|
|
if c != "" {
|
|
|
|
c = "-classpath " + c
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
2017-09-30 08:58:17 +08:00
|
|
|
system := ""
|
|
|
|
if testcase.system == "none" {
|
|
|
|
system = "--system=none"
|
|
|
|
} else if testcase.system != "" {
|
|
|
|
system = "--system=" + filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system") + "/"
|
2017-09-16 10:44:24 +08:00
|
|
|
}
|
|
|
|
|
2017-09-30 08:58:17 +08:00
|
|
|
t.Run("1.8", func(t *testing.T) {
|
|
|
|
// Test default javac 1.8
|
|
|
|
ctx := testJava(t, bp)
|
|
|
|
|
|
|
|
javac := ctx.ModuleForTests("foo", variant).Rule("javac")
|
|
|
|
|
|
|
|
got := javac.Args["bootClasspath"]
|
|
|
|
if got != bc {
|
|
|
|
t.Errorf("bootclasspath expected %q != got %q", bc, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
got = javac.Args["classpath"]
|
|
|
|
if got != c {
|
|
|
|
t.Errorf("classpath expected %q != got %q", c, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
var deps []string
|
|
|
|
if len(bootclasspath) > 0 && bootclasspath[0] != `""` {
|
|
|
|
deps = append(deps, bootclasspath...)
|
|
|
|
}
|
|
|
|
deps = append(deps, classpath...)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(javac.Implicits.Strings(), deps) {
|
|
|
|
t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Test again with javac 1.9
|
|
|
|
t.Run("1.9", func(t *testing.T) {
|
2017-12-01 14:56:16 +08:00
|
|
|
config := testConfig(map[string]string{"EXPERIMENTAL_USE_OPENJDK9": "true"})
|
|
|
|
ctx := testContext(config, bp, nil)
|
|
|
|
run(t, ctx, config)
|
2017-09-30 08:58:17 +08:00
|
|
|
|
|
|
|
javac := ctx.ModuleForTests("foo", variant).Rule("javac")
|
|
|
|
got := javac.Args["bootClasspath"]
|
|
|
|
expected := system
|
|
|
|
if testcase.system == "bootclasspath" {
|
|
|
|
expected = bc
|
|
|
|
}
|
|
|
|
if got != expected {
|
|
|
|
t.Errorf("bootclasspath expected %q != got %q", expected, got)
|
|
|
|
}
|
|
|
|
})
|
2017-09-16 10:44:24 +08:00
|
|
|
})
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrebuilts(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2017-07-20 02:22:16 +08:00
|
|
|
libs: ["bar"],
|
|
|
|
static_libs: ["baz"],
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
java_import {
|
2017-07-14 07:23:21 +08:00
|
|
|
name: "bar",
|
2017-08-03 02:05:49 +08:00
|
|
|
jars: ["a.jar"],
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
java_import {
|
2017-07-14 07:23:21 +08:00
|
|
|
name: "baz",
|
2017-08-03 02:05:49 +08:00
|
|
|
jars: ["b.jar"],
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2017-09-16 08:36:05 +08:00
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
2017-10-20 04:06:22 +08:00
|
|
|
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
|
2017-07-14 07:23:21 +08:00
|
|
|
|
|
|
|
bar := "a.jar"
|
|
|
|
if !strings.Contains(javac.Args["classpath"], bar) {
|
|
|
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
|
|
|
}
|
|
|
|
|
2017-08-31 05:24:55 +08:00
|
|
|
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != "b.jar" {
|
|
|
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, "b.jar")
|
2017-07-14 07:23:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-08 05:35:50 +08: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 08:36:05 +08:00
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
2017-10-20 04:06:22 +08:00
|
|
|
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
|
2017-07-08 05:35:50 +08:00
|
|
|
|
|
|
|
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
|
|
|
}
|
|
|
|
|
2017-10-20 04:06:22 +08: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-08 05:35:50 +08:00
|
|
|
}
|
|
|
|
|
2017-10-19 05:44:18 +08:00
|
|
|
baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String()
|
2017-08-31 05:24:55 +08: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-08 05:35:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 08:42:05 +08:00
|
|
|
func TestResources(t *testing.T) {
|
|
|
|
var table = []struct {
|
|
|
|
name string
|
|
|
|
prop string
|
|
|
|
extra string
|
|
|
|
args string
|
|
|
|
}{
|
|
|
|
{
|
2017-10-04 05:50:08 +08:00
|
|
|
// Test that a module with java_resource_dirs includes the files
|
2017-09-28 08:42:05 +08:00
|
|
|
name: "resource dirs",
|
2017-11-23 09:27:51 +08:00
|
|
|
prop: `java_resource_dirs: ["java-res"]`,
|
|
|
|
args: "-C java-res -f java-res/a -f java-res/b",
|
2017-09-28 08:42:05 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test that a module with java_resources includes the files
|
|
|
|
name: "resource files",
|
2017-11-23 09:27:51 +08:00
|
|
|
prop: `java_resources: ["java-res/a", "java-res/b"]`,
|
|
|
|
args: "-C . -f java-res/a -f java-res/b",
|
2017-09-28 08:42:05 +08: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 09:27:51 +08:00
|
|
|
path: "java-res",
|
|
|
|
srcs: ["java-res/a", "java-res/b"],
|
2017-09-28 08:42:05 +08:00
|
|
|
}`,
|
2017-11-23 09:27:51 +08:00
|
|
|
args: "-C java-res -f java-res/a -f java-res/b",
|
2017-09-28 08:42:05 +08: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-04 05:50:08 +08:00
|
|
|
args: "-C . -f a.java -f b.java -f c.java",
|
2017-09-28 08:42:05 +08: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)
|
|
|
|
|
2017-10-19 05:44:18 +08:00
|
|
|
foo := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar")
|
|
|
|
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
2017-09-28 08:42:05 +08: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-04 05:50:08 +08:00
|
|
|
if fooRes.Args["jarArgs"] != test.args {
|
|
|
|
t.Errorf("foo resource jar args %q is not %q",
|
2017-09-28 08:42:05 +08:00
|
|
|
fooRes.Args["jarArgs"], test.args)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 07:57:40 +08:00
|
|
|
func TestExcludeResources(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2017-11-23 09:27:51 +08:00
|
|
|
java_resource_dirs: ["java-res", "java-res2"],
|
|
|
|
exclude_java_resource_dirs: ["java-res2"],
|
2017-10-03 07:57:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["a.java"],
|
2017-11-23 09:27:51 +08:00
|
|
|
java_resources: ["java-res/*"],
|
|
|
|
exclude_java_resources: ["java-res/b"],
|
2017-10-03 07:57:40 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2017-10-19 05:44:18 +08:00
|
|
|
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
2017-10-03 07:57:40 +08:00
|
|
|
|
2017-11-23 09:27:51 +08:00
|
|
|
expected := "-C java-res -f java-res/a -f java-res/b"
|
2017-10-03 07:57:40 +08:00
|
|
|
if fooRes.Args["jarArgs"] != expected {
|
|
|
|
t.Errorf("foo resource jar args %q is not %q",
|
|
|
|
fooRes.Args["jarArgs"], expected)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-19 05:44:18 +08:00
|
|
|
barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
|
2017-10-03 07:57:40 +08:00
|
|
|
|
2017-11-23 09:27:51 +08:00
|
|
|
expected = "-C . -f java-res/a"
|
2017-10-03 07:57:40 +08:00
|
|
|
if barRes.Args["jarArgs"] != expected {
|
|
|
|
t.Errorf("bar resource jar args %q is not %q",
|
|
|
|
barRes.Args["jarArgs"], expected)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 06:34:10 +08: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 09:27:51 +08:00
|
|
|
tool_files: ["java-res/a"],
|
2017-10-10 06:34:10 +08:00
|
|
|
out: ["gen.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
|
|
|
genrule := ctx.ModuleForTests("gen", "").Rule("generator")
|
|
|
|
|
2017-10-21 06:07:08 +08: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 06:34:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(javac.Inputs) != 3 ||
|
|
|
|
javac.Inputs[0].String() != "a.java" ||
|
2017-10-21 06:07:08 +08:00
|
|
|
javac.Inputs[1].String() != genrule.Output.String() ||
|
2017-10-10 06:34:10 +08:00
|
|
|
javac.Inputs[2].String() != "b.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java", ".../gen.java", "b.java"]`, javac.Inputs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:34:18 +08:00
|
|
|
func TestKotlin(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
2017-12-16 12:20:39 +08:00
|
|
|
srcs: ["a.java", "b.kt"],
|
2017-08-16 04:34:18 +08:00
|
|
|
}
|
2017-10-26 11:32:18 +08:00
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
2017-12-16 12:20:39 +08:00
|
|
|
srcs: ["b.kt"],
|
|
|
|
libs: ["foo"],
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
2017-10-26 11:32:18 +08:00
|
|
|
}
|
2018-03-08 21:21:55 +08:00
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "blorg",
|
|
|
|
renamed_kotlin_stdlib: true,
|
|
|
|
srcs: ["b.kt"],
|
|
|
|
}
|
2017-08-16 04:34:18 +08:00
|
|
|
`)
|
|
|
|
|
2017-12-16 12:20:39 +08:00
|
|
|
fooKotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
|
|
|
|
fooJavac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
|
|
|
fooJar := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar")
|
2017-08-16 04:34:18 +08:00
|
|
|
|
2017-12-16 12:20:39 +08:00
|
|
|
if len(fooKotlinc.Inputs) != 2 || fooKotlinc.Inputs[0].String() != "a.java" ||
|
|
|
|
fooKotlinc.Inputs[1].String() != "b.kt" {
|
|
|
|
t.Errorf(`foo kotlinc inputs %v != ["a.java", "b.kt"]`, fooKotlinc.Inputs)
|
2017-08-16 04:34:18 +08:00
|
|
|
}
|
|
|
|
|
2017-12-16 12:20:39 +08:00
|
|
|
if len(fooJavac.Inputs) != 1 || fooJavac.Inputs[0].String() != "a.java" {
|
|
|
|
t.Errorf(`foo inputs %v != ["a.java"]`, fooJavac.Inputs)
|
2017-08-16 04:34:18 +08:00
|
|
|
}
|
|
|
|
|
2017-12-16 12:20:39 +08:00
|
|
|
if !strings.Contains(fooJavac.Args["classpath"], fooKotlinc.Output.String()) {
|
2017-08-16 04:34:18 +08:00
|
|
|
t.Errorf("foo classpath %v does not contain %q",
|
2017-12-16 12:20:39 +08:00
|
|
|
fooJavac.Args["classpath"], fooKotlinc.Output.String())
|
2017-08-16 04:34:18 +08:00
|
|
|
}
|
|
|
|
|
2017-12-16 12:20:39 +08:00
|
|
|
if !inList(fooKotlinc.Output.String(), fooJar.Inputs.Strings()) {
|
2017-08-16 04:34:18 +08:00
|
|
|
t.Errorf("foo jar inputs %v does not contain %q",
|
2017-12-16 12:20:39 +08:00
|
|
|
fooJar.Inputs.Strings(), fooKotlinc.Output.String())
|
2017-08-16 04:34:18 +08:00
|
|
|
}
|
2017-10-26 11:32:18 +08:00
|
|
|
|
2017-12-16 12:20:39 +08:00
|
|
|
fooHeaderJar := ctx.ModuleForTests("foo", "android_common").Output("turbine-combined/foo.jar")
|
|
|
|
bazHeaderJar := ctx.ModuleForTests("baz", "android_common").Output("turbine-combined/baz.jar")
|
|
|
|
barKotlinc := ctx.ModuleForTests("bar", "android_common").Rule("kotlinc")
|
|
|
|
|
|
|
|
if len(barKotlinc.Inputs) != 1 || barKotlinc.Inputs[0].String() != "b.kt" {
|
|
|
|
t.Errorf(`bar kotlinc inputs %v != ["b.kt"]`, barKotlinc.Inputs)
|
|
|
|
}
|
2017-10-26 11:32:18 +08:00
|
|
|
|
2017-12-16 12:20:39 +08:00
|
|
|
if !inList(fooHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) {
|
|
|
|
t.Errorf(`expected %q in bar implicits %v`,
|
|
|
|
fooHeaderJar.Output.String(), barKotlinc.Implicits.Strings())
|
|
|
|
}
|
|
|
|
|
|
|
|
if !inList(bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) {
|
|
|
|
t.Errorf(`expected %q in bar implicits %v`,
|
|
|
|
bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings())
|
2017-10-26 11:32:18 +08:00
|
|
|
}
|
2018-03-08 21:21:55 +08:00
|
|
|
|
|
|
|
blorgRenamedJar := ctx.ModuleForTests("blorg", "android_common").Output("kotlin-renamed/blorg.jar")
|
|
|
|
if blorgRenamedJar.Implicit.String() != "external/kotlinc/jarjar-rules.txt" {
|
|
|
|
t.Errorf(`expected external/kotlinc/jarjar-rules.txt in blorg implicit %q`,
|
|
|
|
blorgRenamedJar.Implicit.String())
|
|
|
|
}
|
2017-08-16 04:34:18 +08:00
|
|
|
}
|
|
|
|
|
2017-11-03 04:28:15 +08:00
|
|
|
func TestTurbine(t *testing.T) {
|
|
|
|
ctx := testJava(t, `
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
2017-12-16 12:20:39 +08:00
|
|
|
srcs: ["b.java"],
|
2017-11-03 04:28:15 +08:00
|
|
|
static_libs: ["foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
if !strings.Contains(bazJavac.Args["classpath"], "prebuilts/sdk/14/android.jar") {
|
|
|
|
t.Errorf("baz javac classpath %v does not contain %q", bazJavac.Args["classpath"],
|
|
|
|
"prebuilts/sdk/14/android.jar")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 08:06:12 +08: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-27 06:33:31 +08:00
|
|
|
droiddoc_template {
|
|
|
|
name: "droiddoc-templates-sdk",
|
|
|
|
path: ".",
|
|
|
|
}
|
2018-01-11 08:06:12 +08:00
|
|
|
droiddoc {
|
|
|
|
name: "bar-doc",
|
|
|
|
srcs: [
|
|
|
|
"bar-doc/*.java",
|
|
|
|
],
|
|
|
|
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-27 06:33:31 +08:00
|
|
|
custom_template: "droiddoc-templates-sdk",
|
2018-01-11 08:06:12 +08: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-03-01 02:14:25 +08: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 08:06:12 +08:00
|
|
|
if stubsJar != barDoc.Output.String() {
|
|
|
|
t.Errorf("expected stubs Jar [%q], got %q", stubsJar, barDoc.Output.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 01:28:08 +08: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-10 05:03:53 +08: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)
|
|
|
|
}
|
|
|
|
}
|