use of org.gradle.language.swift.internal.DefaultSwiftSharedLibrary 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();
});
}
Aggregations