Skip to content

Commit a69f52c

Browse files
authored
Fix mobile examples CI pipeline (#454)
* update Podfiles to use ios 13 * update prepare_model.sh to use new model download URL. * update pipeline to use stages instead of jobs so they can be run individually * remove job dependency * get labelmap.txt * use variables for agent pool specification * remove mobile build related stuff, put podfile update into template * fix podfile paths * add python version parameter * default to jdk 17 * remove explicit jdk version arg * sync android python helper scripts with ORT version * update run android emulator yaml * add platform_helpers.py * add step to install emulator * add step to install platform tools * use template for running android emulator
1 parent 0de2e66 commit a69f52c

File tree

16 files changed

+553
-439
lines changed

16 files changed

+553
-439
lines changed

ci_build/azure_pipelines/mobile-examples-pipeline.yml

Lines changed: 306 additions & 326 deletions
Large diffs are not rendered by default.

ci_build/azure_pipelines/templates/run-with-android-emulator-steps.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,34 @@ parameters:
33
type: stepList
44

55
steps:
6-
- bash: |
6+
- script: |
7+
if [[ ":$PATH:" == *":${ANDROID_SDK_ROOT}/emulator:"* ]]; then
8+
echo "${ANDROID_SDK_ROOT}/emulator is in PATH"
9+
else
10+
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "emulator"
11+
echo "##vso[task.prependpath]${ANDROID_SDK_ROOT}/emulator"
12+
fi
13+
displayName: Check if emulator is installed and add to PATH
14+
15+
- script: |
16+
if [[ ":$PATH:" == *":${ANDROID_SDK_ROOT}/platform-tools:"* ]]; then
17+
echo "${ANDROID_SDK_ROOT}/platform-tools is in PATH"
18+
else
19+
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "platform-tools"
20+
echo "##vso[task.prependpath]${ANDROID_SDK_ROOT}/platform-tools"
21+
fi
22+
ls -R ${ANDROID_SDK_ROOT}/platform-tools
23+
displayName: Check if platform tools are installed and add to PATH
24+
25+
- script: |
726
set -e -x
827
928
ORT_EXAMPLES_BUILD_ANDROID_EMULATOR_PID_FILE="$(Build.BinariesDirectory)/android_emulator.pid"
1029
1130
python ./ci_build/python/run_android_emulator.py \
1231
--android-sdk-root "${ANDROID_SDK_ROOT}" \
13-
--create-avd --system-image "system-images;android-30;default;x86_64" \
14-
--start --emulator-extra-args="-partition-size 4096" \
32+
--create-avd --system-image "system-images;android-31;default;x86_64" \
33+
--start --emulator-extra-args="-partition-size 2047" \
1534
--emulator-pid-file "${ORT_EXAMPLES_BUILD_ANDROID_EMULATOR_PID_FILE}"
1635
1736
set +x # do not output next line or it may be parsed again with a trailing quote
@@ -20,7 +39,13 @@ steps:
2039

2140
- ${{ parameters.steps }}
2241

23-
- bash: |
42+
- script: |
43+
set -e -x
44+
python3 -m pip install psutil
45+
displayName: Install psutil for emulator shutdown by run_android_emulator.py
46+
condition: always()
47+
48+
- script: |
2449
set -e -x
2550
2651
if [[ -n "${ORT_EXAMPLES_BUILD_ANDROID_EMULATOR_PID_FILE-}" ]]; then
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
parameters:
2+
- name: podfilePath
3+
type: string
4+
- name: ortPodVersionSpecifier
5+
type: string
6+
default: ""
7+
- name: ortPodName
8+
type: string
9+
default: "onnxruntime-objc"
10+
11+
steps:
12+
- bash: |
13+
set -e
14+
15+
if [[ -z "${{ parameters.OrtPodVersionSpecifier }}" ]]; then
16+
echo "Using original Podfile"
17+
exit 0
18+
fi
19+
20+
PODFILE="${{ parameters.PodfilePath }}"
21+
ORT_POD_NAME="${{ parameters.OrtPodName }}"
22+
sed -i "" -e "s/pod '${ORT_POD_NAME}'/pod '${ORT_POD_NAME}'$(OrtPodVersionSpecifier)/" "${PODFILE}"
23+
cat "${PODFILE}"
24+
displayName: "Update Podfile at ${{ parameters.PodfilePath }}"

ci_build/azure_pipelines/templates/use-jdk-step.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parameters:
22
- name: jdkVersion
33
type: string
4-
default: "11"
4+
default: "17"
55

66
steps:
77
- task: JavaToolInstaller@0
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
parameters:
2+
- name: pythonVersion
3+
type: string
4+
default: "3.9"
5+
16
steps:
27
- task: UsePythonVersion@0
38
inputs:
4-
versionSpec: '3.9'
9+
versionSpec: "${{ parameters.pythonVersion }}"
510
addToPath: true
611
architecture: 'x64'
7-
displayName: "Use Python 3.9"
12+
displayName: "Use Python ${{ parameters.pythonVersion }}"

ci_build/python/run_android_emulator.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,44 @@
77
import shlex
88
import sys
99

10-
from util.logger import get_logger
1110
import util.android as android
12-
11+
from util.logger import get_logger
1312

1413
log = get_logger("run_android_emulator")
1514

1615

1716
def parse_args():
1817
parser = argparse.ArgumentParser(
1918
description="Manages the running of an Android emulator. "
20-
"Supported modes are to start and stop (default), only start, or only "
21-
"stop the emulator.")
19+
"Supported modes are to create an AVD, and start or stop the emulator. "
20+
"The default is to start the emulator and wait for a keypress to stop it (start and stop)."
21+
)
2222

