blob: 2d059ebd1532b0139f80834621e5c2535ef0c452 [file] [log] [blame]
Colin Cross19878da2019-03-28 14:45:07 -07001// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "strings"
19 "testing"
Colin Crossfe17f6f2019-03-28 19:30:56 -070020
21 "android/soong/android"
Colin Cross19878da2019-03-28 14:45:07 -070022)
23
24func TestProto(t *testing.T) {
Colin Cross323dc602020-09-18 14:25:31 -070025 t.Parallel()
Colin Cross19878da2019-03-28 14:45:07 -070026 t.Run("simple", func(t *testing.T) {
27 ctx := testCc(t, `
28 cc_library_shared {
29 name: "libfoo",
30 srcs: ["a.proto"],
31 }`)
32
Colin Cross7113d202019-11-20 16:39:12 -080033 proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("proto/a.pb.cc")
Colin Cross19878da2019-03-28 14:45:07 -070034
35 if cmd := proto.RuleParams.Command; !strings.Contains(cmd, "--cpp_out=") {
36 t.Errorf("expected '--cpp_out' in %q", cmd)
37 }
38 })
Colin Crossfe17f6f2019-03-28 19:30:56 -070039
40 t.Run("plugin", func(t *testing.T) {
41 ctx := testCc(t, `
42 cc_binary_host {
43 name: "protoc-gen-foobar",
44 stl: "none",
45 }
46
47 cc_library_shared {
48 name: "libfoo",
49 srcs: ["a.proto"],
50 proto: {
51 plugin: "foobar",
52 },
53 }`)
54
55 buildOS := android.BuildOs.String()
56
Colin Cross7113d202019-11-20 16:39:12 -080057 proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("proto/a.pb.cc")
Colin Crossfe17f6f2019-03-28 19:30:56 -070058 foobar := ctx.ModuleForTests("protoc-gen-foobar", buildOS+"_x86_64")
59
60 cmd := proto.RuleParams.Command
61 if w := "--foobar_out="; !strings.Contains(cmd, w) {
62 t.Errorf("expected %q in %q", w, cmd)
63 }
64
65 foobarPath := foobar.Module().(android.HostToolProvider).HostToolPath().String()
66
67 if w := "--plugin=protoc-gen-foobar=" + foobarPath; !strings.Contains(cmd, w) {
68 t.Errorf("expected %q in %q", w, cmd)
69 }
70 })
71
Colin Cross19878da2019-03-28 14:45:07 -070072}