use of org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadataProvider 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;
}
Aggregations