use of org.gradle.nativeplatform.TargetMachineFactory in project gradle by gradle.
the class SwiftApplicationPlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(SwiftBasePlugin.class);
final ObjectFactory objectFactory = project.getObjects();
final ProviderFactory providers = project.getProviders();
// Add the application and extension
final DefaultSwiftApplication application = componentFactory.newInstance(SwiftApplication.class, DefaultSwiftApplication.class, "main");
project.getExtensions().add(SwiftApplication.class, "application", application);
project.getComponents().add(application);
// Setup component
application.getModule().convention(GUtil.toCamelCase(project.getName()));
application.getTargetMachines().convention(Dimensions.useHostAsDefaultTargetMachine(targetMachineFactory));
application.getDevelopmentBinary().convention(project.provider(() -> {
return application.getBinaries().get().stream().filter(SwiftExecutable.class::isInstance).map(SwiftExecutable.class::cast).filter(binary -> !binary.isOptimized() && Architectures.forInput(binary.getTargetMachine().getArchitecture().getName()).equals(DefaultNativePlatform.host().getArchitecture())).findFirst().orElse(application.getBinaries().get().stream().filter(SwiftExecutable.class::isInstance).map(SwiftExecutable.class::cast).filter(binary -> !binary.isOptimized()).findFirst().orElse(null));
}));
project.afterEvaluate(p -> {
// TODO: make build type configurable for components
Dimensions.applicationVariants(application.getModule(), application.getTargetMachines(), objectFactory, attributesFactory, providers.provider(() -> project.getGroup().toString()), providers.provider(() -> project.getVersion().toString()), variantIdentity -> {
if (tryToBuildOnHost(variantIdentity)) {
application.getSourceCompatibility().finalizeValue();
ToolChainSelector.Result<SwiftPlatform> result = toolChainSelector.select(SwiftPlatform.class, new DefaultSwiftPlatform(variantIdentity.getTargetMachine(), application.getSourceCompatibility().getOrNull()));
application.addExecutable(variantIdentity, variantIdentity.isDebuggable() && !variantIdentity.isOptimized(), result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
}
});
// Configure the binaries
application.getBinaries().realizeNow();
});
}
use of org.gradle.nativeplatform.TargetMachineFactory in project gradle by gradle.
the class CppApplicationPlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(CppBasePlugin.class);
final ObjectFactory objectFactory = project.getObjects();
final ProviderFactory providers = project.getProviders();
// Add the application and extension
final DefaultCppApplication application = componentFactory.newInstance(CppApplication.class, DefaultCppApplication.class, "main");
project.getExtensions().add(CppApplication.class, "application", application);
project.getComponents().add(application);
// Configure the component
application.getBaseName().convention(project.getName());
application.getTargetMachines().convention(useHostAsDefaultTargetMachine(targetMachineFactory));
application.getDevelopmentBinary().convention(project.provider(() -> {
// Prefer the host architecture, if present, else use the first architecture specified
return application.getBinaries().get().stream().filter(CppExecutable.class::isInstance).map(CppExecutable.class::cast).filter(binary -> !binary.isOptimized() && Architectures.forInput(binary.getTargetMachine().getArchitecture().getName()).equals(DefaultNativePlatform.host().getArchitecture())).findFirst().orElse(application.getBinaries().get().stream().filter(CppExecutable.class::isInstance).map(CppExecutable.class::cast).filter(binary -> !binary.isOptimized()).findFirst().orElse(null));
}));
application.getBinaries().whenElementKnown(binary -> {
application.getMainPublication().addVariant(binary);
});
project.afterEvaluate(p -> {
// TODO: make build type configurable for components
Dimensions.applicationVariants(application.getBaseName(), application.getTargetMachines(), objectFactory, attributesFactory, providers.provider(() -> project.getGroup().toString()), providers.provider(() -> project.getVersion().toString()), variantIdentity -> {
if (tryToBuildOnHost(variantIdentity)) {
ToolChainSelector.Result<CppPlatform> result = toolChainSelector.select(CppPlatform.class, new DefaultCppPlatform(variantIdentity.getTargetMachine()));
application.addExecutable(variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
} else {
// Known, but not buildable
application.getMainPublication().addVariant(variantIdentity);
}
});
// Configure the binaries
application.getBinaries().realizeNow();
});
}
use of org.gradle.nativeplatform.TargetMachineFactory in project gradle by gradle.
the class XCTestConventionPlugin method apply.
@Override
public void apply(Project project) {
project.getPluginManager().apply(SwiftBasePlugin.class);
project.getPluginManager().apply(NativeTestingBasePlugin.class);
final ProviderFactory providers = project.getProviders();
// Create test suite component
// TODO - Reuse logic from Swift*Plugin
// TODO - component name and extension name aren't the same
// TODO - should use `src/xctest/swift` as the convention?
// Add the test suite and extension
DefaultSwiftXCTestSuite testSuite = componentFactory.newInstance(SwiftXCTestSuite.class, DefaultSwiftXCTestSuite.class, "test");
project.getExtensions().add(SwiftXCTestSuite.class, "xctest", testSuite);
project.getComponents().add(testSuite);
// Setup component
testSuite.getModule().set(GUtil.toCamelCase(project.getName() + "Test"));
final DefaultSwiftXCTestSuite testComponent = testSuite;
testComponent.getTargetMachines().convention(useHostAsDefaultTargetMachine(targetMachineFactory));
testComponent.getSourceCompatibility().convention(testComponent.getTestedComponent().flatMap(it -> it.getSourceCompatibility()));
final String mainComponentName = "main";
project.getComponents().withType(ProductionSwiftComponent.class, component -> {
if (mainComponentName.equals(component.getName())) {
testComponent.getTargetMachines().convention(component.getTargetMachines());
testComponent.getTestedComponent().convention(component);
}
});
testComponent.getTestBinary().convention(project.provider(() -> {
return testComponent.getBinaries().get().stream().filter(SwiftXCTestBinary.class::isInstance).map(SwiftXCTestBinary.class::cast).findFirst().orElse(null);
}));
testComponent.getBinaries().whenElementKnown(DefaultSwiftXCTestBinary.class, binary -> {
// Create test suite test task
TaskProvider<XCTest> testingTask = project.getTasks().register("xcTest", XCTest.class, task -> {
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
task.setDescription("Executes XCTest suites");
task.getTestInstallDirectory().set(binary.getInstallDirectory());
task.getRunScriptFile().set(binary.getRunScriptFile());
task.getWorkingDirectory().set(binary.getInstallDirectory());
});
binary.getRunTask().set(testingTask);
configureTestSuiteBuildingTasks(project, binary);
configureTestSuiteWithTestedComponentWhenAvailable(project, testComponent, binary);
});
project.afterEvaluate(p -> {
final SwiftComponent mainComponent = testComponent.getTestedComponent().getOrNull();
final SetProperty<TargetMachine> mainTargetMachines = mainComponent != null ? mainComponent.getTargetMachines() : null;
Dimensions.unitTestVariants(testComponent.getModule(), testComponent.getTargetMachines(), mainTargetMachines, objectFactory, attributesFactory, providers.provider(() -> project.getGroup().toString()), providers.provider(() -> project.getVersion().toString()), variantIdentity -> {
if (tryToBuildOnHost(variantIdentity)) {
testComponent.getSourceCompatibility().finalizeValue();
ToolChainSelector.Result<SwiftPlatform> result = toolChainSelector.select(SwiftPlatform.class, new DefaultSwiftPlatform(variantIdentity.getTargetMachine(), testComponent.getSourceCompatibility().getOrNull()));
// Create test suite executable
if (result.getTargetPlatform().getTargetMachine().getOperatingSystemFamily().isMacOs()) {
testComponent.addBundle(variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
} else {
testComponent.addExecutable(variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
}
}
});
testComponent.getBinaries().realizeNow();
});
}
use of org.gradle.nativeplatform.TargetMachineFactory in project gradle by gradle.
the class NativeBasePlugin method addLifecycleTasks.
private void addLifecycleTasks(final Project project, final TaskContainer tasks, final SoftwareComponentContainer components) {
components.withType(ComponentWithBinaries.class, component -> {
// Register each child of each component
component.getBinaries().whenElementKnown(binary -> components.add(binary));
if (component instanceof ProductionComponent) {
// Add an assemble task for each binary and also wire the development binary in to the `assemble` task
component.getBinaries().whenElementFinalized(ComponentWithOutputs.class, binary -> {
// Determine which output to produce at development time.
final FileCollection outputs = binary.getOutputs();
Names names = ((ComponentWithNames) binary).getNames();
tasks.register(names.getTaskName("assemble"), task -> task.dependsOn(outputs));
if (binary == ((ProductionComponent) component).getDevelopmentBinary().get()) {
tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME, task -> task.dependsOn(outputs));
}
});
}
if (component instanceof ComponentWithTargetMachines) {
ComponentWithTargetMachines componentWithTargetMachines = (ComponentWithTargetMachines) component;
tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME, task -> {
task.dependsOn((Callable) () -> {
TargetMachine currentHost = ((DefaultTargetMachineFactory) targetMachineFactory).host();
boolean targetsCurrentMachine = componentWithTargetMachines.getTargetMachines().get().stream().anyMatch(targetMachine -> currentHost.getOperatingSystemFamily().equals(targetMachine.getOperatingSystemFamily()));
if (!targetsCurrentMachine) {
task.getLogger().warn("'" + component.getName() + "' component in project '" + project.getPath() + "' does not target this operating system.");
}
return Collections.emptyList();
});
});
}
});
}
Aggregations