Search in sources :

Example 6 with ModelRegistry

use of org.gradle.model.internal.registry.ModelRegistry in project gradle by gradle.

the class XCTestConventionPlugin method configureTestSuiteBuildingTasks.

private void configureTestSuiteBuildingTasks(final Project project, final DefaultSwiftXCTestBinary binary) {
    // Overwrite the source to exclude `LinuxMain.swift`
    SwiftCompile compile = binary.getCompileTask().get();
    compile.getSource().setFrom(binary.getSwiftSource().getAsFileTree().matching(patterns -> patterns.include("**/*").exclude("**/LinuxMain.swift")));
    if (binary instanceof SwiftXCTestBundle) {
        TaskContainer tasks = project.getTasks();
        final Names names = binary.getNames();
        // TODO - creating a bundle should be done by some general purpose plugin
        // TODO - make this lazy
        final DefaultNativePlatform currentPlatform = new DefaultNativePlatform("current");
        final ModelRegistry modelRegistry = ((ProjectInternal) project).getModelRegistry();
        final NativeToolChain toolChain = modelRegistry.realize("toolChains", NativeToolChainRegistryInternal.class).getForPlatform(currentPlatform);
        // Platform specific arguments
        // TODO: Need to lazily configure compile task
        // TODO: Ultimately, this should be some kind of 3rd party dependency that's visible to dependency management.
        compile.getCompilerArgs().addAll(project.provider(() -> {
            File platformSdkPath = sdkPlatformPathLocator.find();
            File frameworkDir = new File(platformSdkPath, "Developer/Library/Frameworks");
            // Since Xcode 11/12, the XCTest framework is being replaced by a different library that's available in the sdk root
            File extraInclude = new File(platformSdkPath, "Developer/usr/lib");
            return Arrays.asList("-parse-as-library", "-F" + frameworkDir.getAbsolutePath(), "-I", extraInclude.getAbsolutePath(), "-v");
        }));
        // Add a link task
        final TaskProvider<LinkMachOBundle> link = tasks.register(names.getTaskName("link"), LinkMachOBundle.class, task -> {
            task.getLinkerArgs().set(project.provider(() -> {
                File platformSdkPath = sdkPlatformPathLocator.find();
                File frameworkDir = new File(platformSdkPath, "Developer/Library/Frameworks");
                // Since Xcode 11/12, the XCTest framework is being replaced by a different library that's available in the sdk root
                File extraInclude = new File(platformSdkPath, "Developer/usr/lib");
                return Lists.newArrayList("-F" + frameworkDir.getAbsolutePath(), "-L", extraInclude.getAbsolutePath(), "-framework", "XCTest", "-Xlinker", "-rpath", "-Xlinker", "@executable_path/../Frameworks", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/../Frameworks");
            }));
            task.source(binary.getObjects());
            task.lib(binary.getLinkLibraries());
            final PlatformToolProvider toolProvider = ((NativeToolChainInternal) toolChain).select(currentPlatform);
            Provider<RegularFile> exeLocation = project.getLayout().getBuildDirectory().file(binary.getBaseName().map(baseName -> toolProvider.getExecutableName("exe/" + names.getDirName() + baseName)));
            task.getLinkedFile().set(exeLocation);
            task.getTargetPlatform().set(currentPlatform);
            task.getToolChain().set(toolChain);
            task.getDebuggable().set(binary.isDebuggable());
        });
        final TaskProvider<InstallXCTestBundle> install = tasks.register(names.getTaskName("install"), InstallXCTestBundle.class, task -> {
            task.getBundleBinaryFile().set(link.get().getLinkedFile());
            task.getInstallDirectory().set(project.getLayout().getBuildDirectory().dir("install/" + names.getDirName()));
        });
        binary.getInstallDirectory().set(install.flatMap(task -> task.getInstallDirectory()));
        binary.getExecutableFile().set(link.flatMap(task -> task.getLinkedFile()));
        DefaultSwiftXCTestBundle bundle = (DefaultSwiftXCTestBundle) binary;
        bundle.getLinkTask().set(link);
        bundle.getRunScriptFile().set(install.flatMap(task -> task.getRunScriptFile()));
    } else {
        DefaultSwiftXCTestExecutable executable = (DefaultSwiftXCTestExecutable) binary;
        executable.getRunScriptFile().set(executable.getInstallTask().flatMap(task -> task.getRunScriptFile()));
        // Rename `LinuxMain.swift` to `main.swift` so the entry point is correctly detected by swiftc
        if (binary.getTargetMachine().getOperatingSystemFamily().isLinux()) {
            TaskProvider<Sync> renameLinuxMainTask = project.getTasks().register("renameLinuxMain", Sync.class, task -> {
                task.from(binary.getSwiftSource());
                task.into(project.provider(() -> task.getTemporaryDir()));
                task.include("LinuxMain.swift");
                task.rename(it -> "main.swift");
            });
            compile.getSource().from(project.files(renameLinuxMainTask).getAsFileTree().matching(patterns -> patterns.include("**/*.swift")));
        }
    }
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) Arrays(java.util.Arrays) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) GUtil(org.gradle.util.internal.GUtil) Provider(org.gradle.api.provider.Provider) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite) TaskProvider(org.gradle.api.tasks.TaskProvider) XCTest(org.gradle.nativeplatform.test.xctest.tasks.XCTest) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) SwiftBasePlugin(org.gradle.language.swift.plugins.SwiftBasePlugin) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) MacOSSdkPlatformPathLocator(org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPlatformPathLocator) TaskContainer(org.gradle.api.tasks.TaskContainer) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) SwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.SwiftXCTestBinary) DefaultSwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary) NativeTestingBasePlugin(org.gradle.nativeplatform.test.plugins.NativeTestingBasePlugin) Dimensions.useHostAsDefaultTargetMachine(org.gradle.language.nativeplatform.internal.Dimensions.useHostAsDefaultTargetMachine) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) Inject(javax.inject.Inject) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Lists(com.google.common.collect.Lists) Sync(org.gradle.api.tasks.Sync) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) SwiftApplication(org.gradle.language.swift.SwiftApplication) SwiftComponent(org.gradle.language.swift.SwiftComponent) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) File(java.io.File) SetProperty(org.gradle.api.provider.SetProperty) ProviderFactory(org.gradle.api.provider.ProviderFactory) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) ObjectFactory(org.gradle.api.model.ObjectFactory) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) RegularFile(org.gradle.api.file.RegularFile) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) SwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.SwiftXCTestSuite) DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) RegularFile(org.gradle.api.file.RegularFile) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) Names(org.gradle.language.nativeplatform.internal.Names) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) TaskContainer(org.gradle.api.tasks.TaskContainer) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) Sync(org.gradle.api.tasks.Sync) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Example 7 with ModelRegistry

