Search in sources :

Example 6 with Runfiles

use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.

the class JavaProtoLibrary method create.

@Override
public ConfiguredTarget create(final RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    JavaCompilationArgsProvider dependencyArgsProviders = JavaCompilationArgsProvider.merge(Iterables.<JavaCompilationArgsAspectProvider, JavaCompilationArgsProvider>transform(this.<JavaCompilationArgsAspectProvider>getDeps(ruleContext, JavaCompilationArgsAspectProvider.class), JavaCompilationArgsAspectProvider.GET_PROVIDER));
    if (!StrictDepsUtils.isStrictDepsJavaProtoLibrary(ruleContext)) {
        dependencyArgsProviders = StrictDepsUtils.makeNonStrict(dependencyArgsProviders);
    }
    Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName()).addArtifacts(dependencyArgsProviders.getRecursiveJavaCompilationArgs().getRuntimeJars()).build();
    JavaSourceJarsProvider sourceJarsProvider = JavaSourceJarsProvider.merge(Iterables.<JavaSourceJarsAspectProvider, JavaSourceJarsProvider>transform(this.<JavaSourceJarsAspectProvider>getDeps(ruleContext, JavaSourceJarsAspectProvider.class), JavaSourceJarsAspectProvider.GET_PROVIDER));
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
    filesToBuild.addAll(sourceJarsProvider.getSourceJars());
    for (JavaProtoLibraryTransitiveFilesToBuildProvider provider : ruleContext.getPrerequisites("deps", Mode.TARGET, JavaProtoLibraryTransitiveFilesToBuildProvider.class)) {
        filesToBuild.addTransitive(provider.getJars());
    }
    JavaRuleOutputJarsProvider ruleOutputJarsProvider = JavaRuleOutputJarsProvider.builder().build();
    JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(ruleOutputJarsProvider).setSourceJarsProvider(sourceJarsProvider).setCompilationArgsProvider(dependencyArgsProviders);
    return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(filesToBuild.build()).addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, skylarkApiProvider.build()).addProvider(RunfilesProvider.class, RunfilesProvider.withData(Runfiles.EMPTY, runfiles)).addOutputGroup(OutputGroupProvider.DEFAULT, NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER)).add(JavaCompilationArgsProvider.class, dependencyArgsProviders).add(JavaSourceJarsProvider.class, sourceJarsProvider).add(JavaRunfilesProvider.class, new JavaRunfilesProvider(runfiles)).add(JavaRuleOutputJarsProvider.class, ruleOutputJarsProvider).build();
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) JavaSkylarkApiProvider(com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaRunfilesProvider(com.google.devtools.build.lib.rules.java.JavaRunfilesProvider)

Example 7 with Runfiles

use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.

the class JavaLiteProtoLibrary method create.

@Override
public ConfiguredTarget create(final RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    JavaCompilationArgsProvider dependencyArgsProviders = JavaCompilationArgsProvider.merge(Iterables.<JavaCompilationArgsAspectProvider, JavaCompilationArgsProvider>transform(getDeps(ruleContext, JavaCompilationArgsAspectProvider.class), JavaCompilationArgsAspectProvider.GET_PROVIDER));
    if (!StrictDepsUtils.isStrictDepsJavaProtoLibrary(ruleContext)) {
        dependencyArgsProviders = StrictDepsUtils.makeNonStrict(dependencyArgsProviders);
    }
    Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName()).addArtifacts(dependencyArgsProviders.getRecursiveJavaCompilationArgs().getRuntimeJars()).build();
    JavaSourceJarsProvider sourceJarsProvider = JavaSourceJarsProvider.merge(Iterables.<JavaSourceJarsAspectProvider, JavaSourceJarsProvider>transform(getDeps(ruleContext, JavaSourceJarsAspectProvider.class), JavaSourceJarsAspectProvider.GET_PROVIDER));
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
    filesToBuild.addAll(sourceJarsProvider.getSourceJars());
    for (JavaProtoLibraryTransitiveFilesToBuildProvider provider : ruleContext.getPrerequisites("deps", Mode.TARGET, JavaProtoLibraryTransitiveFilesToBuildProvider.class)) {
        filesToBuild.addTransitive(provider.getJars());
    }
    JavaRuleOutputJarsProvider javaRuleOutputJarsProvider = JavaRuleOutputJarsProvider.builder().build();
    JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(javaRuleOutputJarsProvider).setSourceJarsProvider(sourceJarsProvider).setCompilationArgsProvider(dependencyArgsProviders);
    return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(filesToBuild.build()).addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, skylarkApiProvider.build()).addProvider(RunfilesProvider.class, RunfilesProvider.withData(Runfiles.EMPTY, runfiles)).addOutputGroup(OutputGroupProvider.DEFAULT, NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER)).add(JavaCompilationArgsProvider.class, dependencyArgsProviders).add(JavaSourceJarsProvider.class, sourceJarsProvider).add(JavaRunfilesProvider.class, new JavaRunfilesProvider(runfiles)).add(ProguardSpecProvider.class, getJavaLiteRuntimeSpec(ruleContext)).add(JavaRuleOutputJarsProvider.class, javaRuleOutputJarsProvider).build();
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) JavaSkylarkApiProvider(com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) JavaRunfilesProvider(com.google.devtools.build.lib.rules.java.JavaRunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaRunfilesProvider(com.google.devtools.build.lib.rules.java.JavaRunfilesProvider)

Example 8 with Runfiles

use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.

the class ApkActionsBuilder method legacyBuildApk.

/**
   * Registers generating actions for {@code outApk} that builds the APK specified.
   *
   * <p>If {@code signingKey} is not null, the apk will be signed with it using the V1 signature
   * scheme.
   */
private void legacyBuildApk(RuleContext ruleContext, Artifact outApk, Artifact signingKey, String message) {
    SpawnAction.Builder actionBuilder = new SpawnAction.Builder().setExecutable(AndroidSdkProvider.fromRuleContext(ruleContext).getApkBuilder()).setProgressMessage(message).setMnemonic("AndroidApkBuilder").addOutputArgument(outApk);
    if (javaResourceZip != null) {
        actionBuilder.addArgument("-rj").addInputArgument(javaResourceZip);
    }
    Pair<Artifact, Runfiles> nativeSymlinksManifestAndRunfiles = nativeLibs.createApkBuilderSymlinks(ruleContext);
    if (nativeSymlinksManifestAndRunfiles != null) {
        Artifact nativeSymlinksManifest = nativeSymlinksManifestAndRunfiles.first;
        Runfiles nativeSymlinksRunfiles = nativeSymlinksManifestAndRunfiles.second;
        PathFragment nativeSymlinksDir = nativeSymlinksManifest.getExecPath().getParentDirectory();
        actionBuilder.addRunfilesSupplier(new RunfilesSupplierImpl(nativeSymlinksDir, nativeSymlinksRunfiles, nativeSymlinksManifest)).addInput(nativeSymlinksManifest).addInputs(nativeLibs.getAllNativeLibs()).addArgument("-nf").addArgument(nativeSymlinksDir.getPathString());
    }
    if (nativeLibs.getName() != null) {
        actionBuilder.addArgument("-rf").addArgument(nativeLibs.getName().getExecPath().getParentDirectory().getPathString()).addInput(nativeLibs.getName());
    }
    if (nativeLibsZips != null) {
        for (Artifact nativeLibsZip : nativeLibsZips) {
            actionBuilder.addArgument("-z").addInputArgument(nativeLibsZip);
        }
    }
    if (javaResourceFile != null) {
        actionBuilder.addArgument("-rf").addArgument((javaResourceFile.getExecPath().getParentDirectory().getPathString())).addInput(javaResourceFile);
    }
    if (signingKey == null) {
        actionBuilder.addArgument("-u");
    } else {
        actionBuilder.addArgument("-ks").addArgument(signingKey.getExecPathString());
        actionBuilder.addInput(signingKey);
    }
    actionBuilder.addArgument("-z").addInputArgument(resourceApk);
    if (classesDex != null) {
        actionBuilder.addArgument(classesDex.getFilename().endsWith(".dex") ? "-f" : "-z").addInputArgument(classesDex);
    }
    ruleContext.registerAction(actionBuilder.build(ruleContext));
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 9 with Runfiles

use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.

the class SkylarkRuleConfiguredTargetBuilder method parseProviderKeys.

private static void parseProviderKeys(SkylarkClassObject provider, Boolean isDefaultProvider, RuleContext ruleContext, Location loc, Artifact executable, Map<String, Class<? extends TransitiveInfoProvider>> registeredProviderTypes, RuleConfiguredTargetBuilder builder) throws EvalException {
    Runfiles statelessRunfiles = null;
    Runfiles dataRunfiles = null;
    Runfiles defaultRunfiles = null;
    for (String key : provider.getKeys()) {
        if (key.equals("files")) {
            // If we specify files_to_build we don't have the executable in it by default.
            builder.setFilesToBuild(cast("files", provider, SkylarkNestedSet.class, Artifact.class, loc).getSet(Artifact.class));
        } else if (key.equals("runfiles")) {
            statelessRunfiles = cast("runfiles", provider, Runfiles.class, loc);
        } else if (key.equals("data_runfiles")) {
            dataRunfiles = cast("data_runfiles", provider, Runfiles.class, loc);
        } else if (key.equals("default_runfiles")) {
            defaultRunfiles = cast("default_runfiles", provider, Runfiles.class, loc);
        } else if (key.equals("output_groups")) {
            addOutputGroups(provider.getValue(key), loc, builder);
        } else if (key.equals("instrumented_files")) {
            SkylarkClassObject insStruct = cast("instrumented_files", provider, SkylarkClassObject.class, loc);
            Location insLoc = insStruct.getCreationLoc();
            FileTypeSet fileTypeSet = FileTypeSet.ANY_FILE;
            if (insStruct.getKeys().contains("extensions")) {
                @SuppressWarnings("unchecked") List<String> exts = cast("extensions", insStruct, SkylarkList.class, String.class, insLoc);
                if (exts.isEmpty()) {
                    fileTypeSet = FileTypeSet.NO_FILE;
                } else {
                    FileType[] fileTypes = new FileType[exts.size()];
                    for (int i = 0; i < fileTypes.length; i++) {
                        fileTypes[i] = FileType.of(exts.get(i));
                    }
                    fileTypeSet = FileTypeSet.of(fileTypes);
                }
            }
            List<String> dependencyAttributes = Collections.emptyList();
            if (insStruct.getKeys().contains("dependency_attributes")) {
                dependencyAttributes = cast("dependency_attributes", insStruct, SkylarkList.class, String.class, insLoc);
            }
            List<String> sourceAttributes = Collections.emptyList();
            if (insStruct.getKeys().contains("source_attributes")) {
                sourceAttributes = cast("source_attributes", insStruct, SkylarkList.class, String.class, insLoc);
            }
            InstrumentationSpec instrumentationSpec = new InstrumentationSpec(fileTypeSet).withSourceAttributes(sourceAttributes.toArray(new String[0])).withDependencyAttributes(dependencyAttributes.toArray(new String[0]));
            InstrumentedFilesProvider instrumentedFilesProvider = InstrumentedFilesCollector.collect(ruleContext, instrumentationSpec, InstrumentedFilesCollector.NO_METADATA_COLLECTOR, Collections.<Artifact>emptySet());
            builder.addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider);
        } else if (registeredProviderTypes.containsKey(key)) {
            Class<? extends TransitiveInfoProvider> providerType = registeredProviderTypes.get(key);
            TransitiveInfoProvider providerField = cast(key, provider, providerType, loc);
            builder.addProvider(providerType, providerField);
        } else if (isDefaultProvider) {
            // Custom keys are not allowed for default providers
            throw new EvalException(loc, "Invalid key for default provider: " + key);
        } else if (key.equals("providers")) {
            Iterable iterable = cast(key, provider, Iterable.class, loc);
            for (Object o : iterable) {
                SkylarkClassObject declaredProvider = SkylarkType.cast(o, SkylarkClassObject.class, loc, "The value of 'providers' should be a sequence of declared providers");
                builder.addSkylarkDeclaredProvider(declaredProvider, loc);
            }
        } else if (!key.equals("executable")) {
            // We handled executable already.
            builder.addSkylarkTransitiveInfo(key, provider.getValue(key), loc);
        }
    }
    addSimpleProviders(builder, ruleContext, loc, executable, statelessRunfiles, dataRunfiles, defaultRunfiles, (isDefaultProvider ? provider : null));
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) InstrumentationSpec(com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector.InstrumentationSpec) InstrumentedFilesProvider(com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider) EvalException(com.google.devtools.build.lib.syntax.EvalException) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) FileTypeSet(com.google.devtools.build.lib.util.FileTypeSet) SkylarkList(com.google.devtools.build.lib.syntax.SkylarkList) SkylarkList(com.google.devtools.build.lib.syntax.SkylarkList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) ClassObject(com.google.devtools.build.lib.syntax.ClassObject) TransitiveInfoProvider(com.google.devtools.build.lib.analysis.TransitiveInfoProvider) Location(com.google.devtools.build.lib.events.Location)

