Skip to content

Commit

Permalink
Reference .proto source files using their exec path instead of their…
Browse files Browse the repository at this point in the history
… root-relative path so as to be a bit more consistent.

    RELNOTES: None.
    PiperOrigin-RevId: 238185563
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 1311bed commit dd56bdb
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.AbstractAction;
Expand Down Expand Up @@ -72,7 +73,8 @@ public class ProtoCompileActionBuilder {
private Iterable<Artifact> inputs;
private String langParameter;
private String langPluginName;
private Supplier<String> langPluginParameter;
private String langPluginParameter;
private Supplier<String> langPluginParameterSupplier;
private boolean hasServices;
private Iterable<String> additionalCommandLineArguments;
private Iterable<FilesToRunProvider> additionalTools;
Expand All @@ -98,11 +100,17 @@ public ProtoCompileActionBuilder setLangPluginName(String langPluginName) {
return this;
}

public ProtoCompileActionBuilder setLangPluginParameter(Supplier<String> langPluginParameter) {
public ProtoCompileActionBuilder setLangPluginParameter(String langPluginParameter) {
this.langPluginParameter = langPluginParameter;
return this;
}

public ProtoCompileActionBuilder setLangPluginParameterSupplier(
Supplier<String> langPluginParameterSupplier) {
this.langPluginParameterSupplier = langPluginParameterSupplier;
return this;
}

public ProtoCompileActionBuilder setAdditionalCommandLineArguments(
Iterable<String> additionalCmdLine) {
this.additionalCommandLineArguments = additionalCmdLine;
Expand Down Expand Up @@ -198,6 +206,10 @@ public String lookupFunction(String name, String param) throws ExpansionExceptio
}

public Action[] build() {
checkState(
langPluginParameter == null || langPluginParameterSupplier == null,
"Only one of {langPluginParameter, langPluginParameterSupplier} should be set.");

if (isEmpty(outputs)) {
return NO_ACTIONS;
}
Expand Down Expand Up @@ -274,13 +286,18 @@ CustomCommandLine.Builder createProtoCompilerCommandLine() throws MissingPrerequ
}
} else {
FilesToRunProvider langPluginTarget = getLangPluginTarget();
Supplier<String> langPluginParameter1 =
langPluginParameter == null
? langPluginParameterSupplier
: Suppliers.ofInstance(langPluginParameter);

Preconditions.checkArgument(langParameter == null);
Preconditions.checkArgument(langPluginParameter != null);
Preconditions.checkArgument(langPluginParameter1 != null);
// We pass a separate langPluginName as there are plugins that cannot be overridden
// and thus we have to deal with "$xx_plugin" and "xx_plugin".
result.addFormatted(
"--plugin=protoc-gen-%s=%s", langPrefix, langPluginTarget.getExecutable().getExecPath());
result.addLazyString(new LazyLangPluginFlag(langPrefix, langPluginParameter));
result.addLazyString(new LazyLangPluginFlag(langPrefix, langPluginParameter1));
}

result.addAll(ruleContext.getFragment(ProtoConfiguration.class).protocOpts());
Expand Down

0 comments on commit dd56bdb

Please sign in to comment.