aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
diff options
context:
space:
mode:
authorGravatar Mouad Benchchaoui <mbenchchaoui@newstore.com>2018-02-14 05:09:15 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-14 05:10:36 -0800
commit0f9c6ea574918dda094cf5423fa3822112846c30 (patch)
tree52b1deea8f09ef9ed23fd68589a227f8f14c412f /src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
parentb4545ba2b1aa4079b09a346a6d441ffa1e1b7d20 (diff)
Make __init__.py files creation optional
Introduce a new attribute to py_binary and py_test to control whether to create `__init__.py` or not. Fixes https://github.com/bazelbuild/rules_python/issues/55 Closes #4470. PiperOrigin-RevId: 185672243
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
index e0706923f2..b2ef88db97 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
@@ -27,6 +27,7 @@ import com.google.devtools.build.lib.rules.cpp.CcCommon.CcFlagsSupplier;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
+import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.ArrayList;
import java.util.List;
@@ -140,7 +141,11 @@ public abstract class PyBinary implements RuleConfiguredTargetFactory {
}
semantics.collectDefaultRunfiles(ruleContext, builder);
builder.add(ruleContext, PythonRunfilesProvider.TO_RUNFILES);
- builder.setEmptyFilesSupplier(PythonUtils.GET_INIT_PY_FILES);
+
+ if (!ruleContext.attributes().has("legacy_create_init", Type.BOOLEAN)
+ || ruleContext.attributes().get("legacy_create_init", Type.BOOLEAN)) {
+ builder.setEmptyFilesSupplier(PythonUtils.GET_INIT_PY_FILES);
+ }
semantics.collectRunfilesForBinary(ruleContext, builder, common);
return builder.build();
}