Skip to content

Commit 9c42c9e

Browse files
committed
emulator.sh: add support for the special value of "gradle" for the -c command-line argument, causing it to use the same data connect emulator binary that is used by the gradle build.
1 parent 803857d commit 9c42c9e

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

firebase-dataconnect/emulator/emulator.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,26 @@ function parse_args {
5858
exit 2
5959
;;
6060
*)
61-
echo "INTERNAL ERROR: unknown argument: $arg" >&2
62-
exit 1
61+
log_error_and_exit "INTERNAL ERROR: unknown argument: $arg"
6362
;;
6463
esac
6564
done
6665

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

@@ -90,8 +103,9 @@ function print_help {
90103
echo
91104
echo "Options:"
92105
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."
106+
echo " Uses the Data Connect Emulator binary at the given path. A value of \"gradle\" "
107+
echo " will use the same CLI as the Gradle build. If not specified, or if specified "
108+
echo " as the empty string, then the emulator binary is downloaded."
95109
echo
96110
echo " -p <postgresql_connection_string>"
97111
echo " Uses the given string to connect to the PostgreSQL server. If not specified "
@@ -116,4 +130,9 @@ function log {
116130
echo "${LOG_PREFIX}$*"
117131
}
118132

133+
function log_error_and_exit {
134+
echo "${LOG_PREFIX}ERROR: $*" >&2
135+
exit 1
136+
}
137+
119138
main "$@"

0 commit comments

Comments
 (0)