Example 10 with Runfiles

use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.

the class ShBinary method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
    ImmutableList<Artifact> srcs = ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list();
    if (srcs.size() != 1) {
        ruleContext.attributeError("srcs", "you must specify exactly one file in 'srcs'");
        return null;
    }
    Artifact symlink = ruleContext.createOutputArtifact();
    // Note that src is used as the executable script too
    Artifact src = srcs.get(0);
    // The interpretation of this deceptively simple yet incredibly generic rule is complicated
    // by the distinction between targets and (not properly encapsulated) artifacts. It depends
    // on the notion of other rule's "files-to-build" sets, which are undocumented, making it
    // impossible to give a precise definition of what this rule does in all cases (e.g. what
    // happens when srcs = ['x', 'y'] but 'x' is an empty filegroup?). This is a pervasive
    // problem in Blaze.
    ruleContext.registerAction(new ExecutableSymlinkAction(ruleContext.getActionOwner(), src, symlink));
    NestedSet<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(src).add(symlink).build();
    Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addTransitiveArtifacts(filesToBuild).addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES).build();
    RunfilesSupport runfilesSupport = RunfilesSupport.withExecutable(ruleContext, runfiles, symlink);
    return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(filesToBuild).setRunfilesSupport(runfilesSupport, symlink).addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles)).build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ExecutableSymlinkAction(com.google.devtools.build.lib.analysis.actions.ExecutableSymlinkAction) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

Runfiles (com.google.devtools.build.lib.analysis.Runfiles)28 Artifact (com.google.devtools.build.lib.actions.Artifact)24 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)15 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)11 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)10 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)9 RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)7 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)7 Test (org.junit.Test)7 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)6 EmptyRunfilesSupplier (com.google.devtools.build.lib.actions.EmptyRunfilesSupplier)6 RunfilesSupplier (com.google.devtools.build.lib.actions.RunfilesSupplier)6 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)6 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)3 LibraryToLink (com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink)3 InstrumentedFilesProvider (com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider)3 Label (com.google.devtools.build.lib.cmdline.Label)2 NestedSet (com.google.devtools.build.lib.collect.nestedset.NestedSet)2