Skip to content

Commit 638b8b4

Browse files
lberkicopybara-github
authored andcommitted
Update some options classes to user the new interface based on getters and setters.
RELNOTES: None PiperOrigin-RevId: 900561977 Change-Id: Ie9cbc385e9a322b50357039eaae719b8d913bfb8
1 parent f3aeafe commit 638b8b4

12 files changed

Lines changed: 86 additions & 72 deletions

File tree

src/main/java/com/google/devtools/build/lib/analysis/test/CoverageConfiguration.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.devtools.common.options.Option;
2828
import com.google.devtools.common.options.OptionDocumentationCategory;
2929
import com.google.devtools.common.options.OptionEffectTag;
30+
import com.google.devtools.common.options.OptionsClass;
3031
import javax.annotation.Nullable;
3132

3233
/** The coverage configuration fragment. */
@@ -35,7 +36,8 @@
3536
public class CoverageConfiguration extends Fragment implements CoverageConfigurationApi {
3637

3738
/** Command-line options. */
38-
public static class CoverageOptions extends FragmentOptions {
39+
@OptionsClass
40+
public abstract static class CoverageOptions extends FragmentOptions {
3941

4042
@Option(
4143
name = "coverage_output_generator",
@@ -52,7 +54,7 @@ public static class CoverageOptions extends FragmentOptions {
5254
Location of the binary that is used to postprocess raw coverage reports. This must
5355
be a binary target. Defaults to `@bazel_tools//tools/test:lcov_merger`.
5456
""")
55-
public Label coverageOutputGenerator;
57+
public abstract Label getCoverageOutputGenerator();
5658

5759
@Option(
5860
name = "coverage_report_generator",
@@ -69,7 +71,7 @@ public static class CoverageOptions extends FragmentOptions {
6971
Location of the binary that is used to generate coverage reports. This must
7072
be a binary target. Defaults to `@bazel_tools//tools/test:coverage_report_generator`.
7173
""")
72-
public Label coverageReportGenerator;
74+
public abstract Label getCoverageReportGenerator();
7375
}
7476

7577
private final CoverageOptions coverageOptions;
@@ -91,14 +93,14 @@ public Label outputGenerator() {
9193
if (coverageOptions == null) {
9294
return null;
9395
}
94-
return coverageOptions.coverageOutputGenerator;
96+
return coverageOptions.getCoverageOutputGenerator();
9597
}
9698

9799
@Nullable
98100
public Label reportGenerator() {
99101
if (coverageOptions == null) {
100102
return null;
101103
}
102-
return coverageOptions.coverageReportGenerator;
104+
return coverageOptions.getCoverageReportGenerator();
103105
}
104106
}

src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void globalInit(
196196
OptionsParsingResult startupOptions, Iterable<BlazeService> blazeServices) {
197197
outputBase = startupOptions.getOptions(BlazeServerStartupOptions.class).getOutputBase();
198198
useRemoteRepoContentsCache =
199-
startupOptions.getOptions(RemoteStartupOptions.class).useRemoteRepoContentsCache;
199+
startupOptions.getOptions(RemoteStartupOptions.class).getUseRemoteRepoContentsCache();
200200
}
201201

202202
@Nullable

src/main/java/com/google/devtools/build/lib/remote/options/RemoteStartupOptions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
import com.google.devtools.common.options.OptionDocumentationCategory;
1919
import com.google.devtools.common.options.OptionEffectTag;
2020
import com.google.devtools.common.options.OptionsBase;
21+
import com.google.devtools.common.options.OptionsClass;
2122

2223
/**
2324
* Additional startup options provided by the {@link
2425
* com.google.devtools.build.lib.remote.RemoteModule}.
2526
*/
26-
public final class RemoteStartupOptions extends OptionsBase {
27+
@OptionsClass
28+
public abstract class RemoteStartupOptions extends OptionsBase {
2729
@Option(
2830
name = "experimental_remote_repo_contents_cache",
2931
defaultValue = "false",
@@ -36,5 +38,5 @@ public final class RemoteStartupOptions extends OptionsBase {
3638
cache, the contents of the repository will be kept in an in-memory file system and are
3739
only downloaded when needed, either by Bazel itself or an action that runs locally.
3840
""")
39-
public boolean useRemoteRepoContentsCache;
41+
public abstract boolean getUseRemoteRepoContentsCache();
4042
}

src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagOptions.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import com.google.devtools.common.options.OptionDocumentationCategory;
2020
import com.google.devtools.common.options.OptionEffectTag;
2121
import com.google.devtools.common.options.OptionMetadataTag;
22+
import com.google.devtools.common.options.OptionsClass;
2223

2324
/** The options fragment which defines options related to tagged trimming of feature flags. */
24-
public final class ConfigFeatureFlagOptions extends FragmentOptions {
25+
@OptionsClass
26+
public abstract class ConfigFeatureFlagOptions extends FragmentOptions {
2527
/**
2628
* Whether to perform user-guided trimming of feature flags based on the tagging in the
2729
* transitive_configs attribute.
@@ -37,7 +39,7 @@ public final class ConfigFeatureFlagOptions extends FragmentOptions {
3739
OptionEffectTag.LOADING_AND_ANALYSIS
3840
},
3941
defaultValue = "false")
40-
public boolean enforceTransitiveConfigsForConfigFeatureFlag = false;
42+
public abstract boolean getEnforceTransitiveConfigsForConfigFeatureFlag();
4143

4244
/**
4345
* If {@code true}, the configuration contains all non-default feature flag values, and any flags
@@ -57,5 +59,7 @@ public final class ConfigFeatureFlagOptions extends FragmentOptions {
5759
},
5860
metadataTags = {OptionMetadataTag.INTERNAL},
5961
defaultValue = "true")
60-
public boolean allFeatureFlagValuesArePresent = true;
62+
public abstract boolean getAllFeatureFlagValuesArePresent();
63+
64+
public abstract void setAllFeatureFlagValuesArePresent(boolean value);
6165
}

src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTaggedTrimmingTransitionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ImmutableSet<Class<? extends FragmentOptions>> requiresOptionFragments()
6363
public BuildOptions patch(BuildOptionsView options, EventHandler eventHandler) {
6464
var configFeatureFlagOptions = options.get(ConfigFeatureFlagOptions.class);
6565
if (configFeatureFlagOptions == null
66-
|| !configFeatureFlagOptions.enforceTransitiveConfigsForConfigFeatureFlag) {
66+
|| !configFeatureFlagOptions.getEnforceTransitiveConfigsForConfigFeatureFlag()) {
6767
return options.underlying();
6868
}
6969
return FeatureFlagValue.trimFlagValues(options.underlying(), flags);

src/main/java/com/google/devtools/build/lib/rules/config/FeatureFlagValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static BuildOptions replaceFlagValues(BuildOptions original, Map<Label, String>
8181
BuildOptions builtResult = result.build();
8282
var configFeatureFlagOptions = builtResult.get(ConfigFeatureFlagOptions.class);
8383
if (configFeatureFlagOptions != null) {
84-
configFeatureFlagOptions.allFeatureFlagValuesArePresent = true;
84+
configFeatureFlagOptions.setAllFeatureFlagValuesArePresent(true);
8585
}
8686
return builtResult;
8787
}
@@ -98,7 +98,7 @@ static BuildOptions trimFlagValues(BuildOptions original, Set<Label> availableFl
9898
var originalConfigFeatureFlagOptions = original.get(ConfigFeatureFlagOptions.class);
9999
boolean changeAllValuesPresentOption =
100100
originalConfigFeatureFlagOptions != null
101-
&& originalConfigFeatureFlagOptions.allFeatureFlagValuesArePresent;
101+
&& originalConfigFeatureFlagOptions.getAllFeatureFlagValuesArePresent();
102102

103103
// What do we need to change?
104104
original.getStarlarkOptions().entrySet().stream()
@@ -125,7 +125,7 @@ static BuildOptions trimFlagValues(BuildOptions original, Set<Label> availableFl
125125
BuildOptions builtResult = result.build();
126126
var builtConfigFeatureFlagOptions = builtResult.get(ConfigFeatureFlagOptions.class);
127127
if (builtConfigFeatureFlagOptions != null) {
128-
builtConfigFeatureFlagOptions.allFeatureFlagValuesArePresent = false;
128+
builtConfigFeatureFlagOptions.setAllFeatureFlagValuesArePresent(false);
129129
}
130130
return builtResult;
131131
}

src/test/java/com/google/devtools/build/lib/rules/config/FeatureFlagValueTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public void replaceFlagValues_emptiesKnownDefaultFlagsAndUnknownFlags() throws E
100100
Label.parseCanonicalUnchecked("//label:c"),
101101
Label.parseCanonicalUnchecked("//label:d")));
102102
options = FeatureFlagValue.replaceFlagValues(options, originalMap);
103-
assertThat(options.get(ConfigFeatureFlagOptions.class).allFeatureFlagValuesArePresent).isTrue();
103+
assertThat(options.get(ConfigFeatureFlagOptions.class).getAllFeatureFlagValuesArePresent())
104+
.isTrue();
104105
}
105106

106107
@Test
@@ -130,7 +131,7 @@ public void trimFlagValues_defaults_toEmptySetProducesEmptyOptions() throws Exce
130131
options = FeatureFlagValue.trimFlagValues(options, ImmutableSet.of());
131132

132133
assertThat(options.getStarlarkOptions()).isEmpty();
133-
assertThat(options.get(ConfigFeatureFlagOptions.class).allFeatureFlagValuesArePresent)
134+
assertThat(options.get(ConfigFeatureFlagOptions.class).getAllFeatureFlagValuesArePresent())
134135
.isFalse();
135136
assertThat(getKnownDefaultFlags(options)).isEmpty();
136137
}
@@ -152,7 +153,7 @@ public void trimFlagValues_defaults_toPopulatedSetPopulatesKnownDefaultFlags() t
152153
Label.parseCanonicalUnchecked("//label:a"), FeatureFlagValue.DefaultValue.INSTANCE,
153154
Label.parseCanonicalUnchecked("//label:b"), FeatureFlagValue.DefaultValue.INSTANCE,
154155
Label.parseCanonicalUnchecked("//label:c"), FeatureFlagValue.DefaultValue.INSTANCE);
155-
assertThat(options.get(ConfigFeatureFlagOptions.class).allFeatureFlagValuesArePresent)
156+
assertThat(options.get(ConfigFeatureFlagOptions.class).getAllFeatureFlagValuesArePresent())
156157
.isFalse();
157158
assertThat(getKnownDefaultFlags(options))
158159
.containsExactly(
@@ -176,7 +177,7 @@ public void trimFlagValues_withFlagsSet_toEmptySetProducesEmptyOptions() throws
176177
options = FeatureFlagValue.trimFlagValues(options, ImmutableSet.of());
177178

178179
assertThat(options.getStarlarkOptions()).isEmpty();
179-
assertThat(options.get(ConfigFeatureFlagOptions.class).allFeatureFlagValuesArePresent)
180+
assertThat(options.get(ConfigFeatureFlagOptions.class).getAllFeatureFlagValuesArePresent())
180181
.isFalse();
181182
assertThat(getKnownDefaultFlags(options)).isEmpty();
182183
}
@@ -207,7 +208,7 @@ public void trimFlagValues_withFlagsSet_toPopulatedSetPopulatesFlagValuesAndKnow
207208
Label.parseCanonicalUnchecked("//label:a"), FeatureFlagValue.SetValue.of("value"),
208209
Label.parseCanonicalUnchecked("//label:b"), FeatureFlagValue.DefaultValue.INSTANCE,
209210
Label.parseCanonicalUnchecked("//label:c"), FeatureFlagValue.DefaultValue.INSTANCE);
210-
assertThat(options.get(ConfigFeatureFlagOptions.class).allFeatureFlagValuesArePresent)
211+
assertThat(options.get(ConfigFeatureFlagOptions.class).getAllFeatureFlagValuesArePresent())
211212
.isFalse();
212213
assertThat(getKnownDefaultFlags(options))
213214
.containsExactly(
@@ -235,7 +236,7 @@ public void trimFlagValues_withTrimmedFlagsSet_toEmptySetProducesEmptyOptions()
235236
options = FeatureFlagValue.trimFlagValues(options, ImmutableSet.of());
236237

237238
assertThat(options.getStarlarkOptions()).isEmpty();
238-
assertThat(options.get(ConfigFeatureFlagOptions.class).allFeatureFlagValuesArePresent)
239+
assertThat(options.get(ConfigFeatureFlagOptions.class).getAllFeatureFlagValuesArePresent())
239240
.isFalse();
240241
assertThat(getKnownDefaultFlags(options)).isEmpty();
241242
}

src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/CapabilitiesServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void getCapabilities(
4646
DigestFunction.Value df = digestUtil.getDigestFunction();
4747

4848
var builder = ServerCapabilities.newBuilder();
49-
if (workerOptions.legacyApi) {
49+
if (workerOptions.getLegacyApi()) {
5050
builder
5151
.setLowApiVersion(ApiVersion.twoPointZero.toSemVer())
5252
.setHighApiVersion(ApiVersion.twoPointZero.toSemVer());

src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ExecutionServer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ public ExecutionServer(
130130
ThreadPoolExecutor realExecutor =
131131
new ThreadPoolExecutor(
132132
// This is actually the max number of concurrent jobs.
133-
workerOptions.jobs,
133+
workerOptions.getJobs(),
134134
// Since we use an unbounded queue, the executor ignores this value, but it still checks
135135
// that it is greater or equal to the value above.
136-
workerOptions.jobs,
136+
workerOptions.getJobs(),
137137
// Shut down idle threads after one minute. Threads aren't all that expensive, but we
138138
// also
139139
// don't need to keep them around if we don't need them.
@@ -272,7 +272,7 @@ private ActionResult execute(
272272
logger.atSevere().withCause(e).log("Work failed: %s", workDetails);
273273
throw e;
274274
} finally {
275-
if (workerOptions.debug) {
275+
if (workerOptions.getDebug()) {
276276
logger.atInfo().log("Preserving work directory %s", tempRoot);
277277
} else {
278278
try {
@@ -619,14 +619,14 @@ private com.google.devtools.build.lib.shell.Command getCommand(
619619
// Run command with sandboxing.
620620
ArrayList<String> newCommandLineElements = new ArrayList<>(arguments.size());
621621
newCommandLineElements.add(sandboxPath.getPathString());
622-
if (workerOptions.sandboxingBlockNetwork) {
622+
if (workerOptions.getSandboxingBlockNetwork()) {
623623
newCommandLineElements.add("-N");
624624
}
625-
for (PathFragment writablePath : workerOptions.sandboxingWritablePaths) {
625+
for (PathFragment writablePath : workerOptions.getSandboxingWritablePaths()) {
626626
newCommandLineElements.add("-w");
627627
newCommandLineElements.add(writablePath.getPathString());
628628
}
629-
for (PathFragment tmpfsDir : workerOptions.sandboxingTmpfsDirs) {
629+
for (PathFragment tmpfsDir : workerOptions.getSandboxingTmpfsDirs()) {
630630
newCommandLineElements.add("-e");
631631
newCommandLineElements.add(tmpfsDir.getPathString());
632632
}

src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void downloadTree(
113113
@Override
114114
public ListenableFuture<byte[]> downloadBlob(
115115
RemoteActionExecutionContext context, Digest digest) {
116-
if (remoteWorkerOptions.errorOnDuplicateDownloads) {
116+
if (remoteWorkerOptions.getErrorOnDuplicateDownloads()) {
117117
// Only populate numberOfDownloadsPerDigestAndInvocation when fakeErrorForDuplicatedDownloads
118118
// is enabled to avoid unnecessary unbounded memory growth.
119119
int numberOfDownloads =

0 commit comments

Comments
 (0)