Skip to content

Commit 59df53b

Browse files
authored
dataconnect: emulator.sh: add flag to use the same data connect emulator as the gradle build (#7209)
1 parent 0c1302f commit 59df53b

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

firebase-dataconnect/emulator/emulator.sh

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ function parse_args {
3737

3838
local OPTIND=1
3939
local OPTERR=0
40-
while getopts ":c:p:v:hw" arg ; do
40+
while getopts ":c:p:v:hwg" arg ; do
4141
case "$arg" in
4242
c) emulator_binary="${OPTARG}" ;;
43+
g) emulator_binary="gradle" ;;
4344
p) postgresql_string="${OPTARG}" ;;
4445
v) preview_flags="${OPTARG}" ;;
4546
w) wipe_and_restart_postgres_pod=1 ;;
@@ -58,13 +59,26 @@ function parse_args {
5859
exit 2
5960
;;
6061
*)
61-
echo "INTERNAL ERROR: unknown argument: $arg" >&2
62-
exit 1
62+
log_error_and_exit "INTERNAL ERROR: unknown argument: $arg"
6363
;;
6464
esac
6565
done
6666

67-
export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}"
67+
if [[ $emulator_binary != "gradle" ]] ; then
68+
export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}"
69+
else
70+
run_command "${SCRIPT_DIR}/../../gradlew" -p "${SCRIPT_DIR}/../.." --configure-on-demand :firebase-dataconnect:connectors:downloadDebugDataConnectExecutable
71+
local gradle_emulator_binaries=("${SCRIPT_DIR}"/../connectors/build/intermediates/dataconnect/debug/executable/*)
72+
if [[ ${#gradle_emulator_binaries[@]} -ne 1 ]]; then
73+
log_error_and_exit "expected exactly 1 emulator binary from gradle, but got ${#gradle_emulator_binaries[@]}: ${gradle_emulator_binaries[*]}"
74+
fi
75+
local gradle_emulator_binary="${gradle_emulator_binaries[@]}"
76+
if [[ ! -e $gradle_emulator_binary ]] ; then
77+
log_error_and_exit "emulator binary from gradle does not exist: ${gradle_emulator_binary}"
78+
fi
79+
export DATACONNECT_EMULATOR_BINARY_PATH="${gradle_emulator_binary}"
80+
fi
81+
6882
export FIREBASE_DATACONNECT_POSTGRESQL_STRING="${postgresql_string}"
6983
export DATA_CONNECT_PREVIEW="${preview_flags}"
7084

@@ -90,8 +104,12 @@ function print_help {
90104
echo
91105
echo "Options:"
92106
echo " -c <data_connect_emulator_binary_path>"
93-
echo " Uses the Data Connect Emulator binary at the given path. If not specified, "
94-
echo " or if specified as the empty string, then the emulator binary is downloaded."
107+
echo " Uses the Data Connect Emulator binary at the given path. A value of \"gradle\" "
108+
echo " will use the same binary as the Gradle build. If not specified, or if specified "
109+
echo " as the empty string, then the emulator binary is downloaded."
110+
echo
111+
echo " -g"
112+
echo " Shorthand for: -c gradle"
95113
echo
96114
echo " -p <postgresql_connection_string>"
97115
echo " Uses the given string to connect to the PostgreSQL server. If not specified "
@@ -116,4 +134,9 @@ function log {
116134
echo "${LOG_PREFIX}$*"
117135
}
118136

137+
function log_error_and_exit {
138+
echo "${LOG_PREFIX}ERROR: $*" >&2
139+
exit 1
140+
}
141+
119142
main "$@"

0 commit comments

Comments
 (0)