Search in sources :

Example 1 with LinkSharedLibrary

use of org.gradle.nativeplatform.tasks.LinkSharedLibrary in project gradle by gradle.

the class NativeBasePlugin method addTasksForComponentWithSharedLibrary.

private void addTasksForComponentWithSharedLibrary(final TaskContainer tasks, final DirectoryProperty buildDirectory, SoftwareComponentContainer components) {
    components.withType(ConfigurableComponentWithSharedLibrary.class, library -> {
        final Names names = library.getNames();
        final NativePlatform targetPlatform = library.getNativePlatform();
        final NativeToolChain toolChain = library.getToolChain();
        final PlatformToolProvider toolProvider = library.getPlatformToolProvider();
        // Add a link task
        final TaskProvider<LinkSharedLibrary> link = tasks.register(names.getTaskName("link"), LinkSharedLibrary.class, task -> {
            task.source(library.getObjects());
            task.lib(library.getLinkLibraries());
            task.getLinkedFile().set(buildDirectory.file(library.getBaseName().map(baseName -> toolProvider.getSharedLibraryName("lib/" + names.getDirName() + baseName))));
            // when Swift depends on C++ libraries built by Gradle.
            if (!targetPlatform.getOperatingSystem().isMacOsX()) {
                Provider<String> installName = task.getLinkedFile().getLocationOnly().map(linkedFile -> linkedFile.getAsFile().getName());
                task.getInstallName().set(installName);
            }
            task.getTargetPlatform().set(targetPlatform);
            task.getToolChain().set(toolChain);
            task.getDebuggable().set(library.isDebuggable());
        });
        Provider<RegularFile> linkFile = link.flatMap(task -> task.getLinkedFile());
        Provider<RegularFile> runtimeFile = link.flatMap(task -> task.getLinkedFile());
        Provider<? extends Task> linkFileTask = link;
        if (toolProvider.producesImportLibrary()) {
            link.configure(linkSharedLibrary -> {
                linkSharedLibrary.getImportLibrary().set(buildDirectory.file(library.getBaseName().map(baseName -> toolProvider.getImportLibraryName("lib/" + names.getDirName() + baseName))));
            });
            linkFile = link.flatMap(task -> task.getImportLibrary());
        }
        if (library.isDebuggable() && library.isOptimized() && toolProvider.requiresDebugBinaryStripping()) {
            Provider<RegularFile> symbolLocation = buildDirectory.file(library.getBaseName().map(baseName -> toolProvider.getLibrarySymbolFileName("lib/" + names.getDirName() + "stripped/" + baseName)));
            Provider<RegularFile> strippedLocation = buildDirectory.file(library.getBaseName().map(baseName -> toolProvider.getSharedLibraryName("lib/" + names.getDirName() + "stripped/" + baseName)));
            TaskProvider<StripSymbols> stripSymbols = stripSymbols(link, names, tasks, toolChain, targetPlatform, strippedLocation);
            linkFile = runtimeFile = stripSymbols.flatMap(task -> task.getOutputFile());
            TaskProvider<ExtractSymbols> extractSymbols = extractSymbols(link, names, tasks, toolChain, targetPlatform, symbolLocation);
            library.getOutputs().from(extractSymbols.flatMap(task -> task.getSymbolFile()));
            linkFileTask = stripSymbols;
        }
        library.getLinkTask().set(link);
        library.getLinkFile().set(linkFile);
        library.getLinkFileProducer().set(linkFileTask);
        library.getRuntimeFile().set(runtimeFile);
        library.getOutputs().from(library.getLinkFile());
        library.getOutputs().from(library.getRuntimeFile());
    });
}
Also used : ConfigurableComponentWithRuntimeUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithRuntimeUsage) ConfigurableComponentWithSharedLibrary(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithSharedLibrary) ComponentWithVariants(org.gradle.api.component.ComponentWithVariants) LinkSharedLibrary(org.gradle.nativeplatform.tasks.LinkSharedLibrary) ComponentWithBinaries(org.gradle.language.ComponentWithBinaries) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) PublishingExtension(org.gradle.api.publish.PublishingExtension) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) MultipleCandidatesDetails(org.gradle.api.attributes.MultipleCandidatesDetails) TaskProvider(org.gradle.api.tasks.TaskProvider) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) Linkage(org.gradle.nativeplatform.Linkage) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) UnzipTransform(org.gradle.api.internal.artifacts.transform.UnzipTransform) Incubating(org.gradle.api.Incubating) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Set(java.util.Set) MutableMavenProjectIdentity(org.gradle.api.publish.maven.internal.publisher.MutableMavenProjectIdentity) DIRECTORY_TYPE(org.gradle.api.artifacts.type.ArtifactTypeDefinition.DIRECTORY_TYPE) AttributeDisambiguationRule(org.gradle.api.attributes.AttributeDisambiguationRule) TaskContainer(org.gradle.api.tasks.TaskContainer) AbstractLinkTask(org.gradle.nativeplatform.tasks.AbstractLinkTask) ArtifactTypeDefinition(org.gradle.api.artifacts.type.ArtifactTypeDefinition) Names(org.gradle.language.nativeplatform.internal.Names) SoftwareComponent(org.gradle.api.component.SoftwareComponent) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) CreateStaticLibrary(org.gradle.nativeplatform.tasks.CreateStaticLibrary) ZIP_TYPE(org.gradle.api.artifacts.type.ArtifactTypeDefinition.ZIP_TYPE) ConfigurableComponentWithStaticLibrary(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithStaticLibrary) StripSymbols(org.gradle.nativeplatform.tasks.StripSymbols) PublishableComponent(org.gradle.api.component.PublishableComponent) Callable(java.util.concurrent.Callable) MavenPublication(org.gradle.api.publish.maven.MavenPublication) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) FileCollection(org.gradle.api.file.FileCollection) ProductionComponent(org.gradle.language.ProductionComponent) ExtractSymbols(org.gradle.nativeplatform.tasks.ExtractSymbols) LinkExecutable(org.gradle.nativeplatform.tasks.LinkExecutable) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) AttributeContainer(org.gradle.api.attributes.AttributeContainer) DefaultTargetMachineFactory(org.gradle.nativeplatform.internal.DefaultTargetMachineFactory) Attribute(org.gradle.api.attributes.Attribute) DirectoryProperty(org.gradle.api.file.DirectoryProperty) DomainObjectSet(org.gradle.api.DomainObjectSet) Usage(org.gradle.api.attributes.Usage) ConfigurableComponentWithLinkUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithLinkUsage) ConfigurableComponentWithExecutable(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithExecutable) PublicationAwareComponent(org.gradle.language.nativeplatform.internal.PublicationAwareComponent) InstallExecutable(org.gradle.nativeplatform.tasks.InstallExecutable) ComponentWithTargetMachines(org.gradle.language.ComponentWithTargetMachines) Cast(org.gradle.internal.Cast) LINKAGE_ATTRIBUTE(org.gradle.language.cpp.CppBinary.LINKAGE_ATTRIBUTE) ObjectFactory(org.gradle.api.model.ObjectFactory) RegularFile(org.gradle.api.file.RegularFile) ComponentWithOutputs(org.gradle.language.ComponentWithOutputs) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) RegularFile(org.gradle.api.file.RegularFile) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) LinkSharedLibrary(org.gradle.nativeplatform.tasks.LinkSharedLibrary) ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Names(org.gradle.language.nativeplatform.internal.Names) StripSymbols(org.gradle.nativeplatform.tasks.StripSymbols) ExtractSymbols(org.gradle.nativeplatform.tasks.ExtractSymbols) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform)

Example 2 with LinkSharedLibrary

use of org.gradle.nativeplatform.tasks.LinkSharedLibrary 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

File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Inject (javax.inject.Inject)1 DomainObjectSet (org.gradle.api.DomainObjectSet)1 Incubating (org.gradle.api.Incubating)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 Configuration (org.gradle.api.artifacts.Configuration)1 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)1 ArtifactTypeDefinition (org.gradle.api.artifacts.type.ArtifactTypeDefinition)1 DIRECTORY_TYPE (org.gradle.api.artifacts.type.ArtifactTypeDefinition.DIRECTORY_TYPE)1 ZIP_TYPE (org.gradle.api.artifacts.type.ArtifactTypeDefinition.ZIP_TYPE)1 Attribute (org.gradle.api.attributes.Attribute)1 AttributeContainer (org.gradle.api.attributes.AttributeContainer)1