use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.
the class PyBinary method init.
static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics semantics, PyCommon common) throws InterruptedException {
CcLinkParamsStore ccLinkParamsStore = initializeCcLinkParamStore(ruleContext);
List<Artifact> srcs = common.validateSrcs();
List<Artifact> allOutputs = new ArrayList<>(semantics.precompiledPythonFiles(ruleContext, srcs, common));
if (ruleContext.hasErrors()) {
return null;
}
common.initBinary(allOutputs);
semantics.validate(ruleContext, common);
if (ruleContext.hasErrors()) {
return null;
}
NestedSet<PathFragment> imports = common.collectImports(ruleContext, semantics);
if (ruleContext.hasErrors()) {
return null;
}
semantics.createExecutable(ruleContext, common, ccLinkParamsStore, imports);
Runfiles commonRunfiles = collectCommonRunfiles(ruleContext, common, semantics);
Runfiles.Builder defaultRunfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).merge(commonRunfiles);
semantics.collectDefaultRunfilesForBinary(ruleContext, defaultRunfilesBuilder);
Runfiles defaultRunfiles = defaultRunfilesBuilder.build();
RunfilesSupport runfilesSupport = RunfilesSupport.withExecutable(ruleContext, defaultRunfiles, common.getExecutable(), ruleContext.shouldCreateRunfilesSymlinks());
if (ruleContext.hasErrors()) {
return null;
}
// Only include common runfiles and middleman. Default runfiles added by semantics are
// excluded. The middleman is necessary to ensure the runfiles trees are generated for all
// dependency binaries.
Runfiles dataRunfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).merge(commonRunfiles).addArtifact(runfilesSupport.getRunfilesMiddleman()).build();
RunfilesProvider runfilesProvider = RunfilesProvider.withData(defaultRunfiles, dataRunfiles);
RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
common.addCommonTransitiveInfoProviders(builder, semantics, common.getFilesToBuild());
semantics.postInitBinary(ruleContext, runfilesSupport, common);
return builder.setFilesToBuild(common.getFilesToBuild()).add(RunfilesProvider.class, runfilesProvider).setRunfilesSupport(runfilesSupport, common.getExecutable()).add(CcLinkParamsProvider.class, new CcLinkParamsProvider(ccLinkParamsStore)).add(PythonImportsProvider.class, new PythonImportsProvider(imports));
}
use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.
the class UnknownRuleConfiguredTarget method create.
@Override
public ConfiguredTarget create(RuleContext context) {
// TODO(bazel-team): (2009) why isn't this an error? It would stop the build more promptly...
context.ruleWarning("cannot build " + context.getRule().getRuleClass() + " rules");
ImmutableList<Artifact> outputArtifacts = context.getOutputArtifacts();
NestedSet<Artifact> filesToBuild;
if (outputArtifacts.isEmpty()) {
// Gotta build *something*...
filesToBuild = NestedSetBuilder.create(Order.STABLE_ORDER, context.createOutputArtifact());
} else {
filesToBuild = NestedSetBuilder.wrap(Order.STABLE_ORDER, outputArtifacts);
}
Rule rule = context.getRule();
context.registerAction(new FailAction(context.getActionOwner(), filesToBuild, "cannot build " + rule.getRuleClass() + " rules such as " + rule.getLabel()));
return new RuleConfiguredTargetBuilder(context).setFilesToBuild(filesToBuild).add(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY)).build();
}
use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.
the class Environment method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
// The main analysis work to do here is to simply fill in SupportedEnvironmentsProvider to
// pass the environment itself to depending rules.
Label label = ruleContext.getLabel();
EnvironmentGroup group;
try {
group = ConstraintSemantics.getEnvironmentGroup(ruleContext.getRule());
} catch (ConstraintSemantics.EnvironmentLookupException e) {
ruleContext.ruleError(e.getMessage());
return null;
}
EnvironmentCollection env = new EnvironmentCollection.Builder().put(group, label).build();
return new RuleConfiguredTargetBuilder(ruleContext).addProvider(SupportedEnvironmentsProvider.class, new SupportedEnvironments(env, env, ImmutableMap.<Label, Target>of())).addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY).add(FileProvider.class, FileProvider.EMPTY).add(FilesToRunProvider.class, FilesToRunProvider.EMPTY).build();
}
use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.
the class ToolchainLookup method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
// This cannot be an ImmutableMap.Builder because that asserts when a key is duplicated
TreeMap<String, String> makeVariables = new TreeMap<>();
Class<? extends BuildConfiguration.Fragment> fragmentClass = fragmentMap.get(ruleContext.getLabel());
if (fragmentClass != null) {
BuildConfiguration.Fragment fragment = ruleContext.getFragment(fragmentClass);
ImmutableMap.Builder<String, String> fragmentBuilder = ImmutableMap.builder();
fragment.addGlobalMakeVariables(fragmentBuilder);
makeVariables.putAll(fragmentBuilder.build());
}
ImmutableMap<String, String> hardcodedVariables = hardcodedVariableMap.get(ruleContext.getLabel());
if (hardcodedVariables != null) {
makeVariables.putAll(hardcodedVariables);
}
// come from BuildConfiguration so no need to ask Skyframe.
return new RuleConfiguredTargetBuilder(ruleContext).addProvider(new ToolchainProvider(ImmutableMap.copyOf(makeVariables))).addProvider(RunfilesProvider.simple(Runfiles.EMPTY)).build();
}
use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.
the class AarImport method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
if (!AndroidSdkProvider.verifyPresence(ruleContext)) {
return null;
}
RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext);
Artifact aar = ruleContext.getPrerequisiteArtifact("aar", Mode.TARGET);
Artifact allAarJars = createAarTreeArtifact(ruleContext, "jars");
Artifact jarMergingParams = createAarArtifact(ruleContext, "jar_merging_params");
ruleContext.registerAction(createAarEmbeddedJarsExtractorActions(ruleContext, aar, allAarJars, jarMergingParams));
Artifact mergedJar = createAarArtifact(ruleContext, MERGED_JAR);
ruleContext.registerAction(createAarJarsMergingActions(ruleContext, allAarJars, mergedJar, jarMergingParams));
// AndroidManifest.xml is required in every AAR.
Artifact androidManifestArtifact = createAarArtifact(ruleContext, ANDROID_MANIFEST);
ruleContext.registerAction(createSingleFileExtractorActions(ruleContext, aar, ANDROID_MANIFEST, androidManifestArtifact));
Artifact resourcesManifest = createAarArtifact(ruleContext, "resource_manifest");
ruleContext.registerAction(createManifestExtractorActions(ruleContext, aar, "res/.*", resourcesManifest));
Artifact resources = createAarTreeArtifact(ruleContext, "resources");
ruleContext.registerAction(createManifestFileEntriesExtractorActions(ruleContext, aar, resourcesManifest, resources));
ApplicationManifest androidManifest = ApplicationManifest.fromExplicitManifest(ruleContext, androidManifestArtifact);
FileProvider resourcesProvider = new FileProvider(new NestedSetBuilder<Artifact>(Order.NAIVE_LINK_ORDER).add(resources).build());
Artifact resourcesZip = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP);
ResourceApk resourceApk = androidManifest.packWithDataAndResources(ruleContext, new LocalResourceContainer.Builder(ruleContext).withResources(ImmutableList.of(resourcesProvider)).build(), ResourceDependencies.fromRuleDeps(ruleContext, JavaCommon.isNeverLink(ruleContext)), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_SYMBOLS), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), resourcesZip, /* alwaysExportManifest = */
true);
// There isn't really any use case for building an aar_import target on its own, so the files to
// build could be empty. The resources zip and merged jars are added here as a sanity check for
// Bazel developers so that `bazel build java/com/my_aar_import` will fail if the resource
// processing or jar merging steps fail.
NestedSetBuilder<Artifact> filesToBuildBuilder = NestedSetBuilder.<Artifact>stableOrder().add(resourcesZip).add(mergedJar);
Artifact nativeLibs = createAarArtifact(ruleContext, "native_libs.zip");
ruleContext.registerAction(createAarNativeLibsFilterActions(ruleContext, aar, nativeLibs));
JavaRuleOutputJarsProvider.Builder jarProviderBuilder = new JavaRuleOutputJarsProvider.Builder().addOutputJar(mergedJar, null, ImmutableList.<Artifact>of());
for (TransitiveInfoCollection export : ruleContext.getPrerequisites("exports", Mode.TARGET)) {
for (OutputJar jar : JavaProvider.getProvider(JavaRuleOutputJarsProvider.class, export).getOutputJars()) {
jarProviderBuilder.addOutputJar(jar);
filesToBuildBuilder.add(jar.getClassJar());
}
}
ImmutableList<TransitiveInfoCollection> targets = ImmutableList.<TransitiveInfoCollection>copyOf(ruleContext.getPrerequisites("exports", Mode.TARGET));
JavaCommon common = new JavaCommon(ruleContext, javaSemantics, /* sources = */
ImmutableList.<Artifact>of(), /* compileDeps = */
targets, /* runtimeDeps = */
targets, /* bothDeps = */
targets);
common.setJavaCompilationArtifacts(new JavaCompilationArtifacts.Builder().addRuntimeJar(mergedJar).addCompileTimeJar(mergedJar).build());
return ruleBuilder.setFilesToBuild(filesToBuildBuilder.build()).addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY).addProvider(AndroidResourcesProvider.class, resourceApk.toResourceProvider(ruleContext.getLabel())).addProvider(NativeLibsZipsProvider.class, new NativeLibsZipsProvider(AndroidCommon.collectTransitiveNativeLibsZips(ruleContext).add(nativeLibs).build())).addProvider(JavaRuntimeJarProvider.class, new JavaRuntimeJarProvider(ImmutableList.of(mergedJar))).addProvider(JavaCompilationArgsProvider.class, JavaCompilationArgsProvider.create(common.collectJavaCompilationArgs(/* recursive = */
false, JavaCommon.isNeverLink(ruleContext), /* srcLessDepsExport = */
false), common.collectJavaCompilationArgs(/* recursive = */
true, JavaCommon.isNeverLink(ruleContext), /* srcLessDepsExport = */
false))).addProvider(JavaRuleOutputJarsProvider.class, jarProviderBuilder.build()).build();
}
Aggregations