diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java | 35 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java | 19 |
2 files changed, 28 insertions, 26 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java index f365f3cb86..2dba69c303 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java @@ -29,7 +29,6 @@ import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.Type; -import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; @@ -330,17 +329,17 @@ public final class Runfiles { } /** - * Returns the symlinks as a map from PathFragment to Artifact, with PathFragments relativized - * and rooted at the specified points. - * @param eventHandler Used for throwing an error if we have an obscuring runlink. - * May be null, in which case obscuring symlinks are silently discarded. + * Returns the symlinks as a map from PathFragment to Artifact. + * + * @param eventHandler Used for throwing an error if we have an obscuring runlink within the + * normal source tree entries. May be null, in which case obscuring symlinks are silently + * discarded. * @param location Location for eventHandler warnings. Ignored if eventHandler is null. - * @return Pair of Maps from remote path fragment to artifact, the first of normal source tree - * entries, the second of any elements that live outside the source tree. + * @return Map<PathFragment, Artifact> path fragment to artifact, of normal source tree entries + * and elements that live outside the source tree. Null values represent empty input files. */ - public Pair<Map<PathFragment, Artifact>, Map<PathFragment, Artifact>> getRunfilesInputs( - EventHandler eventHandler, Location location) - throws IOException { + public Map<PathFragment, Artifact> getRunfilesInputs(EventHandler eventHandler, + Location location) throws IOException { Map<PathFragment, Artifact> manifest = getSymlinksAsMap(); // Add unconditional artifacts (committed to inclusion on construction of runfiles). for (Artifact artifact : getUnconditionalArtifactsWithoutMiddlemen()) { @@ -377,7 +376,21 @@ public final class Runfiles { for (Map.Entry<PathFragment, Artifact> entry : manifest.entrySet()) { result.put(path.getRelative(entry.getKey()), entry.getValue()); } - return Pair.of(result, (Map<PathFragment, Artifact>) new HashMap<>(getRootSymlinksAsMap())); + + // Finally add symlinks outside the source tree on top of everything else. + for (Map.Entry<PathFragment, Artifact> entry : getRootSymlinksAsMap().entrySet()) { + PathFragment mappedPath = entry.getKey(); + Artifact mappedArtifact = entry.getValue(); + if (result.put(mappedPath, mappedArtifact) != null) { + // Emit warning if we overwrote something and we're capable of emitting warnings. + if (eventHandler != null) { + eventHandler.handle(Event.warn(location, "overwrote " + mappedPath + " symlink mapping " + + "with root symlink to " + mappedArtifact)); + } + } + } + + return result; } /** diff --git a/src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java b/src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java index 7ddf308c0a..5d573e5e86 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java @@ -23,7 +23,6 @@ import com.google.devtools.build.lib.actions.Executor; import com.google.devtools.build.lib.analysis.actions.AbstractFileWriteAction; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.util.Fingerprint; -import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.PathFragment; import java.io.BufferedWriter; @@ -116,7 +115,7 @@ public class SourceManifestAction extends AbstractFileWriteAction { @Override public DeterministicWriter newDeterministicWriter(EventHandler eventHandler, Executor executor) throws IOException { - final Pair<Map<PathFragment, Artifact>, Map<PathFragment, Artifact>> runfilesInputs = + final Map<PathFragment, Artifact> runfilesInputs = runfiles.getRunfilesInputs(eventHandler, getOwner().getLocation()); return new DeterministicWriter() { @Override @@ -154,9 +153,7 @@ public class SourceManifestAction extends AbstractFileWriteAction { * @param output The actual mapping of the output manifest. * @throws IOException */ - private void writeFile(OutputStream out, - Pair<Map<PathFragment, Artifact>, Map<PathFragment, Artifact>> output) - throws IOException { + private void writeFile(OutputStream out, Map<PathFragment, Artifact> output) throws IOException { Writer manifestFile = new BufferedWriter(new OutputStreamWriter(out, ISO_8859_1)); Comparator<Map.Entry<PathFragment, Artifact>> fragmentComparator = @@ -168,21 +165,13 @@ public class SourceManifestAction extends AbstractFileWriteAction { } }; - List<Map.Entry<PathFragment, Artifact>> sortedRootLinks = - new ArrayList<>(output.second.entrySet()); - Collections.sort(sortedRootLinks, fragmentComparator); - - List<Map.Entry<PathFragment, Artifact>> sortedManifest = - new ArrayList<>(output.first.entrySet()); + List<Map.Entry<PathFragment, Artifact>> sortedManifest = new ArrayList<>(output.entrySet()); Collections.sort(sortedManifest, fragmentComparator); - for (Map.Entry<PathFragment, Artifact> line : sortedRootLinks) { - manifestWriter.writeEntry(manifestFile, line.getKey(), line.getValue()); - } - for (Map.Entry<PathFragment, Artifact> line : sortedManifest) { manifestWriter.writeEntry(manifestFile, line.getKey(), line.getValue()); } + manifestFile.flush(); } |