use of org.gradle.nativeplatform.TargetMachine in project gradle by gradle.
the class Dimensions method variants.
private static void variants(Provider<String> baseName, Collection<BuildType> buildTypes, Collection<TargetMachine> targetMachines, ObjectFactory objectFactory, ImmutableAttributesFactory attributesFactory, // TODO: These should come from somewhere else, probably
Provider<String> group, Provider<String> version, Action<NativeVariantIdentity> action) {
for (BuildType buildType : buildTypes) {
for (TargetMachine targetMachine : targetMachines) {
Usage runtimeUsage = objectFactory.named(Usage.class, Usage.NATIVE_RUNTIME);
List<String> variantNameToken = Lists.newArrayList();
// FIXME: Always build type name to keep parity with previous Gradle version in tooling API
variantNameToken.add(buildType.getName());
variantNameToken.add(createDimensionSuffix(targetMachine.getOperatingSystemFamily(), targetMachinesToOperatingSystems(targetMachines)));
variantNameToken.add(createDimensionSuffix(targetMachine.getArchitecture(), targetMachinesToArchitectures(targetMachines)));
String variantName = StringUtils.uncapitalize(String.join("", variantNameToken));
AttributeContainer runtimeAttributes = attributesFactory.mutable();
runtimeAttributes.attribute(Usage.USAGE_ATTRIBUTE, runtimeUsage);
addCommonAttributes(buildType, targetMachine, runtimeAttributes);
DefaultUsageContext runtimeUsageContext = new DefaultUsageContext(variantName + "Runtime", runtimeAttributes);
DefaultUsageContext linkUsageContext = null;
NativeVariantIdentity variantIdentity = new NativeVariantIdentity(variantName, baseName, group, version, buildType.isDebuggable(), buildType.isOptimized(), targetMachine, linkUsageContext, runtimeUsageContext, null);
action.execute(variantIdentity);
}
}
}
use of org.gradle.nativeplatform.TargetMachine in project gradle by gradle.
the class Dimensions method variants.
private static void variants(Provider<String> baseName, Collection<BuildType> buildTypes, Collection<Linkage> linkages, Collection<TargetMachine> targetMachines, ObjectFactory objectFactory, ImmutableAttributesFactory attributesFactory, // TODO: These should come from somewhere else, probably
Provider<String> group, Provider<String> version, Action<NativeVariantIdentity> action) {
for (BuildType buildType : buildTypes) {
for (Linkage linkage : linkages) {
for (TargetMachine targetMachine : targetMachines) {
Usage runtimeUsage = objectFactory.named(Usage.class, Usage.NATIVE_RUNTIME);
Usage linkUsage = objectFactory.named(Usage.class, Usage.NATIVE_LINK);
List<String> variantNameToken = Lists.newArrayList();
// FIXME: Always build type name to keep parity with previous Gradle version in tooling API
variantNameToken.add(buildType.getName());
variantNameToken.add(createDimensionSuffix(linkage, linkages));
variantNameToken.add(createDimensionSuffix(targetMachine.getOperatingSystemFamily(), targetMachinesToOperatingSystems(targetMachines)));
variantNameToken.add(createDimensionSuffix(targetMachine.getArchitecture(), targetMachinesToArchitectures(targetMachines)));
String variantName = StringUtils.uncapitalize(String.join("", variantNameToken));
AttributeContainer runtimeAttributes = attributesFactory.mutable();
runtimeAttributes.attribute(Usage.USAGE_ATTRIBUTE, runtimeUsage);
addCommonAttributes(buildType, targetMachine, runtimeAttributes);
runtimeAttributes.attribute(LINKAGE_ATTRIBUTE, linkage);
DefaultUsageContext runtimeUsageContext = new DefaultUsageContext(variantName + "Runtime", runtimeAttributes);
AttributeContainer linkAttributes = attributesFactory.mutable();
linkAttributes.attribute(Usage.USAGE_ATTRIBUTE, linkUsage);
addCommonAttributes(buildType, targetMachine, linkAttributes);
linkAttributes.attribute(LINKAGE_ATTRIBUTE, linkage);
DefaultUsageContext linkUsageContext = new DefaultUsageContext(variantName + "Link", linkAttributes);
NativeVariantIdentity variantIdentity = new NativeVariantIdentity(variantName, baseName, group, version, buildType.isDebuggable(), buildType.isOptimized(), targetMachine, linkUsageContext, runtimeUsageContext, linkage);
action.execute(variantIdentity);
}
}
}
}
use of org.gradle.nativeplatform.TargetMachine 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.TargetMachine in project gradle by gradle.
the class CppUnitTestPlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(CppBasePlugin.class);
project.getPluginManager().apply(NativeTestingBasePlugin.class);
final ProviderFactory providers = project.getProviders();
final TaskContainer tasks = project.getTasks();
// Add the unit test and extension
final DefaultCppTestSuite testComponent = componentFactory.newInstance(CppTestSuite.class, DefaultCppTestSuite.class, "test");
project.getExtensions().add(CppTestSuite.class, "unitTest", testComponent);
project.getComponents().add(testComponent);
testComponent.getBaseName().convention(project.getName() + "Test");
testComponent.getTargetMachines().convention(Dimensions.useHostAsDefaultTargetMachine(targetMachineFactory));
final String mainComponentName = "main";
project.getComponents().withType(ProductionCppComponent.class, component -> {
if (mainComponentName.equals(component.getName())) {
testComponent.getTargetMachines().convention(component.getTargetMachines());
testComponent.getTestedComponent().convention(component);
}
});
testComponent.getTestBinary().convention(project.provider(new Callable<CppTestExecutable>() {
@Override
public CppTestExecutable call() throws Exception {
return getAllBuildableTestExecutable().filter(it -> isCurrentArchitecture(it.getNativePlatform())).findFirst().orElse(getAllBuildableTestExecutable().findFirst().orElse(getAllTestExecutable().findFirst().orElse(null)));
}
private boolean isCurrentArchitecture(NativePlatform targetPlatform) {
return targetPlatform.getArchitecture().equals(DefaultNativePlatform.getCurrentArchitecture());
}
private Stream<DefaultCppTestExecutable> getAllBuildableTestExecutable() {
return getAllTestExecutable().filter(it -> it.getPlatformToolProvider().isAvailable());
}
private Stream<DefaultCppTestExecutable> getAllTestExecutable() {
return testComponent.getBinaries().get().stream().filter(CppTestExecutable.class::isInstance).map(DefaultCppTestExecutable.class::cast);
}
}));
testComponent.getBinaries().whenElementKnown(DefaultCppTestExecutable.class, binary -> {
// TODO: Replace with native test task
final TaskProvider<RunTestExecutable> testTask = tasks.register(binary.getNames().getTaskName("run"), RunTestExecutable.class, task -> {
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
task.setDescription("Executes C++ unit tests.");
final InstallExecutable installTask = binary.getInstallTask().get();
task.onlyIf(element -> binary.getInstallDirectory().get().getAsFile().exists());
task.getInputs().dir(binary.getInstallDirectory()).withPropertyName("installDirectory");
task.setExecutable(installTask.getRunScriptFile().get().getAsFile());
task.dependsOn(binary.getInstallDirectory());
// TODO: Honor changes to build directory
task.setOutputDir(project.getLayout().getBuildDirectory().dir("test-results/" + binary.getNames().getDirName()).get().getAsFile());
});
binary.getRunTask().set(testTask);
configureTestSuiteWithTestedComponentWhenAvailable(project, testComponent, binary);
});
project.afterEvaluate(p -> {
final CppComponent mainComponent = testComponent.getTestedComponent().getOrNull();
final SetProperty<TargetMachine> mainTargetMachines = mainComponent != null ? mainComponent.getTargetMachines() : null;
Dimensions.unitTestVariants(testComponent.getBaseName(), testComponent.getTargetMachines(), mainTargetMachines, 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()));
// TODO: Removing `debug` from variant name to keep parity with previous Gradle version in tooling models
CppTestExecutable testExecutable = testComponent.addExecutable(variantIdentity.getName().replace("debug", ""), variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
}
});
// TODO: Publishing for test executable?
testComponent.getBinaries().realizeNow();
});
}
use of org.gradle.nativeplatform.TargetMachine in project gradle by gradle.
the class NativeTestingBasePlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(LifecycleBasePlugin.class);
project.getPluginManager().apply(NativeBasePlugin.class);
project.getPluginManager().apply(TestingBasePlugin.class);
// Create test lifecycle task
TaskContainer tasks = project.getTasks();
final TaskProvider<Task> test = tasks.register(TEST_TASK_NAME, task -> task.dependsOn((Callable<Object>) () -> {
TestSuiteComponent unitTestSuite = project.getComponents().withType(TestSuiteComponent.class).findByName(TEST_COMPONENT_NAME);
if (unitTestSuite != null && unitTestSuite.getTestBinary().isPresent()) {
return unitTestSuite.getTestBinary().get().getRunTask();
}
return null;
}));
project.getComponents().withType(TestSuiteComponent.class, testSuiteComponent -> {
if (testSuiteComponent instanceof ComponentWithTargetMachines) {
ComponentWithTargetMachines componentWithTargetMachines = (ComponentWithTargetMachines) testSuiteComponent;
if (TEST_COMPONENT_NAME.equals(testSuiteComponent.getName())) {
test.configure(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("'" + testSuiteComponent.getName() + "' component in project '" + project.getPath() + "' does not target this operating system.");
}
return Collections.emptyList();
}));
}
}
});
tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME, task -> task.dependsOn(test));
}
Aggregations