23-
parser.add_argument(
24-
"--create-avd", action="store_true",
25-
help="Whether to create the Android virtual device.")
23+
parser.add_argument("--create-avd", action="store_true", help="Whether to create the Android virtual device.")
2624

27-
parser.add_argument(
28-
"--start", action="store_true", help="Start the emulator.")
29-
parser.add_argument(
30-
"--stop", action="store_true", help="Stop the emulator.")
25+
parser.add_argument("--start", action="store_true", help="Start the emulator.")
26+
parser.add_argument("--stop", action="store_true", help="Stop the emulator.")
3127

28+
parser.add_argument("--android-sdk-root", required=True, help="Path to the Android SDK root.")
3229
parser.add_argument(
33-
"--android-sdk-root", required=True, help="Path to the Android SDK root.")
34-
parser.add_argument(
35-
"--system-image", default="system-images;android-29;google_apis;x86_64",
36-
help="The Android system image package name.")
37-
parser.add_argument(
38-
"--avd-name", default="ort_android",
39-
help="The Android virtual device name.")
30+
"--system-image",
31+
default="system-images;android-31;default;x86_64",
32+
help="The Android system image package name.",
33+
)
34+
parser.add_argument("--avd-name", default="ort_android", help="The Android virtual device name.")
4035
parser.add_argument(
41-
"--emulator-extra-args", default="",
42-
help="A string of extra arguments to pass to the Android emulator.")
36+
"--emulator-extra-args", default="", help="A string of extra arguments to pass to the Android emulator."
37+
)
4338
parser.add_argument(
4439
"--emulator-pid-file",
4540
help="Output/input file containing the PID of the emulator process. "
46-
"This is only required if exactly one of --start or --stop is given.")
41+
"This is only required if exactly one of --start or --stop is given.",
42+
)
4743

4844
args = parser.parse_args()
4945

50-
if not args.start and not args.stop:
51-
# unspecified means start and stop
46+
if not args.start and not args.stop and not args.create_avd:
47+
# unspecified means start and stop if not creating the AVD
5248
args.start = args.stop = True
5349

5450
if args.start != args.stop and args.emulator_pid_file is None:
@@ -84,10 +80,10 @@ def main():
8480
emulator_proc = android.start_emulator(**start_emulator_args)
8581

8682
with open(args.emulator_pid_file, mode="w") as emulator_pid_file:
87-
print("{}".format(emulator_proc.pid), file=emulator_pid_file)
83+
print(f"{emulator_proc.pid}", file=emulator_pid_file)
8884

8985
elif args.stop:
90-
with open(args.emulator_pid_file, mode="r") as emulator_pid_file:
86+
with open(args.emulator_pid_file) as emulator_pid_file:
9187
emulator_pid = int(emulator_pid_file.readline().strip())
9288

9389
android.stop_emulator(emulator_pid)

0 commit comments

Comments
 (0)