Skip to content

Commit

Permalink
Delay resolution of scalac arguments until step construction
Browse files Browse the repository at this point in the history
Test Plan: CI

Reviewed By: Coneko

fbshipit-source-id: 5fbd299
  • Loading branch information
illicitonion authored and facebook-github-bot committed Feb 7, 2017
1 parent 7442bc7 commit 3a4b2a3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ public CompileToJarStepFactory compileToJar(

return new ScalacToJarStepFactory(
getScalac(resolver),
ScalacToJarStepFactory.collectScalacArguments(
scalaBuckConfig,
resolver,
arg.extraArguments),
scalaBuckConfig.getCompilerFlags(),
arg.extraArguments,
resolver.getAllRules(scalaBuckConfig.getCompilerPlugins()),
ANDROID_CLASSPATH_FROM_CONTEXT);
}

Expand Down
8 changes: 4 additions & 4 deletions src/com/facebook/buck/jvm/scala/ScalaLibraryDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public <A extends Arg> BuildRule createBuildRule(
/* additionalClasspathEntries */ ImmutableSet.of(),
new ScalacToJarStepFactory(
scalac,
ScalacToJarStepFactory.collectScalacArguments(
scalaBuckConfig,
resolver,
args.extraArguments)),
scalaBuckConfig.getCompilerFlags(),
args.extraArguments,
resolver.getAllRules(scalaBuckConfig.getCompilerPlugins())
),
args.resourcesRoot,
args.manifestFile,
args.mavenCoords,
Expand Down
7 changes: 3 additions & 4 deletions src/com/facebook/buck/jvm/scala/ScalaTestDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ public <A extends Arg> BuildRule createBuildRule(
/* additionalClasspathEntries */ ImmutableSet.of(),
new ScalacToJarStepFactory(
scalac,
ImmutableList.<String>builder()
.addAll(config.getCompilerFlags())
.addAll(args.extraArguments)
.build()
config.getCompilerFlags(),
args.extraArguments,
ImmutableSet.of()
),
args.resourcesRoot,
args.manifestFile,
Expand Down
49 changes: 29 additions & 20 deletions src/com/facebook/buck/jvm/scala/ScalacToJarStepFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import com.facebook.buck.jvm.java.ClassUsageFileWriter;
import com.facebook.buck.model.BuildTarget;
import com.facebook.buck.rules.BuildContext;
import com.facebook.buck.rules.BuildRuleResolver;
import com.facebook.buck.rules.BuildRule;
import com.facebook.buck.rules.BuildableContext;
import com.facebook.buck.rules.RuleKeyObjectSink;
import com.facebook.buck.rules.SourcePath;
import com.facebook.buck.rules.SourcePathResolver;
import com.facebook.buck.rules.SourcePathRuleFinder;
import com.facebook.buck.rules.Tool;
import com.facebook.buck.step.Step;
import com.facebook.buck.util.MoreCollectors;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;

Expand All @@ -39,36 +42,32 @@

public class ScalacToJarStepFactory extends BaseCompileToJarStepFactory {

public static ImmutableList<String> collectScalacArguments(
ScalaBuckConfig config,
BuildRuleResolver resolver,
ImmutableList<String> extraArguments) {

return ImmutableList.<String>builder()
.addAll(config.getCompilerFlags())
.addAll(extraArguments)
.addAll(
Iterables.transform(
resolver.getAllRules(config.getCompilerPlugins()),
input -> "-Xplugin:" + input.getPathToOutput())
)
.build();
}

private final Tool scalac;
private final ImmutableList<String> configCompilerFlags;
private final ImmutableList<String> extraArguments;
private final ImmutableSet<SourcePath> compilerPlugins;
private final Function<BuildContext, Iterable<Path>> extraClassPath;

public ScalacToJarStepFactory(Tool scalac, ImmutableList<String> extraArguments) {
this(scalac, extraArguments, EMPTY_EXTRA_CLASSPATH);
public ScalacToJarStepFactory(
Tool scalac,
ImmutableList<String> configCompilerFlags,
ImmutableList<String> extraArguments,
ImmutableSet<BuildRule> compilerPlugins) {
this(scalac, configCompilerFlags, extraArguments, compilerPlugins, EMPTY_EXTRA_CLASSPATH);
}

public ScalacToJarStepFactory(
Tool scalac,
ImmutableList<String> configCompilerFlags,
ImmutableList<String> extraArguments,
ImmutableSet<BuildRule> compilerPlugins,
Function<BuildContext, Iterable<Path>> extraClassPath) {
this.scalac = scalac;
this.configCompilerFlags = configCompilerFlags;
this.extraArguments = extraArguments;
this.compilerPlugins = compilerPlugins.stream()
.map(BuildRule::getSourcePathToOutput)
.collect(MoreCollectors.toImmutableSet());
this.extraClassPath = extraClassPath;
}

Expand All @@ -93,7 +92,15 @@ public void createCompileStep(
steps.add(
new ScalacStep(
scalac,
extraArguments,
ImmutableList.<String>builder()
.addAll(configCompilerFlags)
.addAll(extraArguments)
.addAll(
Iterables.transform(
compilerPlugins,
input -> "-Xplugin:" +
context.getSourcePathResolver().getRelativePath(input).toString()))
.build(),
resolver,
outputDirectory,
sourceFilePaths,
Expand All @@ -107,6 +114,8 @@ public void createCompileStep(
@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
scalac.appendToRuleKey(sink);
sink.setReflectively("configCompilerFlags", configCompilerFlags);
sink.setReflectively("extraArguments", extraArguments);
sink.setReflectively("compilerPlugins", compilerPlugins);
}
}

0 comments on commit 3a4b2a3

Please sign in to comment.