blob: a7fcef935dfa694934efcc87f188d655267518f8 [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 (
Colin Cross9a4f3f72019-04-02 10:00:07 -070018 "runtime"
Colin Cross19878da2019-03-28 14:45:07 -070019 "strings"
20 "testing"
Colin Crossfe17f6f2019-03-28 19:30:56 -070021
22 "android/soong/android"
Colin Cross19878da2019-03-28 14:45:07 -070023)
24
25func TestProto(t *testing.T) {
26 t.Run("simple", func(t *testing.T) {
27 ctx := testCc(t, `
28 cc_library_shared {
29 name: "libfoo",
30 srcs: ["a.proto"],
31 }`)
32
33 proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Output("proto/a.pb.cc")
34
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) {
Colin Cross9a4f3f72019-04-02 10:00:07 -070041 if runtime.GOOS != "linux" {
42 t.Skip("TODO(b/129763458): cc_binary_host tests fail on mac when trying to exec xcrun")
43 }
Colin Crossfe17f6f2019-03-28 19:30:56 -070044 ctx := testCc(t, `
45 cc_binary_host {
46 name: "protoc-gen-foobar",
47 stl: "none",
48 }
49
50 cc_library_shared {
51 name: "libfoo",
52 srcs: ["a.proto"],
53 proto: {
54 plugin: "foobar",
55 },
56 }`)
57
58 buildOS := android.BuildOs.String()
59
60 proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Output("proto/a.pb.cc")
61 foobar := ctx.ModuleForTests("protoc-gen-foobar", buildOS+"_x86_64")
62
63 cmd := proto.RuleParams.Command
64 if w := "--foobar_out="; !strings.Contains(cmd, w) {
65 t.Errorf("expected %q in %q", w, cmd)
66 }
67
68 foobarPath := foobar.Module().(android.HostToolProvider).HostToolPath().String()
69
70 if w := "--plugin=protoc-gen-foobar=" + foobarPath; !strings.Contains(cmd, w) {
71 t.Errorf("expected %q in %q", w, cmd)
72 }
73 })
74
Colin Cross19878da2019-03-28 14:45:07 -070075}