Search in sources :

Example 1 with CppApplication

use of org.gradle.language.cpp.CppApplication in project gradle by gradle.

the class VisualStudioPlugin method applyVisualStudioCurrentModelRules.

private void applyVisualStudioCurrentModelRules(final VisualStudioExtensionInternal extension) {
    project.getComponents().withType(CppApplication.class).all(cppApplication -> {
        DefaultVisualStudioProject vsProject = extension.getProjectRegistry().createProject(project.getName(), cppApplication.getName());
        vsProject.getSourceFiles().from(cppApplication.getCppSource());
        vsProject.getHeaderFiles().from(cppApplication.getHeaderFiles());
        cppApplication.getBinaries().whenElementFinalized(CppExecutable.class, executable -> {
            extension.getProjectRegistry().addProjectConfiguration(new CppApplicationVisualStudioTargetBinary(project.getName(), project.getPath(), cppApplication, executable, project.getLayout()));
        });
    });
    project.afterEvaluate(proj -> {
        project.getComponents().withType(CppLibrary.class).all(cppLibrary -> {
            for (Linkage linkage : cppLibrary.getLinkage().get()) {
                VisualStudioTargetBinary.ProjectType projectType = VisualStudioTargetBinary.ProjectType.DLL;
                if (Linkage.STATIC.equals(linkage)) {
                    projectType = VisualStudioTargetBinary.ProjectType.LIB;
                }
                DefaultVisualStudioProject vsProject = extension.getProjectRegistry().createProject(project.getName() + projectType.getSuffix(), cppLibrary.getName());
                vsProject.getSourceFiles().from(cppLibrary.getCppSource());
                vsProject.getHeaderFiles().from(cppLibrary.getHeaderFiles());
            }
            cppLibrary.getBinaries().whenElementFinalized(CppSharedLibrary.class, library -> {
                extension.getProjectRegistry().addProjectConfiguration(new CppSharedLibraryVisualStudioTargetBinary(project.getName(), project.getPath(), cppLibrary, library, project.getLayout()));
            });
            cppLibrary.getBinaries().whenElementFinalized(CppStaticLibrary.class, library -> {
                extension.getProjectRegistry().addProjectConfiguration(new CppStaticLibraryVisualStudioTargetBinary(project.getName(), project.getPath(), cppLibrary, library, project.getLayout()));
            });
        });
    });
}
Also used : CppApplicationVisualStudioTargetBinary(org.gradle.ide.visualstudio.internal.CppApplicationVisualStudioTargetBinary) Linkage(org.gradle.nativeplatform.Linkage) VisualStudioTargetBinary(org.gradle.ide.visualstudio.internal.VisualStudioTargetBinary) CppApplicationVisualStudioTargetBinary(org.gradle.ide.visualstudio.internal.CppApplicationVisualStudioTargetBinary) CppStaticLibraryVisualStudioTargetBinary(org.gradle.ide.visualstudio.internal.CppStaticLibraryVisualStudioTargetBinary) CppSharedLibraryVisualStudioTargetBinary(org.gradle.ide.visualstudio.internal.CppSharedLibraryVisualStudioTargetBinary) CppLibrary(org.gradle.language.cpp.CppLibrary) CppStaticLibraryVisualStudioTargetBinary(org.gradle.ide.visualstudio.internal.CppStaticLibraryVisualStudioTargetBinary) DefaultVisualStudioProject(org.gradle.ide.visualstudio.internal.DefaultVisualStudioProject) CppApplication(org.gradle.language.cpp.CppApplication) CppSharedLibraryVisualStudioTargetBinary(org.gradle.ide.visualstudio.internal.CppSharedLibraryVisualStudioTargetBinary)

Example 2 with CppApplication

use of org.gradle.language.cpp.CppApplication in project gradle by gradle.

the class CppModelBuilder method buildAll.

@Override
public Object buildAll(String modelName, Project project) {
    DefaultProjectIdentifier projectIdentifier = new DefaultProjectIdentifier(project.getRootDir(), project.getPath());
    CompilerOutputFileNamingSchemeFactory namingSchemeFactory = new CompilerOutputFileNamingSchemeFactory(((ProjectInternal) project).getFileResolver());
    DefaultCppComponentModel mainComponent = null;
    CppApplication application = project.getComponents().withType(CppApplication.class).findByName("main");
    if (application != null) {
        mainComponent = new DefaultCppApplicationModel(application.getName(), application.getBaseName().get(), binariesFor(application, application.getPrivateHeaderDirs(), projectIdentifier, namingSchemeFactory));
    } else {
        DefaultCppLibrary library = (DefaultCppLibrary) project.getComponents().withType(CppLibrary.class).findByName("main");
        if (library != null) {
            mainComponent = new DefaultCppLibraryModel(library.getName(), library.getBaseName().get(), binariesFor(library, library.getAllHeaderDirs(), projectIdentifier, namingSchemeFactory));
        }
    }
    DefaultCppComponentModel testComponent = null;
    CppTestSuite testSuite = project.getComponents().withType(CppTestSuite.class).findByName("test");
    if (testSuite != null) {
        testComponent = new DefaultCppTestSuiteModel(testSuite.getName(), testSuite.getBaseName().get(), binariesFor(testSuite, testSuite.getPrivateHeaderDirs(), projectIdentifier, namingSchemeFactory));
    }
    return new DefaultCppProjectModel(projectIdentifier, mainComponent, testComponent);
}
Also used : CompilerOutputFileNamingSchemeFactory(org.gradle.nativeplatform.internal.CompilerOutputFileNamingSchemeFactory) CppTestSuite(org.gradle.nativeplatform.test.cpp.CppTestSuite) CppApplication(org.gradle.language.cpp.CppApplication) DefaultCppLibrary(org.gradle.language.cpp.internal.DefaultCppLibrary) DefaultProjectIdentifier(org.gradle.tooling.internal.gradle.DefaultProjectIdentifier)

