proto_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. package cc
  15. import (
  16. "strings"
  17. "testing"
  18. "android/soong/android"
  19. )
  20. func TestProto(t *testing.T) {
  21. t.Run("simple", func(t *testing.T) {
  22. ctx := testCc(t, `
  23. cc_library_shared {
  24. name: "libfoo",
  25. srcs: ["a.proto"],
  26. }`)
  27. proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("proto/a.pb.cc")
  28. if cmd := proto.RuleParams.Command; !strings.Contains(cmd, "--cpp_out=") {
  29. t.Errorf("expected '--cpp_out' in %q", cmd)
  30. }
  31. })
  32. t.Run("plugin", func(t *testing.T) {
  33. ctx := testCc(t, `
  34. cc_binary_host {
  35. name: "protoc-gen-foobar",
  36. stl: "none",
  37. }
  38. cc_library_shared {
  39. name: "libfoo",
  40. srcs: ["a.proto"],
  41. proto: {
  42. plugin: "foobar",
  43. },
  44. }`)
  45. buildOS := ctx.Config().BuildOS.String()
  46. proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("proto/a.pb.cc")
  47. foobar := ctx.ModuleForTests("protoc-gen-foobar", buildOS+"_x86_64")
  48. cmd := proto.RuleParams.Command
  49. if w := "--foobar_out="; !strings.Contains(cmd, w) {
  50. t.Errorf("expected %q in %q", w, cmd)
  51. }
  52. foobarPath := foobar.Module().(android.HostToolProvider).HostToolPath().RelativeToTop().String()
  53. if w := "--plugin=protoc-gen-foobar=" + foobarPath; !strings.Contains(cmd, w) {
  54. t.Errorf("expected %q in %q", w, cmd)
  55. }
  56. })
  57. }