1ffe3c632Sopenharmony_ci#!/bin/bash
2ffe3c632Sopenharmony_ci#
3ffe3c632Sopenharmony_ci# Helper to run the pods tests.
4ffe3c632Sopenharmony_ci
5ffe3c632Sopenharmony_ciset -eu
6ffe3c632Sopenharmony_ci
7ffe3c632Sopenharmony_cireadonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
8ffe3c632Sopenharmony_ci
9ffe3c632Sopenharmony_ciprintUsage() {
10ffe3c632Sopenharmony_ci  NAME=$(basename "${0}")
11ffe3c632Sopenharmony_ci  cat << EOF
12ffe3c632Sopenharmony_ciusage: ${NAME} [OPTIONS]
13ffe3c632Sopenharmony_ci
14ffe3c632Sopenharmony_ciThis script runs some test to check the CocoaPods integration.
15ffe3c632Sopenharmony_ci
16ffe3c632Sopenharmony_ciOPTIONS:
17ffe3c632Sopenharmony_ci
18ffe3c632Sopenharmony_ci General:
19ffe3c632Sopenharmony_ci
20ffe3c632Sopenharmony_ci   -h, --help
21ffe3c632Sopenharmony_ci         Show this message
22ffe3c632Sopenharmony_ci   --skip-static
23ffe3c632Sopenharmony_ci         Skip the static based pods tests.
24ffe3c632Sopenharmony_ci   --skip-framework
25ffe3c632Sopenharmony_ci         Skip the framework based pods tests.
26ffe3c632Sopenharmony_ci   --skip-ios
27ffe3c632Sopenharmony_ci         Skip the iOS pods tests.
28ffe3c632Sopenharmony_ci   --skip-osx
29ffe3c632Sopenharmony_ci         Skip the OS X pods tests.
30ffe3c632Sopenharmony_ci
31ffe3c632Sopenharmony_ciEOF
32ffe3c632Sopenharmony_ci}
33ffe3c632Sopenharmony_ci
34ffe3c632Sopenharmony_ciTEST_MODES=( "static" "framework" )
35ffe3c632Sopenharmony_ciTEST_NAMES=( "iOSCocoaPodsTester" "OSXCocoaPodsTester" )
36ffe3c632Sopenharmony_ciwhile [[ $# != 0 ]]; do
37ffe3c632Sopenharmony_ci  case "${1}" in
38ffe3c632Sopenharmony_ci    -h | --help )
39ffe3c632Sopenharmony_ci      printUsage
40ffe3c632Sopenharmony_ci      exit 0
41ffe3c632Sopenharmony_ci      ;;
42ffe3c632Sopenharmony_ci    --skip-static )
43ffe3c632Sopenharmony_ci      TEST_MODES=(${TEST_MODES[@]/static})
44ffe3c632Sopenharmony_ci      ;;
45ffe3c632Sopenharmony_ci    --skip-framework )
46ffe3c632Sopenharmony_ci      TEST_MODES=(${TEST_MODES[@]/framework})
47ffe3c632Sopenharmony_ci      ;;
48ffe3c632Sopenharmony_ci    --skip-ios )
49ffe3c632Sopenharmony_ci      TEST_NAMES=(${TEST_NAMES[@]/iOSCocoaPodsTester})
50ffe3c632Sopenharmony_ci      ;;
51ffe3c632Sopenharmony_ci    --skip-osx )
52ffe3c632Sopenharmony_ci      TEST_NAMES=(${TEST_NAMES[@]/OSXCocoaPodsTester})
53ffe3c632Sopenharmony_ci      ;;
54ffe3c632Sopenharmony_ci    -*)
55ffe3c632Sopenharmony_ci      echo "ERROR: Unknown option: ${1}" 1>&2
56ffe3c632Sopenharmony_ci      printUsage
57ffe3c632Sopenharmony_ci      exit 1
58ffe3c632Sopenharmony_ci      ;;
59ffe3c632Sopenharmony_ci    *)
60ffe3c632Sopenharmony_ci      echo "ERROR: Unknown argument: ${1}" 1>&2
61ffe3c632Sopenharmony_ci      printUsage
62ffe3c632Sopenharmony_ci      exit 1
63ffe3c632Sopenharmony_ci      ;;
64ffe3c632Sopenharmony_ci  esac
65ffe3c632Sopenharmony_ci  shift
66ffe3c632Sopenharmony_cidone
67ffe3c632Sopenharmony_ci
68ffe3c632Sopenharmony_ci# Sanity check.
69ffe3c632Sopenharmony_ciif [[ "${#TEST_NAMES[@]}" == 0 ]] ; then
70ffe3c632Sopenharmony_ci  echo "ERROR: Need to run at least iOS or OS X tests." 1>&2
71ffe3c632Sopenharmony_ci  exit 2
72ffe3c632Sopenharmony_cifi
73ffe3c632Sopenharmony_ciif [[ "${#TEST_MODES[@]}" == 0 ]] ; then
74ffe3c632Sopenharmony_ci  echo "ERROR: Need to run at least static or frameworks tests." 1>&2
75ffe3c632Sopenharmony_ci  exit 2
76ffe3c632Sopenharmony_cifi
77ffe3c632Sopenharmony_ci
78ffe3c632Sopenharmony_ciheader() {
79ffe3c632Sopenharmony_ci  echo ""
80ffe3c632Sopenharmony_ci  echo "========================================================================"
81ffe3c632Sopenharmony_ci  echo "    ${@}"
82ffe3c632Sopenharmony_ci  echo "========================================================================"
83ffe3c632Sopenharmony_ci  echo ""
84ffe3c632Sopenharmony_ci}
85ffe3c632Sopenharmony_ci
86ffe3c632Sopenharmony_ci# Cleanup hook for do_test, assumes directory is correct.
87ffe3c632Sopenharmony_cicleanup() {
88ffe3c632Sopenharmony_ci  local TEST_NAME="$1"
89ffe3c632Sopenharmony_ci
90ffe3c632Sopenharmony_ci  echo "Cleaning up..."
91ffe3c632Sopenharmony_ci
92ffe3c632Sopenharmony_ci  # Generally don't let things fail, and eat common stdout, but let stderr show
93ffe3c632Sopenharmony_ci  # incase something does hiccup.
94ffe3c632Sopenharmony_ci  xcodebuild -workspace "${TEST_NAME}.xcworkspace" -scheme "${TEST_NAME}" clean > /dev/null || true
95ffe3c632Sopenharmony_ci  pod deintegrate > /dev/null || true
96ffe3c632Sopenharmony_ci  # Flush the cache so nothing is left behind.
97ffe3c632Sopenharmony_ci  pod cache clean --all || true
98ffe3c632Sopenharmony_ci  # Delete the files left after pod deintegrate.
99ffe3c632Sopenharmony_ci  rm -f Podfile.lock || true
100ffe3c632Sopenharmony_ci  rm -rf "${TEST_NAME}.xcworkspace" || true
101ffe3c632Sopenharmony_ci  git checkout -- "${TEST_NAME}.xcodeproj" || true
102ffe3c632Sopenharmony_ci  # Remove the Podfile that was put in place.
103ffe3c632Sopenharmony_ci  rm -f Podfile || true
104ffe3c632Sopenharmony_ci}
105ffe3c632Sopenharmony_ci
106ffe3c632Sopenharmony_cido_test() {
107ffe3c632Sopenharmony_ci  local TEST_NAME="$1"
108ffe3c632Sopenharmony_ci  local TEST_MODE="$2"
109ffe3c632Sopenharmony_ci
110ffe3c632Sopenharmony_ci  header "${TEST_NAME}" - Mode: "${TEST_MODE}"
111ffe3c632Sopenharmony_ci  cd "${ScriptDir}/${TEST_NAME}"
112ffe3c632Sopenharmony_ci
113ffe3c632Sopenharmony_ci  # Hook in cleanup for any failures.
114ffe3c632Sopenharmony_ci  trap "cleanup ${TEST_NAME}" EXIT
115ffe3c632Sopenharmony_ci
116ffe3c632Sopenharmony_ci  # Ensure nothing is cached by pods to start with that could throw things off.
117ffe3c632Sopenharmony_ci  pod cache clean --all
118ffe3c632Sopenharmony_ci
119ffe3c632Sopenharmony_ci  # Put the right Podfile in place.
120ffe3c632Sopenharmony_ci  cp -f "Podfile-${TEST_MODE}" "Podfile"
121ffe3c632Sopenharmony_ci
122ffe3c632Sopenharmony_ci  xcodebuild_args=( "-workspace" "${TEST_NAME}.xcworkspace" "-scheme" "${TEST_NAME}" )
123ffe3c632Sopenharmony_ci
124ffe3c632Sopenharmony_ci  # For iOS, if the SDK is not provided it tries to use iphoneos, and the test
125ffe3c632Sopenharmony_ci  # fail on Travis since those machines don't have a Code Signing identity.
126ffe3c632Sopenharmony_ci  if  [[ "${TEST_NAME}" == iOS* ]] ; then
127ffe3c632Sopenharmony_ci    # Apparently the destination flag is required to avoid "Unsupported architecture"
128ffe3c632Sopenharmony_ci    # errors.
129ffe3c632Sopenharmony_ci    xcodebuild_args+=(
130ffe3c632Sopenharmony_ci        -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
131ffe3c632Sopenharmony_ci        -destination "platform=iOS Simulator,name=iPad 2,OS=9.3"
132ffe3c632Sopenharmony_ci    )
133ffe3c632Sopenharmony_ci  fi
134ffe3c632Sopenharmony_ci
135ffe3c632Sopenharmony_ci  # Do the work!
136ffe3c632Sopenharmony_ci  pod install --verbose
137ffe3c632Sopenharmony_ci
138ffe3c632Sopenharmony_ci  xcodebuild "${xcodebuild_args[@]}" build
139ffe3c632Sopenharmony_ci
140ffe3c632Sopenharmony_ci  # Clear the hook and manually run cleanup.
141ffe3c632Sopenharmony_ci  trap - EXIT
142ffe3c632Sopenharmony_ci  cleanup "${TEST_NAME}"
143ffe3c632Sopenharmony_ci}
144ffe3c632Sopenharmony_ci
145ffe3c632Sopenharmony_ci# Run the tests.
146ffe3c632Sopenharmony_cifor TEST_NAME in "${TEST_NAMES[@]}" ; do
147ffe3c632Sopenharmony_ci  for TEST_MODE in "${TEST_MODES[@]}" ; do
148ffe3c632Sopenharmony_ci    do_test "${TEST_NAME}" "${TEST_MODE}"
149ffe3c632Sopenharmony_ci  done
150ffe3c632Sopenharmony_cidone
151