use of org.gradle.language.swift.internal.DefaultSwiftPlatform in project gradle by gradle.
the class DefaultToolChainSelector method select.
@Override
public <T extends NativePlatform> Result<T> select(Class<T> platformType) {
DefaultNativePlatform targetMachine = host;
// TODO - push all this stuff down to the tool chain and let it create the specific platform and provider
NativeLanguage sourceLanguage = platformType == SwiftPlatform.class ? NativeLanguage.SWIFT : NativeLanguage.CPP;
NativeToolChainRegistryInternal registry = modelRegistry.realize("toolChains", NativeToolChainRegistryInternal.class);
NativeToolChainInternal toolChain = registry.getForPlatform(sourceLanguage, targetMachine);
// TODO - don't select again here, as the selection is already performed to select the toolchain
PlatformToolProvider toolProvider = toolChain.select(sourceLanguage, targetMachine);
if (!toolProvider.isAvailable() && targetMachine.getOperatingSystem().isWindows() && targetMachine.getArchitecture().isAmd64()) {
// Try building x86 on Windows. Don't do this for other operating systems (yet)
DefaultNativePlatform x86platformRequest = targetMachine.withArchitecture(Architectures.of(Architectures.X86));
NativeToolChainInternal x86ToolChain = registry.getForPlatform(sourceLanguage, x86platformRequest);
// TODO - don't select again here, as the selection is already performed to select the toolchain
PlatformToolProvider x86ToolProvider = x86ToolChain.select(sourceLanguage, x86platformRequest);
if (x86ToolProvider.isAvailable()) {
targetMachine = x86platformRequest;
toolChain = x86ToolChain;
toolProvider = x86ToolProvider;
}
}
// TODO - use a better name for the platforms, rather than "current"
T targetPlatform = null;
if (CppPlatform.class.isAssignableFrom(platformType)) {
targetPlatform = platformType.cast(new DefaultCppPlatform("host", targetMachine));
} else if (SwiftPlatform.class.isAssignableFrom(platformType)) {
targetPlatform = platformType.cast(new DefaultSwiftPlatform("host", targetMachine));
}
return new DefaultResult<T>(toolChain, toolProvider, targetPlatform);
}
use of org.gradle.language.swift.internal.DefaultSwiftPlatform in project gradle by gradle.
the class DefaultToolChainSelector method select.
public Result<SwiftPlatform> select(SwiftPlatform requestPlatform) {
DefaultNativePlatform targetNativePlatform = newNativePlatform(requestPlatform.getTargetMachine());
// TODO - push all this stuff down to the tool chain and let it create the specific platform and provider
NativeLanguage sourceLanguage = NativeLanguage.SWIFT;
NativeToolChainInternal toolChain = getToolChain(sourceLanguage, targetNativePlatform);
// TODO - don't select again here, as the selection is already performed to select the toolchain
PlatformToolProvider toolProvider = toolChain.select(sourceLanguage, targetNativePlatform);
SwiftVersion sourceCompatibility = requestPlatform.getSourceCompatibility();
if (sourceCompatibility == null && toolProvider.isAvailable()) {
sourceCompatibility = toSwiftVersion(toolProvider.getCompilerMetadata(ToolType.SWIFT_COMPILER).getVersion());
}
SwiftPlatform targetPlatform = new DefaultSwiftPlatform(requestPlatform.getTargetMachine(), sourceCompatibility, targetNativePlatform);
return new DefaultResult<SwiftPlatform>(toolChain, toolProvider, targetPlatform);
}
use of org.gradle.language.swift.internal.DefaultSwiftPlatform 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.language.swift.internal.DefaultSwiftPlatform in project gradle by gradle.
the class SwiftLibraryPlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(SwiftBasePlugin.class);
final ConfigurationContainer configurations = project.getConfigurations();
final ObjectFactory objectFactory = project.getObjects();
final ProviderFactory providers = project.getProviders();
final DefaultSwiftLibrary library = componentFactory.newInstance(SwiftLibrary.class, DefaultSwiftLibrary.class, "main");
project.getExtensions().add(SwiftLibrary.class, "library", library);
project.getComponents().add(library);
// Setup component
final Property<String> module = library.getModule();
module.set(GUtil.toCamelCase(project.getName()));
library.getTargetMachines().convention(useHostAsDefaultTargetMachine(targetMachineFactory));
library.getDevelopmentBinary().convention(project.provider(new Callable<SwiftBinary>() {
@Override
public SwiftBinary call() throws Exception {
return getDebugSharedHostStream().findFirst().orElse(getDebugStaticHostStream().findFirst().orElse(getDebugSharedStream().findFirst().orElse(getDebugStaticStream().findFirst().orElse(null))));
}
private Stream<SwiftBinary> getDebugStream() {
return library.getBinaries().get().stream().filter(binary -> !binary.isOptimized());
}
private Stream<SwiftBinary> getDebugSharedStream() {
return getDebugStream().filter(SwiftSharedLibrary.class::isInstance);
}
private Stream<SwiftBinary> getDebugSharedHostStream() {
return getDebugSharedStream().filter(binary -> Architectures.forInput(binary.getTargetMachine().getArchitecture().getName()).equals(DefaultNativePlatform.host().getArchitecture()));
}
private Stream<SwiftBinary> getDebugStaticStream() {
return getDebugStream().filter(SwiftStaticLibrary.class::isInstance);
}
private Stream<SwiftBinary> getDebugStaticHostStream() {
return getDebugStaticStream().filter(binary -> Architectures.forInput(binary.getTargetMachine().getArchitecture().getName()).equals(DefaultNativePlatform.host().getArchitecture()));
}
}));
project.afterEvaluate(p -> {
// TODO: make build type configurable for components
Dimensions.libraryVariants(library.getModule(), library.getLinkage(), library.getTargetMachines(), objectFactory, attributesFactory, providers.provider(() -> project.getGroup().toString()), providers.provider(() -> project.getVersion().toString()), variantIdentity -> {
if (tryToBuildOnHost(variantIdentity)) {
library.getSourceCompatibility().finalizeValue();
ToolChainSelector.Result<SwiftPlatform> result = toolChainSelector.select(SwiftPlatform.class, new DefaultSwiftPlatform(variantIdentity.getTargetMachine(), library.getSourceCompatibility().getOrNull()));
if (variantIdentity.getLinkage().equals(Linkage.SHARED)) {
library.addSharedLibrary(variantIdentity, variantIdentity.isDebuggable() && !variantIdentity.isOptimized(), result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
} else {
library.addStaticLibrary(variantIdentity, variantIdentity.isDebuggable() && !variantIdentity.isOptimized(), result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
}
}
});
library.getBinaries().whenElementKnown(SwiftSharedLibrary.class, sharedLibrary -> {
Names names = ((ComponentWithNames) sharedLibrary).getNames();
Configuration apiElements = configurations.create(names.withSuffix("SwiftApiElements"));
// TODO This should actually extend from the api dependencies, but since Swift currently
// requires all dependencies to be treated like api dependencies (with transitivity) we just
// use the implementation dependencies here. See https://bugs.swift.org/browse/SR-1393.
apiElements.extendsFrom(((DefaultSwiftSharedLibrary) sharedLibrary).getImplementationDependencies());
apiElements.setCanBeResolved(false);
apiElements.getAttributes().attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.SWIFT_API));
apiElements.getAttributes().attribute(LINKAGE_ATTRIBUTE, Linkage.SHARED);
apiElements.getAttributes().attribute(DEBUGGABLE_ATTRIBUTE, sharedLibrary.isDebuggable());
apiElements.getAttributes().attribute(OPTIMIZED_ATTRIBUTE, sharedLibrary.isOptimized());
apiElements.getAttributes().attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, sharedLibrary.getTargetMachine().getOperatingSystemFamily());
apiElements.getOutgoing().artifact(sharedLibrary.getModuleFile());
});
library.getBinaries().whenElementKnown(SwiftStaticLibrary.class, staticLibrary -> {
Names names = ((ComponentWithNames) staticLibrary).getNames();
Configuration apiElements = configurations.create(names.withSuffix("SwiftApiElements"));
// TODO This should actually extend from the api dependencies, but since Swift currently
// requires all dependencies to be treated like api dependencies (with transitivity) we just
// use the implementation dependencies here. See https://bugs.swift.org/browse/SR-1393.
apiElements.extendsFrom(((DefaultSwiftStaticLibrary) staticLibrary).getImplementationDependencies());
apiElements.setCanBeResolved(false);
apiElements.getAttributes().attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.SWIFT_API));
apiElements.getAttributes().attribute(LINKAGE_ATTRIBUTE, Linkage.STATIC);
apiElements.getAttributes().attribute(DEBUGGABLE_ATTRIBUTE, staticLibrary.isDebuggable());
apiElements.getAttributes().attribute(OPTIMIZED_ATTRIBUTE, staticLibrary.isOptimized());
apiElements.getAttributes().attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, staticLibrary.getTargetMachine().getOperatingSystemFamily());
apiElements.getOutgoing().artifact(staticLibrary.getModuleFile());
});
library.getBinaries().realizeNow();
});
}
use of org.gradle.language.swift.internal.DefaultSwiftPlatform 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();
});
}
Aggregations