Search in sources :

Example 1 with SwiftcMetadata

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;
}
Also used : VisualStudioLocatorTestFixture(org.gradle.nativeplatform.fixtures.msvcpp.VisualStudioLocatorTestFixture) CollectionUtils(org.gradle.util.internal.CollectionUtils) Arrays(java.util.Arrays) GradleExecuter(org.gradle.integtests.fixtures.executer.GradleExecuter) MicrosoftVisualCppCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.MicrosoftVisualCppCompilerPlugin) TestFiles(org.gradle.api.internal.file.TestFiles) VisualCpp(org.gradle.nativeplatform.toolchain.VisualCpp) SwiftcMetadata(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadata) GccMetadataProvider(org.gradle.nativeplatform.toolchain.internal.gcc.metadata.GccMetadataProvider) ProcessEnvironment(org.gradle.internal.nativeintegration.ProcessEnvironment) SwiftCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.SwiftCompilerPlugin) ArrayList(java.util.ArrayList) GccCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.GccCompilerPlugin) GUtil(org.gradle.util.internal.GUtil) SearchResult(org.gradle.platform.base.internal.toolchain.SearchResult) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) Lists(com.google.common.collect.Lists) Swiftc(org.gradle.nativeplatform.toolchain.Swiftc) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) Gcc(org.gradle.nativeplatform.toolchain.Gcc) VersionedTool(org.gradle.integtests.fixtures.VersionedTool) VersionNumber(org.gradle.util.internal.VersionNumber) VisualStudioInstall(org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualStudioInstall) VisualStudioVersion(org.gradle.nativeplatform.fixtures.msvcpp.VisualStudioVersion) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) NativeServicesTestFixture(org.gradle.testfixtures.internal.NativeServicesTestFixture) Clang(org.gradle.nativeplatform.toolchain.Clang) GccMetadata(org.gradle.nativeplatform.toolchain.internal.gcc.metadata.GccMetadata) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) OperatingSystem(org.gradle.internal.os.OperatingSystem) ClangCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.ClangCompilerPlugin) List(java.util.List) Spec(org.gradle.api.specs.Spec) Optional(java.util.Optional) TestFile(org.gradle.test.fixtures.file.TestFile) Pattern(java.util.regex.Pattern) SwiftcMetadataProvider(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadataProvider) Comparator(java.util.Comparator) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) Optional(java.util.Optional) SwiftcMetadataProvider(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadataProvider) SwiftcMetadata(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadata) File(java.io.File) TestFile(org.gradle.test.fixtures.file.TestFile)

Example 2 with SwiftcMetadata

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());
}
Also used : UnavailablePlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnavailablePlatformToolProvider) ToolChainAvailability(org.gradle.platform.base.internal.toolchain.ToolChainAvailability) CommandLineToolSearchResult(org.gradle.nativeplatform.toolchain.internal.tools.CommandLineToolSearchResult) SwiftcMetadata(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadata) UnsupportedPlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnsupportedPlatformToolProvider)

Aggregations

SwiftcMetadata (org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadata)2 Joiner (com.google.common.base.Joiner)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 TestFiles (org.gradle.api.internal.file.TestFiles)1 Spec (org.gradle.api.specs.Spec)1