Search in sources :

Example 21 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.

the class CppBasePlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(StandardToolChainsPlugin.class);
    final TaskContainerInternal tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    // Enable the use of Gradle metadata. This is a temporary opt-in switch until available by default
    project.getGradle().getServices().get(FeaturePreviews.class).enableFeature(GRADLE_METADATA);
    // Create the tasks for each C++ binary that is registered
    project.getComponents().withType(DefaultCppBinary.class, new Action<DefaultCppBinary>() {

        @Override
        public void execute(final DefaultCppBinary binary) {
            final Names names = binary.getNames();
            String language = "cpp";
            final NativePlatform currentPlatform = binary.getTargetPlatform();
            // TODO - make this lazy
            final NativeToolChainInternal toolChain = binary.getToolChain();
            Callable<List<File>> systemIncludes = new Callable<List<File>>() {

                @Override
                public List<File> call() {
                    PlatformToolProvider platformToolProvider = binary.getPlatformToolProvider();
                    return platformToolProvider.getSystemLibraries(ToolType.CPP_COMPILER).getIncludeDirs();
                }
            };
            CppCompile compile = tasks.create(names.getCompileTaskName(language), CppCompile.class);
            compile.includes(binary.getCompileIncludePath());
            compile.includes(systemIncludes);
            compile.source(binary.getCppSource());
            if (binary.isDebuggable()) {
                compile.setDebuggable(true);
            }
            if (binary.isOptimized()) {
                compile.setOptimized(true);
            }
            compile.getTargetPlatform().set(currentPlatform);
            compile.getToolChain().set(toolChain);
            compile.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            binary.getObjectsDir().set(compile.getObjectFileDir());
            binary.getCompileTask().set(compile);
        }
    });
    project.getComponents().withType(CppSharedLibrary.class, new Action<CppSharedLibrary>() {

        @Override
        public void execute(CppSharedLibrary library) {
            library.getCompileTask().get().setPositionIndependentCode(true);
        }
    });
    project.getComponents().withType(ProductionCppComponent.class, new Action<ProductionCppComponent>() {

        @Override
        public void execute(final ProductionCppComponent component) {
            project.afterEvaluate(new Action<Project>() {

                @Override
                public void execute(Project project) {
                    DefaultCppComponent componentInternal = (DefaultCppComponent) component;
                    publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getBaseName().get()), false));
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) Callable(java.util.concurrent.Callable) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) List(java.util.List) CppSharedLibrary(org.gradle.language.cpp.CppSharedLibrary) FeaturePreviews(org.gradle.api.internal.FeaturePreviews) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) Project(org.gradle.api.Project) DefaultCppComponent(org.gradle.language.cpp.internal.DefaultCppComponent) DirectoryProperty(org.gradle.api.file.DirectoryProperty) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) CppCompile(org.gradle.language.cpp.tasks.CppCompile) DefaultProjectPublication(org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication) File(java.io.File)

Example 22 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.

the class StripSymbols method createCompiler.

private Compiler<StripperSpec> 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(StripperSpec.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 23 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.

the class SwiftcToolChain method select.

@Override
public PlatformToolProvider select(NativePlatformInternal targetPlatform) {
    PlatformToolProvider toolProvider = toolProviders.get(targetPlatform);
    if (toolProvider == null) {
        toolProvider = createPlatformToolProvider(targetPlatform);
        toolProviders.put(targetPlatform, toolProvider);
    }
    return toolProvider;
}
Also used : UnavailablePlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnavailablePlatformToolProvider) UnsupportedPlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.UnsupportedPlatformToolProvider) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)

Example 24 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.

the class AbstractNativeCompileTask method compile.

@TaskAction
protected void compile(InputChanges inputs) {
    BuildOperationLogger operationLogger = getOperationLoggerFactory().newOperationLogger(getName(), getTemporaryDir());
    NativeCompileSpec spec = createCompileSpec();
    spec.setTargetPlatform(targetPlatform.get());
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(objectFileDir.get().getAsFile());
    spec.include(includes);
    spec.systemInclude(systemIncludes);
    spec.source(getSource());
    spec.setMacros(getMacros());
    spec.args(getCompilerArgs().get());
    spec.setPositionIndependentCode(isPositionIndependentCode());
    spec.setDebuggable(isDebuggable());
    spec.setOptimized(isOptimized());
    spec.setIncrementalCompile(inputs.isIncremental());
    spec.setOperationLogger(operationLogger);
    configureSpec(spec);
    NativeToolChainInternal nativeToolChain = (NativeToolChainInternal) toolChain.get();
    NativePlatformInternal nativePlatform = (NativePlatformInternal) targetPlatform.get();
    PlatformToolProvider platformToolProvider = nativeToolChain.select(nativePlatform);
    setDidWork(doCompile(spec, platformToolProvider).getDidWork());
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativeCompileSpec(org.gradle.nativeplatform.toolchain.internal.NativeCompileSpec) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) TaskAction(org.gradle.api.tasks.TaskAction)

Example 25 with PlatformToolProvider

use of org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider in project gradle by gradle.

the class AbstractNativeSourceCompileTask method getCompilerVersion.

/**
 * The compiler used, including the type and the version.
 *
 * @since 4.4
 */
@Nullable
@Optional
@Nested
protected CompilerVersion getCompilerVersion() {
    NativeToolChainInternal toolChain = (NativeToolChainInternal) getToolChain().get();
    NativePlatformInternal targetPlatform = (NativePlatformInternal) getTargetPlatform().get();
    PlatformToolProvider toolProvider = toolChain.select(targetPlatform);
    Compiler<? extends NativeCompileSpec> compiler = toolProvider.newCompiler(createCompileSpec().getClass());
    if (!(compiler instanceof VersionAwareCompiler)) {
        return null;
    }
    return ((VersionAwareCompiler) compiler).getVersion();
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) VersionAwareCompiler(org.gradle.language.base.internal.compile.VersionAwareCompiler) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) Optional(org.gradle.api.tasks.Optional) Nested(org.gradle.api.tasks.Nested) Nullable(javax.annotation.Nullable)

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