Search in sources :

Example 16 with NativeToolChainInternal

use of org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal in project gradle by gradle.

the class Assemble method assemble.

@TaskAction
public void assemble() {
    BuildOperationLogger operationLogger = getOperationLoggerFactory().newOperationLogger(getName(), getTemporaryDir());
    boolean cleanedOutputs = StaleOutputCleaner.cleanOutputs(getDeleter(), getOutputs().getPreviousOutputFiles(), getObjectFileDir());
    DefaultAssembleSpec spec = new DefaultAssembleSpec();
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(getObjectFileDir());
    spec.source(getSource());
    spec.include(getIncludes());
    spec.args(getAssemblerArgs());
    spec.setOperationLogger(operationLogger);
    NativeToolChainInternal nativeToolChain = (NativeToolChainInternal) toolChain.get();
    NativePlatformInternal nativePlatform = (NativePlatformInternal) targetPlatform.get();
    Compiler<AssembleSpec> compiler = nativeToolChain.select(nativePlatform).newCompiler(AssembleSpec.class);
    WorkResult result = BuildOperationLoggingCompilerDecorator.wrap(compiler).execute(spec);
    setDidWork(result.getDidWork() || cleanedOutputs);
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) AssembleSpec(org.gradle.nativeplatform.toolchain.internal.compilespec.AssembleSpec) DefaultAssembleSpec(org.gradle.language.assembler.internal.DefaultAssembleSpec) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) DefaultAssembleSpec(org.gradle.language.assembler.internal.DefaultAssembleSpec) WorkResult(org.gradle.api.tasks.WorkResult) TaskAction(org.gradle.api.tasks.TaskAction)

Example 17 with NativeToolChainInternal

use of org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal 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 18 with NativeToolChainInternal

use of org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal in project gradle by gradle.

the class CppBasePlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(StandardToolChainsPlugin.class);
    final TaskContainerInternal tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    // Enable the use of Gradle metadata. This is a temporary opt-in switch until available by default
    project.getGradle().getServices().get(FeaturePreviews.class).enableFeature(GRADLE_METADATA);
    // Create the tasks for each C++ binary that is registered
    project.getComponents().withType(DefaultCppBinary.class, new Action<DefaultCppBinary>() {

        @Override
        public void execute(final DefaultCppBinary binary) {
            final Names names = binary.getNames();
            String language = "cpp";
            final NativePlatform currentPlatform = binary.getTargetPlatform();
            // TODO - make this lazy
            final NativeToolChainInternal toolChain = binary.getToolChain();
            Callable<List<File>> systemIncludes = new Callable<List<File>>() {

                @Override
                public List<File> call() {
                    PlatformToolProvider platformToolProvider = binary.getPlatformToolProvider();
                    return platformToolProvider.getSystemLibraries(ToolType.CPP_COMPILER).getIncludeDirs();
                }
            };
            CppCompile compile = tasks.create(names.getCompileTaskName(language), CppCompile.class);
            compile.includes(binary.getCompileIncludePath());
            compile.includes(systemIncludes);
            compile.source(binary.getCppSource());
            if (binary.isDebuggable()) {
                compile.setDebuggable(true);
            }
            if (binary.isOptimized()) {
                compile.setOptimized(true);
            }
            compile.getTargetPlatform().set(currentPlatform);
            compile.getToolChain().set(toolChain);
            compile.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            binary.getObjectsDir().set(compile.getObjectFileDir());
            binary.getCompileTask().set(compile);
        }
    });
    project.getComponents().withType(CppSharedLibrary.class, new Action<CppSharedLibrary>() {

        @Override
        public void execute(CppSharedLibrary library) {
            library.getCompileTask().get().setPositionIndependentCode(true);
        }
    });
    project.getComponents().withType(ProductionCppComponent.class, new Action<ProductionCppComponent>() {

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

                @Override
                public void execute(Project project) {
                    DefaultCppComponent componentInternal = (DefaultCppComponent) component;
                    publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getBaseName().get()), false));
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) Callable(java.util.concurrent.Callable) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) List(java.util.List) CppSharedLibrary(org.gradle.language.cpp.CppSharedLibrary) FeaturePreviews(org.gradle.api.internal.FeaturePreviews) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) Project(org.gradle.api.Project) DefaultCppComponent(org.gradle.language.cpp.internal.DefaultCppComponent) DirectoryProperty(org.gradle.api.file.DirectoryProperty) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) CppCompile(org.gradle.language.cpp.tasks.CppCompile) DefaultProjectPublication(org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication) File(java.io.File)

