Make the module extension more user-friendly. (#56)
This is a followup to a post-merge comment on the preceding commit:
https://github.com/pybind/pybind11_bazel/pull/55#discussion_r1289616169
diff --git a/python_configure.bzl b/python_configure.bzl
index abaf69a..4f2c0f9 100644
--- a/python_configure.bzl
+++ b/python_configure.bzl
@@ -456,22 +456,13 @@
def _extension_impl(ctx):
toolchain = None
for module in ctx.modules:
- if module.is_root:
- if not module.tags.toolchain:
- pass
- elif len(module.tags.toolchain) == 1:
- toolchain = module.tags.toolchain[0]
- else:
- _fail("The root module may not specify multiple `toolchain` " +
- "tags. Found %r `toolchain` tags specified." % (
- len(module.tags.toolchain),
- ))
- elif module.tags.toolchain:
- _fail("A non-root module may not specify any `toolchain` tags. " +
- "Found %r `toolchain` tags specified by module %r." % (
- len(module.tags.toolchain),
- module.name,
- ))
+ if not module.is_root or not module.tags.toolchain:
+ continue
+ toolchain = module.tags.toolchain[0]
+ if len(module.tags.toolchain) >= 2:
+ print("The root module specified two or more `toolchain` tags. " +
+ "Using only the first of %r `toolchain` tags specified." % (
+ len(module.tags.toolchain)))
if toolchain == None:
python_configure(
name = "local_config_python",