From 15add1af49f13d1661d3910d0eb6697b415a19d1 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 29 Jan 2022 01:44:42 +0100 Subject: [PATCH] Selectively add source or gen dir to includes. (#9438) When both directories are added this results in protoc emitting a "warning: directory does not exist.". This makes sense because when there are no inputs from the other directory, it is also not present n the sandbox where protoc is executed. --- protobuf.bzl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/protobuf.bzl b/protobuf.bzl index 26b6625327..826b6100b8 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -80,7 +80,14 @@ def _proto_gen_impl(ctx): source_dir = _SourceDir(ctx) gen_dir = _GenDir(ctx).rstrip("/") if source_dir: - import_flags = depset(direct=["-I" + source_dir, "-I" + gen_dir]) + has_sources = any([src.is_source for src in srcs]) + has_generated = any([not src.is_source for src in srcs]) + import_flags = [] + if has_sources: + import_flags += ["-I" + source_dir] + if has_generated: + import_flags += ["-I" + gen_dir] + import_flags = depset(direct=import_flags) else: import_flags = depset(direct=["-I."])