From ac879b96ceeb40679e8d452220d1ec95ad77e830 Mon Sep 17 00:00:00 2001 From: Michajlo Matijkiw Date: Wed, 15 Apr 2015 21:28:33 +0000 Subject: 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 --- .../build/lib/rules/python/PythonUtils.java | 49 ++++++---------------- 1 file changed, 13 insertions(+), 36 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java') 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> - GET_INIT_PY_FILES = new Function, Map>() - { + public static final Runfiles.EmptyFilesSupplier GET_INIT_PY_FILES = + new Runfiles.EmptyFilesSupplier() { @Override - public Map apply(Map input) { - return getInitDotPyFiles(input); + public Iterable getExtraPaths(Set 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); + } } } } @@ -78,27 +76,6 @@ public final class PythonUtils { return ImmutableSet.copyOf(result); } - /** - * Creates a new map that contains all the __init__.py files that are necessary for - * Python to find the .py and .so files in it. - * - * @param inputManifest The input mapping of source files to absolute paths on disk. - * @return The revised mapping. Contains null values for the added - * __init.py__ files. - */ - private static Map getInitDotPyFiles( - Map inputManifest) { - Map 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). -- cgit v1.2.3