From 11b62989e7887912542e633302bd6e693832790f Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 30 Dec 2020 20:34:34 +0000 Subject: [PATCH] Cleanup output files when remap fails. Fixes #321 --- .../net/fabricmc/loom/build/ModCompileRemapper.java | 11 +++-------- .../java/net/fabricmc/loom/util/SourceRemapper.java | 7 ++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java b/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java index 8fe879a..c257a69 100644 --- a/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java +++ b/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java @@ -107,6 +107,8 @@ public class ModCompileRemapper { try { ModProcessor.processMods(project, modDependencies); } catch (IOException e) { + // Failed to remap, lets clean up to ensure we try again next time + modDependencies.forEach(info -> info.getRemappedOutput().delete()); throw new RuntimeException("Failed to remap mods", e); } @@ -170,14 +172,7 @@ public class ModCompileRemapper { boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies(); if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified() || refreshDeps) { - try { - sourceRemapper.scheduleRemapSources(sources, remappedSources, false, true); // Depenedency sources are used in ide only so don't need to be reproducable - - // Set the remapped sources creation date to match the sources if we're likely succeeded in making it - remappedSources.setLastModified(sources.lastModified()); - } catch (Exception e) { - e.printStackTrace(); - } + sourceRemapper.scheduleRemapSources(sources, remappedSources, false, true); // Depenedency sources are used in ide only so don't need to be reproducable } else { project.getLogger().info(remappedSources.getName() + " is up to date with " + sources.getName()); } diff --git a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java index e7a5bef..4664225 100644 --- a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java @@ -72,13 +72,18 @@ public class SourceRemapper { scheduleRemapSources(source, destination, false, true); // Not reproducable by default, old behavior } - public void scheduleRemapSources(File source, File destination, boolean reproducibleFileOrder, boolean preserveFileTimestamps) throws Exception { + public void scheduleRemapSources(File source, File destination, boolean reproducibleFileOrder, boolean preserveFileTimestamps) { remapTasks.add((logger) -> { try { logger.progress("remapping sources - " + source.getName()); remapSourcesInner(source, destination); ZipReprocessorUtil.reprocessZip(destination, reproducibleFileOrder, preserveFileTimestamps); + + // Set the remapped sources creation date to match the sources if we're likely succeeded in making it + destination.setLastModified(source.lastModified()); } catch (Exception e) { + // Failed to remap, lets clean up to ensure we try again next time + destination.delete(); throw new RuntimeException("Failed to remap sources for " + source, e); } });