Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CommandLine class initialization deadlock. #21608

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
/** A representation of a list of arguments. */
public abstract class CommandLine {

public static final CommandLine EMPTY = new EmptyCommandLine();
public static CommandLine empty() {
return EmptyCommandLine.INSTANCE;
}

/** Returns a {@link CommandLine} backed by the given list of arguments. */
public static CommandLine of(ImmutableList<String> arguments) {
return arguments.isEmpty() ? CommandLine.EMPTY : new SimpleCommandLine(arguments);
return arguments.isEmpty() ? empty() : new SimpleCommandLine(arguments);
}

/**
Expand All @@ -40,7 +42,7 @@ public static CommandLine concat(CommandLine commandLine, ImmutableList<String>
if (args.isEmpty()) {
return commandLine;
}
if (commandLine == EMPTY) {
if (commandLine == EmptyCommandLine.INSTANCE) {
return CommandLine.of(args);
}
return new SuffixedCommandLine(args, commandLine);
Expand Down Expand Up @@ -126,6 +128,8 @@ public abstract void addToFingerprint(
throws CommandLineExpansionException, InterruptedException;

private static final class EmptyCommandLine extends AbstractCommandLine {
private static final EmptyCommandLine INSTANCE = new EmptyCommandLine();

@Override
public ImmutableList<String> arguments() {
return ImmutableList.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ private static CommandLine computeArgs(RuleContext ruleContext) throws Interrupt
if (!ruleContext.getRule().isAttrDefined("args", Type.STRING_LIST)) {
// Some non-_binary rules create RunfilesSupport instances; it is fine to not have an args
// attribute here.
return CommandLine.EMPTY;
return CommandLine.empty();
}
ImmutableList<String> args = ruleContext.getExpander().withDataLocations().tokenized("args");
return args.isEmpty() ? CommandLine.EMPTY : CommandLine.of(args);
return args.isEmpty() ? CommandLine.empty() : CommandLine.of(args);
}

private static ActionEnvironment computeActionEnvironment(RuleContext ruleContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ Builder addFormatted(Object object, String format) {

CommandLine build(boolean flagPerLine) {
if (arguments.isEmpty()) {
return CommandLine.EMPTY;
return CommandLine.empty();
}
Object[] args = arguments.toArray();
return flagPerLine
Expand Down
Loading