From 9c42c9e26de916eade5d68d8e50a8e01b8e1308b Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 1 Aug 2025 00:39:58 -0400 Subject: [PATCH 1/4] 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. --- firebase-dataconnect/emulator/emulator.sh | 29 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/firebase-dataconnect/emulator/emulator.sh b/firebase-dataconnect/emulator/emulator.sh index 0074c175c0b..185d5707773 100755 --- a/firebase-dataconnect/emulator/emulator.sh +++ b/firebase-dataconnect/emulator/emulator.sh @@ -58,13 +58,26 @@ function parse_args { exit 2 ;; *) - echo "INTERNAL ERROR: unknown argument: $arg" >&2 - exit 1 + log_error_and_exit "INTERNAL ERROR: unknown argument: $arg" ;; esac done - export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}" + if [[ $emulator_binary != "gradle" ]] ; then + export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}" + else + run_command "${SCRIPT_DIR}/../../gradlew" -p "${SCRIPT_DIR}/../.." --configure-on-demand :firebase-dataconnect:connectors:downloadDebugDataConnectExecutable + local gradle_emulator_binaries=("${SCRIPT_DIR}"/../connectors/build/intermediates/dataconnect/debug/executable/*) + if [[ ${#gradle_emulator_binaries[@]} -ne 1 ]]; then + log_error_and_exit "expected exactly 1 emulator binary from gradle, but got ${#gradle_emulator_binaries[@]}: ${gradle_emulator_binaries[*]}" + fi + local gradle_emulator_binary="${gradle_emulator_binaries[@]}" + if [[ ! -e $gradle_emulator_binary ]] ; then + log_error_and_exit "emulator binary from gradle does not exist: ${gradle_emulator_binary}" + fi + export DATACONNECT_EMULATOR_BINARY_PATH="${gradle_emulator_binaries[0]}" + fi + export FIREBASE_DATACONNECT_POSTGRESQL_STRING="${postgresql_string}" export DATA_CONNECT_PREVIEW="${preview_flags}" @@ -90,8 +103,9 @@ function print_help { echo echo "Options:" echo " -c " - echo " Uses the Data Connect Emulator binary at the given path. If not specified, " - echo " or if specified as the empty string, then the emulator binary is downloaded." + echo " Uses the Data Connect Emulator binary at the given path. A value of \"gradle\" " + echo " will use the same CLI as the Gradle build. If not specified, or if specified " + echo " as the empty string, then the emulator binary is downloaded." echo echo " -p " echo " Uses the given string to connect to the PostgreSQL server. If not specified " @@ -116,4 +130,9 @@ function log { echo "${LOG_PREFIX}$*" } +function log_error_and_exit { + echo "${LOG_PREFIX}ERROR: $*" >&2 + exit 1 +} + main "$@" From c6739c037f1d1eb0409b3eeb60b24f3cbb584ac2 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 1 Aug 2025 00:48:07 -0400 Subject: [PATCH 2/4] dedupe --- firebase-dataconnect/emulator/emulator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-dataconnect/emulator/emulator.sh b/firebase-dataconnect/emulator/emulator.sh index 185d5707773..7358a82a680 100755 --- a/firebase-dataconnect/emulator/emulator.sh +++ b/firebase-dataconnect/emulator/emulator.sh @@ -75,7 +75,7 @@ function parse_args { if [[ ! -e $gradle_emulator_binary ]] ; then log_error_and_exit "emulator binary from gradle does not exist: ${gradle_emulator_binary}" fi - export DATACONNECT_EMULATOR_BINARY_PATH="${gradle_emulator_binaries[0]}" + export DATACONNECT_EMULATOR_BINARY_PATH="${gradle_emulator_binary}" fi export FIREBASE_DATACONNECT_POSTGRESQL_STRING="${postgresql_string}" From f06a739e5027f7590f15e545e57e33655612b4f8 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 1 Aug 2025 11:46:52 -0400 Subject: [PATCH 3/4] emulator.sh: add -g shorthand for "-c gradle" diff --git a/firebase-dataconnect/emulator/emulator.sh b/firebase-dataconnect/emulator/emulator.sh index 7358a82a6..3efc204a3 100755 --- a/firebase-dataconnect/emulator/emulator.sh +++ b/firebase-dataconnect/emulator/emulator.sh @@ -37,9 +37,10 @@ function parse_args { local OPTIND=1 local OPTERR=0 - while getopts ":c:p:v:hw" arg ; do + while getopts ":c:p:v:hwg" arg ; do case "$arg" in c) emulator_binary="${OPTARG}" ;; + g) emulator_binary="gradle" ;; p) postgresql_string="${OPTARG}" ;; v) preview_flags="${OPTARG}" ;; w) wipe_and_restart_postgres_pod=1 ;; @@ -107,6 +108,9 @@ function print_help { echo " will use the same CLI as the Gradle build. If not specified, or if specified " echo " as the empty string, then the emulator binary is downloaded." echo + echo " -g" + echo " Shorthand for: -c gradle" + echo echo " -p " echo " Uses the given string to connect to the PostgreSQL server. If not specified " echo " the the default value of \"${DEFAULT_POSTGRESQL_STRING}\" is used." --- firebase-dataconnect/emulator/emulator.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/firebase-dataconnect/emulator/emulator.sh b/firebase-dataconnect/emulator/emulator.sh index 7358a82a680..3efc204a33c 100755 --- a/firebase-dataconnect/emulator/emulator.sh +++ b/firebase-dataconnect/emulator/emulator.sh @@ -37,9 +37,10 @@ function parse_args { local OPTIND=1 local OPTERR=0 - while getopts ":c:p:v:hw" arg ; do + while getopts ":c:p:v:hwg" arg ; do case "$arg" in c) emulator_binary="${OPTARG}" ;; + g) emulator_binary="gradle" ;; p) postgresql_string="${OPTARG}" ;; v) preview_flags="${OPTARG}" ;; w) wipe_and_restart_postgres_pod=1 ;; @@ -107,6 +108,9 @@ function print_help { echo " will use the same CLI as the Gradle build. If not specified, or if specified " echo " as the empty string, then the emulator binary is downloaded." echo + echo " -g" + echo " Shorthand for: -c gradle" + echo echo " -p " echo " Uses the given string to connect to the PostgreSQL server. If not specified " echo " the the default value of \"${DEFAULT_POSTGRESQL_STRING}\" is used." From 75da7ee6dff64a7260d47711c340f840da102749 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 1 Aug 2025 13:10:05 -0400 Subject: [PATCH 4/4] CLI -> binary in help text Co-authored-by: Maneesh Tewani --- firebase-dataconnect/emulator/emulator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-dataconnect/emulator/emulator.sh b/firebase-dataconnect/emulator/emulator.sh index 3efc204a33c..39a45ec6a4e 100755 --- a/firebase-dataconnect/emulator/emulator.sh +++ b/firebase-dataconnect/emulator/emulator.sh @@ -105,7 +105,7 @@ function print_help { echo "Options:" echo " -c " echo " Uses the Data Connect Emulator binary at the given path. A value of \"gradle\" " - echo " will use the same CLI as the Gradle build. If not specified, or if specified " + echo " will use the same binary as the Gradle build. If not specified, or if specified " echo " as the empty string, then the emulator binary is downloaded." echo echo " -g"