use of org.gradle.nativeplatform.test.cpp.CppTestExecutable in project gradle by gradle.
the class DefaultCppTestSuite method addExecutable.
public CppTestExecutable addExecutable(String variantName, NativeVariantIdentity identity, CppPlatform targetPlatform, NativeToolChainInternal toolChain, PlatformToolProvider platformToolProvider) {
Names executableNames = Names.of(getName() + variantName + "Executable", getName() + variantName);
CppTestExecutable testBinary = objectFactory.newInstance(DefaultCppTestExecutable.class, executableNames, getBaseName(), getCppSource(), getPrivateHeaderDirs(), getImplementationDependencies(), getTestedComponent(), targetPlatform, toolChain, platformToolProvider, identity);
getBinaries().add(testBinary);
return testBinary;
}
use of org.gradle.nativeplatform.test.cpp.CppTestExecutable in project gradle by gradle.
the class CppUnitTestPlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(CppBasePlugin.class);
project.getPluginManager().apply(NativeTestingBasePlugin.class);
final ProviderFactory providers = project.getProviders();
final TaskContainer tasks = project.getTasks();
// Add the unit test and extension
final DefaultCppTestSuite testComponent = componentFactory.newInstance(CppTestSuite.class, DefaultCppTestSuite.class, "test");
project.getExtensions().add(CppTestSuite.class, "unitTest", testComponent);
project.getComponents().add(testComponent);
testComponent.getBaseName().convention(project.getName() + "Test");
testComponent.getTargetMachines().convention(Dimensions.useHostAsDefaultTargetMachine(targetMachineFactory));
final String mainComponentName = "main";
project.getComponents().withType(ProductionCppComponent.class, component -> {
if (mainComponentName.equals(component.getName())) {
testComponent.getTargetMachines().convention(component.getTargetMachines());
testComponent.getTestedComponent().convention(component);
}
});
testComponent.getTestBinary().convention(project.provider(new Callable<CppTestExecutable>() {
@Override
public CppTestExecutable call() throws Exception {
return getAllBuildableTestExecutable().filter(it -> isCurrentArchitecture(it.getNativePlatform())).findFirst().orElse(getAllBuildableTestExecutable().findFirst().orElse(getAllTestExecutable().findFirst().orElse(null)));
}
private boolean isCurrentArchitecture(NativePlatform targetPlatform) {
return targetPlatform.getArchitecture().equals(DefaultNativePlatform.getCurrentArchitecture());
}
private Stream<DefaultCppTestExecutable> getAllBuildableTestExecutable() {
return getAllTestExecutable().filter(it -> it.getPlatformToolProvider().isAvailable());
}
private Stream<DefaultCppTestExecutable> getAllTestExecutable() {
return testComponent.getBinaries().get().stream().filter(CppTestExecutable.class::isInstance).map(DefaultCppTestExecutable.class::cast);
}
}));
testComponent.getBinaries().whenElementKnown(DefaultCppTestExecutable.class, binary -> {
// TODO: Replace with native test task
final TaskProvider<RunTestExecutable> testTask = tasks.register(binary.getNames().getTaskName("run"), RunTestExecutable.class, task -> {
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
task.setDescription("Executes C++ unit tests.");
final InstallExecutable installTask = binary.getInstallTask().get();
task.onlyIf(element -> binary.getInstallDirectory().get().getAsFile().exists());
task.getInputs().dir(binary.getInstallDirectory()).withPropertyName("installDirectory");
task.setExecutable(installTask.getRunScriptFile().get().getAsFile());
task.dependsOn(binary.getInstallDirectory());
// TODO: Honor changes to build directory
task.setOutputDir(project.getLayout().getBuildDirectory().dir("test-results/" + binary.getNames().getDirName()).get().getAsFile());
});
binary.getRunTask().set(testTask);
configureTestSuiteWithTestedComponentWhenAvailable(project, testComponent, binary);
});
project.afterEvaluate(p -> {
final CppComponent mainComponent = testComponent.getTestedComponent().getOrNull();
final SetProperty<TargetMachine> mainTargetMachines = mainComponent != null ? mainComponent.getTargetMachines() : null;
Dimensions.unitTestVariants(testComponent.getBaseName(), testComponent.getTargetMachines(), mainTargetMachines, objectFactory, attributesFactory, providers.provider(() -> project.getGroup().toString()), providers.provider(() -> project.getVersion().toString()), variantIdentity -> {
if (tryToBuildOnHost(variantIdentity)) {
ToolChainSelector.Result<CppPlatform> result = toolChainSelector.select(CppPlatform.class, new DefaultCppPlatform(variantIdentity.getTargetMachine()));
// TODO: Removing `debug` from variant name to keep parity with previous Gradle version in tooling models
CppTestExecutable testExecutable = testComponent.addExecutable(variantIdentity.getName().replace("debug", ""), variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
}
});
// TODO: Publishing for test executable?
testComponent.getBinaries().realizeNow();
});
}
use of org.gradle.nativeplatform.test.cpp.CppTestExecutable in project gradle by gradle.
the class CppModelBuilder method binariesFor.
private List<DefaultCppBinaryModel> binariesFor(CppComponent component, Iterable<File> headerDirs, DefaultProjectIdentifier projectIdentifier, CompilerOutputFileNamingSchemeFactory namingSchemeFactory) {
List<File> headerDirsCopy = ImmutableList.copyOf(headerDirs);
List<DefaultCppBinaryModel> binaries = new ArrayList<DefaultCppBinaryModel>();
for (CppBinary binary : component.getBinaries().get()) {
DefaultCppBinary cppBinary = (DefaultCppBinary) binary;
PlatformToolProvider platformToolProvider = cppBinary.getPlatformToolProvider();
CppCompile compileTask = binary.getCompileTask().get();
List<DefaultSourceFile> sourceFiles = sourceFiles(namingSchemeFactory, platformToolProvider, compileTask.getObjectFileDir().get().getAsFile(), binary.getCppSource().getFiles());
List<File> systemIncludes = ImmutableList.copyOf(compileTask.getSystemIncludes().getFiles());
List<File> userIncludes = ImmutableList.copyOf(compileTask.getIncludes().getFiles());
List<DefaultMacroDirective> macroDefines = macroDefines(compileTask);
List<String> additionalArgs = args(compileTask.getCompilerArgs().get());
CommandLineToolSearchResult compilerLookup = platformToolProvider.locateTool(ToolType.CPP_COMPILER);
File compilerExe = compilerLookup.isAvailable() ? compilerLookup.getTool() : null;
LaunchableGradleTask compileTaskModel = ToolingModelBuilderSupport.buildFromTask(new LaunchableGradleTask(), projectIdentifier, compileTask);
DefaultCompilationDetails compilationDetails = new DefaultCompilationDetails(compileTaskModel, compilerExe, compileTask.getObjectFileDir().get().getAsFile(), sourceFiles, headerDirsCopy, systemIncludes, userIncludes, macroDefines, additionalArgs);
if (binary instanceof CppExecutable || binary instanceof CppTestExecutable) {
ComponentWithExecutable componentWithExecutable = (ComponentWithExecutable) binary;
LinkExecutable linkTask = componentWithExecutable.getLinkTask().get();
LaunchableGradleTask linkTaskModel = ToolingModelBuilderSupport.buildFromTask(new LaunchableGradleTask(), projectIdentifier, componentWithExecutable.getExecutableFileProducer().get());
DefaultLinkageDetails linkageDetails = new DefaultLinkageDetails(linkTaskModel, componentWithExecutable.getExecutableFile().get().getAsFile(), args(linkTask.getLinkerArgs().get()));
binaries.add(new DefaultCppExecutableModel(binary.getName(), cppBinary.getIdentity().getName(), binary.getBaseName().get(), compilationDetails, linkageDetails));
} else if (binary instanceof CppSharedLibrary) {
CppSharedLibrary sharedLibrary = (CppSharedLibrary) binary;
LinkSharedLibrary linkTask = sharedLibrary.getLinkTask().get();
LaunchableGradleTask linkTaskModel = ToolingModelBuilderSupport.buildFromTask(new LaunchableGradleTask(), projectIdentifier, sharedLibrary.getLinkFileProducer().get());
DefaultLinkageDetails linkageDetails = new DefaultLinkageDetails(linkTaskModel, sharedLibrary.getLinkFile().get().getAsFile(), args(linkTask.getLinkerArgs().get()));
binaries.add(new DefaultCppSharedLibraryModel(binary.getName(), cppBinary.getIdentity().getName(), binary.getBaseName().get(), compilationDetails, linkageDetails));
} else if (binary instanceof CppStaticLibrary) {
CppStaticLibrary staticLibrary = (CppStaticLibrary) binary;
LaunchableGradleTask createTaskModel = ToolingModelBuilderSupport.buildFromTask(new LaunchableGradleTask(), projectIdentifier, staticLibrary.getLinkFileProducer().get());
DefaultLinkageDetails linkageDetails = new DefaultLinkageDetails(createTaskModel, staticLibrary.getLinkFile().get().getAsFile(), Collections.<String>emptyList());
binaries.add(new DefaultCppStaticLibraryModel(binary.getName(), cppBinary.getIdentity().getName(), binary.getBaseName().get(), compilationDetails, linkageDetails));
}
}
return binaries;
}
Aggregations