use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.
the class CreateStaticLibrary method createCompiler.
private Compiler<StaticLibraryArchiverSpec> createCompiler() {
NativePlatformInternal targetPlatform = Cast.cast(NativePlatformInternal.class, this.targetPlatform.get());
NativeToolChainInternal toolChain = Cast.cast(NativeToolChainInternal.class, getToolChain().get());
PlatformToolProvider toolProvider = toolChain.select(targetPlatform);
return toolProvider.newCompiler(StaticLibraryArchiverSpec.class);
}
use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.
the class CompileTaskConfig method configureCompileTaskCommon.
private void configureCompileTaskCommon(final AbstractNativeCompileTask task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal sourceSet) {
task.getToolChain().set(binary.getToolChain());
task.getTargetPlatform().set(binary.getTargetPlatform());
task.setPositionIndependentCode(binary instanceof SharedLibraryBinarySpec);
task.includes(((HeaderExportingSourceSet) sourceSet).getExportedHeaders().getSourceDirectories());
task.includes(new Callable<List<FileCollection>>() {
@Override
public List<FileCollection> call() {
Collection<NativeDependencySet> libs = binary.getLibs((DependentSourceSet) sourceSet);
return CollectionUtils.collect(libs, new Transformer<FileCollection, NativeDependencySet>() {
@Override
public FileCollection transform(NativeDependencySet original) {
return original.getIncludeRoots();
}
});
}
});
FileCollectionFactory fileCollectionFactory = ((ProjectInternal) task.getProject()).getServices().get(FileCollectionFactory.class);
task.getSystemIncludes().from(fileCollectionFactory.create(new MinimalFileSet() {
@Override
public Set<File> getFiles() {
PlatformToolProvider platformToolProvider = ((NativeToolChainInternal) binary.getToolChain()).select((NativePlatformInternal) binary.getTargetPlatform());
ToolType toolType = languageTransform.getToolType();
return new LinkedHashSet<File>(platformToolProvider.getSystemLibraries(toolType).getIncludeDirs());
}
@Override
public String getDisplayName() {
return "System includes for " + binary.getToolChain().getDisplayName();
}
}));
for (String toolName : languageTransform.getBinaryTools().keySet()) {
Tool tool = binary.getToolByName(toolName);
if (tool instanceof PreprocessingTool) {
task.setMacros(((PreprocessingTool) tool).getMacros());
}
task.getCompilerArgs().set(tool.getArgs());
}
}
use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.
the class AssembleTaskConfig method configureAssembleTask.
private void configureAssembleTask(Assemble task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal sourceSet) {
task.setDescription("Assembles the " + sourceSet + " of " + binary);
task.getToolChain().set(binary.getToolChain());
task.getTargetPlatform().set(binary.getTargetPlatform());
task.source(sourceSet.getSource());
FileCollectionFactory fileCollectionFactory = ((ProjectInternal) task.getProject()).getServices().get(FileCollectionFactory.class);
task.includes(fileCollectionFactory.create(new MinimalFileSet() {
@Override
public Set<File> getFiles() {
PlatformToolProvider platformToolProvider = ((NativeToolChainInternal) binary.getToolChain()).select((NativePlatformInternal) binary.getTargetPlatform());
return new LinkedHashSet<File>(platformToolProvider.getSystemLibraries(ToolType.ASSEMBLER).getIncludeDirs());
}
@Override
public String getDisplayName() {
return "System includes for " + binary.getToolChain().getDisplayName();
}
}));
final Project project = task.getProject();
task.setObjectFileDir(new File(binary.getNamingScheme().getOutputDirectory(project.getBuildDir(), "objs"), sourceSet.getProjectScopedName()));
Tool assemblerTool = binary.getToolByName("assembler");
task.setAssemblerArgs(assemblerTool.getArgs());
binary.binaryInputs(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
}
use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.
the class VisualCppToolChain method select.
@Override
public PlatformToolProvider select(NativeLanguage sourceLanguage, NativePlatformInternal targetMachine) {
switch(sourceLanguage) {
case CPP:
PlatformToolProvider toolProvider = select(targetMachine);
if (!toolProvider.isAvailable()) {
return toolProvider;
}
ToolSearchResult cppCompiler = toolProvider.locateTool(ToolType.CPP_COMPILER);
if (!cppCompiler.isAvailable()) {
return new UnavailablePlatformToolProvider(targetMachine.getOperatingSystem(), cppCompiler);
}
return toolProvider;
case ANY:
return select(targetMachine);
default:
return new UnsupportedPlatformToolProvider(targetMachine.getOperatingSystem(), String.format("Don't know how to compile language %s.", sourceLanguage));
}
}
use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.
the class XCTestConventionPlugin method configureTestSuiteBuildingTasks.
private void configureTestSuiteBuildingTasks(final Project project, final DefaultSwiftXCTestBinary binary) {
// Overwrite the source to exclude `LinuxMain.swift`
SwiftCompile compile = binary.getCompileTask().get();
compile.getSource().setFrom(binary.getSwiftSource().getAsFileTree().matching(patterns -> patterns.include("**/*").exclude("**/LinuxMain.swift")));
if (binary instanceof SwiftXCTestBundle) {
TaskContainer tasks = project.getTasks();
final Names names = binary.getNames();
// TODO - creating a bundle should be done by some general purpose plugin
// TODO - make this lazy
final DefaultNativePlatform currentPlatform = new DefaultNativePlatform("current");
final ModelRegistry modelRegistry = ((ProjectInternal) project).getModelRegistry();
final NativeToolChain toolChain = modelRegistry.realize("toolChains", NativeToolChainRegistryInternal.class).getForPlatform(currentPlatform);
// Platform specific arguments
// TODO: Need to lazily configure compile task
// TODO: Ultimately, this should be some kind of 3rd party dependency that's visible to dependency management.
compile.getCompilerArgs().addAll(project.provider(() -> {
File platformSdkPath = sdkPlatformPathLocator.find();
File frameworkDir = new File(platformSdkPath, "Developer/Library/Frameworks");
// Since Xcode 11/12, the XCTest framework is being replaced by a different library that's available in the sdk root
File extraInclude = new File(platformSdkPath, "Developer/usr/lib");
return Arrays.asList("-parse-as-library", "-F" + frameworkDir.getAbsolutePath(), "-I", extraInclude.getAbsolutePath(), "-v");
}));
// Add a link task
final TaskProvider<LinkMachOBundle> link = tasks.register(names.getTaskName("link"), LinkMachOBundle.class, task -> {
task.getLinkerArgs().set(project.provider(() -> {
File platformSdkPath = sdkPlatformPathLocator.find();
File frameworkDir = new File(platformSdkPath, "Developer/Library/Frameworks");
// Since Xcode 11/12, the XCTest framework is being replaced by a different library that's available in the sdk root
File extraInclude = new File(platformSdkPath, "Developer/usr/lib");
return Lists.newArrayList("-F" + frameworkDir.getAbsolutePath(), "-L", extraInclude.getAbsolutePath(), "-framework", "XCTest", "-Xlinker", "-rpath", "-Xlinker", "@executable_path/../Frameworks", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/../Frameworks");
}));
task.source(binary.getObjects());
task.lib(binary.getLinkLibraries());
final PlatformToolProvider toolProvider = ((NativeToolChainInternal) toolChain).select(currentPlatform);
Provider<RegularFile> exeLocation = project.getLayout().getBuildDirectory().file(binary.getBaseName().map(baseName -> toolProvider.getExecutableName("exe/" + names.getDirName() + baseName)));
task.getLinkedFile().set(exeLocation);
task.getTargetPlatform().set(currentPlatform);
task.getToolChain().set(toolChain);
task.getDebuggable().set(binary.isDebuggable());
});
final TaskProvider<InstallXCTestBundle> install = tasks.register(names.getTaskName("install"), InstallXCTestBundle.class, task -> {
task.getBundleBinaryFile().set(link.get().getLinkedFile());
task.getInstallDirectory().set(project.getLayout().getBuildDirectory().dir("install/" + names.getDirName()));
});
binary.getInstallDirectory().set(install.flatMap(task -> task.getInstallDirectory()));
binary.getExecutableFile().set(link.flatMap(task -> task.getLinkedFile()));
DefaultSwiftXCTestBundle bundle = (DefaultSwiftXCTestBundle) binary;
bundle.getLinkTask().set(link);
bundle.getRunScriptFile().set(install.flatMap(task -> task.getRunScriptFile()));
} else {
DefaultSwiftXCTestExecutable executable = (DefaultSwiftXCTestExecutable) binary;
executable.getRunScriptFile().set(executable.getInstallTask().flatMap(task -> task.getRunScriptFile()));
// Rename `LinuxMain.swift` to `main.swift` so the entry point is correctly detected by swiftc
if (binary.getTargetMachine().getOperatingSystemFamily().isLinux()) {
TaskProvider<Sync> renameLinuxMainTask = project.getTasks().register("renameLinuxMain", Sync.class, task -> {
task.from(binary.getSwiftSource());
task.into(project.provider(() -> task.getTemporaryDir()));
task.include("LinuxMain.swift");
task.rename(it -> "main.swift");
});
compile.getSource().from(project.files(renameLinuxMainTask).getAsFileTree().matching(patterns -> patterns.include("**/*.swift")));
}
}
}
Aggregations