java_host_for_device_conversion_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2023 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 bp2build
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. "android/soong/java"
  19. )
  20. func runJavaHostForDeviceTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
  21. t.Helper()
  22. (&tc).ModuleTypeUnderTest = "java_host_for_device"
  23. (&tc).ModuleTypeUnderTestFactory = java.HostForDeviceFactory
  24. RunBp2BuildTestCase(t, registrationCtxFunc, tc)
  25. }
  26. func runJavaHostForDeviceTestCase(t *testing.T, tc Bp2buildTestCase) {
  27. t.Helper()
  28. runJavaHostForDeviceTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {
  29. ctx.RegisterModuleType("java_library", java.LibraryFactory)
  30. })
  31. }
  32. func TestJavaHostForDevice(t *testing.T) {
  33. runJavaHostForDeviceTestCase(t, Bp2buildTestCase{
  34. Description: "java_host_for_device test",
  35. Blueprint: `java_host_for_device {
  36. name: "java-lib-1",
  37. libs: ["java-lib-2"],
  38. bazel_module: { bp2build_available: true },
  39. }
  40. java_library {
  41. name: "java-lib-2",
  42. srcs: ["b.java"],
  43. bazel_module: { bp2build_available: true },
  44. }`,
  45. ExpectedBazelTargets: []string{
  46. MakeBazelTarget("java_host_for_device", "java-lib-1", AttrNameToString{
  47. "exports": `[":java-lib-2"]`,
  48. }),
  49. MakeNeverlinkDuplicateTargetWithAttrs("java_library", "java-lib-1", AttrNameToString{
  50. "sdk_version": `"none"`,
  51. }),
  52. MakeBazelTarget("java_library", "java-lib-2", AttrNameToString{
  53. "srcs": `["b.java"]`,
  54. }),
  55. MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"),
  56. },
  57. })
  58. }