use of org.gradle.language.swift.SwiftApplication in project gradle by gradle.
the class XCTestConventionPlugin method configureTestSuiteWithTestedComponentWhenAvailable.
private void configureTestSuiteWithTestedComponentWhenAvailable(final Project project, final DefaultSwiftXCTestSuite testSuite, final DefaultSwiftXCTestBinary testExecutable) {
SwiftComponent target = testSuite.getTestedComponent().getOrNull();
if (!(target instanceof ProductionSwiftComponent)) {
return;
}
final ProductionSwiftComponent testedComponent = (ProductionSwiftComponent) target;
final TaskContainer tasks = project.getTasks();
testedComponent.getBinaries().whenElementFinalized(testedBinary -> {
if (testedBinary != testedComponent.getDevelopmentBinary().get()) {
return;
}
// Setup the dependency on the main binary
// This should all be replaced by a single dependency that points at some "testable" variants of the main binary
// Inherit implementation dependencies
testExecutable.getImplementationDependencies().extendsFrom(((DefaultSwiftBinary) testedBinary).getImplementationDependencies());
// Configure test binary to compile against binary under test
Dependency compileDependency = project.getDependencies().create(project.files(testedBinary.getModuleFile()));
testExecutable.getImportPathConfiguration().getDependencies().add(compileDependency);
// Configure test binary to link against tested component compiled objects
ConfigurableFileCollection testableObjects = project.files();
if (testedComponent instanceof SwiftApplication) {
TaskProvider<UnexportMainSymbol> unexportMainSymbol = tasks.register("relocateMainForTest", UnexportMainSymbol.class, task -> {
String dirName = ((DefaultSwiftBinary) testedBinary).getNames().getDirName();
task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("obj/for-test/" + dirName));
task.getObjects().from(testedBinary.getObjects());
});
testableObjects.from(unexportMainSymbol.map(task -> task.getRelocatedObjects()));
} else {
testableObjects.from(testedBinary.getObjects());
}
Dependency linkDependency = project.getDependencies().create(testableObjects);
testExecutable.getLinkConfiguration().getDependencies().add(linkDependency);
});
}
Aggregations