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
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);
if (rule != null) {
rulesToBuild.add(rule);
@ -66,6 +74,10 @@ public class DependencyResolver {
// D'abord traiter les dépendances
for (String dep : rule.getDependencies()) {
// Skip dependencies with tilde in path
if (dep.startsWith("~")) {
continue;
}
topologicalSort(dep, processed, buildOrder);
}
@ -73,7 +85,7 @@ public class DependencyResolver {
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) {
if (stack.contains(ruleName)) {
if (parent != null) {
@ -95,6 +107,11 @@ public class DependencyResolver {
if (rule != null) {
List<String> dependenciesCopy = new ArrayList<>(rule.getDependencies());
for (String dependency : dependenciesCopy) {
// Skip dependencies with tilde in path
if (dependency.startsWith("~")) {
continue;
}
if (ruleMap.containsKey(dependency)) {
detectCycle(dependency, visited, stack, ruleName);
}

@ -23,87 +23,110 @@ public class Rule {
public boolean isEmpty() { return dependencies.isEmpty() && commands.isEmpty(); }
public boolean needsUpdate() {
if (BakeCLI.isDebug()){
System.out.println("Debug : Checking if rule " + name + " needs update");
}
// Les règles phony sont toujours mises à jour
if (isPhony) {
if (BakeCLI.isDebug()) {
System.out.println("Debug : Rule " + name + " is phony, always needs update");
}
return true;
}
// Vérifier d'abord toutes les dépendances avant d'exécuter quoi que ce soit
for (String dependency : dependencies) {
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);
}
}
if (BakeCLI.isDebug()){
System.out.println("Debug : Checking if rule " + name + " needs update");
}
// Les règles phony sont toujours mises à jour
if (isPhony) {
if (BakeCLI.isDebug()) {
System.out.println("Debug : Rule " + name + " is phony, always needs update");
}
return true;
}
// Skip targets with tilde in path (home directory) to match make behavior
if (name.startsWith("~")) {
if (BakeCLI.isDebug()) {
System.out.println("Debug : Skipping home directory path: " + name);
}
return false;
}
// 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
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()) {
for (String dependency : dependencies) {
Rule depRule = BakeEngine.getRule(dependency);
if (depRule != null && depRule.needsUpdate()) {
if (BakeCLI.isDebug()) {
System.out.println("Debug : Dependency rule " + dependency + " needs update");
}
return true;
}
}
return false;
}
// 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");
}
long targetTimestamp = targetFile.exists() ? TimestampManager.getTimestamp(targetFile) : 0;
if (BakeCLI.isDebug()) {
System.out.println("Debug : Target file '" + name + "' last modified at " + TimestampManager.formatTimestamp(targetTimestamp));
}
for (String dependency : dependencies) {
File depFile = new File(dependency);
long depTimestamp = depFile.exists() ? TimestampManager.getTimestamp(depFile) : 0;
if (BakeCLI.isDebug()) {
System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp));
}
// 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()) {
if (BakeCLI.isDebug()) {
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()) {
System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update");
}
return true;
}
}
return false;
}
// 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()) {
for (String dependency : dependencies) {
// Skip dependencies with tilde in path
if (dependency.startsWith("~")) {
continue;
}
Rule depRule = BakeEngine.getRule(dependency);
if (depRule != null && depRule.needsUpdate()) {
if (BakeCLI.isDebug()) {
System.out.println("Debug : Dependency rule " + dependency + " needs update");
}
return true;
}
}
return false;
}
// 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");
}
long targetTimestamp = targetFile.exists() ? TimestampManager.getTimestamp(targetFile) : 0;
if (BakeCLI.isDebug()) {
System.out.println("Debug : Target file '" + name + "' last modified at " + TimestampManager.formatTimestamp(targetTimestamp));
}
for (String dependency : dependencies) {
// Skip dependencies with tilde in path
if (dependency.startsWith("~")) {
continue;
}
File depFile = new File(dependency);
long depTimestamp = depFile.exists() ? TimestampManager.getTimestamp(depFile) : 0;
if (BakeCLI.isDebug()) {
System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp));
}
// 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()) {
if (BakeCLI.isDebug()) {
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()) {
System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update");
}
return true;
}
}
return false;
}
}