|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script lints and tests iOS and macOS platform code. |
| 4 | + |
| 5 | +# So that users can run this script from anywhere and it will work as expected. |
| 6 | +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" |
| 7 | +readonly REPO_DIR="$(dirname "$SCRIPT_DIR")" |
| 8 | + |
| 9 | +source "$SCRIPT_DIR/common.sh" |
| 10 | + |
| 11 | +function lint_package() { |
| 12 | + local package_name="$1" |
| 13 | + local package_dir="${REPO_DIR}/packages/$package_name/" |
| 14 | + local failure_count=0 |
| 15 | + |
| 16 | + for podspec in "$(find "${package_dir}" -name '*\.podspec')"; do |
| 17 | + echo "Linting $package_name.podspec" |
| 18 | + |
| 19 | + # Build as frameworks. |
| 20 | + # This will also run any tests set up as a test_spec. See https://blog.cocoapods.org/CocoaPods-1.3.0. |
| 21 | + # TODO: Add --analyze flag https://github.com/flutter/flutter/issues/41443 |
| 22 | + # TODO: Remove --allow-warnings flag https://github.com/flutter/flutter/issues/41444 |
| 23 | + pod lib lint "${podspec}" --allow-warnings --fail-fast --silent |
| 24 | + if [[ "$?" -ne 0 ]]; then |
| 25 | + error "Package ${package_name} has framework issues. Run \"pod lib lint $podspec\" to inspect." |
| 26 | + failure_count+=1 |
| 27 | + fi |
| 28 | + |
| 29 | + # Build as libraries. |
| 30 | + pod lib lint "${podspec}" --allow-warnings --use-libraries --fail-fast --silent |
| 31 | + if [[ "$?" -ne 0 ]]; then |
| 32 | + error "Package ${package_name} has library issues. Run \"pod lib lint $podspec --use-libraries\" to inspect." |
| 33 | + failure_count+=1 |
| 34 | + fi |
| 35 | + done |
| 36 | + |
| 37 | + return "${failure_count}" |
| 38 | +} |
| 39 | + |
| 40 | +function lint_packages() { |
| 41 | + if [[ ! "$(which pod)" ]]; then |
| 42 | + echo "pod not installed. Skipping." |
| 43 | + return |
| 44 | + fi |
| 45 | + |
| 46 | + # TODO: These packages have linter errors. Remove plugins from this list as linter issues are fixed. |
| 47 | + local skipped_packages=( |
| 48 | + 'android_alarm_manager' |
| 49 | + 'android_intent' |
| 50 | + 'battery' |
| 51 | + 'connectivity' |
| 52 | + 'device_info' |
| 53 | + 'google_maps_flutter' |
| 54 | + 'google_sign_in' |
| 55 | + 'image_picker' |
| 56 | + 'in_app_purchase' |
| 57 | + 'instrumentation_adapter' |
| 58 | + 'local_auth' |
| 59 | + 'package_info' |
| 60 | + 'path_provider' |
| 61 | + 'quick_actions' |
| 62 | + 'sensors' |
| 63 | + 'share' |
| 64 | + 'shared_preferences' |
| 65 | + 'url_launcher' |
| 66 | + 'video_player' |
| 67 | + 'webview_flutter' |
| 68 | + ) |
| 69 | + |
| 70 | + local failure_count=0 |
| 71 | + for package_name in "$@"; do |
| 72 | + if [[ "${skipped_packages[*]}" =~ "${package_name}" ]]; then |
| 73 | + continue |
| 74 | + fi |
| 75 | + lint_package "${package_name}" |
| 76 | + failure_count+="$?" |
| 77 | + done |
| 78 | + |
| 79 | + return "${failure_count}" |
| 80 | +} |
| 81 | + |
| 82 | +# Sets CHANGED_PACKAGE_LIST |
| 83 | +check_changed_packages |
| 84 | + |
| 85 | +if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then |
| 86 | + lint_packages "${CHANGED_PACKAGE_LIST[@]}" |
| 87 | +fi |
0 commit comments