Search in sources :

Example 1 with DefaultNativePlatform

use of org.gradle.nativeplatform.platform.internal.DefaultNativePlatform in project gradle by gradle.

the class XCTestConventionPlugin method configureTestSuiteBuildingTasks.

private void configureTestSuiteBuildingTasks(ProjectInternal project, final DefaultSwiftXCTestBinary binary) {
    if (binary instanceof SwiftXCTestBundle) {
        TaskContainer tasks = project.getTasks();
        final Names names = binary.getNames();
        SwiftCompile compile = binary.getCompileTask().get();
        // TODO - creating a bundle should be done by some general purpose plugin
        // TODO - make this lazy
        DefaultNativePlatform currentPlatform = new DefaultNativePlatform("current");
        final ModelRegistry modelRegistry = project.getModelRegistry();
        NativeToolChain toolChain = modelRegistry.realize("toolChains", NativeToolChainRegistryInternal.class).getForPlatform(currentPlatform);
        // Platform specific arguments
        compile.getCompilerArgs().addAll(project.provider(new Callable<List<String>>() {

            @Override
            public List<String> call() {
                File frameworkDir = new File(sdkPlatformPathLocator.find(), "Developer/Library/Frameworks");
                return Arrays.asList("-parse-as-library", "-F" + frameworkDir.getAbsolutePath());
            }
        }));
        // Add a link task
        final LinkMachOBundle link = tasks.create(names.getTaskName("link"), LinkMachOBundle.class);
        link.getLinkerArgs().set(project.provider(new Callable<List<String>>() {

            @Override
            public List<String> call() {
                File frameworkDir = new File(sdkPlatformPathLocator.find(), "Developer/Library/Frameworks");
                return Lists.newArrayList("-F" + frameworkDir.getAbsolutePath(), "-framework", "XCTest", "-Xlinker", "-rpath", "-Xlinker", "@executable_path/../Frameworks", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/../Frameworks");
            }
        }));
        InstallXCTestBundle install = tasks.create(names.getTaskName("install"), InstallXCTestBundle.class);
        install.getBundleBinaryFile().set(link.getLinkedFile());
        install.getInstallDirectory().set(project.getLayout().getBuildDirectory().dir("install/" + names.getDirName()));
        binary.getInstallDirectory().set(install.getInstallDirectory());
        link.source(binary.getObjects());
        link.lib(binary.getLinkLibraries());
        final PlatformToolProvider toolProvider = ((NativeToolChainInternal) toolChain).select(currentPlatform);
        Provider<RegularFile> exeLocation = project.getLayout().getBuildDirectory().file(project.getProviders().provider(new Callable<String>() {

            @Override
            public String call() {
                return toolProvider.getExecutableName("exe/" + names.getDirName() + binary.getBaseName().get());
            }
        }));
        link.getLinkedFile().set(exeLocation);
        link.getTargetPlatform().set(currentPlatform);
        link.getToolChain().set(toolChain);
        link.getDebuggable().set(binary.isDebuggable());
        binary.getExecutableFile().set(link.getLinkedFile());
        DefaultSwiftXCTestBundle bundle = (DefaultSwiftXCTestBundle) binary;
        bundle.getLinkTask().set(link);
        bundle.getRunScriptFile().set(install.getRunScriptFile());
    } else {
        DefaultSwiftXCTestExecutable executable = (DefaultSwiftXCTestExecutable) binary;
        executable.getRunScriptFile().set(executable.getInstallTask().get().getRunScriptFile());
    }
}
Also used : DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) RegularFile(org.gradle.api.file.RegularFile) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) Callable(java.util.concurrent.Callable) Names(org.gradle.language.nativeplatform.internal.Names) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) TaskContainer(org.gradle.api.tasks.TaskContainer) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Example 2 with DefaultNativePlatform

use of org.gradle.nativeplatform.platform.internal.DefaultNativePlatform in project gradle by gradle.

the class DefaultToolChainSelector method select.

@Override
public <T extends NativePlatform> Result<T> select(Class<T> platformType) {
    DefaultNativePlatform targetMachine = host;
    // TODO - push all this stuff down to the tool chain and let it create the specific platform and provider
    NativeLanguage sourceLanguage = platformType == SwiftPlatform.class ? NativeLanguage.SWIFT : NativeLanguage.CPP;
    NativeToolChainRegistryInternal registry = modelRegistry.realize("toolChains", NativeToolChainRegistryInternal.class);
    NativeToolChainInternal toolChain = registry.getForPlatform(sourceLanguage, targetMachine);
    // TODO - don't select again here, as the selection is already performed to select the toolchain
    PlatformToolProvider toolProvider = toolChain.select(sourceLanguage, targetMachine);
    if (!toolProvider.isAvailable() && targetMachine.getOperatingSystem().isWindows() && targetMachine.getArchitecture().isAmd64()) {
        // Try building x86 on Windows. Don't do this for other operating systems (yet)
        DefaultNativePlatform x86platformRequest = targetMachine.withArchitecture(Architectures.of(Architectures.X86));
        NativeToolChainInternal x86ToolChain = registry.getForPlatform(sourceLanguage, x86platformRequest);
        // TODO - don't select again here, as the selection is already performed to select the toolchain
        PlatformToolProvider x86ToolProvider = x86ToolChain.select(sourceLanguage, x86platformRequest);
        if (x86ToolProvider.isAvailable()) {
            targetMachine = x86platformRequest;
            toolChain = x86ToolChain;
            toolProvider = x86ToolProvider;
        }
    }
    // TODO - use a better name for the platforms, rather than "current"
    T targetPlatform = null;
    if (CppPlatform.class.isAssignableFrom(platformType)) {
        targetPlatform = platformType.cast(new DefaultCppPlatform("host", targetMachine));
    } else if (SwiftPlatform.class.isAssignableFrom(platformType)) {
        targetPlatform = platformType.cast(new DefaultSwiftPlatform("host", targetMachine));
    }
    return new DefaultResult<T>(toolChain, toolProvider, targetPlatform);
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) NativeLanguage(org.gradle.nativeplatform.toolchain.internal.NativeLanguage) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform)

Aggregations

DefaultNativePlatform (org.gradle.nativeplatform.platform.internal.DefaultNativePlatform)2 NativeToolChainInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal)2 NativeToolChainRegistryInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal)2 PlatformToolProvider (org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)2 File (java.io.File)1 Callable (java.util.concurrent.Callable)1 RegularFile (org.gradle.api.file.RegularFile)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 DefaultCppPlatform (org.gradle.language.cpp.internal.DefaultCppPlatform)1 Names (org.gradle.language.nativeplatform.internal.Names)1 SwiftPlatform (org.gradle.language.swift.SwiftPlatform)1 DefaultSwiftPlatform (org.gradle.language.swift.internal.DefaultSwiftPlatform)1 SwiftCompile (org.gradle.language.swift.tasks.SwiftCompile)1 ModelRegistry (org.gradle.model.internal.registry.ModelRegistry)1 LinkMachOBundle (org.gradle.nativeplatform.tasks.LinkMachOBundle)1 SwiftXCTestBundle (org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle)1 DefaultSwiftXCTestBundle (org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle)1 DefaultSwiftXCTestExecutable (org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable)1 InstallXCTestBundle (org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle)1 NativeToolChain (org.gradle.nativeplatform.toolchain.NativeToolChain)1