Search in sources :

Example 1 with IncrementalSwiftCompiler

use of org.gradle.nativeplatform.toolchain.internal.swift.IncrementalSwiftCompiler in project gradle by gradle.

the class SwiftCompile method compile.

@TaskAction
protected void compile(InputChanges inputs) {
    final List<File> removedFiles = Lists.newArrayList();
    final Set<File> changedFiles = Sets.newHashSet();
    boolean isIncremental = inputs.isIncremental();
    // which files changed .
    if (isIncremental) {
        for (FileChange fileChange : inputs.getFileChanges(getSource())) {
            if (fileChange.getChangeType() == ChangeType.REMOVED) {
                removedFiles.add(fileChange.getFile());
            } else {
                changedFiles.add(fileChange.getFile());
            }
        }
    }
    BuildOperationLogger operationLogger = getServices().get(BuildOperationLoggerFactory.class).newOperationLogger(getName(), getTemporaryDir());
    NativePlatformInternal targetPlatform = Cast.cast(NativePlatformInternal.class, this.targetPlatform.get());
    SwiftCompileSpec spec = createSpec(operationLogger, isIncremental, changedFiles, removedFiles, targetPlatform);
    Compiler<SwiftCompileSpec> baseCompiler = new IncrementalSwiftCompiler(createCompiler(), getOutputs(), compilerOutputFileNamingSchemeFactory, deleter);
    Compiler<SwiftCompileSpec> loggingCompiler = BuildOperationLoggingCompilerDecorator.wrap(baseCompiler);
    WorkResult result = loggingCompiler.execute(spec);
    setDidWork(result.getDidWork());
}
Also used : BuildOperationLoggerFactory(org.gradle.internal.operations.logging.BuildOperationLoggerFactory) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) DefaultSwiftCompileSpec(org.gradle.language.swift.tasks.internal.DefaultSwiftCompileSpec) SwiftCompileSpec(org.gradle.nativeplatform.toolchain.internal.compilespec.SwiftCompileSpec) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) FileChange(org.gradle.work.FileChange) IncrementalSwiftCompiler(org.gradle.nativeplatform.toolchain.internal.swift.IncrementalSwiftCompiler) WorkResult(org.gradle.api.tasks.WorkResult) OutputFile(org.gradle.api.tasks.OutputFile) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with IncrementalSwiftCompiler

use of org.gradle.nativeplatform.toolchain.internal.swift.IncrementalSwiftCompiler in project gradle by gradle.

the class SwiftCompile method compile.

@TaskAction
void compile(IncrementalTaskInputs inputs) {
    final List<File> removedFiles = Lists.newArrayList();
    final Set<File> changedFiles = Sets.newHashSet();
    boolean isIncremental = inputs.isIncremental();
    // which files changed and marking the compilation incremental or not.
    if (isIncremental) {
        inputs.outOfDate(new Action<InputFileDetails>() {

            @Override
            public void execute(InputFileDetails inputFileDetails) {
                if (inputFileDetails.isModified()) {
                    changedFiles.add(inputFileDetails.getFile());
                }
            }
        });
        inputs.removed(new Action<InputFileDetails>() {

            @Override
            public void execute(InputFileDetails removed) {
                removedFiles.add(removed.getFile());
            }
        });
        Set<File> allSourceFiles = getSource().getFiles();
        if (!allSourceFiles.containsAll(changedFiles)) {
            // If a non-source file changed, the compilation cannot be incremental
            // due to the way the Swift compiler detects changes from other modules
            isIncremental = false;
        }
    }
    BuildOperationLogger operationLogger = getServices().get(BuildOperationLoggerFactory.class).newOperationLogger(getName(), getTemporaryDir());
    NativePlatformInternal targetPlatform = Cast.cast(NativePlatformInternal.class, this.targetPlatform.get());
    SwiftCompileSpec spec = createSpec(operationLogger, isIncremental, changedFiles, removedFiles, targetPlatform);
    Compiler<SwiftCompileSpec> baseCompiler = new IncrementalSwiftCompiler(createCompiler(), getOutputs(), compilerOutputFileNamingSchemeFactory);
    Compiler<SwiftCompileSpec> loggingCompiler = BuildOperationLoggingCompilerDecorator.wrap(baseCompiler);
    WorkResult result = loggingCompiler.execute(spec);
    setDidWork(result.getDidWork());
}
Also used : BuildOperationLoggerFactory(org.gradle.internal.operations.logging.BuildOperationLoggerFactory) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) InputFileDetails(org.gradle.api.tasks.incremental.InputFileDetails) DefaultSwiftCompileSpec(org.gradle.language.swift.tasks.internal.DefaultSwiftCompileSpec) SwiftCompileSpec(org.gradle.nativeplatform.toolchain.internal.compilespec.SwiftCompileSpec) IncrementalSwiftCompiler(org.gradle.nativeplatform.toolchain.internal.swift.IncrementalSwiftCompiler) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) WorkResult(org.gradle.api.tasks.WorkResult) OutputFile(org.gradle.api.tasks.OutputFile) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

File (java.io.File)2 OutputFile (org.gradle.api.tasks.OutputFile)2 TaskAction (org.gradle.api.tasks.TaskAction)2 WorkResult (org.gradle.api.tasks.WorkResult)2 BuildOperationLogger (org.gradle.internal.operations.logging.BuildOperationLogger)2 BuildOperationLoggerFactory (org.gradle.internal.operations.logging.BuildOperationLoggerFactory)2 DefaultSwiftCompileSpec (org.gradle.language.swift.tasks.internal.DefaultSwiftCompileSpec)2 NativePlatformInternal (org.gradle.nativeplatform.platform.internal.NativePlatformInternal)2 SwiftCompileSpec (org.gradle.nativeplatform.toolchain.internal.compilespec.SwiftCompileSpec)2 IncrementalSwiftCompiler (org.gradle.nativeplatform.toolchain.internal.swift.IncrementalSwiftCompiler)2 InputFileDetails (org.gradle.api.tasks.incremental.InputFileDetails)1 FileChange (org.gradle.work.FileChange)1