Ajout de la gestion des chemins d'accès avec tilde pour ignorer les règles et dépendances dans le répertoire personnel, afin de correspondre au comportement de Make.

This commit is contained in:
Moncef STITI 2025-02-28 21:11:41 +01:00
parent 0ad41c748f
commit a6a7fe322d
2 changed files with 123 additions and 83 deletions
src/fr/monlouyan/bakefile

@ -47,6 +47,14 @@ public class DependencyResolver {
// Construire la liste finale des règles dans l'ordre // Construire la liste finale des règles dans l'ordre
for (String ruleName : buildOrder) { for (String ruleName : buildOrder) {
// Skip rules with tilde in path (home directory) to match make behavior
if (ruleName.startsWith("~")) {
if (debug) {
System.out.println("Debug: Skipping home directory path in resolution: " + ruleName);
}
continue;
}
Rule rule = ruleMap.get(ruleName); Rule rule = ruleMap.get(ruleName);
if (rule != null) { if (rule != null) {
rulesToBuild.add(rule); rulesToBuild.add(rule);
@ -66,6 +74,10 @@ public class DependencyResolver {
// D'abord traiter les dépendances // D'abord traiter les dépendances
for (String dep : rule.getDependencies()) { for (String dep : rule.getDependencies()) {
// Skip dependencies with tilde in path
if (dep.startsWith("~")) {
continue;
}
topologicalSort(dep, processed, buildOrder); topologicalSort(dep, processed, buildOrder);
} }
@ -73,7 +85,7 @@ public class DependencyResolver {
buildOrder.add(ruleName); buildOrder.add(ruleName);
} }
// La méthode detectCycle reste inchangée // La méthode detectCycle avec une modification pour les chemins home
private void detectCycle(String ruleName, Set<String> visited, Set<String> stack, String parent) { private void detectCycle(String ruleName, Set<String> visited, Set<String> stack, String parent) {
if (stack.contains(ruleName)) { if (stack.contains(ruleName)) {
if (parent != null) { if (parent != null) {
@ -95,6 +107,11 @@ public class DependencyResolver {
if (rule != null) { if (rule != null) {
List<String> dependenciesCopy = new ArrayList<>(rule.getDependencies()); List<String> dependenciesCopy = new ArrayList<>(rule.getDependencies());
for (String dependency : dependenciesCopy) { for (String dependency : dependenciesCopy) {
// Skip dependencies with tilde in path
if (dependency.startsWith("~")) {
continue;
}
if (ruleMap.containsKey(dependency)) { if (ruleMap.containsKey(dependency)) {
detectCycle(dependency, visited, stack, ruleName); detectCycle(dependency, visited, stack, ruleName);
} }

@ -23,87 +23,110 @@ 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;
} }
// Vérifier d'abord toutes les dépendances avant d'exécuter quoi que ce soit // Skip targets with tilde in path (home directory) to match make behavior
for (String dependency : dependencies) { if (name.startsWith("~")) {
File depFile = new File(dependency); if (BakeCLI.isDebug()) {
boolean hasRule = BakeEngine.hasRule(dependency); System.out.println("Debug : Skipping home directory path: " + name);
if (!depFile.exists() && !dependency.isEmpty() && !hasRule) { }
System.out.println("bake: *** No rule to make target `" + dependency + "', needed by `" + name + "'. Stop."); return false;
System.exit(1); }
}
} // Vérifier d'abord toutes les dépendances avant d'exécuter quoi que ce soit
for (String dependency : dependencies) {
// Skip dependencies with tilde in path
if (dependency.startsWith("~")) {
continue;
}
File depFile = new File(dependency);
boolean hasRule = BakeEngine.hasRule(dependency);
if (!depFile.exists() && !dependency.isEmpty() && !hasRule) {
System.out.println("bake: *** No rule to make target `" + dependency + "', needed by `" + name + "'. Stop.");
System.exit(1);
}
}
// Si le fichier cible n'existe pas et qu'il y a des commandes, il doit être mis à jour // Si le fichier cible n'existe pas et qu'il y a des commandes, il doit être mis à jour
File targetFile = new File(name); File targetFile = new File(name);
if (!targetFile.exists() && !commands.isEmpty()) { if (!targetFile.exists() && !commands.isEmpty()) {
if (BakeCLI.isDebug()) { if (BakeCLI.isDebug()) {
System.out.println("Debug : Target file " + name + " does not exist and has commands, needs update"); System.out.println("Debug : Target file " + name + " does not exist and has commands, 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 // Si la règle n'a pas de commandes, on vérifie seulement si une dépendance doit être mise à jour
if (commands.isEmpty()) { if (commands.isEmpty()) {
for (String dependency : dependencies) { for (String dependency : dependencies) {
Rule depRule = BakeEngine.getRule(dependency); // Skip dependencies with tilde in path
if (depRule != null && depRule.needsUpdate()) { if (dependency.startsWith("~")) {
if (BakeCLI.isDebug()) { continue;
System.out.println("Debug : Dependency rule " + dependency + " needs update"); }
}
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 }
if (BakeCLI.isDebug()){ }
System.out.println("Debug : Checking if target file " + name + " exist and is up to date"); return false;
} }
long targetTimestamp = targetFile.exists() ? TimestampManager.getTimestamp(targetFile) : 0; // Pour les règles avec des commandes, on vérifie aussi les timestamps
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) {
} // Skip dependencies with tilde in path
if (dependency.startsWith("~")) {
// Si la dépendance est une règle et qu'elle a besoin d'être mise à jour continue;
Rule depRule = BakeEngine.getRule(dependency); }
if (depRule != null && depRule.needsUpdate()) {
if (BakeCLI.isDebug()) { File depFile = new File(dependency);
System.out.println("Debug : Dependency rule " + dependency + " needs update"); long depTimestamp = depFile.exists() ? TimestampManager.getTimestamp(depFile) : 0;
}
return true; if (BakeCLI.isDebug()) {
} System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp));
}
// Vérifier les timestamps seulement si le fichier existe
if (depFile.exists() && TimestampManager.getTimestamp(depFile) > targetTimestamp) { // 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 " + dependency + " is newer than target file " + name + ", needs update"); if (depRule != null && depRule.needsUpdate()) {
} if (BakeCLI.isDebug()) {
return true; System.out.println("Debug : Dependency rule " + dependency + " needs update");
} }
} return true;
return false; }
}
// Vérifier les timestamps seulement si le fichier existe
if (depFile.exists() && TimestampManager.getTimestamp(depFile) > targetTimestamp) {
if (BakeCLI.isDebug()) {
System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update");
}
return true;
}
}
return false;
}
} }