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();
}
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;
}
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());
}
Aggregations