Search in sources :

Example 1 with NativeProjectPublication

use of org.gradle.swiftpm.internal.NativeProjectPublication in project gradle by gradle.

the class CppBasePlugin method apply.

@Override
public void apply(final Project project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(StandardToolChainsPlugin.class);
    final TaskContainer tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    // Create the tasks for each C++ binary that is registered
    project.getComponents().withType(DefaultCppBinary.class, binary -> {
        final Names names = binary.getNames();
        String language = "cpp";
        TaskProvider<CppCompile> compile = tasks.register(names.getCompileTaskName(language), CppCompile.class, task -> {
            final Callable<List<File>> systemIncludes = () -> binary.getPlatformToolProvider().getSystemLibraries(ToolType.CPP_COMPILER).getIncludeDirs();
            task.includes(binary.getCompileIncludePath());
            task.getSystemIncludes().from(systemIncludes);
            task.source(binary.getCppSource());
            if (binary.isDebuggable()) {
                task.setDebuggable(true);
            }
            if (binary.isOptimized()) {
                task.setOptimized(true);
            }
            task.getTargetPlatform().set(binary.getNativePlatform());
            task.getToolChain().set(binary.getToolChain());
            task.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            if (binary instanceof CppSharedLibrary) {
                task.setPositionIndependentCode(true);
            }
        });
        binary.getObjectsDir().set(compile.flatMap(task -> task.getObjectFileDir()));
        binary.getCompileTask().set(compile);
    });
    project.getComponents().withType(ProductionCppComponent.class, component -> {
        project.afterEvaluate(p -> {
            DefaultCppComponent componentInternal = (DefaultCppComponent) component;
            publicationRegistry.registerPublication((ProjectInternal) project, new NativeProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getBaseName().get())));
        });
    });
}
Also used : ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) ProjectPublicationRegistry(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry) Project(org.gradle.api.Project) DefaultCppComponent(org.gradle.language.cpp.internal.DefaultCppComponent) ToolType(org.gradle.nativeplatform.toolchain.internal.ToolType) Callable(java.util.concurrent.Callable) CppSharedLibrary(org.gradle.language.cpp.CppSharedLibrary) NativeBasePlugin(org.gradle.language.plugins.NativeBasePlugin) NonNullApi(org.gradle.api.NonNullApi) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) StandardToolChainsPlugin(org.gradle.nativeplatform.toolchain.internal.plugins.StandardToolChainsPlugin) File(java.io.File) Inject(javax.inject.Inject) List(java.util.List) TaskContainer(org.gradle.api.tasks.TaskContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) CppCompile(org.gradle.language.cpp.tasks.CppCompile) NativeProjectPublication(org.gradle.swiftpm.internal.NativeProjectPublication) Names(org.gradle.language.nativeplatform.internal.Names) Plugin(org.gradle.api.Plugin) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) Names(org.gradle.language.nativeplatform.internal.Names) DefaultCppComponent(org.gradle.language.cpp.internal.DefaultCppComponent) TaskContainer(org.gradle.api.tasks.TaskContainer) DirectoryProperty(org.gradle.api.file.DirectoryProperty) List(java.util.List) NativeProjectPublication(org.gradle.swiftpm.internal.NativeProjectPublication) CppCompile(org.gradle.language.cpp.tasks.CppCompile) CppSharedLibrary(org.gradle.language.cpp.CppSharedLibrary)

Example 2 with NativeProjectPublication

use of org.gradle.swiftpm.internal.NativeProjectPublication in project gradle by gradle.

the class SwiftBasePlugin method apply.

