diff options
author | 2017-03-28 12:36:47 +0000 | |
---|---|---|
committer | 2017-03-28 19:51:04 +0000 | |
commit | 3718a36c83657238f458076ddf5da957f6b54118 (patch) | |
tree | 38bb200c34b7aa1c280e853371818df1c04b2967 /src/tools/android/java/com/google/devtools/build/android/DataSource.java | |
parent | 78b8be6486d4cd0e1515e5cc19b865671e01c743 (diff) |
DataSource Fixes
* Fix the overwrite algorithm to be handled entirely in the accumulators.
* Improve the conflict error messages for attributes and simple values.
* Refactor the UnwrittenDataSubject to top level for reuse.
--
PiperOrigin-RevId: 151439084
MOS_MIGRATED_REVID=151439084
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/DataSource.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/DataSource.java | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/DataSource.java b/src/tools/android/java/com/google/devtools/build/android/DataSource.java index 1e4580eec9..16c79d7f81 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DataSource.java +++ b/src/tools/android/java/com/google/devtools/build/android/DataSource.java @@ -16,7 +16,6 @@ package com.google.devtools.build.android; import com.android.SdkConstants; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.android.proto.SerializeFormat.ProtoSource; import java.io.BufferedInputStream; @@ -99,10 +98,19 @@ public class DataSource implements Comparable<DataSource> { } public DataSource overwrite(DataSource... sources) { - ImmutableSet<DataSource> overrides = - ImmutableSet.<DataSource>builder().addAll(this.overrides).add(sources).build(); - Preconditions.checkArgument(!overrides.contains(this)); - return new DataSource(path, overrides); + ImmutableSet.Builder<DataSource> overridesBuilder = + ImmutableSet.<DataSource>builder().addAll(this.overrides); + for (DataSource dataSource : sources) { + // A DataSource cannot overwrite itself. + // This will be an error once the depot can be assured not have source files. + if (!dataSource.path.equals(path)) { + // Flatten the DataSource to a placeholder to avoid building trees, which end up being + // expensive, slow, and hard to reason about. + overridesBuilder.add(of(dataSource.path)); + } + overridesBuilder.addAll(dataSource.overrides); + } + return new DataSource(path, overridesBuilder.build()); } public ImmutableSet<DataSource> overrides() { @@ -124,4 +132,9 @@ public class DataSource implements Comparable<DataSource> { .add("overrides", overrides) .toString(); } + + /** Returns a representation suitible for a conflict message. */ + public String asConflictString() { + return path.toString(); + } } |