Home | History | Annotate | Download | only in cc
      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 	"runtime"
     19 	"strings"
     20 	"testing"
     21 
     22 	"android/soong/android"
     23 )
     24 
     25 func 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 	})
     39 
     40 	t.Run("plugin", func(t *testing.T) {
     41 		if runtime.GOOS != "linux" {
     42 			t.Skip("TODO(b/129763458): cc_binary_host tests fail on mac when trying to exec xcrun")
     43 		}
     44 		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 
     75 }
     76