Skip to content

Commit 7b87ae1

Browse files
tjgqcopybara-github
authored andcommitted
Obey --experimental_inprocess_symlink_creation in RunfilesTreeUpdater.
The bulk of this CL is just plumbing the flag from the configuration into the RunfilesSupplier implementations. The functional changes are in RunfilesTreeUpdater; compare with the preexisting SymlinkTreeStrategy implementation. Additionally, I've fixed some variable and method names to exactly match the flags defined in CoreOptions; the code is less confusing and easier to refactor that way. The motivation behind this change is to investigate the feasibility of defaulting to the in-process implementation and deleting the out-of-process one, which has known issues (see #4327). PiperOrigin-RevId: 558112830 Change-Id: I4c509be665776013ffc2d483694df515d5ab32f2
1 parent 93253ee commit 7b87ae1

26 files changed

+278
-237
lines changed

src/main/java/com/google/devtools/build/lib/actions/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,12 @@ java_library(
488488
srcs = ["RunfilesSupplier.java"],
489489
deps = [
490490
":artifacts",
491+
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_configuration",
491492
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
492493
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
493494
"//src/main/java/net/starlark/java/eval",
494495
"//third_party:guava",
496+
"//third_party:jsr305",
495497
],
496498
)
497499

src/main/java/com/google/devtools/build/lib/actions/CompositeRunfilesSupplier.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import com.google.common.collect.ImmutableMap;
1919
import com.google.common.collect.ImmutableSet;
2020
import com.google.common.collect.Maps;
21+
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
2122
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
2223
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
2324
import com.google.devtools.build.lib.vfs.PathFragment;
2425
import java.util.Collection;
2526
import java.util.Map;
27+
import javax.annotation.Nullable;
2628

