use of com.google.devtools.build.lib.analysis.FilesToRunProvider in project bazel by bazelbuild.
the class AndroidBinary method createSplitInstallAction.
private static void createSplitInstallAction(RuleContext ruleContext, Artifact marker, Artifact argsArtifact, Artifact splitMainApk, NestedSet<Artifact> splitApks, Artifact stubDataFile) {
FilesToRunProvider adb = AndroidSdkProvider.fromRuleContext(ruleContext).getAdb();
SpawnAction.Builder builder = new SpawnAction.Builder().setExecutable(ruleContext.getExecutablePrerequisite("$incremental_install", Mode.HOST)).addTool(adb).executeUnconditionally().setMnemonic("AndroidInstall").setProgressMessage("Installing " + ruleContext.getLabel() + " using split apks").setExecutionInfo(ImmutableMap.of("local", "")).addArgument("--output_marker").addOutputArgument(marker).addArgument("--stub_datafile").addInputArgument(stubDataFile).addArgument("--adb").addArgument(adb.getExecutable().getExecPathString()).addTool(adb).addArgument("--flagfile").addInputArgument(argsArtifact).addArgument("--split_main_apk").addInputArgument(splitMainApk);
for (Artifact splitApk : splitApks) {
builder.addArgument("--split_apk").addInputArgument(splitApk);
}
ruleContext.registerAction(builder.build(ruleContext));
}
use of com.google.devtools.build.lib.analysis.FilesToRunProvider in project bazel by bazelbuild.
the class ProtoCompileActionBuilder method createActions.
@Nullable
private static SpawnAction.Builder createActions(RuleContext ruleContext, List<ToolchainInvocation> toolchainInvocations, Iterable<Artifact> protosToCompile, NestedSet<Artifact> transitiveSources, @Nullable NestedSet<Artifact> protosInDirectDeps, String ruleLabel, Iterable<Artifact> outputs, String flavorName, boolean allowServices) {
if (isEmpty(outputs)) {
return null;
}
SpawnAction.Builder result = new SpawnAction.Builder().addTransitiveInputs(transitiveSources);
for (ToolchainInvocation invocation : toolchainInvocations) {
ProtoLangToolchainProvider toolchain = invocation.toolchain;
if (toolchain.pluginExecutable() != null) {
result.addTool(toolchain.pluginExecutable());
}
}
FilesToRunProvider compilerTarget = ruleContext.getExecutablePrerequisite(":proto_compiler", RuleConfiguredTarget.Mode.HOST);
if (compilerTarget == null) {
return null;
}
result.useParameterFile(ParameterFile.ParameterFileType.UNQUOTED).addOutputs(outputs).setResources(GENPROTO_RESOURCE_SET).useDefaultShellEnvironment().setExecutable(compilerTarget).setCommandLine(createCommandLineFromToolchains(toolchainInvocations, protosToCompile, transitiveSources, areDepsStrict(ruleContext) ? protosInDirectDeps : null, ruleLabel, allowServices, ruleContext.getFragment(ProtoConfiguration.class).protocOpts())).setProgressMessage("Generating " + flavorName + " proto_library " + ruleContext.getLabel()).setMnemonic(MNEMONIC);
return result;
}
use of com.google.devtools.build.lib.analysis.FilesToRunProvider in project bazel by bazelbuild.
the class ProtoCompileActionBuilder method createProtoCompilerCommandLine.
/** Commandline generator for protoc invocations. */
@VisibleForTesting
CustomCommandLine.Builder createProtoCompilerCommandLine() throws MissingPrerequisiteException {
CustomCommandLine.Builder result = CustomCommandLine.builder();
if (langPluginName == null) {
if (langParameter != null) {
result.add(langParameter);
}
} else {
FilesToRunProvider langPluginTarget = getLangPluginTarget();
Supplier<String> langPluginParameter1 = langPluginParameter == null ? langPluginParameterSupplier : Suppliers.ofInstance(langPluginParameter);
Preconditions.checkArgument(langParameter == 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.add(String.format("--plugin=protoc-gen-%s=%s", langPrefix, langPluginTarget.getExecutable().getExecPathString()));
result.add(new LazyLangPluginFlag(langPrefix, langPluginParameter1));
}
result.add(ruleContext.getFragment(ProtoConfiguration.class).protocOpts());
boolean areDepsStrict = areDepsStrict(ruleContext);
// Add include maps
result.add(new ProtoCommandLineArgv(areDepsStrict ? supportData.getProtosInDirectDeps() : null, supportData.getTransitiveImports()));
if (areDepsStrict) {
// Note: the %s in the line below is used by proto-compiler. That is, the string we create
// here should have a literal %s in it.
result.add(createStrictProtoDepsViolationErrorMessage(ruleContext.getLabel().getCanonicalForm()));
}
for (Artifact src : supportData.getDirectProtoSources()) {
result.addPath(src.getRootRelativePath());
}
if (!hasServices) {
result.add("--disallow_services");
}
if (additionalCommandLineArguments != null) {
result.add(additionalCommandLineArguments);
}
return result;
}
use of com.google.devtools.build.lib.analysis.FilesToRunProvider in project bazel by bazelbuild.
the class ProtoCompileActionBuilder method createAction.
private SpawnAction.Builder createAction() throws MissingPrerequisiteException {
SpawnAction.Builder result = new SpawnAction.Builder().addTransitiveInputs(supportData.getTransitiveImports());
FilesToRunProvider langPluginTarget = getLangPluginTarget();
if (langPluginTarget != null) {
result.addTool(langPluginTarget);
}
FilesToRunProvider compilerTarget = ruleContext.getExecutablePrerequisite(":proto_compiler", RuleConfiguredTarget.Mode.HOST);
if (compilerTarget == null) {
throw new MissingPrerequisiteException();
}
if (this.additionalTools != null) {
for (FilesToRunProvider tool : additionalTools) {
result.addTool(tool);
}
}
result.useParameterFile(ParameterFile.ParameterFileType.UNQUOTED).addOutputs(outputs).setResources(GENPROTO_RESOURCE_SET).useDefaultShellEnvironment().setExecutable(compilerTarget).setCommandLine(createProtoCompilerCommandLine().build()).setProgressMessage("Generating " + language + " proto_library " + ruleContext.getLabel()).setMnemonic(MNEMONIC);
return result;
}
use of com.google.devtools.build.lib.analysis.FilesToRunProvider in project bazel by bazelbuild.
the class ProtoCompileActionBuilderTest method commandLine_basic.
@Test
public void commandLine_basic() throws Exception {
FilesToRunProvider plugin = new FilesToRunProvider(ImmutableList.<Artifact>of(), null, /* runfilesSupport */
artifact("//:dont-care", "protoc-gen-javalite.exe"));
ProtoLangToolchainProvider toolchainNoPlugin = ProtoLangToolchainProvider.create("--java_out=param1,param2:$(OUT)", null, /* pluginExecutable */
mock(TransitiveInfoCollection.class), /* runtime */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
ProtoLangToolchainProvider toolchainWithPlugin = ProtoLangToolchainProvider.create("--$(PLUGIN_OUT)=param3,param4:$(OUT)", plugin, mock(TransitiveInfoCollection.class), /* runtime */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysFalse(), ImmutableList.of(artifact("//:dont-care", "source_file.proto")), NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER), /* protosInDirectDeps */
NestedSetBuilder.create(STABLE_ORDER, artifact("//:dont-care", "import1.proto"), artifact("//:dont-care", "import2.proto")), true);
CustomCommandLine cmdLine = createCommandLineFromToolchains(ImmutableList.of(new ToolchainInvocation("dontcare_because_no_plugin", toolchainNoPlugin, "foo.srcjar"), new ToolchainInvocation("pluginName", toolchainWithPlugin, "bar.srcjar")), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), null, /* protosInDirectDeps */
"//foo:bar", true, /* allowServices */
ImmutableList.<String>of());
assertThat(cmdLine.arguments()).containsExactly("--java_out=param1,param2:foo.srcjar", "--PLUGIN_pluginName_out=param3,param4:bar.srcjar", "--plugin=protoc-gen-PLUGIN_pluginName=protoc-gen-javalite.exe", "-Iimport1.proto=import1.proto", "-Iimport2.proto=import2.proto", "source_file.proto").inOrder();
}
Aggregations