use of org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadata in project gradle by gradle.
the class AvailableToolChains method findSwiftcs.
static List<ToolChainCandidate> findSwiftcs() {
List<ToolChainCandidate> toolChains = Lists.newArrayList();
SwiftcMetadataProvider versionDeterminer = new SwiftcMetadataProvider(TestFiles.execActionFactory());
// On Linux, we assume swift is installed into /opt/swift
File rootSwiftInstall = new File("/opt/swift");
File[] swiftCandidates = GUtil.getOrDefault(rootSwiftInstall.listFiles(swiftInstall -> swiftInstall.isDirectory() && !swiftInstall.getName().equals("latest")), () -> new File[0]);
for (File swiftInstall : swiftCandidates) {
File swiftc = new File(swiftInstall, "/usr/bin/swiftc");
SearchResult<SwiftcMetadata> version = versionDeterminer.getCompilerMetaData(Collections.emptyList(), spec -> spec.executable(swiftc));
if (version.isAvailable()) {
File binDir = swiftc.getParentFile();
toolChains.add(new InstalledSwiftc(binDir, version.getComponent().getVersion()).inPath(binDir, new File("/usr/bin")));
}
}
// On macOS, we assume co-located Xcode is installed into /opt/xcode and default location at /Applications/Xcode.app
toolChains.addAll(findXcodes().stream().map(InstalledXcode::getSwiftc).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
List<File> swiftcCandidates = OperatingSystem.current().findAllInPath("swiftc");
for (File candidate : swiftcCandidates) {
SearchResult<SwiftcMetadata> version = versionDeterminer.getCompilerMetaData(Collections.emptyList(), spec -> spec.executable(candidate));
if (version.isAvailable()) {
File binDir = candidate.getParentFile();
InstalledSwiftc swiftc = new InstalledSwiftc(binDir, version.getComponent().getVersion());
swiftc.inPath(binDir, new File("/usr/bin"));
toolChains.add(swiftc);
}
}
if (toolChains.isEmpty()) {
toolChains.add(new UnavailableToolChain(ToolFamily.SWIFTC));
} else {
toolChains.sort(LATEST_RELEASED_FIRST);
}
return toolChains;
}
use of org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadata in project gradle by gradle.
the class SwiftcToolChain method createPlatformToolProvider.
private PlatformToolProvider createPlatformToolProvider(NativePlatformInternal targetPlatform) {
DefaultSwiftcPlatformToolChain configurableToolChain = instantiator.newInstance(DefaultSwiftcPlatformToolChain.class, targetPlatform);
addDefaultTools(configurableToolChain);
configureActions.execute(configurableToolChain);
// TODO: this is an approximation as we know swift currently supports only 64-bit runtimes - eventually, we'll want to query for this
if (!isCurrentArchitecture(targetPlatform)) {
return new UnsupportedPlatformToolProvider(targetPlatform.getOperatingSystem(), String.format("Don't know how to build for %s.", targetPlatform.getDisplayName()));
}
CommandLineToolSearchResult compiler = toolSearchPath.locate(ToolType.SWIFT_COMPILER, "swiftc");
ToolChainAvailability result = new ToolChainAvailability();
result.mustBeAvailable(compiler);
if (!result.isAvailable()) {
return new UnavailablePlatformToolProvider(targetPlatform.getOperatingSystem(), result);
}
SearchResult<SwiftcMetadata> swiftcMetaData = compilerMetaDataProvider.getCompilerMetaData(toolSearchPath.getPath(), spec -> spec.executable(compiler.getTool()));
result.mustBeAvailable(swiftcMetaData);
if (!result.isAvailable()) {
return new UnavailablePlatformToolProvider(targetPlatform.getOperatingSystem(), result);
}
return new SwiftPlatformToolProvider(buildOperationExecutor, targetPlatform.getOperatingSystem(), toolSearchPath, configurableToolChain, execActionFactory, compilerOutputFileNamingSchemeFactory, workerLeaseService, swiftcMetaData.getComponent());
}
Aggregations