Skip to content

Commit

Permalink
Get color diagnostic option directly from passed in tool
Browse files Browse the repository at this point in the history
Summary:
Instead of passing it down via preprocessor/compiler delegate, into
ToolCommand, into Step, just get the args from the tool, which is already
passed into the step.

Test Plan: CI

Reviewed By: beefon

fbshipit-source-id: 18d6399
  • Loading branch information
yiding authored and facebook-github-bot committed May 15, 2017
1 parent 6a85182 commit 3286637
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 42 deletions.
5 changes: 0 additions & 5 deletions src/com/facebook/buck/cxx/CompilerDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Ordering;
import java.nio.file.Path;
import java.util.Optional;

/** Helper class for generating compiler invocations for a cxx compilation rule. */
class CompilerDelegate implements RuleKeyAppendable {
Expand Down Expand Up @@ -90,10 +89,6 @@ public ImmutableList<SourcePath> getInputsAfterBuildingLocally() {
return Ordering.natural().immutableSortedCopy(compiler.getInputs());
}

public Optional<ImmutableList<String>> getFlagsForColorDiagnostics() {
return compiler.getFlagsForColorDiagnostics();
}

public boolean isArgFileSupported() {
return compiler.isArgFileSupported();
}
Expand Down
3 changes: 1 addition & 2 deletions src/com/facebook/buck/cxx/CxxPrecompiledHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ CxxPreprocessAndCompileStep makeMainStep(SourcePathResolver resolver, Path scrat
compilerFlags, /* no pch */ Optional.empty()))
.build()
.getAllFlags()),
preprocessorDelegate.getEnvironment(),
preprocessorDelegate.getFlagsForColorDiagnostics()),
preprocessorDelegate.getEnvironment()),
preprocessorDelegate.getHeaderPathNormalizer(),
compilerSanitizer,
scratchDir,
Expand Down
5 changes: 1 addition & 4 deletions src/com/facebook/buck/cxx/CxxPreprocessAndCompile.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ CxxPreprocessAndCompileStep makeMainStep(
getRelativeInputPath(resolver),
inputType,
new CxxPreprocessAndCompileStep.ToolCommand(
compilerDelegate.getCommandPrefix(),
arguments,
compilerDelegate.getEnvironment(),
compilerDelegate.getFlagsForColorDiagnostics()),
compilerDelegate.getCommandPrefix(), arguments, compilerDelegate.getEnvironment()),
headerPathNormalizer,
sanitizer,
scratchDir,
Expand Down
29 changes: 10 additions & 19 deletions src/com/facebook/buck/cxx/CxxPreprocessAndCompileStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ ImmutableList<String> getArguments(boolean allowColorsInDiagnostics) {
? inputType.getPrecompiledHeaderLanguage().get()
: inputType.getLanguage();
return ImmutableList.<String>builder()
.addAll(command.getArguments(allowColorsInDiagnostics))
.addAll(command.getArguments())
.addAll(
(allowColorsInDiagnostics
? compiler.getFlagsForColorDiagnostics()
: Optional.<ImmutableList<String>>empty())
.orElseGet(ImmutableList::of))
.addAll(compiler.languageArgs(inputLanguage))
.addAll(sanitizer.getCompilationFlags())
.add("-c")
Expand Down Expand Up @@ -211,7 +216,7 @@ private int executeCompilation(ExecutionContext context) throws Exception {
.post(
createConsoleEvent(
context,
command.supportsColorsInDiagnostics(),
compiler.getFlagsForColorDiagnostics().isPresent(),
exitCode == 0 ? Level.WARNING : Level.SEVERE,
err));
}
Expand Down Expand Up @@ -307,40 +312,26 @@ public static class ToolCommand {
private final ImmutableList<String> commandPrefix;
private final ImmutableList<String> arguments;
private final ImmutableMap<String, String> environment;
private final Optional<ImmutableList<String>> flagsForColorDiagnostics;

public ToolCommand(
ImmutableList<String> commandPrefix,
ImmutableList<String> arguments,
ImmutableMap<String, String> environment,
Optional<ImmutableList<String>> flagsForColorDiagnostics) {
ImmutableMap<String, String> environment) {
this.commandPrefix = commandPrefix;
this.arguments = arguments;
this.environment = environment;
this.flagsForColorDiagnostics = flagsForColorDiagnostics;
}

public ImmutableList<String> getCommandPrefix() {
return commandPrefix;
}

public ImmutableList<String> getArguments(boolean allowColorsInDiagnostics) {
if (allowColorsInDiagnostics && flagsForColorDiagnostics.isPresent()) {
return ImmutableList.<String>builder()
.addAll(arguments)
.addAll(flagsForColorDiagnostics.get())
.build();
} else {
return arguments;
}
public ImmutableList<String> getArguments() {
return arguments;
}

public ImmutableMap<String, String> getEnvironment() {
return environment;
}

public boolean supportsColorsInDiagnostics() {
return flagsForColorDiagnostics.isPresent();
}
}
}
4 changes: 0 additions & 4 deletions src/com/facebook/buck/cxx/PreprocessorDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ public Predicate<SourcePath> getCoveredByDepFilePredicate() {
return (SourcePath path) -> true;
}

public Optional<ImmutableList<String>> getFlagsForColorDiagnostics() {
return preprocessor.getFlagsForColorDiagnostics();
}

public HeaderVerification getHeaderVerification() {
return headerVerification;
}
Expand Down
10 changes: 2 additions & 8 deletions test/com/facebook/buck/cxx/CxxCompileStepIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ private void assertCompDir(Path compDir, Optional<String> failure) throws Except
relativeInput,
CxxSource.Type.C,
new CxxPreprocessAndCompileStep.ToolCommand(
compilerCommandPrefix,
compilerArguments.build(),
ImmutableMap.of(),
Optional.empty()),
compilerCommandPrefix, compilerArguments.build(), ImmutableMap.of()),
HeaderPathNormalizer.empty(pathResolver),
sanitizer,
scratchDir,
Expand Down Expand Up @@ -160,10 +157,7 @@ public void createsAnArgfile() throws Exception {
relativeInput,
CxxSource.Type.C,
new CxxPreprocessAndCompileStep.ToolCommand(
compilerCommandPrefix,
compilerArguments.build(),
ImmutableMap.of(),
Optional.empty()),
compilerCommandPrefix, compilerArguments.build(), ImmutableMap.of()),
HeaderPathNormalizer.empty(pathResolver),
CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER,
scratchDir,
Expand Down

0 comments on commit 3286637

Please sign in to comment.