@@ -37,9 +37,10 @@ function parse_args {
37
37
38
38
local OPTIND=1
39
39
local OPTERR=0
40
- while getopts " :c:p:v:hw " arg ; do
40
+ while getopts " :c:p:v:hwg " arg ; do
41
41
case " $arg " in
42
42
c) emulator_binary=" ${OPTARG} " ;;
43
+ g) emulator_binary=" gradle" ;;
43
44
p) postgresql_string=" ${OPTARG} " ;;
44
45
v) preview_flags=" ${OPTARG} " ;;
45
46
w) wipe_and_restart_postgres_pod=1 ;;
@@ -58,13 +59,26 @@ function parse_args {
58
59
exit 2
59
60
;;
60
61
* )
61
- echo " INTERNAL ERROR: unknown argument: $arg " >&2
62
- exit 1
62
+ log_error_and_exit " INTERNAL ERROR: unknown argument: $arg "
63
63
;;
64
64
esac
65
65
done
66
66
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
+
68
82
export FIREBASE_DATACONNECT_POSTGRESQL_STRING=" ${postgresql_string} "
69
83
export DATA_CONNECT_PREVIEW=" ${preview_flags} "
70
84
@@ -90,8 +104,12 @@ function print_help {
90
104
echo
91
105
echo " Options:"
92
106
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"
95
113
echo
96
114
echo " -p <postgresql_connection_string>"
97
115
echo " Uses the given string to connect to the PostgreSQL server. If not specified "
@@ -116,4 +134,9 @@ function log {
116
134
echo " ${LOG_PREFIX} $* "
117
135
}
118
136
137
+ function log_error_and_exit {
138
+ echo " ${LOG_PREFIX} ERROR: $* " >&2
139
+ exit 1
140
+ }
141
+
119
142
main " $@ "
0 commit comments