Skip to content

Commit

Permalink
Change PlatformFlagsProducer to also include the requested platform l…
Browse files Browse the repository at this point in the history
…abel in the results.

Work towards platform-based flags: #19409.

PiperOrigin-RevId: 623820511
Change-Id: Iaa7bd29654667c8c1ec12828ac7f54043915ed04
  • Loading branch information
katre authored and copybara-github committed Apr 11, 2024
1 parent 8eba4e4 commit b4f9cfd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
public class PlatformFlagsProducer implements StateMachine, PlatformInfoProducer.ResultSink {

interface ResultSink {
void acceptPlatformFlags(NativeAndStarlarkFlags flags);
void acceptPlatformFlags(Label platform, NativeAndStarlarkFlags flags);

void acceptPlatformFlagsError(InvalidPlatformException error);
void acceptPlatformFlagsError(Label platform, InvalidPlatformException error);

void acceptPlatformFlagsError(OptionsParsingException error);
void acceptPlatformFlagsError(Label platform, OptionsParsingException error);
}

// -------------------- Input --------------------
Expand Down Expand Up @@ -85,7 +85,7 @@ public void acceptPlatformInfo(PlatformInfo info) {

@Override
public void acceptPlatformInfoError(InvalidPlatformException error) {
sink.acceptPlatformFlagsError(error);
sink.acceptPlatformFlagsError(this.platformLabel, error);
}

private StateMachine parsePlatformFlags(Tasks tasks) {
Expand Down Expand Up @@ -113,7 +113,7 @@ private void acceptParsedFlagsValue(
return;
}
if (exception != null) {
sink.acceptPlatformFlagsError(exception);
sink.acceptPlatformFlagsError(this.platformLabel, exception);
return;
}
throw new IllegalStateException("Both value and exception are null");
Expand All @@ -123,7 +123,7 @@ private StateMachine handleParsedFlags(Tasks tasks) {
if (this.parsedFlags == null) {
return DONE; // There was an error.
}
sink.acceptPlatformFlags(this.parsedFlags);
sink.acceptPlatformFlags(this.platformLabel, this.parsedFlags);
return this.runAfter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void starlarkFlag_invalid() throws Exception {

private NativeAndStarlarkFlags fetch(Label platformLabel)
throws InvalidPlatformException, InterruptedException, OptionsParsingException {
PlatformFlagsSink sink = new PlatformFlagsSink();
PlatformFlagsSink sink = new PlatformFlagsSink(platformLabel);
PlatformFlagsProducer producer =
new PlatformFlagsProducer(platformLabel, sink, StateMachine.DONE);
var unused = executeProducer(producer);
Expand All @@ -120,22 +120,30 @@ private NativeAndStarlarkFlags fetch(Label platformLabel)

/** Receiver for platform info from {@link PlatformFlagsProducer}. */
private static class PlatformFlagsSink implements PlatformFlagsProducer.ResultSink {
private final Label expectedPlatform;
@Nullable private NativeAndStarlarkFlags parsedFlags = null;
@Nullable private InvalidPlatformException invalidPlatformException = null;
@Nullable private OptionsParsingException optionParsingException = null;

private PlatformFlagsSink(Label expectedPlatform) {
this.expectedPlatform = expectedPlatform;
}

@Override
public void acceptPlatformFlags(NativeAndStarlarkFlags parsedFlags) {
public void acceptPlatformFlags(Label platform, NativeAndStarlarkFlags parsedFlags) {
assertThat(platform).isEqualTo(this.expectedPlatform);
this.parsedFlags = parsedFlags;
}

@Override
public void acceptPlatformFlagsError(InvalidPlatformException error) {
public void acceptPlatformFlagsError(Label platform, InvalidPlatformException error) {
assertThat(platform).isEqualTo(this.expectedPlatform);
this.invalidPlatformException = error;
}

@Override
public void acceptPlatformFlagsError(OptionsParsingException error) {
public void acceptPlatformFlagsError(Label platform, OptionsParsingException error) {
assertThat(platform).isEqualTo(this.expectedPlatform);
this.optionParsingException = error;
}

Expand Down

0 comments on commit b4f9cfd

Please sign in to comment.