use of org.gradle.model.internal.registry.ModelRegistry in project gradle by gradle.

the class LocalLibraryDependencyResolver method doResolve.

private LibraryResolutionResult doResolve(String selectorProjectPath, String libraryName) {
    try {
        ModelRegistry projectModel = projectModelResolver.resolveProjectModel(selectorProjectPath);
        Collection<VariantComponent> candidates = libraryResolver.resolveCandidates(projectModel, libraryName);
        if (candidates.isEmpty()) {
            return LibraryResolutionResult.emptyResolutionResult(binaryType);
        }
        return LibraryResolutionResult.of(binaryType, candidates, libraryName, binaryPredicate);
    } catch (UnknownProjectException e) {
        return LibraryResolutionResult.projectNotFound(binaryType);
    }
}
Also used : ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) VariantComponent(org.gradle.platform.base.VariantComponent) UnknownProjectException(org.gradle.api.UnknownProjectException)

Example 8 with ModelRegistry

use of org.gradle.model.internal.registry.ModelRegistry in project gradle by gradle.

the class RuleExtractorUtils method configureRuleAction.

public static void configureRuleAction(MethodModelRuleApplicationContext context, RuleApplicationScope ruleApplicationScope, ModelActionRole role, MethodRuleAction ruleAction) {
    ModelAction action = context.contextualize(ruleAction);
    ModelRegistry registry = context.getRegistry();
    switch(ruleApplicationScope) {
        case SELF:
            registry.configure(role, action);
            break;
        case DESCENDANTS:
            registry.configureMatching(new NonReferenceDescendantsSpec(context.getScope()), role, action);
            break;
        default:
            throw new AssertionError();
    }
}
Also used : ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) ModelAction(org.gradle.model.internal.core.ModelAction)

Example 9 with ModelRegistry

use of org.gradle.model.internal.registry.ModelRegistry in project gradle by gradle.

the class NativeDependentBinariesResolutionStrategy method buildState.

