Search in sources :

Example 1 with SymlinkTreeAction

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

the class BuildViewTestCase method getSymlinkTreeManifest.

protected Map<String, String> getSymlinkTreeManifest(Artifact outputManifest) throws Exception {
    SymlinkTreeAction symlinkTreeAction = (SymlinkTreeAction) getGeneratingAction(outputManifest);
    Artifact inputManifest = Iterables.getOnlyElement(symlinkTreeAction.getInputs());
    SourceManifestAction inputManifestAction = (SourceManifestAction) getGeneratingAction(inputManifest);
    // Ask the manifest to write itself to a byte array so that we can
    // read its contents.
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    inputManifestAction.writeOutputFile(stream, reporter);
    String contents = stream.toString();
    // Get the file names from the manifest output.
    ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
    for (String line : Splitter.on('\n').split(contents)) {
        int space = line.indexOf(' ');
        if (space < 0) {
            continue;
        }
        result.put(line.substring(0, space), line.substring(space + 1));
    }
    return result.build();
}
Also used : SourceManifestAction(com.google.devtools.build.lib.analysis.SourceManifestAction) SymlinkTreeAction(com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Artifact(com.google.devtools.build.lib.actions.Artifact) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with SymlinkTreeAction

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

the class RunfilesSupport method createRunfilesAction.

/**
   * Creates a runfiles action for all of the specified files, and returns the
   * output artifact (the artifact for the MANIFEST file).
   *
   * <p>The "runfiles" action creates a symlink farm that links all the runfiles
   * (which may come from different places, e.g. different package paths,
   * generated files, etc.) into a single tree, so that programs can access them
   * using the workspace-relative name.
   */
private Artifact createRunfilesAction(ActionConstructionContext context, Runfiles runfiles, Artifact artifactsMiddleman) {
    // Compute the names of the runfiles directory and its MANIFEST file.
    Artifact inputManifest = getRunfilesInputManifest();
    context.getAnalysisEnvironment().registerAction(SourceManifestAction.forRunfiles(ManifestType.SOURCE_SYMLINKS, context.getActionOwner(), inputManifest, runfiles));
    if (!createSymlinks) {
        // Just return the manifest if that's all the build calls for.
        return inputManifest;
    }
    PathFragment runfilesDir = FileSystemUtils.replaceExtension(inputManifest.getRootRelativePath(), RUNFILES_DIR_EXT);
    PathFragment outputManifestPath = runfilesDir.getRelative("MANIFEST");
    BuildConfiguration config = context.getConfiguration();
    Artifact outputManifest = context.getDerivedArtifact(outputManifestPath, config.getBinDirectory(context.getRule().getRepository()));
    context.getAnalysisEnvironment().registerAction(new SymlinkTreeAction(context.getActionOwner(), inputManifest, artifactsMiddleman, outputManifest, /*filesetTree=*/
    false, config.getLocalShellEnvironment(), config.runfilesEnabled()));
    return outputManifest;
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SymlinkTreeAction(com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 3 with SymlinkTreeAction

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

the class NativeLibs method createApkBuilderSymlinks.

public Pair<Artifact, Runfiles> createApkBuilderSymlinks(RuleContext ruleContext) {
    Map<PathFragment, Artifact> symlinks = new LinkedHashMap<>();
    for (Map.Entry<String, Iterable<Artifact>> entry : nativeLibs.entrySet()) {
        String arch = entry.getKey();
        for (Artifact lib : entry.getValue()) {
            symlinks.put(new PathFragment(arch + "/" + lib.getExecPath().getBaseName()), lib);
        }
    }
    if (symlinks.isEmpty()) {
        return null;
    }
    Artifact inputManifest = AndroidBinary.getDxArtifact(ruleContext, "native_symlinks.manifest");
    SourceManifestAction sourceManifestAction = new SourceManifestAction.Builder(ruleContext.getWorkspaceName(), ManifestType.SOURCE_SYMLINKS, ruleContext.getActionOwner(), inputManifest, ruleContext.getConfiguration().legacyExternalRunfiles()).addRootSymlinks(symlinks).build();
    ruleContext.registerAction(sourceManifestAction);
    Artifact outputManifest = AndroidBinary.getDxArtifact(ruleContext, "native_symlinks/MANIFEST");
    Artifact nativeLibsMiddleman = ruleContext.getAnalysisEnvironment().getMiddlemanFactory().createRunfilesMiddleman(ruleContext.getActionOwner(), null, symlinks.values(), ruleContext.getConfiguration().getMiddlemanDirectory(ruleContext.getRule().getRepository()), "android_native_libs");
    ruleContext.registerAction(new SymlinkTreeAction(ruleContext.getActionOwner(), inputManifest, nativeLibsMiddleman, outputManifest, false, ruleContext.getConfiguration().getLocalShellEnvironment(), ruleContext.getConfiguration().runfilesEnabled()));
    return Pair.of(outputManifest, sourceManifestAction.getGeneratedRunfiles());
}
Also used : SourceManifestAction(com.google.devtools.build.lib.analysis.SourceManifestAction) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SymlinkTreeAction(com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Artifact(com.google.devtools.build.lib.actions.Artifact) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)3 SymlinkTreeAction (com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 SourceManifestAction (com.google.devtools.build.lib.analysis.SourceManifestAction)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1