Skip to content

Commit

Permalink
Simplify cloning BuildOptions.
Browse files Browse the repository at this point in the history
Work towards platform-based flags: #19409.

PiperOrigin-RevId: 580317682
Change-Id: Ia84894632c8344b983f73e41070a1a24ac43bc2b
  • Loading branch information
katre authored and copybara-github committed Nov 7, 2023
1 parent 19632af commit 6a08b2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/common/options",
"//third_party:error_prone_annotations",
"//third_party:guava",
"//third_party:jsr305",
"//third_party/protobuf:protobuf_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
Expand Down Expand Up @@ -230,14 +231,16 @@ public ImmutableMap<Label, Object> getStarlarkOptions() {
*/
@Override
public BuildOptions clone() {
ImmutableMap.Builder<Class<? extends FragmentOptions>, FragmentOptions> nativeOptionsBuilder =
ImmutableMap.builderWithExpectedSize(fragmentOptionsMap.size());
for (Map.Entry<Class<? extends FragmentOptions>, FragmentOptions> entry :
fragmentOptionsMap.entrySet()) {
nativeOptionsBuilder.put(entry.getKey(), entry.getValue().clone());
}
return new BuildOptions(
nativeOptionsBuilder.buildOrThrow(), ImmutableMap.copyOf(starlarkOptionsMap));
ImmutableMap<Class<? extends FragmentOptions>, FragmentOptions> nativeOptions =
fragmentOptionsMap.entrySet().stream()
.collect(
toImmutableMap(
Map.Entry::getKey,
// Explicitly clone native options because FragmentOptions is mutable.
e -> e.getValue().clone()));
// Note that this assumes that starlark option values are immutable.
ImmutableMap<Label, Object> starlarkOptions = ImmutableMap.copyOf(starlarkOptionsMap);
return new BuildOptions(nativeOptions, starlarkOptions);
}

@Override
Expand Down

0 comments on commit 6a08b2f

Please sign in to comment.