blob: 4f0de7801274b7e6516dafbc6a892a5aa9fb532b [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) {
25 t.Run("simple", func(t *testing.T) {
26 ctx := testCc(t, `
27 cc_library_shared {
28 name: "libfoo",
29 srcs: ["a.proto"],
30 }`)
31
32 proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Output("proto/a.pb.cc")
33
34 if cmd := proto.RuleParams.Command; !strings.Contains(cmd, "--cpp_out=") {
35 t.Errorf("expected '--cpp_out' in %q", cmd)
36 }
37 })
Colin Crossfe17f6f2019-03-28 19:30:56 -070038
39 t.Run("plugin", func(t *testing.T) {
40 ctx := testCc(t, `
41 cc_binary_host {
42 name: "protoc-gen-foobar",
43 stl: "none",
44 }
45
46 cc_library_shared {
47 name: "libfoo",
48 srcs: ["a.proto"],
49 proto: {
50 plugin: "foobar",
51 },
52 }`)
53
54 buildOS := android.BuildOs.String()
55
56 proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Output("proto/a.pb.cc")
57 foobar := ctx.ModuleForTests("protoc-gen-foobar", buildOS+"_x86_64")
58
59 cmd := proto.RuleParams.Command
60 if w := "--foobar_out="; !strings.Contains(cmd, w) {
61 t.Errorf("expected %q in %q", w, cmd)
62 }
63
64 foobarPath := foobar.Module().(android.HostToolProvider).HostToolPath().String()
65
66 if w := "--plugin=protoc-gen-foobar=" + foobarPath; !strings.Contains(cmd, w) {
67 t.Errorf("expected %q in %q", w, cmd)
68 }
69 })
70
Colin Cross19878da2019-03-28 14:45:07 -070071}