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

Gradle: ability to disable worker process isolation, pass all envs+sys-props #32524

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -163,9 +163,7 @@ void generateBuild() {
.collect(Collectors.joining("\n ", "\n ", "")));
}

WorkQueue workQueue = getWorkerExecutor()
.processIsolation(processWorkerSpec -> configureProcessWorkerSpec(processWorkerSpec, effectiveConfig,
extension().buildForkOptions));
WorkQueue workQueue = workQueue(effectiveConfig, () -> extension().buildForkOptions);

workQueue.submit(BuildWorker.class, params -> {
params.getBuildSystemProperties().putAll(effectiveConfig.configMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ public void generateCode() {
getLogger().debug("Will trigger preparing sources for source directory: {} buildDir: {}",
sourcesDirectories, getProject().getBuildDir().getAbsolutePath());

WorkQueue workQueue = getWorkerExecutor()
.processIsolation(processWorkerSpec -> configureProcessWorkerSpec(processWorkerSpec, effectiveConfig,
extension().codeGenForkOptions));
WorkQueue workQueue = workQueue(effectiveConfig, () -> extension().codeGenForkOptions);

workQueue.submit(CodeGenWorker.class, params -> {
params.getBuildSystemProperties().putAll(effectiveConfig.configMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.function.Supplier;

import javax.inject.Inject;

import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.process.JavaForkOptions;
import org.gradle.workers.ProcessWorkerSpec;
import org.gradle.workers.WorkQueue;
import org.gradle.workers.WorkerExecutor;

import io.quarkus.gradle.extension.QuarkusPluginExtension;
Expand All @@ -35,12 +37,34 @@ QuarkusPluginExtension extension() {
return extension;
}

void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, EffectiveConfig effectiveConfig,
WorkQueue workQueue(EffectiveConfig effectiveConfig, Supplier<List<Action<? super JavaForkOptions>>> forkOptionsActions) {
WorkerExecutor workerExecutor = getWorkerExecutor();

// Use process isolation by default, unless Gradle's started with its debugging system property or the
// system property `quarkus.gradle-worker.no-process is set to `true`.
if (Boolean.getBoolean("org.gradle.debug") || Boolean.getBoolean("quarkus.gradle-worker.no-process")) {
return workerExecutor.classLoaderIsolation();
}

return workerExecutor.processIsolation(processWorkerSpec -> configureProcessWorkerSpec(processWorkerSpec,
effectiveConfig, forkOptionsActions.get()));
}

private void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, EffectiveConfig effectiveConfig,
List<Action<? super JavaForkOptions>> customizations) {
JavaForkOptions forkOptions = processWorkerSpec.getForkOptions();

customizations.forEach(a -> a.execute(forkOptions));

// Pass all system properties
System.getProperties().forEach((k, v) -> {
String key = k.toString();
forkOptions.systemProperty(key, v);
});

// Pass all environment variables
forkOptions.environment(System.getenv());

if (OS.determineOS() == OS.WINDOWS) {
// On Windows, gRPC code generation is sometimes(?) unable to find "java.exe". Feels (not proven) that
// the grpc code generation tool looks up "java.exe" instead of consulting the 'JAVA_HOME' environment.
Expand Down