Search in sources :

Example 1 with UnexportMainSymbol

use of org.gradle.language.swift.tasks.UnexportMainSymbol 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(new Action<SwiftBinary>() {

        @Override
        public void execute(SwiftBinary testedBinary) {
            if (testedBinary != testedComponent.getDevelopmentBinary().get()) {
                return;
            }
            // If nothing was configured for the test suite source compatibility, use the tested component one.
            if (testSuite.getSourceCompatibility().getOrNull() == null) {
                testExecutable.getSourceCompatibility().set(testedBinary.getSourceCompatibility());
            }
            // Configure test suite link task from tested component compiled objects
            final AbstractLinkTask linkTest = testExecutable.getLinkTask().get();
            if (testedComponent instanceof SwiftApplication) {
                final UnexportMainSymbol unexportMainSymbol = tasks.create("relocateMainForTest", UnexportMainSymbol.class);
                unexportMainSymbol.source(testedBinary.getObjects());
                linkTest.source(testedBinary.getObjects().filter(new Spec<File>() {

                    @Override
                    public boolean isSatisfiedBy(File objectFile) {
                        return !objectFile.equals(unexportMainSymbol.getMainObject());
                    }
                }));
                linkTest.source(unexportMainSymbol.getObjects());
            } else {
                linkTest.source(testedBinary.getObjects());
            }
        }
    });
}
Also used : TaskContainer(org.gradle.api.tasks.TaskContainer) SwiftBinary(org.gradle.language.swift.SwiftBinary) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) UnexportMainSymbol(org.gradle.language.swift.tasks.UnexportMainSymbol) AbstractLinkTask(org.gradle.nativeplatform.tasks.AbstractLinkTask) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftComponent(org.gradle.language.swift.SwiftComponent) SwiftApplication(org.gradle.language.swift.SwiftApplication)

Aggregations

File (java.io.File)1 RegularFile (org.gradle.api.file.RegularFile)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 ProductionSwiftComponent (org.gradle.language.swift.ProductionSwiftComponent)1 SwiftApplication (org.gradle.language.swift.SwiftApplication)1 SwiftBinary (org.gradle.language.swift.SwiftBinary)1 SwiftComponent (org.gradle.language.swift.SwiftComponent)1 UnexportMainSymbol (org.gradle.language.swift.tasks.UnexportMainSymbol)1 AbstractLinkTask (org.gradle.nativeplatform.tasks.AbstractLinkTask)1