use of org.graalvm.buildtools.gradle.internal.NativeConfigurations in project native-build-tools by graalvm.
the class NativeImagePlugin method createNativeConfigurations.
@SuppressWarnings("unchecked")
private static NativeConfigurations createNativeConfigurations(Project project, String binaryName, String baseClasspathConfigurationName) {
ConfigurationContainer configurations = project.getConfigurations();
String prefix = "main".equals(binaryName) ? "" : capitalize(binaryName);
Configuration baseClasspath = configurations.getByName(baseClasspathConfigurationName);
Configuration compileOnly = configurations.create("nativeImage" + prefix + "CompileOnly", c -> {
c.setCanBeResolved(false);
c.setCanBeConsumed(false);
});
Configuration classpath = configurations.create("nativeImage" + prefix + "Classpath", c -> {
c.setCanBeConsumed(false);
c.setCanBeResolved(true);
c.extendsFrom(compileOnly);
baseClasspath.getExtendsFrom().forEach(c::extendsFrom);
c.attributes(attrs -> {
AttributeContainer baseAttributes = baseClasspath.getAttributes();
for (Attribute<?> attribute : baseAttributes.keySet()) {
Attribute<Object> attr = (Attribute<Object>) attribute;
Object value = baseAttributes.getAttribute(attr);
attrs.attribute(attr, value);
}
});
});
compileOnly.getDependencies().add(project.getDependencies().create(project));
return new NativeConfigurations(compileOnly, classpath);
}
use of org.graalvm.buildtools.gradle.internal.NativeConfigurations in project native-build-tools by graalvm.
the class NativeImagePlugin method createMainOptions.
private static NativeImageOptions createMainOptions(GraalVMExtension graalExtension, Project project) {
NativeImageOptions buildExtension = graalExtension.getBinaries().create(NATIVE_MAIN_EXTENSION);
NativeConfigurations configs = createNativeConfigurations(project, "main", JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
buildExtension.getClasspath().from(configs.getImageClasspathConfiguration());
return buildExtension;
}
use of org.graalvm.buildtools.gradle.internal.NativeConfigurations 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;
}
Aggregations