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