Example 19 with NativeToolChainInternal

use of org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal in project gradle by gradle.

the class StripSymbols method createCompiler.

private Compiler<StripperSpec> createCompiler() {
    NativePlatformInternal targetPlatform = Cast.cast(NativePlatformInternal.class, this.targetPlatform.get());
    NativeToolChainInternal toolChain = Cast.cast(NativeToolChainInternal.class, getToolChain().get());
    PlatformToolProvider toolProvider = toolChain.select(targetPlatform);
    return toolProvider.newCompiler(StripperSpec.class);
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal)

Example 20 with NativeToolChainInternal

use of org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal in project gradle by gradle.

the class AbstractNativeCompileTask method compile.

@TaskAction
protected void compile(InputChanges inputs) {
    BuildOperationLogger operationLogger = getOperationLoggerFactory().newOperationLogger(getName(), getTemporaryDir());
    NativeCompileSpec spec = createCompileSpec();
    spec.setTargetPlatform(targetPlatform.get());
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(objectFileDir.get().getAsFile());
    spec.include(includes);
    spec.systemInclude(systemIncludes);
    spec.source(getSource());
    spec.setMacros(getMacros());
    spec.args(getCompilerArgs().get());
    spec.setPositionIndependentCode(isPositionIndependentCode());
    spec.setDebuggable(isDebuggable());
    spec.setOptimized(isOptimized());
    spec.setIncrementalCompile(inputs.isIncremental());
    spec.setOperationLogger(operationLogger);
    configureSpec(spec);
    NativeToolChainInternal nativeToolChain = (NativeToolChainInternal) toolChain.get();
    NativePlatformInternal nativePlatform = (NativePlatformInternal) targetPlatform.get();
    PlatformToolProvider platformToolProvider = nativeToolChain.select(nativePlatform);
    setDidWork(doCompile(spec, platformToolProvider).getDidWork());
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativeCompileSpec(org.gradle.nativeplatform.toolchain.internal.NativeCompileSpec) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

NativeToolChainInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal)23 PlatformToolProvider (org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)20 NativePlatformInternal (org.gradle.nativeplatform.platform.internal.NativePlatformInternal)12 File (java.io.File)6 TaskAction (org.gradle.api.tasks.TaskAction)5 BuildOperationLogger (org.gradle.internal.operations.logging.BuildOperationLogger)5 DefaultNativePlatform (org.gradle.nativeplatform.platform.internal.DefaultNativePlatform)5 Project (org.gradle.api.Project)4 NativeCompileSpec (org.gradle.nativeplatform.toolchain.internal.NativeCompileSpec)4 NativeToolChainRegistryInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal)4 LinkedHashSet (java.util.LinkedHashSet)3 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)3 MinimalFileSet (org.gradle.api.internal.file.collections.MinimalFileSet)3 WorkResult (org.gradle.api.tasks.WorkResult)3 Names (org.gradle.language.nativeplatform.internal.Names)3 SwiftPlatform (org.gradle.language.swift.SwiftPlatform)3 DefaultSwiftPlatform (org.gradle.language.swift.internal.DefaultSwiftPlatform)3 NativeLanguage (org.gradle.nativeplatform.toolchain.internal.NativeLanguage)3 List (java.util.List)2 Callable (java.util.concurrent.Callable)2