@dashevo/dapi-grpc 4.2.0-beta.5 → 4.2.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/build.rs +4 -0
- package/clients/drive/v0/nodejs/drive_pbjs.js +528 -0
- package/clients/platform/v0/nodejs/platform_pbjs.js +528 -0
- package/clients/platform/v0/nodejs/platform_protoc.js +490 -2
- package/clients/platform/v0/web/platform_pb.d.ts +63 -0
- package/clients/platform/v0/web/platform_pb.js +490 -2
- package/codegen.json +31 -0
- package/package.json +4 -3
- package/protos/platform/v0/platform.proto +41 -4
- package/scripts/build.sh +61 -247
- package/scripts/check-packed-clients.py +32 -0
- package/scripts/patch-protobuf-js.sh +11 -6
- package/scripts/setup-codegen.py +74 -0
package/scripts/build.sh
CHANGED
|
@@ -1,252 +1,66 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
|
|
2
|
+
# Generate all published clients with the locked native toolchain.
|
|
3
|
+
set -euo pipefail
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
echo WARN: Skipping GRPC protobuf definitions rebuild
|
|
5
|
+
if [[ "${SKIP_GRPC_PROTO_BUILD:-0}" == 1 ]]; then
|
|
6
|
+
echo 'WARN: Skipping GRPC protobuf definitions rebuild'
|
|
8
7
|
exit 0
|
|
9
8
|
fi
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
-o "$CORE_CLIENTS_PATH/nodejs/core_pbjs.js" \
|
|
69
|
-
"$CORE_PROTO_PATH/core.proto"
|
|
70
|
-
|
|
71
|
-
#####################################################
|
|
72
|
-
# Generate JavaScript client for `DriveInternal` service #
|
|
73
|
-
#####################################################
|
|
74
|
-
|
|
75
|
-
rm -rf "${DRIVE_WEB_OUT_PATH:?}/*" || true
|
|
76
|
-
|
|
77
|
-
docker run -v "$DRIVE_PROTO_PATH:$DRIVE_PROTO_PATH" \
|
|
78
|
-
-v "$DRIVE_WEB_OUT_PATH:$DRIVE_WEB_OUT_PATH" \
|
|
79
|
-
-v "$PROTOS_PATH:$PROTOS_PATH" \
|
|
80
|
-
--rm \
|
|
81
|
-
"$PROTOC_IMAGE" \
|
|
82
|
-
--js_out="import_style=commonjs:$DRIVE_WEB_OUT_PATH" \
|
|
83
|
-
--ts_out="service=grpc-web:$DRIVE_WEB_OUT_PATH" \
|
|
84
|
-
-I="$DRIVE_PROTO_PATH" \
|
|
85
|
-
-I="$PROTOS_PATH" \
|
|
86
|
-
"drive.proto"
|
|
87
|
-
|
|
88
|
-
# Clean node message classes
|
|
89
|
-
|
|
90
|
-
rm -rf "$DRIVE_CLIENTS_PATH/nodejs/*_protoc.js" || true
|
|
91
|
-
rm -rf "$DRIVE_CLIENTS_PATH/nodejs/*_pbjs.js" || true
|
|
92
|
-
|
|
93
|
-
# Copy compiled modules with message classes
|
|
94
|
-
|
|
95
|
-
cp "$DRIVE_WEB_OUT_PATH/drive_pb.js" "$DRIVE_CLIENTS_PATH/nodejs/drive_protoc.js"
|
|
96
|
-
|
|
97
|
-
pbjs \
|
|
98
|
-
-t static-module \
|
|
99
|
-
-w commonjs \
|
|
100
|
-
-r platform_root \
|
|
101
|
-
-p "$PROTOS_PATH" \
|
|
102
|
-
-o "$DRIVE_CLIENTS_PATH/nodejs/drive_pbjs.js" \
|
|
103
|
-
"$DRIVE_PROTO_PATH/drive.proto"
|
|
104
|
-
|
|
105
|
-
#####################################################
|
|
106
|
-
# Generate JavaScript client for `Platform` service #
|
|
107
|
-
#####################################################
|
|
108
|
-
|
|
109
|
-
rm -rf "${PLATFORM_WEB_OUT_PATH:?}/*" || true
|
|
110
|
-
|
|
111
|
-
docker run -v "$PLATFORM_PROTO_PATH:$PLATFORM_PROTO_PATH" \
|
|
112
|
-
-v "$PLATFORM_WEB_OUT_PATH:$PLATFORM_WEB_OUT_PATH" \
|
|
113
|
-
-v "$PROTOS_PATH:$PROTOS_PATH" \
|
|
114
|
-
--rm \
|
|
115
|
-
"$PROTOC_IMAGE" \
|
|
116
|
-
--js_out="import_style=commonjs:$PLATFORM_WEB_OUT_PATH" \
|
|
117
|
-
--ts_out="service=grpc-web:$PLATFORM_WEB_OUT_PATH" \
|
|
118
|
-
-I="$PLATFORM_PROTO_PATH" \
|
|
119
|
-
-I="$PROTOS_PATH" \
|
|
120
|
-
"platform.proto"
|
|
121
|
-
|
|
122
|
-
# Clean node message classes
|
|
123
|
-
|
|
124
|
-
rm -rf "$PLATFORM_CLIENTS_PATH/nodejs/*_protoc.js" || true
|
|
125
|
-
rm -rf "$PLATFORM_CLIENTS_PATH/nodejs/*_pbjs.js" || true
|
|
126
|
-
|
|
127
|
-
# Copy compiled modules with message classes
|
|
128
|
-
|
|
129
|
-
cp "$PLATFORM_WEB_OUT_PATH/platform_pb.js" "$PLATFORM_CLIENTS_PATH/nodejs/platform_protoc.js"
|
|
130
|
-
|
|
131
|
-
pbjs \
|
|
132
|
-
-t static-module \
|
|
133
|
-
-w commonjs \
|
|
134
|
-
-r platform_root \
|
|
135
|
-
-o "$PLATFORM_CLIENTS_PATH/nodejs/platform_pbjs.js" \
|
|
136
|
-
-p "$PROTOS_PATH" \
|
|
137
|
-
"$PLATFORM_PROTO_PATH/platform.proto"
|
|
138
|
-
|
|
139
|
-
###################################
|
|
140
|
-
# Generate Java client for `Core` #
|
|
141
|
-
###################################
|
|
142
|
-
|
|
143
|
-
rm -rf "${CORE_JAVA_OUT_PATH:?}/*" || true
|
|
144
|
-
|
|
145
|
-
docker run -v "$CORE_PROTO_PATH:$CORE_PROTO_PATH" \
|
|
146
|
-
-v "$CORE_JAVA_OUT_PATH:$CORE_JAVA_OUT_PATH" \
|
|
147
|
-
-v "$PROTOS_PATH:$PROTOS_PATH" \
|
|
148
|
-
--rm \
|
|
149
|
-
"$PROTOC_IMAGE" \
|
|
150
|
-
--plugin=protoc-gen-grpc=/usr/bin/protoc-gen-grpc-java \
|
|
151
|
-
--grpc-java_out="$CORE_JAVA_OUT_PATH" \
|
|
152
|
-
--proto_path="$CORE_PROTO_PATH" \
|
|
153
|
-
-I="$CORE_PROTO_PATH" \
|
|
154
|
-
-I="$PROTOS_PATH" \
|
|
155
|
-
"core.proto"
|
|
156
|
-
|
|
157
|
-
#######################################
|
|
158
|
-
# Generate Java client for `Platform` #
|
|
159
|
-
#######################################
|
|
160
|
-
|
|
161
|
-
rm -rf "${PLATFORM_JAVA_OUT_PATH:?}/*" || true
|
|
162
|
-
|
|
163
|
-
docker run -v "$PLATFORM_PROTO_PATH:$PLATFORM_PROTO_PATH" \
|
|
164
|
-
-v "$PLATFORM_JAVA_OUT_PATH:$PLATFORM_JAVA_OUT_PATH" \
|
|
165
|
-
-v "$PROTOS_PATH:$PROTOS_PATH" \
|
|
166
|
-
--rm \
|
|
167
|
-
"$PROTOC_IMAGE" \
|
|
168
|
-
--plugin=protoc-gen-grpc=/usr/bin/protoc-gen-grpc-java \
|
|
169
|
-
--grpc-java_out="$PLATFORM_JAVA_OUT_PATH" \
|
|
170
|
-
--proto_path="$PLATFORM_PROTO_PATH" \
|
|
171
|
-
-I="$PLATFORM_PROTO_PATH" \
|
|
172
|
-
-I="$PROTOS_PATH" \
|
|
173
|
-
"platform.proto"
|
|
174
|
-
|
|
175
|
-
##########################################
|
|
176
|
-
# Generate Objective-C client for `Core` #
|
|
177
|
-
##########################################
|
|
178
|
-
|
|
179
|
-
rm -rf "${CORE_OBJ_C_OUT_PATH:?}/*" || true
|
|
180
|
-
|
|
181
|
-
docker run -v "$CORE_PROTO_PATH:$CORE_PROTO_PATH" \
|
|
182
|
-
-v "$CORE_OBJ_C_OUT_PATH:$CORE_OBJ_C_OUT_PATH" \
|
|
183
|
-
-v "$PROTOS_PATH:$PROTOS_PATH" \
|
|
184
|
-
--rm \
|
|
185
|
-
"$PROTOC_IMAGE" \
|
|
186
|
-
--plugin=protoc-gen-grpc=/usr/bin/grpc_objective_c_plugin \
|
|
187
|
-
--objc_out="$CORE_OBJ_C_OUT_PATH" \
|
|
188
|
-
--grpc_out="$CORE_OBJ_C_OUT_PATH" \
|
|
189
|
-
--proto_path="$CORE_PROTO_PATH" \
|
|
190
|
-
-I="$CORE_PROTO_PATH" \
|
|
191
|
-
-I="$PROTOS_PATH" \
|
|
192
|
-
"core.proto"
|
|
193
|
-
|
|
194
|
-
##############################################
|
|
195
|
-
# Generate Objective-C client for `Platform` #
|
|
196
|
-
##############################################
|
|
197
|
-
|
|
198
|
-
rm -rf "${PLATFORM_OBJ_C_OUT_PATH:?}/*" || true
|
|
199
|
-
|
|
200
|
-
docker run -v "$PLATFORM_PROTO_PATH:$PLATFORM_PROTO_PATH" \
|
|
201
|
-
-v "$PLATFORM_OBJ_C_OUT_PATH:$PLATFORM_OBJ_C_OUT_PATH" \
|
|
202
|
-
-v "$PROTOS_PATH:$PROTOS_PATH" \
|
|
203
|
-
--rm \
|
|
204
|
-
"$PROTOC_IMAGE" \
|
|
205
|
-
--plugin=protoc-gen-grpc=/usr/bin/grpc_objective_c_plugin \
|
|
206
|
-
--objc_out="$PLATFORM_OBJ_C_OUT_PATH" \
|
|
207
|
-
--grpc_out="$PLATFORM_OBJ_C_OUT_PATH" \
|
|
208
|
-
--proto_path="$PLATFORM_PROTO_PATH" \
|
|
209
|
-
-I="$PLATFORM_PROTO_PATH" \
|
|
210
|
-
-I="$PROTOS_PATH" \
|
|
211
|
-
"platform.proto"
|
|
212
|
-
|
|
213
|
-
#####################################
|
|
214
|
-
# Generate Python client for `Core` #
|
|
215
|
-
#####################################
|
|
216
|
-
|
|
217
|
-
rm -rf "${CORE_PYTHON_OUT_PATH:?}/*" || true
|
|
218
|
-
|
|
219
|
-
docker run -v "$CORE_PROTO_PATH:$CORE_PROTO_PATH" \
|
|
220
|
-
-v "$CORE_PYTHON_OUT_PATH:$CORE_PYTHON_OUT_PATH" \
|
|
221
|
-
-v "$PROTOS_PATH:$PROTOS_PATH" \
|
|
222
|
-
--rm \
|
|
223
|
-
"$PROTOC_IMAGE" \
|
|
224
|
-
--plugin=protoc-gen-grpc=/usr/bin/grpc_python_plugin \
|
|
225
|
-
--python_out="$CORE_PYTHON_OUT_PATH" \
|
|
226
|
-
--grpc_out="$CORE_PYTHON_OUT_PATH" \
|
|
227
|
-
--proto_path="$CORE_PROTO_PATH" \
|
|
228
|
-
-I="$CORE_PROTO_PATH" \
|
|
229
|
-
-I="$PROTOS_PATH" \
|
|
230
|
-
"core.proto"
|
|
231
|
-
|
|
232
|
-
#########################################
|
|
233
|
-
# Generate Python client for `Platform` #
|
|
234
|
-
#########################################
|
|
235
|
-
|
|
236
|
-
rm -rf "${PLATFORM_PYTHON_OUT_PATH:?}/*" || true
|
|
237
|
-
|
|
238
|
-
docker run -v "$PLATFORM_PROTO_PATH:$PLATFORM_PROTO_PATH" \
|
|
239
|
-
-v "$PLATFORM_PYTHON_OUT_PATH:$PLATFORM_PYTHON_OUT_PATH" \
|
|
240
|
-
-v "$PROTOS_PATH:$PROTOS_PATH" \
|
|
241
|
-
--rm \
|
|
242
|
-
"$PROTOC_IMAGE" \
|
|
243
|
-
--plugin=protoc-gen-grpc=/usr/bin/grpc_python_plugin \
|
|
244
|
-
--python_out="$PLATFORM_PYTHON_OUT_PATH" \
|
|
245
|
-
--grpc_out="$PLATFORM_PYTHON_OUT_PATH" \
|
|
246
|
-
--proto_path="$PLATFORM_PROTO_PATH" \
|
|
247
|
-
-I="$PLATFORM_PROTO_PATH" \
|
|
248
|
-
-I="$PROTOS_PATH" \
|
|
249
|
-
"platform.proto"
|
|
250
|
-
|
|
251
|
-
# Patch generated protobuf files
|
|
252
|
-
exec "${PWD}/scripts/patch-protobuf-js.sh"
|
|
10
|
+
PACKAGE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
11
|
+
TOOLCHAIN=$(python3 "$PACKAGE_DIR/scripts/setup-codegen.py")
|
|
12
|
+
PROTOC="$TOOLCHAIN/bin/protoc"
|
|
13
|
+
TS_PLUGIN=$(command -v protoc-gen-ts)
|
|
14
|
+
command -v pbjs >/dev/null
|
|
15
|
+
|
|
16
|
+
# Keep the existing clients intact when any generator fails. Stage beneath the
|
|
17
|
+
# package so replacement stays on the same filesystem and Yarn PnP still works.
|
|
18
|
+
STAGING=$(mktemp -d "$PACKAGE_DIR/.clients-build.XXXXXX")
|
|
19
|
+
cleanup() {
|
|
20
|
+
# Restore the previous tree if interrupted between the two renames.
|
|
21
|
+
if [[ ! -e "$PACKAGE_DIR/clients" && -d "$STAGING/previous" ]]; then
|
|
22
|
+
mv "$STAGING/previous" "$PACKAGE_DIR/clients"
|
|
23
|
+
fi
|
|
24
|
+
rm -rf "$STAGING"
|
|
25
|
+
}
|
|
26
|
+
trap cleanup EXIT
|
|
27
|
+
trap 'exit 130' INT
|
|
28
|
+
trap 'exit 143' TERM
|
|
29
|
+
cp -R "$PACKAGE_DIR/clients" "$STAGING/clients"
|
|
30
|
+
|
|
31
|
+
for service in core drive platform; do
|
|
32
|
+
output="$STAGING/clients/$service/v0"
|
|
33
|
+
schema="$PACKAGE_DIR/protos/$service/v0/$service.proto"
|
|
34
|
+
includes=(-I"$PACKAGE_DIR/protos/$service/v0" -I"$PACKAGE_DIR/protos" -I"$TOOLCHAIN/include")
|
|
35
|
+
# Preserve handwritten PromiseClient modules and documentation.
|
|
36
|
+
rm -f "$output/web/${service}_pb"* "$output/nodejs/${service}_protoc.js" "$output/nodejs/${service}_pbjs.js"
|
|
37
|
+
"$PROTOC" "${includes[@]}" --plugin="protoc-gen-ts=$TS_PLUGIN" \
|
|
38
|
+
--js_out="import_style=commonjs:$output/web" \
|
|
39
|
+
--ts_out="service=grpc-web:$output/web" "$schema"
|
|
40
|
+
cp "$output/web/${service}_pb.js" "$output/nodejs/${service}_protoc.js"
|
|
41
|
+
root=platform_root
|
|
42
|
+
if [[ "$service" == core ]]; then root=core_root; fi
|
|
43
|
+
pbjs -t static-module -w commonjs -r "$root" -p "$PACKAGE_DIR/protos" \
|
|
44
|
+
-o "$output/nodejs/${service}_pbjs.js" "$schema"
|
|
45
|
+
if [[ "$service" != drive ]]; then
|
|
46
|
+
for language in java objective-c python; do
|
|
47
|
+
rm -rf "${output:?}/$language"
|
|
48
|
+
mkdir -p "$output/$language"
|
|
49
|
+
done
|
|
50
|
+
"$PROTOC" "${includes[@]}" --plugin="protoc-gen-grpc-java=$TOOLCHAIN/bin/protoc-gen-grpc-java" \
|
|
51
|
+
--grpc-java_out="$output/java" "$schema"
|
|
52
|
+
"$PROTOC" "${includes[@]}" --plugin="protoc-gen-grpc=$TOOLCHAIN/bin/grpc_objective_c_plugin" \
|
|
53
|
+
--objc_out="$output/objective-c" --grpc_out="$output/objective-c" "$schema"
|
|
54
|
+
"$PROTOC" "${includes[@]}" --plugin="protoc-gen-grpc=$TOOLCHAIN/bin/grpc_python_plugin" \
|
|
55
|
+
--python_out="$output/python" --grpc_out="$output/python" "$schema"
|
|
56
|
+
fi
|
|
57
|
+
done
|
|
58
|
+
|
|
59
|
+
(cd "$STAGING" && "$PACKAGE_DIR/scripts/patch-protobuf-js.sh")
|
|
60
|
+
# Generation and patching have all succeeded. Preserve handwritten files by
|
|
61
|
+
# replacing the staged copy of the complete client tree.
|
|
62
|
+
mv "$PACKAGE_DIR/clients" "$STAGING/previous"
|
|
63
|
+
if ! mv "$STAGING/clients" "$PACKAGE_DIR/clients"; then
|
|
64
|
+
mv "$STAGING/previous" "$PACKAGE_DIR/clients"
|
|
65
|
+
exit 1
|
|
66
|
+
fi
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Check that packing preserved the freshly generated DAPI clients."""
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import sys
|
|
6
|
+
import tarfile
|
|
7
|
+
|
|
8
|
+
package = Path(__file__).resolve().parent.parent
|
|
9
|
+
expected = {p.relative_to(package).as_posix(): p.read_bytes()
|
|
10
|
+
for p in (package / 'clients').rglob('*')
|
|
11
|
+
if p.is_file() and p.relative_to(package).parts[3] in ('web', 'nodejs')}
|
|
12
|
+
required = {f'clients/{service}/v0/{directory}/{service}{suffix}'
|
|
13
|
+
for service in ('core', 'drive', 'platform')
|
|
14
|
+
for directory, suffix in (('web', '_pb.js'), ('web', '_pb.d.ts'),
|
|
15
|
+
('web', '_pb_service.js'), ('web', '_pb_service.d.ts'),
|
|
16
|
+
('nodejs', '_protoc.js'), ('nodejs', '_pbjs.js'))}
|
|
17
|
+
if not required <= expected.keys():
|
|
18
|
+
raise SystemExit('Missing generated source clients: ' + ', '.join(sorted(required - expected.keys())))
|
|
19
|
+
found = 0
|
|
20
|
+
for archive in Path(sys.argv[1]).glob('*.tgz'):
|
|
21
|
+
with tarfile.open(archive) as tar:
|
|
22
|
+
manifest = tar.extractfile('package/package.json')
|
|
23
|
+
if manifest is None or json.load(manifest)['name'] != '@dashevo/dapi-grpc':
|
|
24
|
+
continue
|
|
25
|
+
found += 1
|
|
26
|
+
for name, content in expected.items():
|
|
27
|
+
member = tar.extractfile('package/' + name)
|
|
28
|
+
if member is None or member.read() != content:
|
|
29
|
+
raise SystemExit(f'Packed client differs from generated source: {name}')
|
|
30
|
+
if found != 1:
|
|
31
|
+
raise SystemExit(f'Expected one DAPI package archive, found {found}')
|
|
32
|
+
print(f'Verified {len(expected)} packed client files')
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
# shellcheck disable=SC2250
|
|
3
|
-
set -
|
|
3
|
+
set -euo pipefail
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
OS=$(uname)
|
|
6
6
|
|
|
7
7
|
function replace_in_file() {
|
|
8
8
|
if [[ "$OS" = 'Darwin' ]]; then
|
|
@@ -15,18 +15,23 @@ function replace_in_file() {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
# Loop over the files
|
|
18
|
-
|
|
18
|
+
while IFS= read -r -d '' file; do
|
|
19
19
|
|
|
20
20
|
replace_in_file 's/var global = Function('\''return this'\'')();/const proto = {};/g' "$file"
|
|
21
21
|
if grep -qrE "[^a-zA-Z]Function\(" "$file"; then
|
|
22
|
-
echo "Error: Function( still present"
|
|
22
|
+
echo "Error: Function( still present in $file" >&2
|
|
23
|
+
exit 1
|
|
23
24
|
fi
|
|
24
25
|
|
|
25
26
|
replace_in_file 's/, global);/, { proto });/g' "$file"
|
|
26
27
|
if grep -qrE '(^|[^a-zA-Z."])global([^a-zA-Z]|$)' "$file"; then
|
|
27
|
-
echo "Error: global still present"
|
|
28
|
+
echo "Error: global still present in $file" >&2
|
|
29
|
+
exit 1
|
|
28
30
|
fi
|
|
29
31
|
|
|
30
32
|
replace_in_file 's/require('\''.\/platform\/v0\/platform_pb.js'\'')/require('\''..\/..\/..\/platform\/v0\/web\/platform_pb.js'\'')/g' "$file"
|
|
31
33
|
|
|
32
|
-
done
|
|
34
|
+
done < <(find "$PWD/clients/core/v0/web" "$PWD/clients/core/v0/nodejs" \
|
|
35
|
+
"$PWD/clients/platform/v0/web" "$PWD/clients/platform/v0/nodejs" \
|
|
36
|
+
"$PWD/clients/drive/v0/web" "$PWD/clients/drive/v0/nodejs" \
|
|
37
|
+
\( -name "*_pb.js" -o -name "*_protoc.js" \) -print0)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Verify or install the pinned native DAPI generators (no root or Docker)."""
|
|
3
|
+
import argparse
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import platform
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import tempfile
|
|
12
|
+
import urllib.request
|
|
13
|
+
|
|
14
|
+
PACKAGE = Path(__file__).resolve().parent.parent
|
|
15
|
+
CONFIG = PACKAGE / 'codegen.json'
|
|
16
|
+
BINARIES = ('protoc', 'protoc-gen-grpc-java', 'grpc_objective_c_plugin', 'grpc_python_plugin')
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def verify(destination, config):
|
|
20
|
+
if json.loads((destination / 'lock.json').read_text()) != config['toolchain']:
|
|
21
|
+
raise ValueError(f'Client generator versions differ at {destination}')
|
|
22
|
+
for binary in BINARIES:
|
|
23
|
+
if not os.access(destination / 'bin' / binary, os.X_OK):
|
|
24
|
+
raise ValueError(f'Missing client generator: {binary}')
|
|
25
|
+
version = subprocess.check_output([str(destination / 'bin/protoc'), '--version'], text=True).strip()
|
|
26
|
+
if version != 'libprotoc ' + config['toolchain']['versions']['protobuf']:
|
|
27
|
+
raise ValueError(f'Wrong client compiler: {version}')
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main():
|
|
31
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
32
|
+
parser.add_argument('--install', action='store_true', help='Build a user-local toolchain when absent')
|
|
33
|
+
args = parser.parse_args()
|
|
34
|
+
config = json.loads(CONFIG.read_text())
|
|
35
|
+
revision = config['recipe_revision']
|
|
36
|
+
cache = Path(os.environ.get('XDG_CACHE_HOME', str(Path.home() / '.cache')))
|
|
37
|
+
local = cache / 'dash/client-codegen' / f'{revision}-{platform.system()}-{platform.machine()}'
|
|
38
|
+
explicit = os.environ.get('DAPI_GRPC_TOOLCHAIN')
|
|
39
|
+
if explicit:
|
|
40
|
+
destination = Path(explicit).resolve()
|
|
41
|
+
elif Path('/opt/client-codegen').exists():
|
|
42
|
+
destination = Path('/opt/client-codegen')
|
|
43
|
+
else:
|
|
44
|
+
destination = local
|
|
45
|
+
if destination.exists():
|
|
46
|
+
verify(destination, config)
|
|
47
|
+
elif args.install and not explicit:
|
|
48
|
+
with tempfile.TemporaryDirectory(prefix='client-codegen-recipe-') as tmp:
|
|
49
|
+
recipe = Path(tmp)
|
|
50
|
+
for name, expected in config['recipe_files'].items():
|
|
51
|
+
url = f"https://raw.githubusercontent.com/{config['recipe_repository']}/{revision}/client-codegen/{name}"
|
|
52
|
+
with urllib.request.urlopen(url, timeout=120) as response:
|
|
53
|
+
content = response.read()
|
|
54
|
+
if hashlib.sha256(content).hexdigest() != expected:
|
|
55
|
+
raise ValueError(f'Recipe checksum mismatch: {name}')
|
|
56
|
+
(recipe / name).write_bytes(content)
|
|
57
|
+
if json.loads((recipe / 'lock.json').read_text()) != config['toolchain']:
|
|
58
|
+
raise ValueError('Recipe and Platform client toolchain locks differ')
|
|
59
|
+
subprocess.run([sys.executable, str(recipe / 'build.py'), str(destination)],
|
|
60
|
+
check=True, stdout=sys.stderr)
|
|
61
|
+
verify(destination, config)
|
|
62
|
+
else:
|
|
63
|
+
raise ValueError('Native client generators are missing. Run '
|
|
64
|
+
'`python3 packages/dapi-grpc/scripts/setup-codegen.py --install` '
|
|
65
|
+
'(requires Python 3.12+, CMake and a C++ compiler), or provision the matching runner image.')
|
|
66
|
+
print(destination)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == '__main__':
|
|
70
|
+
try:
|
|
71
|
+
main()
|
|
72
|
+
except (ValueError, OSError, subprocess.CalledProcessError) as error:
|
|
73
|
+
print(f'Client codegen: {error}', file=sys.stderr)
|
|
74
|
+
sys.exit(1)
|