Fix a bug with PythonBinary where I returned the wrong subset of deps.
Test Plan:
Unit tests
diff --git a/plugin/plugin.iml b/plugin/plugin.iml
index b455e26..24e36ea 100644
--- a/plugin/plugin.iml
+++ b/plugin/plugin.iml
@@ -6,7 +6,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
- <orderEntry type="jdk" jdkName="IDEA IC-129.713" jdkType="IDEA JDK" />
+ <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Java-WebSocket-1.3.0" level="project" />
<orderEntry type="library" name="buck-lib" level="project" />
diff --git a/src/com/facebook/buck/python/PythonBinaryRule.java b/src/com/facebook/buck/python/PythonBinaryRule.java
index 6a38113..dc617b2 100644
--- a/src/com/facebook/buck/python/PythonBinaryRule.java
+++ b/src/com/facebook/buck/python/PythonBinaryRule.java
@@ -34,6 +34,7 @@
import com.facebook.buck.rules.RuleKey;
import com.facebook.buck.step.Step;
import com.facebook.buck.util.ProjectFilesystem;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@@ -81,7 +82,8 @@
projectFilesystem.getPathRelativizer().apply(main));
}
- private ImmutableSet<Path> getPythonPathEntries() {
+ @VisibleForTesting
+ ImmutableSet<Path> getPythonPathEntries() {
final ImmutableSet.Builder<Path> entries = ImmutableSet.builder();
final PythonBinaryRule pythonBinaryRule = this;
@@ -95,7 +97,7 @@
Path pythonPathEntry = pythonLibrary.getPythonPathDirectory();
entries.add(pythonPathEntry);
- return getDeps();
+ return rule.getDeps();
}
// AbstractDependencyVisitor will start from this (PythonBinaryRule) so make sure it
diff --git a/test/com/facebook/buck/python/BUCK b/test/com/facebook/buck/python/BUCK
index 45d7bf3..9b22033 100644
--- a/test/com/facebook/buck/python/BUCK
+++ b/test/com/facebook/buck/python/BUCK
@@ -7,6 +7,7 @@
deps = [
'//lib:guava',
'//lib:junit',
+ '//src/com/facebook/buck/java:rules',
'//src/com/facebook/buck/model:model',
'//src/com/facebook/buck/python:rules',
'//src/com/facebook/buck/rules:build_rule',
diff --git a/test/com/facebook/buck/python/PythonBinaryRuleTest.java b/test/com/facebook/buck/python/PythonBinaryRuleTest.java
new file mode 100644
index 0000000..df457f8
--- /dev/null
+++ b/test/com/facebook/buck/python/PythonBinaryRuleTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2013-present Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.facebook.buck.python;
+
+import static org.junit.Assert.assertEquals;
+
+import com.facebook.buck.java.DefaultJavaLibraryRule;
+import com.facebook.buck.model.BuildTarget;
+import com.facebook.buck.model.BuildTargetFactory;
+import com.facebook.buck.model.BuildTargetPattern;
+import com.facebook.buck.rules.BuildRuleResolver;
+import com.facebook.buck.rules.FakeAbstractBuildRuleBuilderParams;
+import com.google.common.collect.ImmutableSet;
+
+import org.junit.Test;
+
+import java.nio.file.Paths;
+
+public class PythonBinaryRuleTest {
+ @Test
+ public void testGetPythonPathEntries() {
+ BuildRuleResolver ruleResolver = new BuildRuleResolver();
+
+ BuildTarget orphanPyLibraryTarget = BuildTargetFactory.newInstance("//:orphan_python_library");
+ ruleResolver.buildAndAddToIndex(
+ PythonLibrary.newPythonLibraryBuilder(new FakeAbstractBuildRuleBuilderParams())
+ .addSrc("java/src/com/javalib/orphan/sadpanda.py")
+ .setBuildTarget(orphanPyLibraryTarget)
+ .addVisibilityPattern(BuildTargetPattern.MATCH_ALL));
+
+ BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//:javalib");
+ ruleResolver.buildAndAddToIndex(
+ DefaultJavaLibraryRule.newJavaLibraryRuleBuilder(new FakeAbstractBuildRuleBuilderParams())
+ .setBuildTarget(javaLibraryTarget)
+ .addSrc("java/src/com/javalib/Bar.java")
+ .addDep(orphanPyLibraryTarget)
+ .addVisibilityPattern(BuildTargetPattern.MATCH_ALL));
+
+ BuildTarget pyLibraryTarget = BuildTargetFactory.newInstance("//:py_library");
+ ruleResolver.buildAndAddToIndex(
+ PythonLibrary.newPythonLibraryBuilder(new FakeAbstractBuildRuleBuilderParams())
+ .addSrc("python/tastypy.py")
+ .setBuildTarget(pyLibraryTarget)
+ .addVisibilityPattern(BuildTargetPattern.MATCH_ALL));
+
+ BuildTarget pyBinaryTarget = BuildTargetFactory.newInstance("//:py_binary");
+ PythonBinaryRule pyBinary = ruleResolver.buildAndAddToIndex(
+ PythonBinaryRule.newPythonBinaryBuilder(new FakeAbstractBuildRuleBuilderParams())
+ .setMain("foo")
+ .addDep(javaLibraryTarget)
+ .addDep(pyLibraryTarget)
+ .setBuildTarget(pyBinaryTarget)
+ .addVisibilityPattern(BuildTargetPattern.MATCH_ALL));
+
+ assertEquals(ImmutableSet.of(Paths.get("buck-out/gen/__pylib_py_library")),
+ pyBinary.getPythonPathEntries());
+ }
+}