Search in sources :

Example 6 with TaskContainerInternal

use of org.gradle.api.internal.tasks.TaskContainerInternal in project gradle by gradle.

the class SwiftBasePlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(SwiftCompilerPlugin.class);
    final TaskContainerInternal tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    final ProviderFactory providers = project.getProviders();
    project.getDependencies().getAttributesSchema().attribute(Usage.USAGE_ATTRIBUTE).getCompatibilityRules().add(SwiftCppUsageCompatibilityRule.class);
    project.getComponents().withType(DefaultSwiftBinary.class, new Action<DefaultSwiftBinary>() {

        @Override
        public void execute(final DefaultSwiftBinary binary) {
            final Names names = binary.getNames();
            SwiftCompile compile = tasks.create(names.getCompileTaskName("swift"), SwiftCompile.class);
            compile.getModules().from(binary.getCompileModules());
            compile.getSource().from(binary.getSwiftSource());
            compile.getDebuggable().set(binary.isDebuggable());
            compile.getOptimized().set(binary.isOptimized());
            if (binary.isTestable()) {
                compile.getCompilerArgs().add("-enable-testing");
            }
            if (binary.getTargetPlatform().getOperatingSystem().isMacOsX()) {
                compile.getCompilerArgs().add("-sdk");
                compile.getCompilerArgs().add(locator.find().getAbsolutePath());
            }
            compile.getModuleName().set(binary.getModule());
            compile.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            compile.getModuleFile().set(buildDirectory.file(providers.provider(new Callable<String>() {

                @Override
                public String call() {
                    return "modules/" + names.getDirName() + binary.getModule().get() + ".swiftmodule";
                }
            })));
            compile.getSourceCompatibility().set(binary.getSourceCompatibility());
            binary.getModuleFile().set(compile.getModuleFile());
            compile.getTargetPlatform().set(binary.getTargetPlatform());
            // TODO - make this lazy
            compile.getToolChain().set(binary.getToolChain());
            binary.getCompileTask().set(compile);
            binary.getObjectsDir().set(compile.getObjectFileDir());
        }
    });
    project.getComponents().withType(SwiftSharedLibrary.class, new Action<SwiftSharedLibrary>() {

        @Override
        public void execute(SwiftSharedLibrary library) {
            // Specific compiler arguments
            library.getCompileTask().get().getCompilerArgs().add("-parse-as-library");
        }
    });
    project.getComponents().withType(SwiftStaticLibrary.class, new Action<SwiftStaticLibrary>() {

        @Override
        public void execute(SwiftStaticLibrary library) {
            // Specific compiler arguments
            library.getCompileTask().get().getCompilerArgs().add("-parse-as-library");
        }
    });
    project.getComponents().withType(DefaultSwiftComponent.class, new Action<DefaultSwiftComponent>() {

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

                @Override
                public void execute(Project project) {
                    component.getSourceCompatibility().lockNow();
                }
            });
            component.getBinaries().whenElementKnown(DefaultSwiftBinary.class, new Action<DefaultSwiftBinary>() {

                @Override
                public void execute(final DefaultSwiftBinary binary) {
                    Provider<SwiftVersion> swiftLanguageVersionProvider = project.provider(new Callable<SwiftVersion>() {

                        @Override
                        public SwiftVersion call() throws Exception {
                            SwiftVersion swiftSourceCompatibility = component.getSourceCompatibility().getOrNull();
                            if (swiftSourceCompatibility == null) {
                                return toSwiftVersion(binary.getPlatformToolProvider().getCompilerMetadata(ToolType.SWIFT_COMPILER).getVersion());
                            }
                            return swiftSourceCompatibility;
                        }
                    });
                    binary.getSourceCompatibility().set(swiftLanguageVersionProvider);
                }
            });
        }
    });
    project.getComponents().withType(ProductionSwiftComponent.class, new Action<ProductionSwiftComponent>() {

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

                @Override
                public void execute(Project project) {
                    DefaultSwiftComponent componentInternal = (DefaultSwiftComponent) component;
                    publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getModule().get()), false));
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) SwiftStaticLibrary(org.gradle.language.swift.SwiftStaticLibrary) Callable(java.util.concurrent.Callable) Names(org.gradle.language.nativeplatform.internal.Names) ProviderFactory(org.gradle.api.provider.ProviderFactory) SwiftVersion(org.gradle.language.swift.SwiftVersion) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal) Project(org.gradle.api.Project) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) SwiftSharedLibrary(org.gradle.language.swift.SwiftSharedLibrary) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) DefaultSwiftComponent(org.gradle.language.swift.internal.DefaultSwiftComponent) DefaultProjectPublication(org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication)

Aggregations

TaskContainerInternal (org.gradle.api.internal.tasks.TaskContainerInternal)6 Callable (java.util.concurrent.Callable)2 Action (org.gradle.api.Action)2 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 DirectoryProperty (org.gradle.api.file.DirectoryProperty)2 DefaultProjectPublication (org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication)2 Names (org.gradle.language.nativeplatform.internal.Names)2 SwiftPmTarget (org.gradle.swiftpm.internal.SwiftPmTarget)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 FeaturePreviews (org.gradle.api.internal.FeaturePreviews)1 TaskInternal (org.gradle.api.internal.TaskInternal)1 CachingTaskDependencyResolveContext (org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext)1 ProviderFactory (org.gradle.api.provider.ProviderFactory)1 CppSharedLibrary (org.gradle.language.cpp.CppSharedLibrary)1 ProductionCppComponent (org.gradle.language.cpp.ProductionCppComponent)1