Prevent NullPointerException when mainArtifact is not defined
I failed to write unit tests to reproduce the NPE.
This requires more investigation.
@@ -277,7 +277,7 @@ public final class PyCommon {
&& semantics.prohibitHyphensInPackagePaths()
&& Util.containsHyphen(src.getLabel().getPackageFragment())
// It's ok to have hyphens in main file - usually no one imports it.
- && !src.getLabel().equals(mainArtifact.getOwnerLabel())) {
+ && (mainArtifact == null || !src.getLabel().equals(mainArtifact.getOwnerLabel()))) {
ruleContext.attributeError(
"srcs",
src.getLabel()
