use of org.graalvm.buildtools.utils.SharedConstants.AGENT_OUTPUT_FOLDER in project native-build-tools by graalvm.
the class NativeImagePlugin method configureAgent.
private static void configureAgent(Project project, Map<String, Provider<Boolean>> agents, Provider<Boolean> disableToolchainDetection, NativeImageOptions nativeImageOptions, ExecOperations execOperations, FileSystemOperations fileOperations) {
String postProcessTaskName = PROCESS_AGENT_RESOURCES_TASK_NAME_PREFIX + capitalize(nativeImageOptions.getName()) + PROCESS_AGENT_RESOURCES_TASK_NAME_SUFFIX;
TaskProvider<ProcessGeneratedGraalResourceFiles> postProcessingTask = registerProcessAgentFilesTask(project, postProcessTaskName);
TaskProvider<? extends JavaForkOptions> instrumentedTask = nativeImageOptions.getAgent().getInstrumentedTask().get();
AgentCommandLineProvider cliProvider = project.getObjects().newInstance(AgentCommandLineProvider.class);
Provider<Boolean> agent = agents.get(nativeImageOptions.getName());
cliProvider.getEnabled().set(agent);
Provider<Directory> outputDir = project.getLayout().getBuildDirectory().dir(AGENT_OUTPUT_FOLDER + "/" + instrumentedTask.getName());
cliProvider.getOutputDirectory().set(outputDir);
cliProvider.getAgentOptions().set(nativeImageOptions.getAgent().getOptions());
instrumentedTask.get().getJvmArgumentProviders().add(cliProvider);
instrumentedTask.configure(task -> task.doLast(new MergeAgentFiles(agent, graalvmHomeProvider(project.getProviders()), outputDir, disableToolchainDetection, nativeImageOptions, execOperations, fileOperations, project.getLogger())));
// Gradle won't let us configure from configure so we have to eagerly create the post-processing task :(
postProcessingTask.get().getGeneratedFilesDir().set(instrumentedTask.map(t -> outputDir.get()));
// We can't set from(postProcessingTask) directly, otherwise a task
// dependency would be introduced even if the agent is not enabled.
// We should be able to write this:
// nativeImageOptions.getConfigurationFileDirectories().from(
// agent.map(enabled -> enabled ? postProcessingTask : project.files())
// )
// but Gradle won't track the postProcessingTask dependency so we have to write this:
ConfigurableFileCollection files = project.getObjects().fileCollection();
files.from(agent.map(enabled -> enabled ? postProcessingTask : project.files()));
files.builtBy((Callable<Task>) () -> agent.get() ? postProcessingTask.get() : null);
nativeImageOptions.getConfigurationFileDirectories().from(files);
}
Aggregations