Search in sources :

Example 1 with DefaultNativeComponent

use of org.gradle.language.nativeplatform.internal.DefaultNativeComponent 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)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 AttributeCompatibilityRule (org.gradle.api.attributes.AttributeCompatibilityRule)1 CompatibilityCheckDetails (org.gradle.api.attributes.CompatibilityCheckDetails)1 Usage (org.gradle.api.attributes.Usage)1 DirectoryProperty (org.gradle.api.file.DirectoryProperty)1 ProjectPublicationRegistry (org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 TaskProvider (org.gradle.api.tasks.TaskProvider)1 DefaultNativeComponent (org.gradle.language.nativeplatform.internal.DefaultNativeComponent)1 Names (org.gradle.language.nativeplatform.internal.Names)1 NativeBasePlugin (org.gradle.language.plugins.NativeBasePlugin)1 ProductionSwiftComponent (org.gradle.language.swift.ProductionSwiftComponent)1 SwiftSharedLibrary (org.gradle.language.swift.SwiftSharedLibrary)1 SwiftStaticLibrary (org.gradle.language.swift.SwiftStaticLibrary)1 DefaultSwiftBinary (org.gradle.language.swift.internal.DefaultSwiftBinary)1 SwiftCompile (org.gradle.language.swift.tasks.SwiftCompile)1 MacOSSdkPathLocator (org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPathLocator)1