use of org.graalvm.buildtools.gradle.dsl.GraalVMExtension in project native-build-tools by graalvm.
the class NativeImagePlugin method configureAutomaticTaskCreation.
private void configureAutomaticTaskCreation(Project project, GraalVMExtension graalExtension, Map<String, Provider<Boolean>> agents, TaskContainer tasks, SourceSetContainer sourceSets) {
graalExtension.getBinaries().configureEach(options -> {
String binaryName = options.getName();
String compileTaskName = deriveTaskName(binaryName, "native", "Compile");
if ("main".equals(binaryName)) {
compileTaskName = NATIVE_COMPILE_TASK_NAME;
}
Provider<Boolean> agent = agentPropertyOverride(project, options);
agents.put(binaryName, agent);
TaskProvider<BuildNativeImageTask> imageBuilder = tasks.register(compileTaskName, BuildNativeImageTask.class, builder -> {
builder.setDescription("Compiles a native image for the " + options.getName() + " binary");
builder.setGroup(LifecycleBasePlugin.BUILD_GROUP);
builder.getOptions().convention(options);
builder.getAgentEnabled().set(agent);
builder.getUseArgFile().convention(graalExtension.getUseArgFile());
});
String runTaskName = deriveTaskName(binaryName, "native", "Run");
if ("main".equals(binaryName)) {
runTaskName = NativeRunTask.TASK_NAME;
} else if (binaryName.toLowerCase(Locale.US).endsWith("test")) {
runTaskName = "native" + capitalize(binaryName);
}
tasks.register(runTaskName, NativeRunTask.class, task -> {
task.setGroup(LifecycleBasePlugin.BUILD_GROUP);
task.setDescription("Executes the " + options.getName() + " native binary");
task.getImage().convention(imageBuilder.map(t -> t.getOutputFile().get()));
task.getRuntimeArgs().convention(options.getRuntimeArgs());
});
configureClasspathJarFor(tasks, options, imageBuilder);
SourceSet sourceSet = "test".equals(binaryName) ? sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME) : sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
TaskProvider<GenerateResourcesConfigFile> generateResourcesConfig = registerResourcesConfigTask(graalExtension.getGeneratedResourcesDirectory(), options, tasks, transitiveProjectArtifacts(project, sourceSet.getRuntimeClasspathConfigurationName()), deriveTaskName(binaryName, "generate", "ResourcesConfigFile"));
options.getConfigurationFileDirectories().from(generateResourcesConfig.map(t -> t.getOutputFile().map(f -> f.getAsFile().getParentFile())));
configureJvmReachabilityConfigurationDirectories(project, graalExtension, options, sourceSet);
});
}
use of org.graalvm.buildtools.gradle.dsl.GraalVMExtension in project native-build-tools by graalvm.
the class NativeImagePlugin method createTestOptions.
private static NativeImageOptions createTestOptions(GraalVMExtension graalExtension, String binaryName, Project project, NativeImageOptions mainExtension, DirectoryProperty testListDirectory, SourceSet sourceSet) {
NativeImageOptions testExtension = graalExtension.getBinaries().create(binaryName);
NativeConfigurations configs = createNativeConfigurations(project, binaryName, JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
testExtension.getMainClass().set("org.graalvm.junit.platform.NativeImageJUnitLauncher");
testExtension.getMainClass().finalizeValue();
testExtension.getImageName().convention(mainExtension.getImageName().map(name -> name + SharedConstants.NATIVE_TESTS_SUFFIX));
ListProperty<String> runtimeArgs = testExtension.getRuntimeArgs();
runtimeArgs.add("--xml-output-dir");
runtimeArgs.add(project.getLayout().getBuildDirectory().dir("test-results/" + binaryName + "-native").map(d -> d.getAsFile().getAbsolutePath()));
testExtension.buildArgs("--features=org.graalvm.junit.platform.JUnitPlatformFeature");
ConfigurableFileCollection classpath = testExtension.getClasspath();
classpath.from(configs.getImageClasspathConfiguration());
classpath.from(sourceSet.getOutput().getClassesDirs());
classpath.from(sourceSet.getOutput().getResourcesDir());
return testExtension;
}
use of org.graalvm.buildtools.gradle.dsl.GraalVMExtension in project native-build-tools by graalvm.
the class NativeImagePlugin method registerGraalVMExtension.
private GraalVMExtension registerGraalVMExtension(Project project) {
NamedDomainObjectContainer<NativeImageOptions> nativeImages = project.getObjects().domainObjectContainer(NativeImageOptions.class, name -> project.getObjects().newInstance(BaseNativeImageOptions.class, name, project.getObjects(), project.getProviders(), project.getExtensions().findByType(JavaToolchainService.class), project.getName()));
GraalVMExtension graalvmNative = project.getExtensions().create(GraalVMExtension.class, "graalvmNative", DefaultGraalVmExtension.class, nativeImages, this, project);
graalvmNative.getGeneratedResourcesDirectory().set(project.getLayout().getBuildDirectory().dir("native/generated/"));
configureNativeConfigurationRepo((ExtensionAware) graalvmNative);
return graalvmNative;
}
Aggregations