Search in sources :

Example 16 with PlatformToolProvider

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);
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal)

Example 17 with PlatformToolProvider

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());
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Transformer(org.gradle.api.Transformer) PreprocessingTool(org.gradle.nativeplatform.PreprocessingTool) ToolType(org.gradle.nativeplatform.toolchain.internal.ToolType) SharedLibraryBinarySpec(org.gradle.nativeplatform.SharedLibraryBinarySpec) MinimalFileSet(org.gradle.api.internal.file.collections.MinimalFileSet) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) DependentSourceSet(org.gradle.language.nativeplatform.DependentSourceSet) HeaderExportingSourceSet(org.gradle.language.nativeplatform.HeaderExportingSourceSet) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) FileCollection(org.gradle.api.file.FileCollection) Collection(java.util.Collection) List(java.util.List) File(java.io.File) NativeDependencySet(org.gradle.nativeplatform.NativeDependencySet) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) PreprocessingTool(org.gradle.nativeplatform.PreprocessingTool) Tool(org.gradle.nativeplatform.Tool)

Example 18 with PlatformToolProvider

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")));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) Project(org.gradle.api.Project) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) MinimalFileSet(org.gradle.api.internal.file.collections.MinimalFileSet) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) Tool(org.gradle.nativeplatform.Tool)

Example 19 with PlatformToolProvider

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));
    }
}
Also used : UnavailablePlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnavailablePlatformToolProvider) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) UnavailablePlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnavailablePlatformToolProvider) UnsupportedPlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnsupportedPlatformToolProvider) ToolSearchResult(org.gradle.platform.base.internal.toolchain.ToolSearchResult) UnsupportedPlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnsupportedPlatformToolProvider)

Example 20 with PlatformToolProvider

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")));
        }
    }
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) Arrays(java.util.Arrays) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) GUtil(org.gradle.util.internal.GUtil) Provider(org.gradle.api.provider.Provider) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite) TaskProvider(org.gradle.api.tasks.TaskProvider) XCTest(org.gradle.nativeplatform.test.xctest.tasks.XCTest) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) SwiftBasePlugin(org.gradle.language.swift.plugins.SwiftBasePlugin) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) MacOSSdkPlatformPathLocator(org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPlatformPathLocator) TaskContainer(org.gradle.api.tasks.TaskContainer) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) SwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.SwiftXCTestBinary) DefaultSwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary) NativeTestingBasePlugin(org.gradle.nativeplatform.test.plugins.NativeTestingBasePlugin) Dimensions.useHostAsDefaultTargetMachine(org.gradle.language.nativeplatform.internal.Dimensions.useHostAsDefaultTargetMachine) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) Inject(javax.inject.Inject) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Lists(com.google.common.collect.Lists) Sync(org.gradle.api.tasks.Sync) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) SwiftApplication(org.gradle.language.swift.SwiftApplication) SwiftComponent(org.gradle.language.swift.SwiftComponent) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) File(java.io.File) SetProperty(org.gradle.api.provider.SetProperty) ProviderFactory(org.gradle.api.provider.ProviderFactory) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) ObjectFactory(org.gradle.api.model.ObjectFactory) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) RegularFile(org.gradle.api.file.RegularFile) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) SwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.SwiftXCTestSuite) DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) RegularFile(org.gradle.api.file.RegularFile) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) Names(org.gradle.language.nativeplatform.internal.Names) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) TaskContainer(org.gradle.api.tasks.TaskContainer) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) Sync(org.gradle.api.tasks.Sync) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Aggregations

PlatformToolProvider (org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)29 NativeToolChainInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal)20 NativePlatformInternal (org.gradle.nativeplatform.platform.internal.NativePlatformInternal)10 File (java.io.File)7 Project (org.gradle.api.Project)7 Names (org.gradle.language.nativeplatform.internal.Names)6 Callable (java.util.concurrent.Callable)5 RegularFile (org.gradle.api.file.RegularFile)5 TaskContainer (org.gradle.api.tasks.TaskContainer)5 DefaultNativePlatform (org.gradle.nativeplatform.platform.internal.DefaultNativePlatform)5 NativeToolChain (org.gradle.nativeplatform.toolchain.NativeToolChain)5 Inject (javax.inject.Inject)4 Plugin (org.gradle.api.Plugin)4 FileCollection (org.gradle.api.file.FileCollection)4 ObjectFactory (org.gradle.api.model.ObjectFactory)4 Provider (org.gradle.api.provider.Provider)4 TaskProvider (org.gradle.api.tasks.TaskProvider)4 LifecycleBasePlugin (org.gradle.language.base.plugins.LifecycleBasePlugin)4 TargetMachine (org.gradle.nativeplatform.TargetMachine)4 TargetMachineFactory (org.gradle.nativeplatform.TargetMachineFactory)4