droidstubs_conversion_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2022 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 registerJavaApiModules(ctx android.RegistrationContext) {
  21. java.RegisterSdkLibraryBuildComponents(ctx)
  22. java.RegisterStubsBuildComponents(ctx)
  23. }
  24. func TestDroidstubsApiContributions(t *testing.T) {
  25. bp := `
  26. droidstubs {
  27. name: "framework-stubs",
  28. check_api: {
  29. current: {
  30. api_file: "framework.current.txt",
  31. },
  32. },
  33. }
  34. // Modules without check_api should not generate a Bazel API target
  35. droidstubs {
  36. name: "framework-docs",
  37. }
  38. // java_sdk_library is a macro that creates droidstubs
  39. java_sdk_library {
  40. name: "module-stubs",
  41. srcs: ["A.java"],
  42. // These api surfaces are added by default, but add them explicitly to make
  43. // this test hermetic
  44. public: {
  45. enabled: true,
  46. },
  47. system: {
  48. enabled: true,
  49. },
  50. // Disable other api surfaces to keep unit test scope limited
  51. module_lib: {
  52. enabled: false,
  53. },
  54. test: {
  55. enabled: false,
  56. },
  57. }
  58. `
  59. expectedBazelTargets := []string{
  60. MakeBazelTargetNoRestrictions(
  61. "java_api_contribution",
  62. "framework-stubs.contribution",
  63. AttrNameToString{
  64. "api": `"framework.current.txt"`,
  65. "api_surface": `"publicapi"`,
  66. "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
  67. }),
  68. MakeBazelTargetNoRestrictions(
  69. "java_api_contribution",
  70. "module-stubs.stubs.source.contribution",
  71. AttrNameToString{
  72. "api": `"api/current.txt"`,
  73. "api_surface": `"publicapi"`,
  74. "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
  75. }),
  76. MakeBazelTargetNoRestrictions(
  77. "java_api_contribution",
  78. "module-stubs.stubs.source.system.contribution",
  79. AttrNameToString{
  80. "api": `"api/system-current.txt"`,
  81. "api_surface": `"systemapi"`,
  82. "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
  83. }),
  84. }
  85. RunApiBp2BuildTestCase(t, registerJavaApiModules, Bp2buildTestCase{
  86. Blueprint: bp,
  87. ExpectedBazelTargets: expectedBazelTargets,
  88. Filesystem: map[string]string{
  89. "api/current.txt": "",
  90. "api/removed.txt": "",
  91. "api/system-current.txt": "",
  92. "api/system-removed.txt": "",
  93. },
  94. })
  95. }