Example 3 with CppApplication

use of org.gradle.language.cpp.CppApplication in project gradle by gradle.

the class CppUnitTestPlugin method configureTestSuiteWithTestedComponentWhenAvailable.

private void configureTestSuiteWithTestedComponentWhenAvailable(Project project, DefaultCppTestSuite testSuite, DefaultCppTestExecutable testExecutable) {
    CppComponent target = testSuite.getTestedComponent().getOrNull();
    if (!(target instanceof ProductionCppComponent)) {
        return;
    }
    final ProductionCppComponent testedComponent = (ProductionCppComponent) target;
    final TaskContainer tasks = project.getTasks();
    testedComponent.getBinaries().whenElementFinalized(testedBinary -> {
        if (!isTestedBinary(testExecutable, testedComponent, testedBinary)) {
            return;
        }
        // TODO - move this to a base plugin
        // Setup the dependency on the main binary
        // This should all be replaced by a single dependency that points at some "testable" variants of the main binary
        // Inherit implementation dependencies
        testExecutable.getImplementationDependencies().extendsFrom(((DefaultCppBinary) testedBinary).getImplementationDependencies());
        // Configure test binary to link against tested component compiled objects
        ConfigurableFileCollection testableObjects = project.files();
        if (target instanceof CppApplication) {
            // TODO - this should be an outgoing variant of the component under test
            TaskProvider<UnexportMainSymbol> unexportMainSymbol = tasks.register(testExecutable.getNames().getTaskName("relocateMainFor"), UnexportMainSymbol.class, task -> {
                String dirName = ((DefaultCppBinary) testedBinary).getNames().getDirName();
                task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("obj/for-test/" + dirName));
                task.getObjects().from(testedBinary.getObjects());
            });
            testableObjects.from(unexportMainSymbol.map(task -> task.getRelocatedObjects()));
        } else {
            testableObjects.from(testedBinary.getObjects());
        }
        Dependency linkDependency = project.getDependencies().create(testableObjects);
        testExecutable.getLinkConfiguration().getDependencies().add(linkDependency);
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) NativeTestingBasePlugin(org.gradle.nativeplatform.test.plugins.NativeTestingBasePlugin) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) DefaultCppTestSuite(org.gradle.nativeplatform.test.cpp.internal.DefaultCppTestSuite) Callable(java.util.concurrent.Callable) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) CppPlatform(org.gradle.language.cpp.CppPlatform) Inject(javax.inject.Inject) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) TaskProvider(org.gradle.api.tasks.TaskProvider) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) CppComponent(org.gradle.language.cpp.CppComponent) CppApplication(org.gradle.language.cpp.CppApplication) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) ConfigurableComponentWithLinkUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithLinkUsage) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) DefaultCppTestExecutable(org.gradle.nativeplatform.test.cpp.internal.DefaultCppTestExecutable) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) InstallExecutable(org.gradle.nativeplatform.tasks.InstallExecutable) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) CppTestSuite(org.gradle.nativeplatform.test.cpp.CppTestSuite) CppTestExecutable(org.gradle.nativeplatform.test.cpp.CppTestExecutable) SetProperty(org.gradle.api.provider.SetProperty) ProviderFactory(org.gradle.api.provider.ProviderFactory) Stream(java.util.stream.Stream) ObjectFactory(org.gradle.api.model.ObjectFactory) TaskContainer(org.gradle.api.tasks.TaskContainer) CppBinary(org.gradle.language.cpp.CppBinary) CppBasePlugin(org.gradle.language.cpp.plugins.CppBasePlugin) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) RunTestExecutable(org.gradle.nativeplatform.test.tasks.RunTestExecutable) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) TaskContainer(org.gradle.api.tasks.TaskContainer) CppComponent(org.gradle.language.cpp.CppComponent) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) CppApplication(org.gradle.language.cpp.CppApplication) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) Dependency(org.gradle.api.artifacts.Dependency) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent)

Aggregations

CppApplication (org.gradle.language.cpp.CppApplication)3 CppTestSuite (org.gradle.nativeplatform.test.cpp.CppTestSuite)2 Callable (java.util.concurrent.Callable)1 Stream (java.util.stream.Stream)1 Inject (javax.inject.Inject)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Dependency (org.gradle.api.artifacts.Dependency)1 ConfigurableFileCollection (org.gradle.api.file.ConfigurableFileCollection)1 ImmutableAttributesFactory (org.gradle.api.internal.attributes.ImmutableAttributesFactory)1 ObjectFactory (org.gradle.api.model.ObjectFactory)1 ProviderFactory (org.gradle.api.provider.ProviderFactory)1 SetProperty (org.gradle.api.provider.SetProperty)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 TaskProvider (org.gradle.api.tasks.TaskProvider)1 CppApplicationVisualStudioTargetBinary (org.gradle.ide.visualstudio.internal.CppApplicationVisualStudioTargetBinary)1 CppSharedLibraryVisualStudioTargetBinary (org.gradle.ide.visualstudio.internal.CppSharedLibraryVisualStudioTargetBinary)1 CppStaticLibraryVisualStudioTargetBinary (org.gradle.ide.visualstudio.internal.CppStaticLibraryVisualStudioTargetBinary)1 DefaultVisualStudioProject (org.gradle.ide.visualstudio.internal.DefaultVisualStudioProject)1 VisualStudioTargetBinary (org.gradle.ide.visualstudio.internal.VisualStudioTargetBinary)1