21
21
import com .google .devtools .build .lib .analysis .config .ConfigurationEnvironment ;
22
22
import com .google .devtools .build .lib .analysis .config .ConfigurationFragmentFactory ;
23
23
import com .google .devtools .build .lib .analysis .config .FragmentOptions ;
24
- import com .google .devtools .build .lib .skyframe .serialization .DeserializationContext ;
25
- import com .google .devtools .build .lib .skyframe .serialization .ObjectCodec ;
26
- import com .google .devtools .build .lib .skyframe .serialization .SerializationContext ;
27
- import com .google .devtools .build .lib .skyframe .serialization .SerializationException ;
28
24
import com .google .devtools .build .lib .skyframe .serialization .autocodec .AutoCodec ;
29
25
import com .google .devtools .build .lib .util .OS ;
30
26
import com .google .devtools .build .lib .util .OptionsUtils .PathFragmentConverter ;
31
27
import com .google .devtools .build .lib .vfs .PathFragment ;
32
28
import com .google .devtools .common .options .Option ;
33
29
import com .google .devtools .common .options .OptionDocumentationCategory ;
34
30
import com .google .devtools .common .options .OptionEffectTag ;
35
- import com .google .protobuf .CodedInputStream ;
36
- import com .google .protobuf .CodedOutputStream ;
37
- import java .io .IOException ;
38
- import java .util .Map ;
39
31
import javax .annotation .Nullable ;
40
32
41
33
/** A configuration fragment that tells where the shell is. */
34
+ @ AutoCodec
42
35
public class ShellConfiguration extends BuildConfiguration .Fragment {
43
-
44
- /**
45
- * A codec for {@link ShellConfiguration}.
46
- *
47
- * <p>It does not handle the Bazel version, but that's fine, because we don't want to serialize
48
- * anything in Bazel.
49
- *
50
- * <p>We cannot use {@code AutoCodec} because the field {@link #actionEnvironment} is a lambda.
51
- * That does not necessarily need to be the case, but it's there in support for
52
- * {@link BuildConfiguration.Fragment#setupActionEnvironment()}, which is slated to be removed.
53
- */
54
- public static final class Codec implements ObjectCodec <ShellConfiguration > {
55
- @ Override
56
- public Class <? extends ShellConfiguration > getEncodedClass () {
57
- return ShellConfiguration .class ;
58
- }
59
-
60
- @ Override
61
- public void serialize (SerializationContext context , ShellConfiguration obj ,
62
- CodedOutputStream codedOut ) throws SerializationException , IOException {
63
- context .serialize (obj .shellExecutable , codedOut );
64
- }
65
-
66
- @ Override
67
- public ShellConfiguration deserialize (DeserializationContext context , CodedInputStream codedIn )
68
- throws SerializationException , IOException {
69
- PathFragment shellExecutable = context .deserialize (codedIn );
70
- return new ShellConfiguration (shellExecutable , NO_ACTION_ENV .fromOptions (null ));
71
- }
72
- }
73
-
74
36
private static final ImmutableMap <OS , PathFragment > OS_SPECIFIC_SHELL =
75
37
ImmutableMap .<OS , PathFragment >builder ()
76
38
.put (OS .WINDOWS , PathFragment .create ("c:/tools/msys64/usr/bin/bash.exe" ))
77
39
.put (OS .FREEBSD , PathFragment .create ("/usr/local/bin/bash" ))
78
40
.build ();
79
41
80
42
private final PathFragment shellExecutable ;
81
- private final ShellActionEnvironment actionEnvironment ;
82
43
83
- public ShellConfiguration (PathFragment shellExecutable ,
84
- ShellActionEnvironment actionEnvironment ) {
44
+ public ShellConfiguration (PathFragment shellExecutable ) {
85
45
this .shellExecutable = shellExecutable ;
86
- this .actionEnvironment = actionEnvironment ;
87
46
}
88
47
89
48
public PathFragment getShellExecutable () {
90
49
return shellExecutable ;
91
50
}
92
51
93
- @ Override
94
- public void setupActionEnvironment (Map <String , String > builder ) {
95
- actionEnvironment .setupActionEnvironment (this , builder );
96
- }
97
-
98
52
/** An option that tells Bazel where the shell is. */
99
53
@ AutoCodec (strategy = AutoCodec .Strategy .PUBLIC_FIELDS )
100
54
public static class Options extends FragmentOptions {
@@ -123,33 +77,6 @@ public Options getHost() {
123
77
}
124
78
}
125
79
126
- /**
127
- * Encapsulates the contributions of {@link ShellConfiguration} to the action environment.
128
- *
129
- * <p>This is done this way because we need the shell environment to be different between Bazel
130
- * and Blaze, but configuration fragments are handed out based on their classes, thus,
131
- * doing this with inheritance would be difficult. The good old "has-a instead of this-a" pattern.
132
- */
133
- public interface ShellActionEnvironment {
134
- void setupActionEnvironment (ShellConfiguration configuration , Map <String , String > builder );
135
- }
136
-
137
- /**
138
- * A factory for shell action environments.
139
- *
140
- * <p>This is necessary because the Bazel shell action environment depends on whether we use
141
- * strict action environments or not, but we cannot simply hardcode the dependency on that bit
142
- * here because it doesn't exist in Blaze. Thus, during configuration creation time, we call this
143
- * factory which returns an object, which, when called, updates the actual action environment.
144
- */
145
- public interface ShellActionEnvironmentFactory {
146
- ShellActionEnvironment fromOptions (BuildOptions options );
147
- }
148
-
149
- /** A {@link ShellConfiguration} that contributes nothing to the action environment. */
150
- public static final ShellActionEnvironmentFactory NO_ACTION_ENV =
151
- (BuildOptions options ) -> (ShellConfiguration config , Map <String , String > builder ) -> {};
152
-
153
80
/** the part of {@link ShellConfiguration} that determines where the shell is. */
154
81
public interface ShellExecutableProvider {
155
82
PathFragment getShellExecutable (BuildOptions options );
@@ -163,23 +90,18 @@ public static ShellExecutableProvider hardcodedShellExecutable(String shell) {
163
90
/** The loader for {@link ShellConfiguration}. */
164
91
public static class Loader implements ConfigurationFragmentFactory {
165
92
private final ShellExecutableProvider shellExecutableProvider ;
166
- private final ShellActionEnvironmentFactory actionEnvironmentFactory ;
167
93
private final ImmutableSet <Class <? extends FragmentOptions >> requiredOptions ;
168
94
169
95
public Loader (ShellExecutableProvider shellExecutableProvider ,
170
- ShellActionEnvironmentFactory actionEnvironmentFactory ,
171
96
Class <? extends FragmentOptions >... requiredOptions ) {
172
97
this .shellExecutableProvider = shellExecutableProvider ;
173
- this .actionEnvironmentFactory = actionEnvironmentFactory ;
174
98
this .requiredOptions = ImmutableSet .copyOf (requiredOptions );
175
99
}
176
100
177
101
@ Nullable
178
102
@ Override
179
103
public Fragment create (ConfigurationEnvironment env , BuildOptions buildOptions ) {
180
- return new ShellConfiguration (
181
- shellExecutableProvider .getShellExecutable (buildOptions ),
182
- actionEnvironmentFactory .fromOptions (buildOptions ));
104
+ return new ShellConfiguration (shellExecutableProvider .getShellExecutable (buildOptions ));
183
105
}
184
106
185
107
public static PathFragment determineShellExecutable (
0 commit comments