Search in sources :

Example 91 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class SpawnHelpers method mountRunfilesFromSuppliers.

/** Mount all runfiles that the spawn needs as specified via its runfiles suppliers. */
void mountRunfilesFromSuppliers(Map<PathFragment, Path> mounts, Spawn spawn) throws IOException {
    Map<PathFragment, Map<PathFragment, Artifact>> rootsAndMappings = spawn.getRunfilesSupplier().getMappings();
    for (Map.Entry<PathFragment, Map<PathFragment, Artifact>> rootAndMappings : rootsAndMappings.entrySet()) {
        PathFragment root = rootAndMappings.getKey();
        if (root.isAbsolute()) {
            root = root.relativeTo(execRoot.asFragment());
        }
        for (Map.Entry<PathFragment, Artifact> mapping : rootAndMappings.getValue().entrySet()) {
            Artifact sourceArtifact = mapping.getValue();
            Path source = (sourceArtifact != null) ? execRoot.getRelative(sourceArtifact.getExecPath()) : null;
            Preconditions.checkArgument(!mapping.getKey().isAbsolute());
            PathFragment target = root.getRelative(mapping.getKey());
            mounts.put(target, source);
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) HashMap(java.util.HashMap) Map(java.util.Map) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 92 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class SpawnHelpers method mountFilesFromFilesetManifests.

/** Mount all files that the spawn needs as specified in its fileset manifests. */
void mountFilesFromFilesetManifests(Map<PathFragment, Path> mounts, Spawn spawn, ActionExecutionContext executionContext) throws IOException {
    final FilesetActionContext filesetContext = executionContext.getExecutor().getContext(FilesetActionContext.class);
    for (Artifact fileset : spawn.getFilesetManifests()) {
        File manifestFile = new File(execRoot.getPathString(), AnalysisUtils.getManifestPathFromFilesetPath(fileset.getExecPath()).getPathString());
        PathFragment targetDirectory = fileset.getExecPath();
        parseManifestFile(execRoot.getFileSystem(), mounts, targetDirectory, manifestFile, true, filesetContext.getWorkspaceName());
    }
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) FilesetActionContext(com.google.devtools.build.lib.rules.fileset.FilesetActionContext) File(java.io.File) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 93 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class J2ObjcAspect method javaJ2ObjcSource.

private static J2ObjcSource javaJ2ObjcSource(RuleContext ruleContext, Iterable<Artifact> javaInputSourceFiles, Iterable<Artifact> javaSourceJarFiles) {
    PathFragment objcFileRootRelativePath = ruleContext.getUniqueDirectory("_j2objc");
    PathFragment objcFileRootExecPath = ruleContext.getConfiguration().getBinFragment().getRelative(objcFileRootRelativePath);
    Iterable<Artifact> objcSrcs = getOutputObjcFiles(ruleContext, javaInputSourceFiles, objcFileRootRelativePath, ".m");
    Iterable<Artifact> objcHdrs = getOutputObjcFiles(ruleContext, javaInputSourceFiles, objcFileRootRelativePath, ".h");
    Iterable<PathFragment> headerSearchPaths = J2ObjcLibrary.j2objcSourceHeaderSearchPaths(ruleContext, objcFileRootExecPath, javaInputSourceFiles);
    Optional<Artifact> sourceJarTranslatedSrcs = Optional.absent();
    Optional<Artifact> sourceJarTranslatedHdrs = Optional.absent();
    Optional<PathFragment> sourceJarFileHeaderSearchPaths = Optional.absent();
    if (!Iterables.isEmpty(javaSourceJarFiles)) {
        sourceJarTranslatedSrcs = Optional.of(j2ObjcSourceJarTranslatedSourceFiles(ruleContext));
        sourceJarTranslatedHdrs = Optional.of(j2objcSourceJarTranslatedHeaderFiles(ruleContext));
        sourceJarFileHeaderSearchPaths = Optional.of(sourceJarTranslatedHdrs.get().getExecPath());
    }
    return new J2ObjcSource(ruleContext.getRule().getLabel(), Iterables.concat(objcSrcs, sourceJarTranslatedSrcs.asSet()), Iterables.concat(objcHdrs, sourceJarTranslatedHdrs.asSet()), objcFileRootExecPath, SourceType.JAVA, Iterables.concat(headerSearchPaths, sourceJarFileHeaderSearchPaths.asSet()));
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 94 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class J2ObjcAspect method createJ2ObjcProtoCompileActions.

private J2ObjcMappingFileProvider createJ2ObjcProtoCompileActions(ConfiguredTarget base, RuleContext ruleContext, Iterable<Artifact> filteredProtoSources, J2ObjcSource j2ObjcSource) {
    Iterable<Artifact> outputHeaderMappingFiles = ProtoCommon.getGeneratedOutputs(ruleContext, ImmutableList.copyOf(filteredProtoSources), ".j2objc.mapping");
    Iterable<Artifact> outputClassMappingFiles = ProtoCommon.getGeneratedOutputs(ruleContext, ImmutableList.copyOf(filteredProtoSources), ".clsmap.properties");
    ImmutableList<Artifact> outputs = ImmutableList.<Artifact>builder().addAll(j2ObjcSource.getObjcSrcs()).addAll(j2ObjcSource.getObjcHdrs()).addAll(outputHeaderMappingFiles).addAll(outputClassMappingFiles).build();
    String langPluginParameter = String.format("%s:%s", Joiner.on(',').join(J2OBJC_PLUGIN_PARAMS), ruleContext.getConfiguration().getGenfilesFragment().getPathString());
    SupportData supportData = base.getProvider(ProtoSupportDataProvider.class).getSupportData();
    ProtoCompileActionBuilder actionBuilder = new ProtoCompileActionBuilder(ruleContext, supportData, "J2ObjC", "j2objc", outputs).setLangPluginName("$j2objc_plugin").setLangPluginParameter(langPluginParameter).allowServices(shouldAllowProtoServices(ruleContext));
    ruleContext.registerAction(actionBuilder.build());
    return new J2ObjcMappingFileProvider(NestedSetBuilder.<Artifact>stableOrder().addAll(outputHeaderMappingFiles).build(), NestedSetBuilder.<Artifact>stableOrder().addAll(outputClassMappingFiles).build(), NestedSetBuilder.<Artifact>stableOrder().build(), NestedSetBuilder.<Artifact>stableOrder().build());
}
Also used : SupportData(com.google.devtools.build.lib.rules.proto.SupportData) ProtoSupportDataProvider(com.google.devtools.build.lib.rules.proto.ProtoSupportDataProvider) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 95 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class J2ObjcAspect method createJ2ObjcTranspilationAction.

private static J2ObjcMappingFileProvider createJ2ObjcTranspilationAction(RuleContext ruleContext, Iterable<Artifact> sources, Iterable<Artifact> sourceJars, J2ObjcMappingFileProvider depJ2ObjcMappingFileProvider, JavaCompilationArgsProvider compArgsProvider, J2ObjcSource j2ObjcSource) {
    CustomCommandLine.Builder argBuilder = CustomCommandLine.builder();
    PathFragment javaExecutable = ruleContext.getFragment(Jvm.class, HOST).getJavaExecutable();
    argBuilder.add("--java").add(javaExecutable.getPathString());
    Artifact j2ObjcDeployJar = ruleContext.getPrerequisiteArtifact("$j2objc", Mode.HOST);
    argBuilder.addExecPath("--j2objc", j2ObjcDeployJar);
    argBuilder.add("--main_class").add("com.google.devtools.j2objc.J2ObjC");
    argBuilder.add("--objc_file_path").addPath(j2ObjcSource.getObjcFilePath());
    Artifact outputDependencyMappingFile = j2ObjcOutputDependencyMappingFile(ruleContext);
    argBuilder.addExecPath("--output_dependency_mapping_file", outputDependencyMappingFile);
    ImmutableList.Builder<Artifact> sourceJarOutputFiles = ImmutableList.builder();
    if (!Iterables.isEmpty(sourceJars)) {
        sourceJarOutputFiles.addAll(sourceJarOutputs(ruleContext));
        argBuilder.addJoinExecPaths("--src_jars", ",", sourceJars);
        argBuilder.add(sourceJarFlags(ruleContext));
    }
    Iterable<String> translationFlags = ruleContext.getFragment(J2ObjcConfiguration.class).getTranslationFlags();
    argBuilder.add(translationFlags);
    NestedSet<Artifact> depsHeaderMappingFiles = depJ2ObjcMappingFileProvider.getHeaderMappingFiles();
    if (!depsHeaderMappingFiles.isEmpty()) {
        argBuilder.addJoinExecPaths("--header-mapping", ",", depsHeaderMappingFiles);
    }
    Artifact outputHeaderMappingFile = j2ObjcOutputHeaderMappingFile(ruleContext);
    argBuilder.addExecPath("--output-header-mapping", outputHeaderMappingFile);
    NestedSet<Artifact> depsClassMappingFiles = depJ2ObjcMappingFileProvider.getClassMappingFiles();
    if (!depsClassMappingFiles.isEmpty()) {
        argBuilder.addJoinExecPaths("--mapping", ",", depsClassMappingFiles);
    }
    Artifact archiveSourceMappingFile = j2ObjcOutputArchiveSourceMappingFile(ruleContext);
    argBuilder.addExecPath("--output_archive_source_mapping_file", archiveSourceMappingFile);
    Artifact compiledLibrary = ObjcRuleClasses.j2objcIntermediateArtifacts(ruleContext).archive();
    argBuilder.addExecPath("--compiled_archive_file_path", compiledLibrary);
    Artifact bootclasspathJar = ruleContext.getPrerequisiteArtifact("$jre_emul_jar", Mode.HOST);
    argBuilder.add("-Xbootclasspath:" + bootclasspathJar.getExecPathString());
    argBuilder.add("-d").addPath(j2ObjcSource.getObjcFilePath());
    NestedSet<Artifact> compileTimeJars = compArgsProvider.getRecursiveJavaCompilationArgs().getCompileTimeJars();
    if (!compileTimeJars.isEmpty()) {
        argBuilder.addJoinExecPaths("-classpath", ":", compileTimeJars);
    }
    argBuilder.addExecPaths(sources);
    Artifact paramFile = j2ObjcOutputParamFile(ruleContext);
    ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile, argBuilder.build(), ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));
    SpawnAction.Builder builder = new SpawnAction.Builder().setMnemonic("TranspilingJ2objc").setExecutable(ruleContext.getPrerequisiteArtifact("$j2objc_wrapper", Mode.HOST)).addInput(ruleContext.getPrerequisiteArtifact("$j2objc_wrapper", Mode.HOST)).addInput(j2ObjcDeployJar).addInput(bootclasspathJar).addInputs(sources).addInputs(sourceJars).addTransitiveInputs(compileTimeJars).addTransitiveInputs(JavaHelper.getHostJavabaseInputs(ruleContext)).addTransitiveInputs(depsHeaderMappingFiles).addTransitiveInputs(depsClassMappingFiles).addInput(paramFile).setCommandLine(CustomCommandLine.builder().addPaths("@%s", paramFile.getExecPath()).build()).addOutputs(j2ObjcSource.getObjcSrcs()).addOutputs(j2ObjcSource.getObjcHdrs()).addOutput(outputHeaderMappingFile).addOutput(outputDependencyMappingFile).addOutput(archiveSourceMappingFile);
    ruleContext.registerAction(builder.build(ruleContext));
    return new J2ObjcMappingFileProvider(NestedSetBuilder.<Artifact>stableOrder().add(outputHeaderMappingFile).build(), NestedSetBuilder.<Artifact>stableOrder().build(), NestedSetBuilder.<Artifact>stableOrder().add(outputDependencyMappingFile).build(), NestedSetBuilder.<Artifact>stableOrder().add(archiveSourceMappingFile).build());
}
Also used : Jvm(com.google.devtools.build.lib.rules.java.Jvm) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) ImmutableList(com.google.common.collect.ImmutableList) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) ParameterFileWriteAction(com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)659 Test (org.junit.Test)242 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)184 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)83 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)65 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)64 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)51 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)50 ImmutableList (com.google.common.collect.ImmutableList)46 Action (com.google.devtools.build.lib.actions.Action)42 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)38 Path (com.google.devtools.build.lib.vfs.Path)37 HashMap (java.util.HashMap)37 Map (java.util.Map)36 Root (com.google.devtools.build.lib.actions.Root)31 LinkedHashMap (java.util.LinkedHashMap)31 ImmutableMap (com.google.common.collect.ImmutableMap)28 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)28