private State buildState() {
    State state = new State();
    List<ProjectInternal> orderedProjects = Ordering.usingToString().sortedCopy(projectRegistry.getAllProjects());
    for (ProjectInternal project : orderedProjects) {
        if (project.getPlugins().hasPlugin(ComponentModelBasePlugin.class)) {
            ModelRegistry modelRegistry = projectModelResolver.resolveProjectModel(project.getPath());
            ModelMap<NativeComponentSpec> components = modelRegistry.realize("components", ModelTypes.modelMap(NativeComponentSpec.class));
            for (NativeBinarySpecInternal binary : allBinariesOf(components.withType(VariantComponentSpec.class))) {
                state.registerBinary(binary);
            }
            ModelMap<Object> testSuites = modelRegistry.find("testSuites", ModelTypes.modelMap(Object.class));
            if (testSuites != null) {
                for (NativeBinarySpecInternal binary : allBinariesOf(testSuites.withType(NativeComponentSpec.class).withType(VariantComponentSpec.class))) {
                    state.registerBinary(binary);
                }
            }
        }
    }
    for (NativeBinarySpecInternal nativeBinary : state.dependencies.keySet()) {
        for (NativeLibraryBinary libraryBinary : nativeBinary.getDependentBinaries()) {
            // Skip prebuilt libraries
            if (libraryBinary instanceof NativeBinarySpecInternal) {
                // Unfortunate cast! see LibraryBinaryLocator
                state.dependencies.get(nativeBinary).add((NativeBinarySpecInternal) libraryBinary);
            }
        }
        if (testSupport != null) {
            state.dependencies.get(nativeBinary).addAll(testSupport.getTestDependencies(nativeBinary));
        }
    }
    return state;
}
Also used : NativeLibraryBinary(org.gradle.nativeplatform.NativeLibraryBinary) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) VariantComponentSpec(org.gradle.platform.base.VariantComponentSpec) NativeComponentSpec(org.gradle.nativeplatform.NativeComponentSpec) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

Example 10 with ModelRegistry

use of org.gradle.model.internal.registry.ModelRegistry in project gradle by gradle.

the class NativeComponents method getDependentTaskDependencies.

private static List<Task> getDependentTaskDependencies(String dependedOnBinaryTaskName, BinarySpecInternal binary, DependentBinariesResolver dependentsResolver, ProjectModelResolver projectModelResolver) {
    List<Task> dependencies = Lists.newArrayList();
    DependentBinariesResolvedResult result = dependentsResolver.resolve(binary).getRoot();
    for (DependentBinariesResolvedResult dependent : result.getChildren()) {
        if (dependent.isBuildable()) {
            ModelRegistry modelRegistry = projectModelResolver.resolveProjectModel(dependent.getId().getProjectPath());
            ModelMap<NativeBinarySpecInternal> projectBinaries = modelRegistry.realize("binaries", ModelTypes.modelMap(NativeBinarySpecInternal.class));
            ModelMap<Task> projectTasks = modelRegistry.realize("tasks", ModelTypes.modelMap(Task.class));
            NativeBinarySpecInternal dependentBinary = projectBinaries.get(dependent.getProjectScopedName());
            dependencies.add(projectTasks.get(dependentBinary.getNamingScheme().getTaskName(dependedOnBinaryTaskName)));
        }
    }
    return dependencies;
}
Also used : Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) DependentBinariesResolvedResult(org.gradle.platform.base.internal.dependents.DependentBinariesResolvedResult)

Aggregations

ModelRegistry (org.gradle.model.internal.registry.ModelRegistry)13 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)3 File (java.io.File)2 Nullable (javax.annotation.Nullable)2 RegularFile (org.gradle.api.file.RegularFile)2 TaskAction (org.gradle.api.tasks.TaskAction)2 TaskContainer (org.gradle.api.tasks.TaskContainer)2 ProjectDetails (org.gradle.api.tasks.diagnostics.internal.ProjectDetails)2 StyledTextOutput (org.gradle.internal.logging.text.StyledTextOutput)2 Names (org.gradle.language.nativeplatform.internal.Names)2 SwiftCompile (org.gradle.language.swift.tasks.SwiftCompile)2 DefaultNativePlatform (org.gradle.nativeplatform.platform.internal.DefaultNativePlatform)2 LinkMachOBundle (org.gradle.nativeplatform.tasks.LinkMachOBundle)2 SwiftXCTestBundle (org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle)2 DefaultSwiftXCTestBundle (org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle)2 DefaultSwiftXCTestExecutable (org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable)2 InstallXCTestBundle (org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle)2 NativeToolChain (org.gradle.nativeplatform.toolchain.NativeToolChain)2 NativeToolChainInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal)2 NativeToolChainRegistryInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal)2