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());
});
}
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;
}
Aggregations