Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize representation of runfiles in compact execution log #23321

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7b47753
Add RunfilesTree proto
fmeum Aug 16, 2024
09bd497
WIP
fmeum Aug 16, 2024
287b3a8
Fix build
fmeum Aug 16, 2024
86ff166
Basic test setup
fmeum Aug 16, 2024
bcfc317
WIP
fmeum Aug 16, 2024
528d1be
Almost passing tests
fmeum Aug 16, 2024
13564a1
Simplify and support legacyExternalRunfiles
fmeum Aug 16, 2024
6b93b38
Fix tests
fmeum Aug 21, 2024
3f9e234
Fix tests and add docs
fmeum Aug 21, 2024
0ac5e81
Explain order
fmeum Aug 21, 2024
1e02f91
Fix test
fmeum Aug 22, 2024
80f81ac
First comments
fmeum Aug 29, 2024
cf0df2b
WIP
fmeum Aug 29, 2024
181901e
Basic runfiles test
fmeum Aug 30, 2024
eafc3e7
Key on legacyExternalRunfiles
fmeum Aug 30, 2024
880b67c
Fix collisions
fmeum Aug 30, 2024
4efa0f4
Improve collision tests
fmeum Aug 30, 2024
3806f46
Add root symlink collision test
fmeum Aug 30, 2024
8989415
Add test for `.runfile` file
fmeum Aug 30, 2024
4f321a7
Fix .runfile logic
fmeum Aug 30, 2024
4711a24
Test for cross type collision
fmeum Aug 30, 2024
06aaf17
Test postorder collisions
fmeum Aug 30, 2024
d63c480
Do not distinguish IDs by type
fmeum Aug 30, 2024
9d3560b
Store dense IDs
fmeum Aug 30, 2024
595613d
Optimize IDs
fmeum Aug 31, 2024
152a60f
Add better postorder test
fmeum Aug 31, 2024
a85be80
Test symlinks
fmeum Aug 31, 2024
0953237
Fix post order
fmeum Aug 31, 2024
8f29296
Cleanup
fmeum Aug 31, 2024
e8f854b
Add logEntryWithoutId
fmeum Sep 1, 2024
7e3df9a
Simplify ID check
fmeum Sep 1, 2024
6c245cc
Sibling test
fmeum Sep 1, 2024
5d4642e
Test with sibling layout
fmeum Sep 2, 2024
64d2c82
Encode sibling
fmeum Sep 2, 2024
a66984b
Implement support for sibling layout
fmeum Sep 2, 2024
2fb002e
Add comments and tests
fmeum Sep 2, 2024
a4413d4
More docs and uint32
fmeum Sep 2, 2024
961218c
Don't retain test runfiles trees
fmeum Sep 2, 2024
56d7a30
Fix build
fmeum Sep 2, 2024
8637fe7
Add more docs
fmeum Sep 2, 2024
b5efe8a
Inline var
fmeum Sep 2, 2024
dab1a5a
Do not flatten symlinks
fmeum Sep 15, 2024
2d87ea9
Better empty files test
fmeum Sep 17, 2024
cc18347
Update docs
fmeum Sep 17, 2024
56b6861
Simplify InputMetadataProvider
fmeum Sep 17, 2024
818f3a0
Cleanup
fmeum Sep 17, 2024
8eadcde
Add docs and test
fmeum Sep 17, 2024
8eb2cef
Simplify supporting both versions
fmeum Sep 17, 2024
786440e
Remove unused methods
fmeum Sep 17, 2024
baa6b38
Fix build
fmeum Sep 18, 2024
f8ea5b2
Address comments
fmeum Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.cache.OutputMetadataStore;
import com.google.devtools.build.lib.analysis.SymlinkEntry;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
import com.google.devtools.build.lib.bugreport.BugReporter;
import com.google.devtools.build.lib.clock.Clock;
Expand Down Expand Up @@ -88,6 +89,37 @@ public boolean isBuildRunfileLinks() {
public String getWorkspaceName() {
return wrapped.getWorkspaceName();
}

@Override
public NestedSet<Artifact> getArtifactsAtCanonicalLocationsForLogging() {
return wrapped.getArtifactsAtCanonicalLocationsForLogging();
}

@Override
public Iterable<PathFragment> getEmptyFilenamesForLogging() {
return wrapped.getEmptyFilenamesForLogging();
}

@Override
public NestedSet<SymlinkEntry> getSymlinksForLogging() {
return wrapped.getSymlinksForLogging();
}

@Override
public NestedSet<SymlinkEntry> getRootSymlinksForLogging() {
return wrapped.getRootSymlinksForLogging();
}

@Nullable
@Override
public Artifact getRepoMappingManifestForLogging() {
return wrapped.getRepoMappingManifestForLogging();
}

@Override
public boolean isLegacyExternalRunfiles() {
return wrapped.isLegacyExternalRunfiles();
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/google/devtools/build/lib/actions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ java_library(
":thread_state_receiver",
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:config/core_options",
"//src/main/java/com/google/devtools/build/lib/analysis:symlink_entry",
"//src/main/java/com/google/devtools/build/lib/analysis/platform",
"//src/main/java/com/google/devtools/build/lib/bugreport",
"//src/main/java/com/google/devtools/build/lib/buildeventstream",
Expand Down Expand Up @@ -553,8 +554,10 @@ java_library(
deps = [
":artifacts",
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:symlink_entry",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//third_party:jsr305",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

package com.google.devtools.build.lib.actions;

import com.google.devtools.build.lib.analysis.SymlinkEntry;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Map;
import javax.annotation.Nullable;

/** Lazy wrapper for a single runfiles tree. */
// TODO(bazel-team): Ideally we could refer to Runfiles objects directly here, but current package
Expand Down Expand Up @@ -45,4 +47,32 @@ public interface RunfilesTree {

/** Returns the name of the workspace that the build is occurring in. */
String getWorkspaceName();

/**
* Returns artifacts the runfiles tree contain symlinks to at their canonical locations.
*
* <p>This does <b>not</b> include artifacts that only the symlinks and root symlinks point to.
*/
NestedSet<Artifact> getArtifactsAtCanonicalLocationsForLogging();

/**
* Returns the set of names of implicit empty files to materialize.
*
* <p>If this runfiles tree does not implicitly add empty files, implementations should have a
* dedicated fast path that returns an empty set without traversing the tree.
*/
Iterable<PathFragment> getEmptyFilenamesForLogging();

/** Returns the set of custom symlink entries. */
NestedSet<SymlinkEntry> getSymlinksForLogging();

/** Returns the set of root symlinks. */
NestedSet<SymlinkEntry> getRootSymlinksForLogging();

/** Returns the repo mapping manifest if it exists. */
@Nullable
Artifact getRepoMappingManifestForLogging();

/** Whether this runfiles tree materializes external runfiles also at their legacy locations. */
boolean isLegacyExternalRunfiles();
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,17 @@ public NestedSet<SymlinkEntry> getSymlinks() {

@Override
public Depset /*<String>*/ getEmptyFilenamesForStarlark() {
return Depset.of(String.class, getEmptyFilenames());
return Depset.of(
String.class,
NestedSetBuilder.wrap(
Order.STABLE_ORDER,
Iterables.transform(getEmptyFilenames(), PathFragment::getPathString)));
}

public NestedSet<String> getEmptyFilenames() {
public Iterable<PathFragment> getEmptyFilenames() {
if (emptyFilesSupplier == DUMMY_EMPTY_FILES_SUPPLIER) {
return ImmutableList.of();
}
Set<PathFragment> manifestKeys =
Streams.concat(
symlinks.toList().stream().map(SymlinkEntry::getPath),
Expand All @@ -259,13 +266,7 @@ public NestedSet<String> getEmptyFilenames() {
? artifact.getOutputDirRelativePath(false)
: artifact.getRunfilesPath()))
.collect(ImmutableSet.toImmutableSet());
Iterable<PathFragment> emptyKeys = emptyFilesSupplier.getExtraPaths(manifestKeys);
return NestedSetBuilder.<String>stableOrder()
.addAll(
Streams.stream(emptyKeys)
.map(PathFragment::toString)
.collect(ImmutableList.toImmutableList()))
.build();
return emptyFilesSupplier.getExtraPaths(manifestKeys);
}

/**
Expand Down Expand Up @@ -383,6 +384,10 @@ public Map<PathFragment, Artifact> getRunfilesInputs(
return builder.build();
}

public boolean isLegacyExternalRunfiles() {
return legacyExternalRunfiles;
}

/**
* Helper class to handle munging the paths of external artifacts.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ public final class RunfilesSupport {
private static final String OUTPUT_MANIFEST_BASENAME = "MANIFEST";
private static final String REPO_MAPPING_MANIFEST_EXT = ".repo_mapping";

private static class RunfilesTreeImpl implements RunfilesTree {
@VisibleForTesting
public static class RunfilesTreeImpl implements RunfilesTree {

private static final WeakReference<Map<PathFragment, Artifact>> NOT_YET_COMPUTED =
new WeakReference<>(null);

private final PathFragment execPath;
private final Runfiles runfiles;
private final Artifact repoMappingManifest;
@Nullable private final Artifact repoMappingManifest;

/**
* The cached runfiles mapping. Possible values:
Expand All @@ -119,7 +120,7 @@ private static class RunfilesTreeImpl implements RunfilesTree {
private RunfilesTreeImpl(
PathFragment execPath,
Runfiles runfiles,
Artifact repoMappingManifest,
@Nullable Artifact repoMappingManifest,
boolean buildRunfileLinks,
boolean cacheMapping,
RunfileSymlinksMode runfileSymlinksMode) {
Expand All @@ -131,6 +132,17 @@ private RunfilesTreeImpl(
this.cachedMapping = cacheMapping ? NOT_YET_COMPUTED : null;
}

@VisibleForTesting
public RunfilesTreeImpl(PathFragment execPath, Runfiles runfiles) {
this(
execPath,
runfiles,
/* repoMappingManifest= */ null,
/* buildRunfileLinks= */ false,
/* cacheMapping= */ false,
RunfileSymlinksMode.EXTERNAL);
}

@Override
public PathFragment getExecPath() {
return execPath;
Expand Down Expand Up @@ -167,6 +179,37 @@ public NestedSet<Artifact> getArtifacts() {
return runfiles.getAllArtifacts();
}

@Override
public NestedSet<Artifact> getArtifactsAtCanonicalLocationsForLogging() {
return runfiles.getArtifacts();
}

@Override
public Iterable<PathFragment> getEmptyFilenamesForLogging() {
return runfiles.getEmptyFilenames();
}

@Override
public NestedSet<SymlinkEntry> getSymlinksForLogging() {
return runfiles.getSymlinks();
}

@Override
public NestedSet<SymlinkEntry> getRootSymlinksForLogging() {
return runfiles.getRootSymlinks();
}

@Nullable
@Override
public Artifact getRepoMappingManifestForLogging() {
return repoMappingManifest;
}

@Override
public boolean isLegacyExternalRunfiles() {
return runfiles.isLegacyExternalRunfiles();
}

@Override
public RunfileSymlinksMode getSymlinksMode() {
return runfileSymlinksMode;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/exec:executor_builder",
"//src/main/java/com/google/devtools/build/lib/exec:module_action_context_registry",
"//src/main/java/com/google/devtools/build/lib/exec:spawn_log_context",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/remote/options",
"//src/main/java/com/google/devtools/build/lib/util:abrupt_exit_exception",
"//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.exec.ExpandedSpawnLogContext.Encoding;
import com.google.devtools.build.lib.exec.ModuleActionContextRegistry;
import com.google.devtools.build.lib.exec.SpawnLogContext;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.remote.options.RemoteOptions;
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
Expand Down Expand Up @@ -104,6 +105,10 @@ private void initOutputs(CommandEnvironment env) throws IOException {
new CompactSpawnLogContext(
outputPath,
env.getExecRoot().asFragment(),
env.getWorkspaceName(),
env.getOptions()
.getOptions(BuildLanguageOptions.class)
.experimentalSiblingRepositoryLayout,
env.getOptions().getOptions(RemoteOptions.class),
env.getRuntime().getFileSystem().getDigestFunction(),
env.getXattrProvider());
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/google/devtools/build/lib/exec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/actions:file_metadata",
"//src/main/java/com/google/devtools/build/lib/actions:runfiles_tree",
"//src/main/java/com/google/devtools/build/lib/analysis:symlink_entry",
"//src/main/java/com/google/devtools/build/lib/analysis/platform:platform_utils",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
Expand Down Expand Up @@ -305,9 +306,11 @@ java_library(
"StableSort.java",
],
deps = [
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/profiler",
"//src/main/java/com/google/devtools/build/lib/util:pair",
"//src/main/java/com/google/devtools/build/lib/util/io:io-proto",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/protobuf:spawn_java_proto",
"//third_party:guava",
"//third_party:jsr305",
Expand Down
Loading
Loading