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