license_sdk_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright (C) 2021 The Android Open Source Project
  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 sdk
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. )
  19. func TestSnapshotWithPackageDefaultLicense(t *testing.T) {
  20. result := android.GroupFixturePreparers(
  21. prepareForSdkTestWithJava,
  22. android.PrepareForTestWithLicenses,
  23. android.PrepareForTestWithLicenseDefaultModules,
  24. android.MockFS{
  25. "NOTICE1": nil,
  26. "NOTICE2": nil,
  27. }.AddToFixture(),
  28. ).RunTestWithBp(t, `
  29. package {
  30. default_applicable_licenses: ["mylicense"],
  31. }
  32. license {
  33. name: "mylicense",
  34. license_kinds: [
  35. "SPDX-license-identifier-Apache-2.0",
  36. "legacy_unencumbered",
  37. ],
  38. license_text: [
  39. "NOTICE1",
  40. "NOTICE2",
  41. ],
  42. }
  43. sdk {
  44. name: "mysdk",
  45. java_header_libs: ["myjavalib"],
  46. }
  47. java_library {
  48. name: "myjavalib",
  49. srcs: ["Test.java"],
  50. system_modules: "none",
  51. sdk_version: "none",
  52. }
  53. `)
  54. CheckSnapshot(t, result, "mysdk", "",
  55. checkAndroidBpContents(`
  56. // This is auto-generated. DO NOT EDIT.
  57. package {
  58. // A default list here prevents the license LSC from adding its own list which would
  59. // be unnecessary as every module in the sdk already has its own licenses property.
  60. default_applicable_licenses: ["Android-Apache-2.0"],
  61. }
  62. java_import {
  63. name: "myjavalib",
  64. prefer: false,
  65. visibility: ["//visibility:public"],
  66. apex_available: ["//apex_available:platform"],
  67. licenses: ["mysdk_mylicense"],
  68. jars: ["java/myjavalib.jar"],
  69. }
  70. license {
  71. name: "mysdk_mylicense",
  72. visibility: ["//visibility:private"],
  73. license_kinds: [
  74. "SPDX-license-identifier-Apache-2.0",
  75. "legacy_unencumbered",
  76. ],
  77. license_text: [
  78. "licenses/NOTICE1",
  79. "licenses/NOTICE2",
  80. ],
  81. }
  82. `),
  83. checkAllCopyRules(`
  84. .intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/myjavalib.jar
  85. NOTICE1 -> licenses/NOTICE1
  86. NOTICE2 -> licenses/NOTICE2
  87. `),
  88. )
  89. }