use of org.gradle.nativeplatform.toolchain.NativeToolChain 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());
}
}
use of org.gradle.nativeplatform.toolchain.NativeToolChain in project gradle by gradle.
the class InstallExecutable method installWindows.
private void installWindows() {
final File executable = getExecutableFile().get().getAsFile();
installToDir(getLibDirectory().get().getAsFile());
StringBuilder toolChainPath = new StringBuilder();
NativeToolChain toolChain = getToolChain().get();
if (toolChain instanceof Gcc) {
// Gcc on windows requires the path to be set
toolChainPath.append("SET PATH=");
for (File pathEntry : ((Gcc) toolChain).getPath()) {
toolChainPath.append(pathEntry.getAbsolutePath()).append(";");
}
toolChainPath.append("%PATH%");
}
String runScriptText = "\n@echo off" + "\nSETLOCAL" + "\n" + toolChainPath + "\nCALL \"%~dp0lib\\" + executable.getName() + "\" %*" + "\nEXIT /B %ERRORLEVEL%" + "\nENDLOCAL" + "\n";
GFileUtils.writeFile(runScriptText, getRunScriptFile().get().getAsFile());
}
use of org.gradle.nativeplatform.toolchain.NativeToolChain 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.toolchain.NativeToolChain 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.toolchain.NativeToolChain in project gradle by gradle.
the class InstallExecutable method installWindows.
private void installWindows(File executable, File runScript) {
StringBuilder toolChainPath = new StringBuilder();
NativeToolChain toolChain = getToolChain().get();
if (toolChain instanceof Gcc) {
// Gcc on windows requires the path to be set
toolChainPath.append("SET PATH=");
for (File pathEntry : ((Gcc) toolChain).getPath()) {
toolChainPath.append(pathEntry.getAbsolutePath()).append(";");
}
toolChainPath.append("%PATH%");
}
String runScriptText = "\n@echo off" + "\nSETLOCAL" + "\n" + toolChainPath + "\nCALL \"%~dp0lib\\" + executable.getName() + "\" %*" + "\nEXIT /B %ERRORLEVEL%" + "\nENDLOCAL" + "\n";
GFileUtils.writeFile(runScriptText, runScript);
}
Aggregations