bp2build converts java_genrule and java_genrule_host
Bp2build currently supports building genrules for cc modules, but does not support building java_genrule* modules. This commit adds this functionality. Bug: 213480907 Test: go test ./bp2build Change-Id: I473196c5bcf5582ba0c8faa65b5005f81ac973a4
This commit is contained in:
@@ -24,8 +24,8 @@ func init() {
|
||||
}
|
||||
|
||||
func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("java_genrule", genRuleFactory)
|
||||
ctx.RegisterModuleType("java_genrule_host", genRuleFactoryHost)
|
||||
ctx.RegisterModuleType("java_genrule", GenRuleFactory)
|
||||
ctx.RegisterModuleType("java_genrule_host", GenRuleFactoryHost)
|
||||
}
|
||||
|
||||
// java_genrule is a genrule that can depend on other java_* objects.
|
||||
@@ -33,7 +33,7 @@ func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) {
|
||||
// By default a java_genrule has a single variant that will run against the device variant of its dependencies and
|
||||
// produce an output that can be used as an input to a device java rule.
|
||||
//
|
||||
// Specifying `host_supported: true` will produce two variants, one that uses device dependencie sand one that uses
|
||||
// Specifying `host_supported: true` will produce two variants, one that uses device dependencies and one that uses
|
||||
// host dependencies. Each variant will run the command.
|
||||
//
|
||||
// Use a java_genrule instead of a genrule when it needs to depend on or be depended on by other java modules, unless
|
||||
@@ -44,7 +44,7 @@ func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) {
|
||||
// Use a java_genrule to package generated java resources:
|
||||
//
|
||||
// java_genrule {
|
||||
// name: "generated_resources",
|
||||
// name: "generated_resources",
|
||||
// tools: [
|
||||
// "generator",
|
||||
// "soong_zip",
|
||||
@@ -60,11 +60,12 @@ func RegisterGenRuleBuildComponents(ctx android.RegistrationContext) {
|
||||
// srcs: ["src/**/*.java"],
|
||||
// static_libs: ["generated_resources"],
|
||||
// }
|
||||
func genRuleFactory() android.Module {
|
||||
func GenRuleFactory() android.Module {
|
||||
module := genrule.NewGenRule()
|
||||
|
||||
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
|
||||
android.InitDefaultableModule(module)
|
||||
android.InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
@@ -73,11 +74,12 @@ func genRuleFactory() android.Module {
|
||||
//
|
||||
// A java_genrule_host has a single variant that will run against the host variant of its dependencies and
|
||||
// produce an output that can be used as an input to a host java rule.
|
||||
func genRuleFactoryHost() android.Module {
|
||||
func GenRuleFactoryHost() android.Module {
|
||||
module := genrule.NewGenRule()
|
||||
|
||||
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
|
||||
android.InitDefaultableModule(module)
|
||||
android.InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
118
java/genrule_test.go
Normal file
118
java/genrule_test.go
Normal file
@@ -0,0 +1,118 @@
|
||||
// Copyright 2018 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 (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
func testGenruleContext(config android.Config) *android.TestContext {
|
||||
ctx := android.NewTestArchContext(config)
|
||||
ctx.RegisterModuleType("java_genrule", GenRuleFactory)
|
||||
ctx.Register()
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
func TestGenruleCmd(t *testing.T) {
|
||||
fs := map[string][]byte{
|
||||
"tool": nil,
|
||||
"foo": nil,
|
||||
}
|
||||
bp := `
|
||||
java_genrule {
|
||||
name: "gen",
|
||||
tool_files: ["tool"],
|
||||
cmd: "$(location tool) $(in) $(out)",
|
||||
srcs: ["foo"],
|
||||
out: ["out"],
|
||||
}
|
||||
`
|
||||
config := android.TestArchConfig(t.TempDir(), nil, bp, fs)
|
||||
|
||||
ctx := testGenruleContext(config)
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
if errs == nil {
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
}
|
||||
if errs != nil {
|
||||
t.Fatal(errs)
|
||||
}
|
||||
|
||||
gen := ctx.ModuleForTests("gen", "android_common").Output("out")
|
||||
expected := []string{"foo"}
|
||||
if !reflect.DeepEqual(expected, gen.Implicits.Strings()[:len(expected)]) {
|
||||
t.Errorf(`want arm inputs %v, got %v`, expected, gen.Implicits.Strings())
|
||||
}
|
||||
}
|
||||
|
||||
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 g, w := jargen.Implicits.Strings(), foo.Output.String(); !android.InList(w, g) {
|
||||
t.Errorf("expected jargen inputs [%q], got %q", w, g)
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
@@ -997,60 +997,6 @@ func TestSharding(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
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 g, w := jargen.Implicits.Strings(), foo.Output.String(); !android.InList(w, g) {
|
||||
t.Errorf("expected jargen inputs [%q], got %q", w, g)
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
func TestExcludeFileGroupInSrcs(t *testing.T) {
|
||||
ctx, _ := testJava(t, `
|
||||
java_library {
|
||||
|
Reference in New Issue
Block a user