aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
diff options
context:
space:
mode:
authorGravatar Michajlo Matijkiw <michajlo@google.com>2015-04-15 21:28:33 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-04-16 18:36:11 +0000
commitac879b96ceeb40679e8d452220d1ec95ad77e830 (patch)
treeeaf40c52aec7951f3b368e6c054e6463ccfccbc5 /src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
parente49b3bac82a2709d897520997135b816721e0ef8 (diff)
Become more restrictive around Runfiles#manifestExpander
Previously the contract was pretty liberal and could allow addition of extra Artifacts. Create a more restrictive interface allowing the bare minimum- adding empty files to the tree. This makes the contract of Runfiles#getAllArtifacts() more sound, since arbitrary artifacts can't be added, and it makes it easier to figure out what implementations of manifest expansion exist out there. -- MOS_MIGRATED_REVID=91233821
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java49
1 files changed, 13 insertions, 36 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
index 0c921c8423..c663b263db 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
@@ -13,13 +13,13 @@
// limitations under the License.
package com.google.devtools.build.lib.rules.python;
-import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Root;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget;
import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -39,12 +39,11 @@ public final class PythonUtils {
private static final FileType REQUIRES_INIT_PY = FileType.of(".py", ".so", ".pyc");
- public static final Function<Map<PathFragment, Artifact>, Map<PathFragment, Artifact>>
- GET_INIT_PY_FILES = new Function<Map<PathFragment, Artifact>, Map<PathFragment, Artifact>>()
- {
+ public static final Runfiles.EmptyFilesSupplier GET_INIT_PY_FILES =
+ new Runfiles.EmptyFilesSupplier() {
@Override
- public Map<PathFragment, Artifact> apply(Map<PathFragment, Artifact> input) {
- return getInitDotPyFiles(input);
+ public Iterable<PathFragment> getExtraPaths(Set<PathFragment> manifestPaths) {
+ return getInitPyFiles(manifestPaths);
}
};
@@ -62,15 +61,14 @@ public final class PythonUtils {
for (PathFragment source : manifestFiles) {
// If we have a python or .so file at this level...
- if (!REQUIRES_INIT_PY.matches(source)) {
- continue;
- }
- // ...then record that we need an __init__.py in this directory...
- while (source.segmentCount() > 1) {
- source = source.getParentDirectory();
- PathFragment initpy = source.getRelative(INIT_PY);
- if (!manifestFiles.contains(initpy)) {
- result.add(initpy);
+ if (REQUIRES_INIT_PY.matches(source)) {
+ // ...then record that we need an __init__.py in this directory...
+ while (source.segmentCount() > 1) {
+ source = source.getParentDirectory();
+ PathFragment initpy = source.getRelative(INIT_PY);
+ if (!manifestFiles.contains(initpy)) {
+ result.add(initpy);
+ }
}
}
}
@@ -79,27 +77,6 @@ public final class PythonUtils {
}
/**
- * Creates a new map that contains all the <code>__init__.py</code> files that are necessary for
- * Python to find the <code>.py</code> and <code>.so</code> files in it.
- *
- * @param inputManifest The input mapping of source files to absolute paths on disk.
- * @return The revised mapping. Contains <code>null</code> values for the added
- * <code>__init.py__</code> files.
- */
- private static Map<PathFragment, Artifact> getInitDotPyFiles(
- Map<PathFragment, Artifact> inputManifest) {
- Map<PathFragment, Artifact> newManifest = new HashMap<>();
-
- for (PathFragment initpy : getInitPyFiles(inputManifest.keySet())) {
- if (newManifest.get(initpy) == null) {
- newManifest.put(initpy, null);
- }
- }
-
- return newManifest;
- }
-
- /**
* Get the artifact generated by the 2to3 action. The artifact is in a python3
* subdirectory to avoid conflicts (eg. when the input file is generated).
*/