@Override
public void apply(final Project project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(SwiftCompilerPlugin.class);
    final TaskContainer tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    project.getDependencies().getAttributesSchema().attribute(Usage.USAGE_ATTRIBUTE).getCompatibilityRules().add(SwiftCppUsageCompatibilityRule.class);
    project.getComponents().withType(DefaultSwiftBinary.class, binary -> {
        final Names names = binary.getNames();
        TaskProvider<SwiftCompile> compile = tasks.register(names.getCompileTaskName("swift"), SwiftCompile.class, task -> {
            task.getModules().from(binary.getCompileModules());
            task.getSource().from(binary.getSwiftSource());
            task.getDebuggable().set(binary.isDebuggable());
            task.getOptimized().set(binary.isOptimized());
            if (binary.isTestable()) {
                task.getCompilerArgs().add("-enable-testing");
            }
            if (binary.getTargetMachine().getOperatingSystemFamily().isMacOs()) {
                task.getCompilerArgs().add("-sdk");
                task.getCompilerArgs().add(locator.find().getAbsolutePath());
            }
            task.getModuleName().set(binary.getModule());
            task.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            task.getModuleFile().set(buildDirectory.file(binary.getModule().map(moduleName -> "modules/" + names.getDirName() + moduleName + ".swiftmodule")));
            task.getSourceCompatibility().set(binary.getTargetPlatform().getSourceCompatibility());
            task.getTargetPlatform().set(binary.getNativePlatform());
            // TODO - make this lazy
            task.getToolChain().set(binary.getToolChain());
            if (binary instanceof SwiftSharedLibrary || binary instanceof SwiftStaticLibrary) {
                task.getCompilerArgs().add("-parse-as-library");
            }
        });
        binary.getModuleFile().set(compile.flatMap(task -> task.getModuleFile()));
        binary.getCompileTask().set(compile);
        binary.getObjectsDir().set(compile.flatMap(task -> task.getObjectFileDir()));
    });
    project.getComponents().withType(ProductionSwiftComponent.class, component -> {
        project.afterEvaluate(p -> {
            DefaultNativeComponent componentInternal = (DefaultNativeComponent) component;
            publicationRegistry.registerPublication((ProjectInternal) project, new NativeProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getModule().get())));
        });
    });
}
Also used : Names(org.gradle.language.nativeplatform.internal.Names) DefaultNativeComponent(org.gradle.language.nativeplatform.internal.DefaultNativeComponent) ProjectPublicationRegistry(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry) Project(org.gradle.api.Project) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) NativeBasePlugin(org.gradle.language.plugins.NativeBasePlugin) SwiftCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.SwiftCompilerPlugin) Inject(javax.inject.Inject) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) SwiftSharedLibrary(org.gradle.language.swift.SwiftSharedLibrary) SwiftStaticLibrary(org.gradle.language.swift.SwiftStaticLibrary) TaskContainer(org.gradle.api.tasks.TaskContainer) AttributeCompatibilityRule(org.gradle.api.attributes.AttributeCompatibilityRule) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) CompatibilityCheckDetails(org.gradle.api.attributes.CompatibilityCheckDetails) NativeProjectPublication(org.gradle.swiftpm.internal.NativeProjectPublication) Names(org.gradle.language.nativeplatform.internal.Names) MacOSSdkPathLocator(org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPathLocator) Plugin(org.gradle.api.Plugin) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) Usage(org.gradle.api.attributes.Usage) TaskContainer(org.gradle.api.tasks.TaskContainer) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) SwiftSharedLibrary(org.gradle.language.swift.SwiftSharedLibrary) DefaultNativeComponent(org.gradle.language.nativeplatform.internal.DefaultNativeComponent) NativeProjectPublication(org.gradle.swiftpm.internal.NativeProjectPublication) SwiftStaticLibrary(org.gradle.language.swift.SwiftStaticLibrary) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget)

Aggregations

Inject (javax.inject.Inject)2 Plugin (org.gradle.api.Plugin)2 Project (org.gradle.api.Project)2 DirectoryProperty (org.gradle.api.file.DirectoryProperty)2 ProjectPublicationRegistry (org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 TaskContainer (org.gradle.api.tasks.TaskContainer)2 TaskProvider (org.gradle.api.tasks.TaskProvider)2 Names (org.gradle.language.nativeplatform.internal.Names)2 NativeBasePlugin (org.gradle.language.plugins.NativeBasePlugin)2 NativeProjectPublication (org.gradle.swiftpm.internal.NativeProjectPublication)2 SwiftPmTarget (org.gradle.swiftpm.internal.SwiftPmTarget)2 File (java.io.File)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 NonNullApi (org.gradle.api.NonNullApi)1 AttributeCompatibilityRule (org.gradle.api.attributes.AttributeCompatibilityRule)1 CompatibilityCheckDetails (org.gradle.api.attributes.CompatibilityCheckDetails)1 Usage (org.gradle.api.attributes.Usage)1 CppSharedLibrary (org.gradle.language.cpp.CppSharedLibrary)1