use of org.gradle.language.nativeplatform.internal.DefaultNativeComponent in project gradle by gradle.
the class SwiftBasePlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(NativeBasePlugin.class);
project.getPluginManager().apply(SwiftCompilerPlugin.class);
final TaskContainer tasks = project.getTasks();
final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
project.getDependencies().getAttributesSchema().attribute(Usage.USAGE_ATTRIBUTE).getCompatibilityRules().add(SwiftCppUsageCompatibilityRule.class);
project.getComponents().withType(DefaultSwiftBinary.class, binary -> {
final Names names = binary.getNames();
TaskProvider<SwiftCompile> compile = tasks.register(names.getCompileTaskName("swift"), SwiftCompile.class, task -> {
task.getModules().from(binary.getCompileModules());
task.getSource().from(binary.getSwiftSource());
task.getDebuggable().set(binary.isDebuggable());
task.getOptimized().set(binary.isOptimized());
if (binary.isTestable()) {
task.getCompilerArgs().add("-enable-testing");
}
if (binary.getTargetMachine().getOperatingSystemFamily().isMacOs()) {
task.getCompilerArgs().add("-sdk");
task.getCompilerArgs().add(locator.find().getAbsolutePath());
}
task.getModuleName().set(binary.getModule());
task.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
task.getModuleFile().set(buildDirectory.file(binary.getModule().map(moduleName -> "modules/" + names.getDirName() + moduleName + ".swiftmodule")));
task.getSourceCompatibility().set(binary.getTargetPlatform().getSourceCompatibility());
task.getTargetPlatform().set(binary.getNativePlatform());
// TODO - make this lazy
task.getToolChain().set(binary.getToolChain());
if (binary instanceof SwiftSharedLibrary || binary instanceof SwiftStaticLibrary) {
task.getCompilerArgs().add("-parse-as-library");
}
});
binary.getModuleFile().set(compile.flatMap(task -> task.getModuleFile()));
binary.getCompileTask().set(compile);
binary.getObjectsDir().set(compile.flatMap(task -> task.getObjectFileDir()));
});
project.getComponents().withType(ProductionSwiftComponent.class, component -> {
project.afterEvaluate(p -> {
DefaultNativeComponent componentInternal = (DefaultNativeComponent) component;
publicationRegistry.registerPublication((ProjectInternal) project, new NativeProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getModule().get())));
});
});
}
Aggregations