À VÉRIFIER : Correction des messages d'erreur pour utiliser des backticks autour des dépendances et réorganisation de la logique de vérification des mises à jour dans la classe Rule + Ajout du test 13

This commit is contained in:
Louay DARDOURI 2025-02-09 17:48:18 +01:00
parent ffc20ae7f3
commit 1bafee8e5c
2 changed files with 76 additions and 79 deletions
src/fr/monlouyan/bakefile

@ -68,7 +68,7 @@ public class CommandExecutor {
// 2. Aucune règle n'avait besoin d'être mise à jour // 2. Aucune règle n'avait besoin d'être mise à jour
// 3. On n'a PAS de commandes à exécuter // 3. On n'a PAS de commandes à exécuter
else if (rule.getName().equals(BakefileParser.getFirstTarget()) && !needsUpdate && rule.getCommands().isEmpty()) { else if (rule.getName().equals(BakefileParser.getFirstTarget()) && !needsUpdate && rule.getCommands().isEmpty()) {
System.out.println("bake: Nothing to be done for '" + rule.getName() + "'."); System.out.println("bake: Nothing to be done for `" + rule.getName() + "'.");
} }
} }
} }

@ -23,82 +23,79 @@ public class Rule {
public boolean isEmpty() { return dependencies.isEmpty() && commands.isEmpty(); } public boolean isEmpty() { return dependencies.isEmpty() && commands.isEmpty(); }
public boolean needsUpdate() { public boolean needsUpdate() {
if (BakeCLI.isDebug()){ if (BakeCLI.isDebug()){
System.out.println("Debug : Checking if rule " + name + " needs update"); System.out.println("Debug : Checking if rule " + name + " needs update");
} }
// Les règles phony sont toujours mises à jour // Les règles phony sont toujours mises à jour
if (isPhony) { if (isPhony) {
if (BakeCLI.isDebug()) { if (BakeCLI.isDebug()) {
System.out.println("Debug : Rule " + name + " is phony, always needs update"); System.out.println("Debug : Rule " + name + " is phony, always needs update");
} }
return true; return true;
} }
// Si la règle n'a pas de commandes, on vérifie seulement si une dépendance doit être mise à jour // Vérifier d'abord toutes les dépendances avant d'exécuter quoi que ce soit
if (commands.isEmpty()) { for (String dependency : dependencies) {
for (String dependency : dependencies) { File depFile = new File(dependency);
File depFile = new File(dependency); boolean hasRule = BakeEngine.hasRule(dependency);
if (!depFile.exists() && !dependency.isEmpty() && !BakeEngine.hasRule(dependency)) { if (!depFile.exists() && !dependency.isEmpty() && !hasRule) {
System.out.println("bake: *** No rule to make target `" + dependency + "', needed by '" + name + "'. Stop."); System.out.println("bake: *** No rule to make target `" + dependency + "', needed by `" + name + "'. Stop.");
System.exit(1); System.exit(1);
} }
Rule depRule = BakeEngine.getRule(dependency); }
if (depRule != null && depRule.needsUpdate()) {
if (BakeCLI.isDebug()) { // Si la règle n'a pas de commandes, on vérifie seulement si une dépendance doit être mise à jour
System.out.println("Debug : Dependency rule " + dependency + " needs update"); if (commands.isEmpty()) {
} for (String dependency : dependencies) {
return true; Rule depRule = BakeEngine.getRule(dependency);
} if (depRule != null && depRule.needsUpdate()) {
} if (BakeCLI.isDebug()) {
return false; System.out.println("Debug : Dependency rule " + dependency + " needs update");
} }
return true;
// Pour les règles avec des commandes, on vérifie aussi les timestamps }
File targetFile = new File(name); }
if (BakeCLI.isDebug()){ return false;
System.out.println("Debug : Checking if target file " + name + " exist and is up to date"); }
}
// Pour les règles avec des commandes, on vérifie aussi les timestamps
long targetTimestamp = targetFile.exists() ? TimestampManager.getTimestamp(targetFile) : 0; File targetFile = new File(name);
if (BakeCLI.isDebug()){
if (BakeCLI.isDebug()) { System.out.println("Debug : Checking if target file " + name + " exist and is up to date");
System.out.println("Debug : Target file '" + name + "' last modified at " + TimestampManager.formatTimestamp(targetTimestamp)); }
}
long targetTimestamp = targetFile.exists() ? TimestampManager.getTimestamp(targetFile) : 0;
for (String dependency : dependencies) {
File depFile = new File(dependency); if (BakeCLI.isDebug()) {
long depTimestamp = depFile.exists() ? TimestampManager.getTimestamp(depFile) : 0; System.out.println("Debug : Target file '" + name + "' last modified at " + TimestampManager.formatTimestamp(targetTimestamp));
}
if (BakeCLI.isDebug()) {
System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp)); for (String dependency : dependencies) {
} File depFile = new File(dependency);
long depTimestamp = depFile.exists() ? TimestampManager.getTimestamp(depFile) : 0;
// Vérifier si une règle existe pour cette dépendance
boolean hasRule = BakeEngine.hasRule(dependency); if (BakeCLI.isDebug()) {
System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp));
if (!depFile.exists() && !dependency.isEmpty() && !hasRule) { }
System.out.println("bake: *** No rule to make target `" + dependency + "', needed by '" + name + "'. Stop.");
System.exit(1); // Si la dépendance est une règle et qu'elle a besoin d'être mise à jour
} Rule depRule = BakeEngine.getRule(dependency);
if (depRule != null && depRule.needsUpdate()) {
// Si la dépendance est une règle et qu'elle a besoin d'être mise à jour if (BakeCLI.isDebug()) {
Rule depRule = BakeEngine.getRule(dependency); System.out.println("Debug : Dependency rule " + dependency + " needs update");
if (depRule != null && depRule.needsUpdate()) { }
if (BakeCLI.isDebug()) { return true;
System.out.println("Debug : Dependency rule " + dependency + " needs update"); }
}
return true; // Vérifier les timestamps seulement si le fichier existe
} if (depFile.exists() && TimestampManager.getTimestamp(depFile) > targetTimestamp) {
if (BakeCLI.isDebug()) {
// Vérifier les timestamps seulement si le fichier existe System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update");
if (depFile.exists() && TimestampManager.getTimestamp(depFile) > targetTimestamp) { }
if (BakeCLI.isDebug()) { return true;
System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update"); }
} }
return true; return false;
} }
}
return false;
}
} }