diff --git a/src/fr/monlouyan/bakefile/CommandExecutor.java b/src/fr/monlouyan/bakefile/CommandExecutor.java index 6a7e07d..f09c767 100644 --- a/src/fr/monlouyan/bakefile/CommandExecutor.java +++ b/src/fr/monlouyan/bakefile/CommandExecutor.java @@ -1,5 +1,6 @@ package fr.monlouyan.bakefile; +import java.io.File; import java.io.IOException; public class CommandExecutor { @@ -37,10 +38,9 @@ public class CommandExecutor { } if (debug) System.out.println("Debug: Executing " + command); ProcessBuilder pb = new ProcessBuilder("sh", "-c", command); - pb.inheritIO(); + pb.inheritIO(); Process process = pb.start(); - // Attendre la fin du processus int exitCode = process.waitFor(); @@ -55,19 +55,28 @@ public class CommandExecutor { } } } + + // Vérifier si cette règle est une cible directement demandée par l'utilisateur + boolean isRequestedTarget = BakeCLI.getTargets().contains(rule.getName()) || + (BakeCLI.getTargets().isEmpty() && rule.getName().equals(BakefileParser.getFirstTarget())); - // On n'affiche le message "up to date" que si : - // 1. C'est la première cible - // 2. Aucune règle n'avait besoin d'être mise à jour - // 3. On a des commandes à exécuter - if (rule.getName().equals(BakefileParser.getFirstTarget()) && !needsUpdate && !rule.getCommands().isEmpty()) { - System.out.println("bake: `" + rule.getName() + "' is up to date."); + if (!isRequestedTarget || needsUpdate) { + // Si ce n'est pas une cible demandée ou si une mise à jour a été nécessaire, + // ne pas afficher de message + return; } - // On affiche "Nothing to be done" uniquement si : - // 1. C'est la première cible - // 2. Aucune règle n'avait besoin d'être mise à jour - // 3. On n'a PAS de commandes à exécuter - else if (rule.getName().equals(BakefileParser.getFirstTarget()) && !needsUpdate && rule.getCommands().isEmpty()) { + + // Vérifier si la cible existe en tant que fichier + File targetFile = new File(rule.getName()); + boolean fileExists = targetFile.exists(); + + if (!rule.getCommands().isEmpty() && fileExists) { + // Si la cible a des commandes et existe en tant que fichier, + // afficher "up to date" + System.out.println("bake: `" + rule.getName() + "' is up to date."); + } else { + // Si la cible n'a pas de commandes ou n'existe pas en tant que fichier, + // afficher "Nothing to be done" System.out.println("bake: Nothing to be done for `" + rule.getName() + "'."); } } diff --git a/src/fr/monlouyan/bakefile/Rule.java b/src/fr/monlouyan/bakefile/Rule.java index 72c2e22..908a195 100644 --- a/src/fr/monlouyan/bakefile/Rule.java +++ b/src/fr/monlouyan/bakefile/Rule.java @@ -44,6 +44,15 @@ public class Rule { System.exit(1); } } + + // Si le fichier cible n'existe pas et qu'il y a des commandes, il doit être mis à jour + File targetFile = new File(name); + if (!targetFile.exists() && !commands.isEmpty()) { + if (BakeCLI.isDebug()) { + System.out.println("Debug : Target file " + name + " does not exist and has commands, needs update"); + } + return true; + } // Si la règle n'a pas de commandes, on vérifie seulement si une dépendance doit être mise à jour if (commands.isEmpty()) { @@ -60,7 +69,6 @@ public class Rule { } // Pour les règles avec des commandes, on vérifie aussi les timestamps - File targetFile = new File(name); if (BakeCLI.isDebug()){ System.out.println("Debug : Checking if target file " + name + " exist and is up to date"); } diff --git a/test.sh b/test.sh index 22d6ea7..27f0fb0 100755 --- a/test.sh +++ b/test.sh @@ -100,6 +100,8 @@ tests_c=( "test-13-dependancy-dont-exist" "test-14-remove-source-and-rebuild" "test-15-subdir-build" + "test-16-strange-variables" + "test-17-rule-without-command" ) tests_java=(