use of org.gradle.nativeplatform.tasks.LinkExecutable in project gradle by gradle.
the class NativeBasePlugin method addTasksForComponentWithExecutable.
private void addTasksForComponentWithExecutable(final TaskContainer tasks, final DirectoryProperty buildDirectory, SoftwareComponentContainer components) {
components.withType(ConfigurableComponentWithExecutable.class, executable -> {
final Names names = executable.getNames();
final NativeToolChain toolChain = executable.getToolChain();
final NativePlatform targetPlatform = executable.getNativePlatform();
final PlatformToolProvider toolProvider = executable.getPlatformToolProvider();
// Add a link task
TaskProvider<LinkExecutable> link = tasks.register(names.getTaskName("link"), LinkExecutable.class, task -> {
task.source(executable.getObjects());
task.lib(executable.getLinkLibraries());
task.getLinkedFile().set(buildDirectory.file(executable.getBaseName().map(baseName -> toolProvider.getExecutableName("exe/" + names.getDirName() + baseName))));
task.getTargetPlatform().set(targetPlatform);
task.getToolChain().set(toolChain);
task.getDebuggable().set(executable.isDebuggable());
});
executable.getLinkTask().set(link);
executable.getDebuggerExecutableFile().set(link.flatMap(linkExecutable -> linkExecutable.getLinkedFile()));
if (executable.isDebuggable() && executable.isOptimized() && toolProvider.requiresDebugBinaryStripping()) {
Provider<RegularFile> symbolLocation = buildDirectory.file(executable.getBaseName().map(baseName -> toolProvider.getExecutableSymbolFileName("exe/" + names.getDirName() + "stripped/" + baseName)));
Provider<RegularFile> strippedLocation = buildDirectory.file(executable.getBaseName().map(baseName -> toolProvider.getExecutableName("exe/" + names.getDirName() + "stripped/" + baseName)));
TaskProvider<StripSymbols> stripSymbols = stripSymbols(link, names, tasks, toolChain, targetPlatform, strippedLocation);
executable.getExecutableFile().set(stripSymbols.flatMap(task -> task.getOutputFile()));
TaskProvider<ExtractSymbols> extractSymbols = extractSymbols(link, names, tasks, toolChain, targetPlatform, symbolLocation);
executable.getOutputs().from(extractSymbols.flatMap(task -> task.getSymbolFile()));
executable.getExecutableFileProducer().set(stripSymbols);
} else {
executable.getExecutableFile().set(link.flatMap(task -> task.getLinkedFile()));
executable.getExecutableFileProducer().set(link);
}
// Add an install task
// TODO - should probably not add this for all executables?
// TODO - add stripped symbols to the installation
final TaskProvider<InstallExecutable> install = tasks.register(names.getTaskName("install"), InstallExecutable.class, task -> {
task.getTargetPlatform().set(targetPlatform);
task.getToolChain().set(toolChain);
task.getInstallDirectory().set(buildDirectory.dir("install/" + names.getDirName()));
task.getExecutableFile().set(executable.getExecutableFile());
task.lib(executable.getRuntimeLibraries());
});
executable.getInstallTask().set(install);
executable.getInstallDirectory().set(install.flatMap(task -> task.getInstallDirectory()));
executable.getOutputs().from(executable.getInstallDirectory());
executable.getDebuggerExecutableFile().set(install.flatMap(task -> task.getInstalledExecutable()));
});
}
use of org.gradle.nativeplatform.tasks.LinkExecutable 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