From 99cb6c616e0bfa984a01d1070c0838a5c1ef022c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 10 Mar 2022 17:24:23 +1000 Subject: [PATCH] Fix intermittent anki/backend_pb2.py build error on Windows The _pb2 files are built for both the host and target architectures (which seems superfluous - we may be able to fix that in the future). Our script wrote the files into the build folder and then moved them into the correct place, but because builds are not sandboxed on Windows, the two actions were racy, and could cause each other to fail. Solved by writing the files directly into their target locations. --- pylib/tools/protoc_wrapper.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pylib/tools/protoc_wrapper.py b/pylib/tools/protoc_wrapper.py index 42c1dc3d8..657338986 100644 --- a/pylib/tools/protoc_wrapper.py +++ b/pylib/tools/protoc_wrapper.py @@ -9,8 +9,10 @@ import os import shutil import subprocess import sys +from pathlib import Path (protoc, mypy_protobuf, outdir, *protos) = sys.argv[1:] +outpath = Path(outdir).parent if protos[0].startswith("external"): prefix = "external/ankidesktop/proto/" @@ -22,8 +24,8 @@ subprocess.run( [ protoc, f"--plugin=protoc-gen-mypy={mypy_protobuf}", - "--python_out=.", - "--mypy_out=.", + f"--python_out={outpath}", + f"--mypy_out={outpath}", f"-I{prefix}", f"-Iexternal/ankidesktop/{prefix}", *protos, @@ -32,9 +34,3 @@ subprocess.run( stderr=subprocess.DEVNULL, check=True, ) - -for proto in protos: - without_prefix_and_ext, _ = os.path.splitext(proto[len(prefix) :]) - for ext in "_pb2.py", "_pb2.pyi": - path = without_prefix_and_ext + ext - shutil.move(path, os.path.join(outdir, os.path.basename(path)))