2729
/** A {@link RunfilesSupplier} implementation for composing multiple instances. */
2830
public final class CompositeRunfilesSupplier implements RunfilesSupplier {
@@ -101,19 +103,21 @@ public ImmutableList<Artifact> getManifests() {
101103
}
102104

103105
@Override
104-
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
106+
@Nullable
107+
public RunfileSymlinksMode getRunfileSymlinksMode(PathFragment runfilesDir) {
105108
for (RunfilesSupplier supplier : suppliers) {
106-
if (supplier.isBuildRunfileLinks(runfilesDir)) {
107-
return true;
109+
RunfileSymlinksMode mode = supplier.getRunfileSymlinksMode(runfilesDir);
110+
if (mode != null) {
111+
return mode;
108112
}
109113
}
110-
return false;
114+
return null;
111115
}
112116

113117
@Override
114-
public boolean isRunfileLinksEnabled(PathFragment runfilesDir) {
118+
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
115119
for (RunfilesSupplier supplier : suppliers) {
116-
if (supplier.isRunfileLinksEnabled(runfilesDir)) {
120+
if (supplier.isBuildRunfileLinks(runfilesDir)) {
117121
return true;
118122
}
119123
}

src/main/java/com/google/devtools/build/lib/actions/EmptyRunfilesSupplier.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
import com.google.common.collect.ImmutableList;
1818
import com.google.common.collect.ImmutableMap;
1919
import com.google.common.collect.ImmutableSet;
20+
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
2021
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
2122
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
2223
import com.google.devtools.build.lib.collect.nestedset.Order;
2324
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
2425
import com.google.devtools.build.lib.vfs.PathFragment;
2526
import java.util.Map;
27+
import javax.annotation.Nullable;
2628

2729
/** Empty implementation of RunfilesSupplier */
2830
public final class EmptyRunfilesSupplier implements RunfilesSupplier {
@@ -53,12 +55,13 @@ public ImmutableList<Artifact> getManifests() {
5355
}
5456

5557
@Override
56-
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
57-
return false;
58+
@Nullable
59+
public RunfileSymlinksMode getRunfileSymlinksMode(PathFragment runfilesDir) {
60+
return null;
5861
}
5962

6063
@Override
61-
public boolean isRunfileLinksEnabled(PathFragment runfilesDir) {
64+
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
6265
return false;
6366
}
6467

src/main/java/com/google/devtools/build/lib/actions/RunfilesSupplier.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
import com.google.common.collect.ImmutableList;
1818
import com.google.common.collect.ImmutableMap;
1919
import com.google.common.collect.ImmutableSet;
20+
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
2021
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
2122
import com.google.devtools.build.lib.vfs.PathFragment;
2223
import java.util.Map;
24+
import javax.annotation.Nullable;
2325
import net.starlark.java.eval.StarlarkValue;
2426

2527
/** Convenience wrapper around runfiles allowing lazy expansion. */
@@ -30,37 +32,35 @@
3032
// they are exposed through ctx.resolve_tools[2], for example.
3133
public interface RunfilesSupplier extends StarlarkValue {
3234

33-
/** @return the contained artifacts */
35+
/** Returns the contained artifacts. */
3436
NestedSet<Artifact> getArtifacts();
3537

36-
/** @return the runfiles' root directories. */
38+
/** Returns the runfiles' root directories. */
3739
ImmutableSet<PathFragment> getRunfilesDirs();
3840

39-
/**
40-
* Returns mappings from runfiles directories to artifact mappings in that directory.
41-
*
42-
* @return runfiles' mappings
43-
*/
41+
/** Returns mappings from runfiles directories to artifact mappings in that directory. */
4442
ImmutableMap<PathFragment, Map<PathFragment, Artifact>> getMappings();
4543

46-
/** @return the runfiles manifest artifacts, if any. */
44+
/** Returns the runfiles manifest artifacts, if any. */
4745
ImmutableList<Artifact> getManifests();
4846

4947
/**
50-
* Returns whether for a given {@code runfilesDir} the runfile symlinks are materialized during
51-
* build. Also returns {@code false} if the runfiles supplier doesn't know about the directory.
48+
* Returns the {@link RunfileSymlinksMode} for the given {@code runfilesDir}, or {@code null} if
49+
* the {@link RunfilesSupplier} doesn't know about the directory.
5250
*
5351
* @param runfilesDir runfiles directory relative to the exec root
5452
*/
55-
boolean isBuildRunfileLinks(PathFragment runfilesDir);
53+
@Nullable
54+
RunfileSymlinksMode getRunfileSymlinksMode(PathFragment runfilesDir);
5655

5756
/**
58-
* Returns whether it's allowed to create runfile symlinks in the {@code runfilesDir}. Also
59-
* returns {@code false} if the runfiles supplier doesn't know about the directory.
57+
* Returns whether the runfile symlinks should be materialized during the build for the given
58+
* {@code runfilesDir}, or {@code false} if the {@link RunfilesSupplier} doesn't know about the
59+
* directory.
6060
*
6161
* @param runfilesDir runfiles directory relative to the exec root
6262
*/
63-
boolean isRunfileLinksEnabled(PathFragment runfilesDir);
63+
boolean isBuildRunfileLinks(PathFragment runfilesDir);
6464

6565
/**
6666
* Returns a {@link RunfilesSupplier} identical to this one, but with the given runfiles

src/main/java/com/google/devtools/build/lib/analysis/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,7 @@ java_library(
16691669
"//src/main/java/com/google/devtools/build/lib/vfs",
16701670
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
16711671
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
1672+
"//src/main/java/com/google/devtools/common/options",
16721673
"//src/main/java/net/starlark/java/annot",
16731674
"//src/main/java/net/starlark/java/eval",
16741675
"//src/main/protobuf:failure_details_java_proto",

src/main/java/com/google/devtools/build/lib/analysis/RunfilesSupport.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.devtools.build.lib.analysis.actions.ActionConstructionContext;
2828
import com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction;
2929
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
30+
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
3031
import com.google.devtools.build.lib.analysis.config.RunUnder;
3132
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
3233
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
@@ -87,8 +88,8 @@ public final class RunfilesSupport implements RunfilesSupplier {
8788
private final Artifact repoMappingManifest;
8889
private final Artifact runfilesMiddleman;
8990
private final Artifact owningExecutable;
91+
private final RunfileSymlinksMode runfileSymlinksMode;
9092
private final boolean buildRunfileLinks;
91-
private final boolean runfilesEnabled;
9293
private final CommandLine args;
9394
private final ActionEnvironment actionEnvironment;
9495

@@ -106,7 +107,9 @@ private static RunfilesSupport create(
106107
CommandLine args,
107108
ActionEnvironment actionEnvironment) {
108109
Artifact owningExecutable = Preconditions.checkNotNull(executable);
109-
boolean createManifest = ruleContext.getConfiguration().buildRunfilesManifests();
110+
RunfileSymlinksMode runfileSymlinksMode =
111+
ruleContext.getConfiguration().getRunfileSymlinksMode();
112+
boolean buildRunfileManifests = ruleContext.getConfiguration().buildRunfileManifests();
110113
boolean buildRunfileLinks = ruleContext.getConfiguration().buildRunfileLinks();
111114

112115
// Adding run_under target to the runfiles manifest so it would become part
@@ -131,7 +134,7 @@ private static RunfilesSupport create(
131134

132135
Artifact runfilesInputManifest;
133136
Artifact runfilesManifest;
134-
if (createManifest) {
137+
if (buildRunfileManifests) {
135138
runfilesInputManifest = createRunfilesInputManifestArtifact(ruleContext, owningExecutable);
136139
runfilesManifest =
137140
createRunfilesAction(
@@ -144,17 +147,15 @@ private static RunfilesSupport create(
144147
createRunfilesMiddleman(
145148
ruleContext, owningExecutable, runfiles, runfilesManifest, repoMappingManifest);
146149

147-
boolean runfilesEnabled = ruleContext.getConfiguration().runfilesEnabled();
148-
149150
return new RunfilesSupport(
150151
runfiles,
151152
runfilesInputManifest,
152153
runfilesManifest,
153154
repoMappingManifest,
154155
runfilesMiddleman,
155156
owningExecutable,
157+
runfileSymlinksMode,
156158
buildRunfileLinks,
157-
runfilesEnabled,
158159
args,
159160
actionEnvironment);
160161
}
@@ -166,8 +167,8 @@ private RunfilesSupport(
166167
Artifact repoMappingManifest,
167168
Artifact runfilesMiddleman,
168169
Artifact owningExecutable,
170+
RunfileSymlinksMode runfileSymlinksMode,
169171
boolean buildRunfileLinks,
170-
boolean runfilesEnabled,
171172
CommandLine args,
172173
ActionEnvironment actionEnvironment) {
173174
this.runfiles = runfiles;
@@ -176,8 +177,8 @@ private RunfilesSupport(
176177
this.repoMappingManifest = repoMappingManifest;
177178
this.runfilesMiddleman = runfilesMiddleman;
178179
this.owningExecutable = owningExecutable;
180+
this.runfileSymlinksMode = runfileSymlinksMode;
179181
this.buildRunfileLinks = buildRunfileLinks;
180-
this.runfilesEnabled = runfilesEnabled;
181182
this.args = args;
182183
this.actionEnvironment = actionEnvironment;
183184
}
@@ -194,27 +195,33 @@ public PathFragment getRunfilesDirectoryExecPath() {
194195
}
195196

196197
/**
197-
* Returns {@code true} if runfile symlinks should be materialized when building an executable.
198-
*
199-
* <p>Also see {@link #isRunfilesEnabled()}.
198+
* Same as {@link #getRunfileSymlinksMode(PathFragment)} with {@link
199+
* #getRunfilesDirectoryExecPath} as the implied argument.
200200
*/
201-
public boolean isBuildRunfileLinks() {
202-
return buildRunfileLinks;
201+
public RunfileSymlinksMode getRunfileSymlinksMode() {
202+
return runfileSymlinksMode;
203203
}
204204

205205
@Override
206-
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
207-
return buildRunfileLinks && runfilesDir.equals(getRunfilesDirectoryExecPath());
206+
@Nullable
207+
public RunfileSymlinksMode getRunfileSymlinksMode(PathFragment runfilesDir) {
208+
if (runfilesDir.equals(getRunfilesDirectoryExecPath())) {
209+
return runfileSymlinksMode;
210+
}
211+
return null;
208212
}
209213

210214
/**
211-
* Returns {@code true} if runfile symlinks are enabled.
212-
*
213-
* <p>This option differs from {@link #isBuildRunfileLinks()} in that if {@code false} it also
214-
* disables runfile symlinks creation during run/test.
215+
* Same as {@link #isBuildRunfileLinks(PathFragment)} with {@link #getRunfilesDirectoryExecPath}
216+
* as the implied argument.
215217
*/
216-
public boolean isRunfilesEnabled() {
217-
return runfilesEnabled;
218+
public boolean isBuildRunfileLinks() {
219+
return buildRunfileLinks;
220+
}
221+
222+
@Override
223+
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
224+
return buildRunfileLinks && runfilesDir.equals(getRunfilesDirectoryExecPath());
218225
}
219226

220227
public Runfiles getRunfiles() {
@@ -552,11 +559,6 @@ public ImmutableList<Artifact> getManifests() {
552559
return ImmutableList.of();
553560
}
554561

555-
@Override
556-
public boolean isRunfileLinksEnabled(PathFragment runfilesDir) {
557-
return runfilesEnabled && runfilesDir.equals(getRunfilesDirectoryExecPath());
558-
}
559-
560562
@Override
561563
public RunfilesSupplier withOverriddenRunfilesDir(PathFragment newRunfilesDir) {
562564
return newRunfilesDir.equals(getRunfilesDirectoryExecPath())
@@ -566,7 +568,7 @@ public RunfilesSupplier withOverriddenRunfilesDir(PathFragment newRunfilesDir) {
566568
runfiles,
567569
/* manifest= */ null,
568570
repoMappingManifest,
569-
buildRunfileLinks,
570-
runfilesEnabled);
571+
runfileSymlinksMode,
572+
buildRunfileLinks);
571573
}
572574
}

0 commit comments

Comments
 (0)