Search in sources :

Example 21 with RuleConfiguredTargetBuilder

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));
}
Also used : CcLinkParamsProvider(com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider) CcLinkParamsStore(com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 22 with RuleConfiguredTargetBuilder

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();
}
Also used : FailAction(com.google.devtools.build.lib.actions.FailAction) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Rule(com.google.devtools.build.lib.packages.Rule) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 23 with RuleConfiguredTargetBuilder

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();
}
Also used : EnvironmentGroup(com.google.devtools.build.lib.packages.EnvironmentGroup) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Target(com.google.devtools.build.lib.packages.Target) FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Label(com.google.devtools.build.lib.cmdline.Label) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider)

Example 24 with RuleConfiguredTargetBuilder

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();
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 25 with RuleConfiguredTargetBuilder

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();
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) OutputJar(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaRuntimeJarProvider(com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) FileProvider(com.google.devtools.build.lib.analysis.FileProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) JavaCommon(com.google.devtools.build.lib.rules.java.JavaCommon)

Aggregations

RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)48 Artifact (com.google.devtools.build.lib.actions.Artifact)36 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)21 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)19 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)17 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)11 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)7 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)6 CcLinkParamsProvider (com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider)5 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 FileProvider (com.google.devtools.build.lib.analysis.FileProvider)4 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)4 Label (com.google.devtools.build.lib.cmdline.Label)4 CcLinkParamsStore (com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)3 JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)3 CompositeRunfilesSupplier (com.google.devtools.build.lib.actions.CompositeRunfilesSupplier)2 CommandHelper (com.google.devtools.build.lib.analysis.CommandHelper)2