[protoc_wrapper] Do not add --import-dir if it doesn't exist

The original issue was `warning: directory does not exist` output in remote proto wrapper command.
https://crrev.com/c/4812586 suppressed it by including --import-dir to remote inputs. But it turned out that it sometimes crushes Reproxy.

This CL instead fixes `protoc_wrapper.py` to check the presence of `--import-dir`.

Fixed: b/297428306, b/298129445
Change-Id: I79bb902af138d7517f8dbd82880639565c59d01d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4829386
Reviewed-by: Dirk Pranke <[email protected]>
Reviewed-by: Fumitoshi Ukai <[email protected]>
Commit-Queue: Junji Watanabe <[email protected]>
Auto-Submit: Junji Watanabe <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1191120}
NOKEYCHECK=True
GitOrigin-RevId: 427382dd9083dc5c5d2b81975e0bdbb7c9300fce
diff --git a/protoc_wrapper.py b/protoc_wrapper.py
index d53fd5e..ebeb5a9 100755
--- a/protoc_wrapper.py
+++ b/protoc_wrapper.py
@@ -166,7 +166,11 @@
 
   protoc_cmd += ["--proto_path", proto_dir]
   for path in options.import_dir:
-    protoc_cmd += ["--proto_path", path]
+    # TODO: crbug.com/1477926 - Do not specify unused `--import-dir`s.
+    # On a remote worker, it shows `warning: directory does not exist` when
+    # there are no dependencies under the directory.
+    if os.path.exists(path):
+      protoc_cmd += ["--proto_path", path]
 
   protoc_cmd += [os.path.join(proto_dir, name) for name in protos]