use of com.google.devtools.build.lib.analysis.MiddlemanProvider in project bazel by bazelbuild.
the class CcToolchain method getFiles.
private NestedSet<Artifact> getFiles(RuleContext context, String attribute) {
TransitiveInfoCollection dep = context.getPrerequisite(attribute, Mode.HOST);
MiddlemanProvider middlemanProvider = dep.getProvider(MiddlemanProvider.class);
// filesToBuild (e.g. if it is a simple input file)
return middlemanProvider != null ? middlemanProvider.getMiddlemanArtifact() : dep.getProvider(FileProvider.class).getFilesToBuild();
}
use of com.google.devtools.build.lib.analysis.MiddlemanProvider in project bazel by bazelbuild.
the class Filegroup method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
String outputGroupName = ruleContext.attributes().get("output_group", Type.STRING);
if (outputGroupName.endsWith(INTERNAL_SUFFIX)) {
ruleContext.throwWithAttributeError("output_group", String.format(ILLEGAL_OUTPUT_GROUP_ERROR, outputGroupName));
}
NestedSet<Artifact> filesToBuild = outputGroupName.isEmpty() ? PrerequisiteArtifacts.nestedSet(ruleContext, "srcs", Mode.TARGET) : getArtifactsForOutputGroup(outputGroupName, ruleContext.getPrerequisites("srcs", Mode.TARGET));
NestedSet<Artifact> middleman = CompilationHelper.getAggregatingMiddleman(ruleContext, Actions.escapeLabel(ruleContext.getLabel()), filesToBuild);
InstrumentedFilesProvider instrumentedFilesProvider = InstrumentedFilesCollector.collect(ruleContext, // what do *we* know about whether this is a source file or not
new InstrumentationSpec(FileTypeSet.ANY_FILE, "srcs", "deps", "data"), InstrumentedFilesCollector.NO_METADATA_COLLECTOR, filesToBuild);
RunfilesProvider runfilesProvider = RunfilesProvider.withData(new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES).build(), // If you're visiting a filegroup as data, then we also visit its data as data.
new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addTransitiveArtifacts(filesToBuild).addDataDeps(ruleContext).build());
return new RuleConfiguredTargetBuilder(ruleContext).add(RunfilesProvider.class, runfilesProvider).setFilesToBuild(filesToBuild).setRunfilesSupport(null, getExecutable(filesToBuild)).add(InstrumentedFilesProvider.class, instrumentedFilesProvider).add(MiddlemanProvider.class, new MiddlemanProvider(middleman)).add(FilegroupPathProvider.class, new FilegroupPathProvider(getFilegroupPath(ruleContext))).build();
}
use of com.google.devtools.build.lib.analysis.MiddlemanProvider in project bazel by bazelbuild.
the class JavaRuntime method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
NestedSet<Artifact> filesToBuild = PrerequisiteArtifacts.nestedSet(ruleContext, "srcs", Mode.TARGET);
NestedSet<Artifact> middleman = CompilationHelper.getAggregatingMiddleman(ruleContext, Actions.escapeLabel(ruleContext.getLabel()), filesToBuild);
// TODO(cushon): clean up uses of java_runtime in data deps and remove this
Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName()).addTransitiveArtifacts(filesToBuild).build();
return new RuleConfiguredTargetBuilder(ruleContext).addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles)).setFilesToBuild(filesToBuild).addProvider(JavaRuntimeProvider.class, JavaRuntimeProvider.create(filesToBuild)).addProvider(MiddlemanProvider.class, new MiddlemanProvider(middleman)).build();
}
use of com.google.devtools.build.lib.analysis.MiddlemanProvider in project bazel by bazelbuild.
the class JavaSkylarkCommon method createJavaCompileAction.
@SkylarkCallable(name = "compile", doc = "Compiles Java source files/jars from the implementation of a Skylark rule and returns a " + "provider that represents the results of the compilation and can be added to the set of " + "providers emitted by this rule.", // There is one mandatory positional: the Skylark rule context.
mandatoryPositionals = 1, parameters = { @Param(name = "source_jars", positional = false, named = true, type = SkylarkList.class, generic1 = Artifact.class, defaultValue = "[]", doc = "A list of the jars to be compiled. At least one of source_jars or source_files" + " should be specified."), @Param(name = "source_files", positional = false, named = true, type = SkylarkList.class, generic1 = Artifact.class, defaultValue = "[]", doc = "A list of the Java source files to be compiled. At least one of source_jars or " + "source_files should be specified."), @Param(name = "output", positional = false, named = true, type = Artifact.class), @Param(name = "javac_opts", positional = false, named = true, type = SkylarkList.class, generic1 = String.class, doc = "A list of the desired javac options. Optional."), @Param(name = "deps", positional = false, named = true, type = SkylarkList.class, generic1 = JavaProvider.class, doc = "A list of dependencies. Optional."), @Param(name = "strict_deps", defaultValue = "OFF", positional = false, named = true, type = String.class, doc = "A string that specifies how to handle strict deps. Possible values: 'OFF' (silently" + " allowing referencing transitive dependencies) and 'ERROR' (failing to build when" + " transitive dependencies are used directly). By default 'OFF'."), @Param(name = "java_toolchain", positional = false, named = true, type = ConfiguredTarget.class, doc = "A label pointing to a java_toolchain rule to be used for this compilation. " + "Mandatory."), @Param(name = "host_javabase", positional = false, named = true, type = ConfiguredTarget.class, doc = "A label pointing to a JDK to be used for this compilation. Mandatory.") })
public JavaProvider createJavaCompileAction(SkylarkRuleContext skylarkRuleContext, SkylarkList<Artifact> sourceJars, SkylarkList<Artifact> sourceFiles, Artifact outputJar, SkylarkList<String> javacOpts, SkylarkList<JavaProvider> deps, String strictDepsMode, ConfiguredTarget javaToolchain, ConfiguredTarget hostJavabase) {
JavaLibraryHelper helper = new JavaLibraryHelper(skylarkRuleContext.getRuleContext()).setOutput(outputJar).addSourceJars(sourceJars).addSourceFiles(sourceFiles).setJavacOpts(javacOpts);
List<JavaCompilationArgsProvider> compilationArgsProviders = JavaProvider.fetchProvidersFromList(deps, JavaCompilationArgsProvider.class);
helper.addAllDeps(compilationArgsProviders);
helper.setCompilationStrictDepsMode(getStrictDepsMode(strictDepsMode));
MiddlemanProvider hostJavabaseProvider = hostJavabase.getProvider(MiddlemanProvider.class);
NestedSet<Artifact> hostJavabaseArtifacts = hostJavabaseProvider == null ? NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER) : hostJavabaseProvider.getMiddlemanArtifact();
JavaToolchainProvider javaToolchainProvider = checkNotNull(javaToolchain.getProvider(JavaToolchainProvider.class));
JavaCompilationArgs artifacts = helper.build(javaSemantics, javaToolchainProvider, hostJavabaseArtifacts, SkylarkList.createImmutable(ImmutableList.<Artifact>of()));
JavaRuleOutputJarsProvider javaRuleOutputJarsProvider = JavaRuleOutputJarsProvider.builder().addOutputJar(new JavaRuleOutputJarsProvider.OutputJar(outputJar, /* ijar */
null, sourceJars)).build();
return JavaProvider.Builder.create().addProvider(JavaCompilationArgsProvider.class, helper.buildCompilationArgsProvider(artifacts, true)).addProvider(JavaSourceJarsProvider.class, createJavaSourceJarsProvider(sourceJars)).addProvider(JavaRuleOutputJarsProvider.class, javaRuleOutputJarsProvider).build();
}
Aggregations