diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java b/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java index 6b64fc9fe1..992cfc1a64 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java +++ b/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java @@ -105,7 +105,10 @@ public final class FilesetTraversalParamsFactory { } /** - * Creates traversal request parameters for a FilesetEntry wrapping another Fileset. + * Creates traversal request parameters for a FilesetEntry wrapping another Fileset. If possible, + * the original {@code nested} is returned to avoid unnecessary object creation. In that case, the + * {@code ownerLabelForErrorMessages} may be ignored. Since the wrapping traversal could not have + * an error on its own, any error messages printed will still be correct. * * @param ownerLabel the rule that created this object * @param nested the traversal params that were used for the nested (inner) Fileset @@ -114,22 +117,31 @@ public final class FilesetTraversalParamsFactory { * @param excludes optional; set of files directly below (not in a subdirectory of) the nested * Fileset that should be excluded from the outer Fileset */ - public static FilesetTraversalParams nestedTraversal(Label ownerLabel, - FilesetTraversalParams nested, PathFragment destDir, @Nullable Set<String> excludes) { + public static FilesetTraversalParams nestedTraversal( + Label ownerLabel, + FilesetTraversalParams nested, + PathFragment destDir, + @Nullable Set<String> excludes) { + if (destDir.segmentCount() == 0 && (excludes == null || excludes.isEmpty())) { + // Wrapping the traversal here would not lead to a different result: the output location is + // the same and there are no additional excludes. + return nested; + } // When srcdir is another Fileset, then files must be null so strip_prefix must also be null. return new NestedTraversalParams(ownerLabel, nested, destDir, excludes); } private abstract static class ParamsCommon implements FilesetTraversalParams { - private final Label ownerLabel; + private final Label ownerLabelForErrorMessages; private final PathFragment destDir; private final ImmutableSet<String> excludes; - ParamsCommon(Label ownerLabel, PathFragment destDir, @Nullable Set<String> excludes) { - this.ownerLabel = ownerLabel; + ParamsCommon( + Label ownerLabelForErrorMessages, PathFragment destDir, @Nullable Set<String> excludes) { + this.ownerLabelForErrorMessages = ownerLabelForErrorMessages; this.destDir = destDir; if (excludes == null) { - this.excludes = ImmutableSet.<String>of(); + this.excludes = ImmutableSet.of(); } else { // Order the set for the sake of deterministic fingerprinting. this.excludes = ImmutableSet.copyOf(Ordering.natural().immutableSortedCopy(excludes)); @@ -137,8 +149,8 @@ public final class FilesetTraversalParamsFactory { } @Override - public Label getOwnerLabel() { - return ownerLabel; + public Label getOwnerLabelForErrorMessages() { + return ownerLabelForErrorMessages; } @Override @@ -160,17 +172,24 @@ public final class FilesetTraversalParamsFactory { @Override public String toString() { - return super.toString() + "[" + destDir + ", " + ownerLabel + ", " + excludes + "]"; + return super.toString() + + "[" + + destDir + + ", " + + ownerLabelForErrorMessages + + ", " + + excludes + + "]"; } protected boolean internalEquals(ParamsCommon that) { - return Objects.equals(this.ownerLabel, that.ownerLabel) + return Objects.equals(this.ownerLabelForErrorMessages, that.ownerLabelForErrorMessages) && Objects.equals(this.destDir, that.destDir) && Objects.equals(this.excludes, that.excludes); } protected int internalHashCode() { - return Objects.hash(ownerLabel, destDir, excludes); + return Objects.hash(ownerLabelForErrorMessages, destDir, excludes); } } @@ -287,8 +306,11 @@ public final class FilesetTraversalParamsFactory { private static final class NestedTraversalParams extends ParamsCommon { private final FilesetTraversalParams nested; - public NestedTraversalParams(Label ownerLabel, FilesetTraversalParams nested, - PathFragment destDir, @Nullable Set<String> excludes) { + NestedTraversalParams( + Label ownerLabel, + FilesetTraversalParams nested, + PathFragment destDir, + @Nullable Set<String> excludes) { super(ownerLabel, destDir, excludes); this.nested = nested; } |