Search in sources :

Example 26 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.

the class DefaultToolChainSelector method select.

public Result<CppPlatform> select(CppPlatform requestPlatform) {
    DefaultNativePlatform targetNativePlatform = newNativePlatform(requestPlatform.getTargetMachine());
    // TODO - push all this stuff down to the tool chain and let it create the specific platform and provider
    NativeLanguage sourceLanguage = NativeLanguage.CPP;
    NativeToolChainInternal toolChain = getToolChain(sourceLanguage, targetNativePlatform);
    // TODO - don't select again here, as the selection is already performed to select the toolchain
    PlatformToolProvider toolProvider = toolChain.select(sourceLanguage, targetNativePlatform);
    CppPlatform targetPlatform = new DefaultCppPlatform(requestPlatform.getTargetMachine(), targetNativePlatform);
    return new DefaultResult<CppPlatform>(toolChain, toolProvider, targetPlatform);
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) CppPlatform(org.gradle.language.cpp.CppPlatform) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) NativeLanguage(org.gradle.nativeplatform.toolchain.internal.NativeLanguage) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform)

Example 27 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.

the class AbstractGccCompatibleToolChain method select.

@Override
public PlatformToolProvider select(NativeLanguage sourceLanguage, NativePlatformInternal targetMachine) {
    PlatformToolProvider toolProvider = getProviderForPlatform(targetMachine);
    switch(sourceLanguage) {
        case CPP:
            if (toolProvider instanceof UnsupportedPlatformToolProvider) {
                return toolProvider;
            }
            ToolSearchResult cppCompiler = toolProvider.locateTool(ToolType.CPP_COMPILER);
            if (cppCompiler.isAvailable()) {
                return toolProvider;
            }
            // No C++ compiler, complain about it
            return new UnavailablePlatformToolProvider(targetMachine.getOperatingSystem(), cppCompiler);
        case ANY:
            if (toolProvider instanceof UnsupportedPlatformToolProvider) {
                return toolProvider;
            }
            ToolSearchResult cCompiler = toolProvider.locateTool(ToolType.C_COMPILER);
            if (cCompiler.isAvailable()) {
                return toolProvider;
            }
            ToolSearchResult compiler = toolProvider.locateTool(ToolType.CPP_COMPILER);
            if (compiler.isAvailable()) {
                return toolProvider;
            }
            compiler = toolProvider.locateTool(ToolType.OBJECTIVEC_COMPILER);
            if (compiler.isAvailable()) {
                return toolProvider;
            }
            compiler = toolProvider.locateTool(ToolType.OBJECTIVECPP_COMPILER);
            if (compiler.isAvailable()) {
                return toolProvider;
            }
            // No compilers available, complain about the missing C compiler
            return new UnavailablePlatformToolProvider(targetMachine.getOperatingSystem(), cCompiler);
        default:
            return new UnsupportedPlatformToolProvider(targetMachine.getOperatingSystem(), String.format("Don't know how to compile language %s.", sourceLanguage));
    }
}
Also used : UnavailablePlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnavailablePlatformToolProvider) UnavailablePlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnavailablePlatformToolProvider) UnsupportedPlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnsupportedPlatformToolProvider) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) ToolSearchResult(org.gradle.platform.base.internal.toolchain.ToolSearchResult) CommandLineToolSearchResult(org.gradle.nativeplatform.toolchain.internal.tools.CommandLineToolSearchResult) UnsupportedPlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnsupportedPlatformToolProvider)

Example 28 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.

the class AbstractGccCompatibleToolChain method getProviderForPlatform.

private PlatformToolProvider getProviderForPlatform(NativePlatformInternal targetPlatform) {
    PlatformToolProvider toolProvider = toolProviders.get(targetPlatform);
    if (toolProvider == null) {
        toolProvider = createPlatformToolProvider(targetPlatform);
        toolProviders.put(targetPlatform, toolProvider);
    }
    return toolProvider;
}
Also used : UnavailablePlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnavailablePlatformToolProvider) UnsupportedPlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnsupportedPlatformToolProvider) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)

Example 29 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider 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;
}
Also used : ArrayList(java.util.ArrayList) LinkSharedLibrary(org.gradle.nativeplatform.tasks.LinkSharedLibrary) CppStaticLibrary(org.gradle.language.cpp.CppStaticLibrary) CommandLineToolSearchResult(org.gradle.nativeplatform.toolchain.internal.tools.CommandLineToolSearchResult) CppSharedLibrary(org.gradle.language.cpp.CppSharedLibrary) ComponentWithExecutable(org.gradle.language.nativeplatform.ComponentWithExecutable) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) CppBinary(org.gradle.language.cpp.CppBinary) CppExecutable(org.gradle.language.cpp.CppExecutable) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) LaunchableGradleTask(org.gradle.plugins.ide.internal.tooling.model.LaunchableGradleTask) LinkExecutable(org.gradle.nativeplatform.tasks.LinkExecutable) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) CppCompile(org.gradle.language.cpp.tasks.CppCompile) File(java.io.File) CppTestExecutable(org.gradle.nativeplatform.test.cpp.CppTestExecutable)

Aggregations

PlatformToolProvider (org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)29 NativeToolChainInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal)20 NativePlatformInternal (org.gradle.nativeplatform.platform.internal.NativePlatformInternal)10 File (java.io.File)7 Project (org.gradle.api.Project)7 Names (org.gradle.language.nativeplatform.internal.Names)6 Callable (java.util.concurrent.Callable)5 RegularFile (org.gradle.api.file.RegularFile)5 TaskContainer (org.gradle.api.tasks.TaskContainer)5 DefaultNativePlatform (org.gradle.nativeplatform.platform.internal.DefaultNativePlatform)5 NativeToolChain (org.gradle.nativeplatform.toolchain.NativeToolChain)5 Inject (javax.inject.Inject)4 Plugin (org.gradle.api.Plugin)4 FileCollection (org.gradle.api.file.FileCollection)4 ObjectFactory (org.gradle.api.model.ObjectFactory)4 Provider (org.gradle.api.provider.Provider)4 TaskProvider (org.gradle.api.tasks.TaskProvider)4 LifecycleBasePlugin (org.gradle.language.base.plugins.LifecycleBasePlugin)4 TargetMachine (org.gradle.nativeplatform.TargetMachine)4 TargetMachineFactory (org.gradle.nativeplatform.TargetMachineFactory)4