From 9c5695775a1ad9bcac3484881d8286abfce96d21 Mon Sep 17 00:00:00 2001 From: Michajlo Matijkiw Date: Thu, 7 May 2015 20:09:14 +0000 Subject: Return all mappings in one Map from Runfiles#getRunfilesInputs(...) We wind up combining them anyway in the manifest file and it seems that this is consistent with how we read them back. Return them all at once to avoid tedious duplication in handling of them. -- MOS_MIGRATED_REVID=93058482 --- .../devtools/build/lib/analysis/Runfiles.java | 35 +++++++++++++++------- .../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 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> getRunfilesInputs( - EventHandler eventHandler, Location location) - throws IOException { + public Map getRunfilesInputs(EventHandler eventHandler, + Location location) throws IOException { Map 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 entry : manifest.entrySet()) { result.put(path.getRelative(entry.getKey()), entry.getValue()); } - return Pair.of(result, (Map) new HashMap<>(getRootSymlinksAsMap())); + + // Finally add symlinks outside the source tree on top of everything else. + for (Map.Entry 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> runfilesInputs = + final Map 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> output) - throws IOException { + private void writeFile(OutputStream out, Map output) throws IOException { Writer manifestFile = new BufferedWriter(new OutputStreamWriter(out, ISO_8859_1)); Comparator> fragmentComparator = @@ -168,21 +165,13 @@ public class SourceManifestAction extends AbstractFileWriteAction { } }; - List> sortedRootLinks = - new ArrayList<>(output.second.entrySet()); - Collections.sort(sortedRootLinks, fragmentComparator); - - List> sortedManifest = - new ArrayList<>(output.first.entrySet()); + List> sortedManifest = new ArrayList<>(output.entrySet()); Collections.sort(sortedManifest, fragmentComparator); - for (Map.Entry line : sortedRootLinks) { - manifestWriter.writeEntry(manifestFile, line.getKey(), line.getValue()); - } - for (Map.Entry line : sortedManifest) { manifestWriter.writeEntry(manifestFile, line.getKey(), line.getValue()); } + manifestFile.flush(); } -- cgit v1.2.3