metadata_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2023 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package apex
  17. import (
  18. "strings"
  19. "testing"
  20. "android/soong/android"
  21. "android/soong/java"
  22. )
  23. func TestModulesSingleton(t *testing.T) {
  24. result := android.GroupFixturePreparers(
  25. PrepareForTestWithApexMultitreeSingleton,
  26. java.PrepareForTestWithJavaDefaultModules,
  27. PrepareForTestWithApexBuildComponents,
  28. java.FixtureConfigureApexBootJars("myapex:foo"),
  29. java.PrepareForTestWithJavaSdkLibraryFiles,
  30. ).RunTestWithBp(t, `
  31. prebuilt_apex {
  32. name: "myapex",
  33. src: "myapex.apex",
  34. exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
  35. }
  36. // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
  37. // because AlwaysUsePrebuiltSdks() is true.
  38. java_sdk_library_import {
  39. name: "foo",
  40. prefer: false,
  41. shared_library: false,
  42. permitted_packages: ["foo"],
  43. public: {
  44. jars: ["sdk_library/public/foo-stubs.jar"],
  45. stub_srcs: ["sdk_library/public/foo_stub_sources"],
  46. current_api: "sdk_library/public/foo.txt",
  47. removed_api: "sdk_library/public/foo-removed.txt",
  48. sdk_version: "current",
  49. },
  50. apex_available: ["myapex"],
  51. }
  52. prebuilt_bootclasspath_fragment {
  53. name: "mybootclasspath-fragment",
  54. apex_available: [
  55. "myapex",
  56. ],
  57. contents: [
  58. "foo",
  59. ],
  60. hidden_api: {
  61. stub_flags: "prebuilt-stub-flags.csv",
  62. annotation_flags: "prebuilt-annotation-flags.csv",
  63. metadata: "prebuilt-metadata.csv",
  64. index: "prebuilt-index.csv",
  65. all_flags: "prebuilt-all-flags.csv",
  66. },
  67. }
  68. platform_bootclasspath {
  69. name: "myplatform-bootclasspath",
  70. fragments: [
  71. {
  72. apex: "myapex",
  73. module:"mybootclasspath-fragment",
  74. },
  75. ],
  76. }
  77. `,
  78. )
  79. outputs := result.SingletonForTests("apex_multitree_singleton").AllOutputs()
  80. for _, output := range outputs {
  81. testingBuildParam := result.SingletonForTests("apex_multitree_singleton").Output(output)
  82. switch {
  83. case strings.Contains(output, "soong/multitree_apex_metadata.json"):
  84. android.AssertStringEquals(t, "Invalid build rule", "android/soong/android.writeFile", testingBuildParam.Rule.String())
  85. android.AssertIntEquals(t, "Invalid input", len(testingBuildParam.Inputs), 0)
  86. android.AssertStringDoesContain(t, "Invalid output path", output, "soong/multitree_apex_metadata.json")
  87. case strings.HasSuffix(output, "multitree_apex_metadata"):
  88. android.AssertStringEquals(t, "Invalid build rule", "<builtin>:phony", testingBuildParam.Rule.String())
  89. android.AssertStringEquals(t, "Invalid input", testingBuildParam.Inputs[0].String(), "out/soong/multitree_apex_metadata.json")
  90. android.AssertStringEquals(t, "Invalid output path", output, "multitree_apex_metadata")
  91. android.AssertIntEquals(t, "Invalid args", len(testingBuildParam.Args), 0)
  92. }
  93. }
  94. }