androidmk_test.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash -eu
  2. set -o pipefail
  3. # How to run: bash path-to-script/androidmk_test.sh
  4. # Tests of converting license functionality of the androidmk tool
  5. REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)"
  6. "$REAL_TOP/build/soong/soong_ui.bash" --make-mode androidmk
  7. source "$(dirname "$0")/lib.sh"
  8. # Expect to create a new license module
  9. function test_rewrite_license_property_inside_current_directory {
  10. setup
  11. # Create an Android.mk file
  12. mkdir -p a/b
  13. cat > a/b/Android.mk <<'EOF'
  14. include $(CLEAR_VARS)
  15. LOCAL_MODULE := foo
  16. LOCAL_LICENSE_KINDS := license_kind1 license_kind2
  17. LOCAL_LICENSE_CONDITIONS := license_condition
  18. LOCAL_NOTICE_FILE := $(LOCAL_PATH)/license_notice1 $(LOCAL_PATH)/license_notice2
  19. include $(BUILD_PACKAGE)
  20. EOF
  21. # Create an expected Android.bp file for the module "foo"
  22. cat > a/b/Android.bp <<'EOF'
  23. package {
  24. // See: http://go/android-license-faq
  25. default_applicable_licenses: [
  26. "a_b_license",
  27. ],
  28. }
  29. license {
  30. name: "a_b_license",
  31. visibility: [":__subpackages__"],
  32. license_kinds: [
  33. "license_kind1",
  34. "license_kind2",
  35. ],
  36. license_text: [
  37. "license_notice1",
  38. "license_notice2",
  39. ],
  40. }
  41. android_app {
  42. name: "foo",
  43. }
  44. EOF
  45. run_androidmk_test "a/b/Android.mk" "a/b/Android.bp"
  46. }
  47. # Expect to reference to an existing license module
  48. function test_rewrite_license_property_outside_current_directory {
  49. setup
  50. # Create an Android.mk file
  51. mkdir -p a/b/c/d
  52. cat > a/b/c/d/Android.mk <<'EOF'
  53. include $(CLEAR_VARS)
  54. LOCAL_MODULE := foo
  55. LOCAL_LICENSE_KINDS := license_kind1 license_kind2
  56. LOCAL_LICENSE_CONDITIONS := license_condition
  57. LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../license_notice1 $(LOCAL_PATH)/../../license_notice2
  58. include $(BUILD_PACKAGE)
  59. EOF
  60. # Create an expected (input) Android.bp file at a/b/
  61. cat > a/b/Android.bp <<'EOF'
  62. package {
  63. // See: http://go/android-license-faq
  64. default_applicable_licenses: [
  65. "a_b_license",
  66. ],
  67. }
  68. license {
  69. name: "a_b_license",
  70. visibility: [":__subpackages__"],
  71. license_kinds: [
  72. "license_kind1",
  73. "license_kind2",
  74. ],
  75. license_text: [
  76. "license_notice1",
  77. "license_notice2",
  78. ],
  79. }
  80. android_app {
  81. name: "bar",
  82. }
  83. EOF
  84. # Create an expected (output) Android.bp file for the module "foo"
  85. cat > a/b/c/d/Android.bp <<'EOF'
  86. package {
  87. // See: http://go/android-license-faq
  88. default_applicable_licenses: [
  89. "a_b_license",
  90. ],
  91. }
  92. android_app {
  93. name: "foo",
  94. }
  95. EOF
  96. run_androidmk_test "a/b/c/d/Android.mk" "a/b/c/d/Android.bp"
  97. }
  98. function run_androidmk_test {
  99. export ANDROID_BUILD_TOP="$MOCK_TOP"
  100. local -r androidmk=("$REAL_TOP"/*/host/*/bin/androidmk)
  101. if [[ ${#androidmk[@]} -ne 1 ]]; then
  102. fail "Multiple androidmk binaries found: ${androidmk[*]}"
  103. fi
  104. local -r out=$("${androidmk[0]}" "$1")
  105. local -r expected=$(<"$2")
  106. if [[ "$out" != "$expected" ]]; then
  107. ANDROID_BUILD_TOP="$REAL_TOP"
  108. cleanup_mock_top
  109. fail "The output is not the same as the expected"
  110. fi
  111. ANDROID_BUILD_TOP="$REAL_TOP"
  112. cleanup_mock_top
  113. echo "Succeeded"
  114. }
  115. scan_and_run_tests