use of org.gradle.nativeplatform.toolchain.internal.compilespec.SwiftCompileSpec in project gradle by gradle.
the class SwiftCompile method createSpec.
private SwiftCompileSpec createSpec(BuildOperationLogger operationLogger, boolean isIncremental, Collection<File> changedFiles, Collection<File> removedFiles, NativePlatformInternal targetPlatform) {
SwiftCompileSpec spec = new DefaultSwiftCompileSpec();
spec.setModuleName(moduleName.getOrNull());
spec.setModuleFile(moduleFile.get().getAsFile());
for (File file : modules.getFiles()) {
if (file.isFile()) {
spec.include(file.getParentFile());
} else {
spec.include(file);
}
}
spec.setTargetPlatform(targetPlatform);
spec.setTempDir(getTemporaryDir());
spec.setObjectFileDir(objectFileDir.get().getAsFile());
spec.source(getSource());
spec.setRemovedSourceFiles(removedFiles);
spec.setChangedFiles(changedFiles);
// Convert Swift-like macros to a Map like NativeCompileSpec expects
Map<String, String> macros = new LinkedHashMap<String, String>();
for (String macro : getMacros().get()) {
macros.put(macro, null);
}
spec.setMacros(macros);
spec.args(getCompilerArgs().get());
spec.setDebuggable(getDebuggable().get());
spec.setOptimized(getOptimized().get());
spec.setIncrementalCompile(isIncremental);
spec.setOperationLogger(operationLogger);
spec.setSourceCompatibility(sourceCompatibility.get());
return spec;
}
use of org.gradle.nativeplatform.toolchain.internal.compilespec.SwiftCompileSpec 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());
}
Aggregations