14
14
package com .google .devtools .build .lib .rules .java ;
15
15
16
16
import static com .google .common .collect .ImmutableList .toImmutableList ;
17
+ import static java .util .Objects .requireNonNull ;
17
18
18
19
import com .google .common .base .Function ;
19
20
import com .google .common .base .Preconditions ;
30
31
import com .google .devtools .build .lib .analysis .actions .SpawnAction ;
31
32
import com .google .devtools .build .lib .collect .nestedset .NestedSet ;
32
33
import com .google .devtools .build .lib .collect .nestedset .NestedSetBuilder ;
34
+ import com .google .devtools .build .lib .collect .nestedset .Order ;
33
35
import com .google .devtools .build .lib .packages .RuleClass .ConfiguredTargetFactory .RuleErrorException ;
34
36
import com .google .devtools .build .lib .packages .TargetUtils ;
35
37
import com .google .devtools .build .lib .rules .cpp .CppHelper ;
36
38
import com .google .devtools .build .lib .rules .java .JavaConfiguration .OneVersionEnforcementLevel ;
39
+ import com .google .devtools .build .lib .vfs .PathFragment ;
37
40
import java .util .HashSet ;
38
41
import java .util .Set ;
39
42
import javax .annotation .Nullable ;
@@ -70,6 +73,9 @@ public class DeployArchiveBuilder {
70
73
@ Nullable private Artifact oneVersionAllowlistArtifact ;
71
74
@ Nullable private Artifact sharedArchive ;
72
75
private boolean multiReleaseDeployJars ;
76
+ @ Nullable private PathFragment javaHome ;
77
+ @ Nullable private Artifact libModules ;
78
+ private NestedSet <Artifact > hermeticInputs = NestedSetBuilder .emptySet (Order .STABLE_ORDER );
73
79
74
80
/** Type of compression to apply to output archive. */
75
81
public enum Compression {
@@ -180,6 +186,21 @@ public DeployArchiveBuilder setSharedArchive(@Nullable Artifact sharedArchive) {
180
186
return this ;
181
187
}
182
188
189
+ public DeployArchiveBuilder setJavaHome (PathFragment javaHome ) {
190
+ this .javaHome = requireNonNull (javaHome );
191
+ return this ;
192
+ }
193
+
194
+ public DeployArchiveBuilder setLibModules (@ Nullable Artifact libModules ) {
195
+ this .libModules = libModules ;
196
+ return this ;
197
+ }
198
+
199
+ public DeployArchiveBuilder setHermeticInputs (NestedSet <Artifact > hermeticInputs ) {
200
+ this .hermeticInputs = requireNonNull (hermeticInputs );
201
+ return this ;
202
+ }
203
+
183
204
public static CustomCommandLine .Builder defaultSingleJarCommandLineWithoutOneVersion (
184
205
Artifact outputJar ,
185
206
String javaMainClass ,
@@ -190,7 +211,10 @@ public static CustomCommandLine.Builder defaultSingleJarCommandLineWithoutOneVer
190
211
boolean includeBuildData ,
191
212
Compression compress ,
192
213
Artifact launcher ,
193
- boolean multiReleaseDeployJars ) {
214
+ boolean multiReleaseDeployJars ,
215
+ PathFragment javaHome ,
216
+ Artifact libModules ,
217
+ NestedSet <Artifact > hermeticInputs ) {
194
218
return defaultSingleJarCommandLine (
195
219
outputJar ,
196
220
javaMainClass ,
@@ -203,7 +227,10 @@ public static CustomCommandLine.Builder defaultSingleJarCommandLineWithoutOneVer
203
227
launcher ,
204
228
OneVersionEnforcementLevel .OFF ,
205
229
null ,
206
- /* multiReleaseDeployJars= */ multiReleaseDeployJars );
230
+ /* multiReleaseDeployJars= */ multiReleaseDeployJars ,
231
+ javaHome ,
232
+ libModules ,
233
+ hermeticInputs );
207
234
}
208
235
209
236
public static CustomCommandLine .Builder defaultSingleJarCommandLine (
@@ -218,7 +245,10 @@ public static CustomCommandLine.Builder defaultSingleJarCommandLine(
218
245
Artifact launcher ,
219
246
OneVersionEnforcementLevel oneVersionEnforcementLevel ,
220
247
@ Nullable Artifact oneVersionAllowlistArtifact ,
221
- boolean multiReleaseDeployJars ) {
248
+ boolean multiReleaseDeployJars ,
249
+ PathFragment javaHome ,
250
+ Artifact libModules ,
251
+ NestedSet <Artifact > hermeticInputs ) {
222
252
223
253
CustomCommandLine .Builder args = CustomCommandLine .builder ();
224
254
args .addExecPath ("--output" , outputJar );
@@ -265,6 +295,9 @@ public static CustomCommandLine.Builder defaultSingleJarCommandLine(
265
295
if (multiReleaseDeployJars ) {
266
296
args .add ("--multi_release" );
267
297
}
298
+ args .addPath ("--hermetic_java_home" , javaHome );
299
+ args .addExecPath ("--jdk_lib_modules" , libModules );
300
+ args .addExecPaths ("--resources" , hermeticInputs );
268
301
return args ;
269
302
}
270
303
@@ -347,6 +380,10 @@ public void build() throws InterruptedException {
347
380
if (sharedArchive != null ) {
348
381
inputs .add (sharedArchive );
349
382
}
383
+ inputs .addTransitive (hermeticInputs );
384
+ if (libModules != null ) {
385
+ inputs .add (libModules );
386
+ }
350
387
351
388
Artifact singlejar = JavaToolchainProvider .from (ruleContext ).getSingleJar ();
352
389
@@ -374,7 +411,10 @@ public void build() throws InterruptedException {
374
411
oneVersionEnforcementLevel ,
375
412
oneVersionAllowlistArtifact ,
376
413
sharedArchive ,
377
- /* multiReleaseDeployJars= */ multiReleaseDeployJars );
414
+ /* multiReleaseDeployJars= */ multiReleaseDeployJars ,
415
+ javaHome ,
416
+ libModules ,
417
+ hermeticInputs );
378
418
if (checkDesugarDeps ) {
379
419
commandLine = CommandLine .concat (commandLine , ImmutableList .of ("--check_desugar_deps" ));
380
420
}
0 commit comments