Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | "testing" |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | func 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 Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 38 | |
| 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 Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 71 | } |