Skip to content

Commit 2f0fea6

Browse files
authored
Revert "chore: remove compile protos from post processor" (#1904)
Revert "chore: remove compile protos from post processor (#1899)" This reverts commit 7324804.
1 parent af16e6d commit 2f0fea6

5 files changed

Lines changed: 97 additions & 2 deletions

File tree

docker/owlbot/nodejs_mono_repo/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ RUN find /synthtool -type d -exec chmod a+x {} \;
5151

5252
# Install dependencies used for post processing:
5353
# * gts/typescript are used for linting.
54-
RUN cd /synthtool && mkdir node_modules && npm i [email protected] \
55-
54+
# * google-gax and gapic-tools are used for compiling protos.
55+
RUN cd /synthtool && mkdir node_modules && npm i [email protected] [email protected] \
56+
5657

5758
ENTRYPOINT [ "/bin/bash", "/synthtool/docker/owlbot/nodejs_mono_repo/entrypoint.sh" ]

synthtool/languages/node.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,43 @@ def fix_hermetic(hide_output=False):
234234
)
235235

236236

237+
def compile_protos(hide_output=False):
238+
"""
239+
Compiles protos into .json, .js, and .d.ts files using
240+
compileProtos script from google-gax.
241+
"""
242+
logger.debug("Compiling protos...")
243+
shell.run(["npx", "compileProtos", "src"], hide_output=hide_output)
244+
245+
246+
# TODO: delete these functions if it turns out we no longer
247+
# need them to be hermetic.
248+
def compile_protos_hermetic(hide_output=False):
249+
"""
250+
Compiles protos into .json, .js, and .d.ts files using
251+
compileProtos script from google-gax. Assumes that compileProtos
252+
is already installed in a well known location on disk (node_modules/.bin).
253+
"""
254+
logger.debug("Compiling protos...")
255+
shell.run(
256+
["node_modules/.bin/compileProtos", "src"],
257+
check=True,
258+
hide_output=hide_output,
259+
)
260+
261+
237262
def postprocess_gapic_library(hide_output=False):
238263
logger.debug("Post-processing GAPIC library...")
239264
install(hide_output=hide_output)
240265
fix(hide_output=hide_output)
266+
compile_protos(hide_output=hide_output)
241267
logger.debug("Post-processing completed")
242268

243269

244270
def postprocess_gapic_library_hermetic(hide_output=False):
245271
logger.debug("Post-processing GAPIC library...")
246272
fix(hide_output=hide_output)
273+
compile_protos(hide_output=hide_output)
247274
logger.debug("Post-processing completed")
248275

249276

synthtool/languages/node_mono_repo.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,52 @@ def fix_hermetic(relative_dir, hide_output=False):
335335
)
336336

337337

338+
def compile_protos(hide_output=False, is_esm=False):
339+
"""
340+
Compiles protos into .json, .js, and .d.ts files using
341+
compileProtos script from google-gax.
342+
"""
343+
logger.debug("Compiling protos...")
344+
command = (
345+
["npx", "compileProtos", "src"]
346+
if not is_esm
347+
else ["npx", "compileProtos", "esm/src", "--esm"]
348+
)
349+
shell.run(command, hide_output=hide_output)
350+
351+
352+
def compile_protos_hermetic(relative_dir, is_esm=False, hide_output=False):
353+
"""
354+
Compiles protos into .json, .js, and .d.ts files using
355+
compileProtos script from google-gax. Assumes that compileProtos
356+
is already installed in a well known location on disk (node_modules/.bin).
357+
"""
358+
logger.debug("Compiling protos...")
359+
command = (
360+
[f"{_TOOLS_DIRECTORY}/node_modules/.bin/compileProtos", "esm/src", "--esm"]
361+
if not is_esm
362+
else [f"{_TOOLS_DIRECTORY}/node_modules/.bin/compileProtos", "esm/src", "--esm"]
363+
)
364+
shell.run(
365+
command,
366+
cwd=relative_dir,
367+
check=True,
368+
hide_output=hide_output,
369+
)
370+
371+
338372
def postprocess_gapic_library(hide_output=False, is_esm=False):
339373
logger.debug("Post-processing GAPIC library...")
340374
install(hide_output=hide_output)
341375
fix(hide_output=hide_output)
376+
compile_protos(hide_output=hide_output, is_esm=is_esm)
342377
logger.debug("Post-processing completed")
343378

