Search in sources :

Example 1 with SwiftApplication

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);
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) Arrays(java.util.Arrays) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) GUtil(org.gradle.util.internal.GUtil) Provider(org.gradle.api.provider.Provider) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite) TaskProvider(org.gradle.api.tasks.TaskProvider) XCTest(org.gradle.nativeplatform.test.xctest.tasks.XCTest) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) SwiftBasePlugin(org.gradle.language.swift.plugins.SwiftBasePlugin) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) MacOSSdkPlatformPathLocator(org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPlatformPathLocator) TaskContainer(org.gradle.api.tasks.TaskContainer) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) SwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.SwiftXCTestBinary) DefaultSwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary) NativeTestingBasePlugin(org.gradle.nativeplatform.test.plugins.NativeTestingBasePlugin) Dimensions.useHostAsDefaultTargetMachine(org.gradle.language.nativeplatform.internal.Dimensions.useHostAsDefaultTargetMachine) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) Inject(javax.inject.Inject) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Lists(com.google.common.collect.Lists) Sync(org.gradle.api.tasks.Sync) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) SwiftApplication(org.gradle.language.swift.SwiftApplication) SwiftComponent(org.gradle.language.swift.SwiftComponent) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) File(java.io.File) SetProperty(org.gradle.api.provider.SetProperty) ProviderFactory(org.gradle.api.provider.ProviderFactory) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) ObjectFactory(org.gradle.api.model.ObjectFactory) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) RegularFile(org.gradle.api.file.RegularFile) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) SwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.SwiftXCTestSuite) TaskContainer(org.gradle.api.tasks.TaskContainer) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) Dependency(org.gradle.api.artifacts.Dependency) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftComponent(org.gradle.language.swift.SwiftComponent) SwiftApplication(org.gradle.language.swift.SwiftApplication)

Aggregations

Lists (com.google.common.collect.Lists)1 File (java.io.File)1 Arrays (java.util.Arrays)1 Inject (javax.inject.Inject)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Dependency (org.gradle.api.artifacts.Dependency)1 ConfigurableFileCollection (org.gradle.api.file.ConfigurableFileCollection)1 RegularFile (org.gradle.api.file.RegularFile)1 ImmutableAttributesFactory (org.gradle.api.internal.attributes.ImmutableAttributesFactory)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 ObjectFactory (org.gradle.api.model.ObjectFactory)1 Provider (org.gradle.api.provider.Provider)1 ProviderFactory (org.gradle.api.provider.ProviderFactory)1 SetProperty (org.gradle.api.provider.SetProperty)1 Sync (org.gradle.api.tasks.Sync)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 TaskProvider (org.gradle.api.tasks.TaskProvider)1 LifecycleBasePlugin (org.gradle.language.base.plugins.LifecycleBasePlugin)1 NativeComponentFactory (org.gradle.language.internal.NativeComponentFactory)1