344379

345380
def postprocess_gapic_library_hermetic(relative_dir, hide_output=False, is_esm=False):
346381
logger.debug("Post-processing GAPIC library...")
347382
fix_hermetic(relative_dir, hide_output=hide_output)
383+
compile_protos_hermetic(relative_dir, hide_output=hide_output, is_esm=is_esm)
348384
logger.debug("Post-processing completed")
349385

350386

tests/test_node.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,19 @@ def test_fix(self, shell_run_mock):
169169
calls = shell_run_mock.call_args_list
170170
assert any(["npm run fix" in " ".join(call[0][0]) for call in calls])
171171

172+
@patch("synthtool.shell.run")
173+
def test_compile_protos(self, shell_run_mock):
174+
node.compile_protos()
175+
calls = shell_run_mock.call_args_list
176+
assert any(["npx compileProtos src" in " ".join(call[0][0]) for call in calls])
177+
172178
@patch("synthtool.shell.run")
173179
def test_postprocess_gapic_library(self, shell_run_mock):
174180
node.postprocess_gapic_library()
175181
calls = shell_run_mock.call_args_list
176182
assert any(["npm install" in " ".join(call[0][0]) for call in calls])
177183
assert any(["npm run fix" in " ".join(call[0][0]) for call in calls])
184+
assert any(["npx compileProtos src" in " ".join(call[0][0]) for call in calls])
178185

179186

180187
# postprocess_gapic_library_hermetic() must be mocked because it depends on node modules

tests/test_node_mono_repo.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,19 +354,43 @@ def test_fix(self, shell_run_mock):
354354
calls = shell_run_mock.call_args_list
355355
assert any(["npm run fix" in " ".join(call[0][0]) for call in calls])
356356

357+
@patch("synthtool.shell.run")
358+
def test_compile_protos(self, shell_run_mock):
359+
node_mono_repo.compile_protos()
360+
calls = shell_run_mock.call_args_list
361+
assert any(["npx compileProtos src" in " ".join(call[0][0]) for call in calls])
362+
363+
@patch("synthtool.shell.run")
364+
def test_compile_protos_esm(self, shell_run_mock):
365+
node_mono_repo.compile_protos(is_esm=True)
366+
calls = shell_run_mock.call_args_list
367+
assert any(
368+
[
369+
"npx compileProtos esm/src --esm" in " ".join(call[0][0])
370+
for call in calls
371+
]
372+
)
373+
357374
@patch("synthtool.shell.run")
358375
def test_postprocess_gapic_library(self, shell_run_mock):
359376
node_mono_repo.postprocess_gapic_library()
360377
calls = shell_run_mock.call_args_list
361378
assert any(["npm install" in " ".join(call[0][0]) for call in calls])
362379
assert any(["npm run fix" in " ".join(call[0][0]) for call in calls])
380+
assert any(["npx compileProtos src" in " ".join(call[0][0]) for call in calls])
363381

364382
@patch("synthtool.shell.run")
365383
def test_postprocess_gapic_library_esm(self, shell_run_mock):
366384
node_mono_repo.postprocess_gapic_library(is_esm=True)
367385
calls = shell_run_mock.call_args_list
368386
assert any(["npm install" in " ".join(call[0][0]) for call in calls])
369387
assert any(["npm run fix" in " ".join(call[0][0]) for call in calls])
388+
assert any(
389+
[
390+
"npx compileProtos esm/src --esm" in " ".join(call[0][0])
391+
for call in calls
392+
]
393+
)
370394

371395

372396
# postprocess_gapic_library_hermetic() must be mocked because it depends on node modules

0 commit comments

Comments
 (0)