Correction de bug - À vérifier
This commit is contained in:
parent
b74fbf3477
commit
7d392117e9
src/fr/monlouyan/bakefile
@ -3,6 +3,7 @@ package fr.monlouyan.bakefile;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moteur principal de l'application Bake.
|
* Moteur principal de l'application Bake.
|
||||||
@ -85,4 +86,12 @@ public class BakeEngine {
|
|||||||
executor.execute(rule);
|
executor.execute(rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère les noms de toutes les règles.
|
||||||
|
* @return Un ensemble contenant les noms de toutes les règles
|
||||||
|
*/
|
||||||
|
public static Set<String> getAllRuleNames() {
|
||||||
|
return ruleMap.keySet();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package fr.monlouyan.bakefile;
|
package fr.monlouyan.bakefile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,135 +74,171 @@ public class Rule {
|
|||||||
* Vérifie si la règle doit être mise à jour.
|
* Vérifie si la règle doit être mise à jour.
|
||||||
* @return true si la règle doit être mise à jour, false sinon
|
* @return true si la règle doit être mise à jour, false sinon
|
||||||
*/
|
*/
|
||||||
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
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Ignorer les options de compilation qui pourraient avoir un ':' dedans
|
|
||||||
if (dependency.startsWith("-") || dependency.contains(":")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!depFile.exists() && !dependency.isEmpty() && !hasRule) {
|
|
||||||
System.out.println("bake: *** No rule to make target `" + dependency + "', needed by `" + name + "'. Stop.");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si le fichier cible n'existe pas et qu'il y a des commandes, il doit être mis à jour
|
// Les règles phony sont toujours mises à jour
|
||||||
File targetFile = new File(name);
|
if (isPhony) {
|
||||||
if (!targetFile.exists() && !commands.isEmpty()) {
|
if (BakeCLI.isDebug()) {
|
||||||
if (BakeCLI.isDebug()) {
|
System.out.println("Debug : Rule " + name + " is phony, always needs update");
|
||||||
System.out.println("Debug : Target file " + name + " does not exist and has commands, needs update");
|
}
|
||||||
}
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
// Skip targets with tilde in path (home directory) to match make behavior
|
||||||
// Si la règle n'a pas de commandes, on vérifie seulement si une dépendance doit être mise à jour
|
if (name.startsWith("~")) {
|
||||||
if (commands.isEmpty()) {
|
if (BakeCLI.isDebug()) {
|
||||||
for (String dependency : dependencies) {
|
System.out.println("Debug : Skipping home directory path: " + name);
|
||||||
// Skip dependencies with tilde in path or compiler options
|
}
|
||||||
if (dependency.startsWith("~") || dependency.startsWith("-") || dependency.contains(":")) {
|
return false;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
// Si le fichier cible n'existe pas et qu'il y a des commandes, il doit être mis à jour
|
||||||
Rule depRule = BakeEngine.getRule(dependency);
|
File targetFile = new File(name);
|
||||||
if (depRule != null && depRule.needsUpdate()) {
|
if (!targetFile.exists() && !commands.isEmpty()) {
|
||||||
if (BakeCLI.isDebug()) {
|
if (BakeCLI.isDebug()) {
|
||||||
System.out.println("Debug : Dependency rule " + dependency + " needs update");
|
System.out.println("Debug : Target file " + name + " does not exist and has commands, needs update");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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
|
||||||
// Pour les règles avec des commandes, on vérifie aussi les timestamps
|
if (dependency.startsWith("~")) {
|
||||||
if (BakeCLI.isDebug()){
|
continue;
|
||||||
System.out.println("Debug : Checking if target file " + name + " exist and is up to date");
|
}
|
||||||
}
|
|
||||||
|
// Ignorer les options de compilation qui pourraient avoir un ':' dedans
|
||||||
long targetTimestamp = targetFile.exists() ? TimestampManager.getTimestamp(targetFile) : 0;
|
if (dependency.startsWith("-") || dependency.contains(":")) {
|
||||||
|
continue;
|
||||||
if (BakeCLI.isDebug()) {
|
}
|
||||||
System.out.println("Debug : Target file '" + name + "' last modified at " + TimestampManager.formatTimestamp(targetTimestamp));
|
|
||||||
}
|
File depFile = new File(dependency);
|
||||||
|
boolean hasRule = BakeEngine.hasRule(dependency);
|
||||||
long currentTime = System.currentTimeMillis();
|
|
||||||
|
if (!depFile.exists() && !dependency.isEmpty() && !hasRule) {
|
||||||
for (String dependency : dependencies) {
|
// Vérifier si on est en situation de dépendance circulaire déjà traitée
|
||||||
// Skip dependencies with tilde in path or compiler options
|
boolean isPartOfCircularDependency = false;
|
||||||
if (dependency.startsWith("~") || dependency.startsWith("-") || dependency.contains(":")) {
|
|
||||||
continue;
|
// Vérifier si cette dépendance est impliquée dans une relation circulaire
|
||||||
}
|
for (Rule rule : getAllRules()) {
|
||||||
|
if (rule.getName().equals(dependency) && rule.getDependencies().contains(name)) {
|
||||||
File depFile = new File(dependency);
|
if (BakeCLI.isDebug()) {
|
||||||
if (!depFile.exists()) {
|
System.out.println("Debug: Found circular dependency between " + name + " and " + dependency);
|
||||||
continue;
|
}
|
||||||
}
|
isPartOfCircularDependency = true;
|
||||||
|
break;
|
||||||
long depTimestamp = TimestampManager.getTimestamp(depFile);
|
}
|
||||||
|
}
|
||||||
// Vérifier si le timestamp de la dépendance est dans le futur
|
|
||||||
if (depTimestamp > currentTime) {
|
if (isPartOfCircularDependency) {
|
||||||
// Avertissement similaire à make
|
if (BakeCLI.isDebug()) {
|
||||||
System.out.println("bake: Warning: File '" + dependency + "' has modification time "
|
System.out.println("Debug: Ignoring circular dependency: " + dependency);
|
||||||
+ ((depTimestamp - currentTime) / 1000) + " s in the future");
|
}
|
||||||
if (BakeCLI.isDebug()) {
|
continue;
|
||||||
System.out.println("Debug : Dependency " + dependency + " has a timestamp in the future, needs update");
|
}
|
||||||
}
|
|
||||||
return true;
|
System.out.println("bake: *** No rule to make target `" + dependency + "', needed by `" + name + "'. Stop.");
|
||||||
}
|
System.exit(2);
|
||||||
|
}
|
||||||
if (BakeCLI.isDebug()) {
|
}
|
||||||
System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp));
|
|
||||||
}
|
// Si la règle n'a pas de commandes, on vérifie seulement si une dépendance doit être mise à jour
|
||||||
|
if (commands.isEmpty()) {
|
||||||
// Si la dépendance est une règle et qu'elle a besoin d'être mise à jour
|
for (String dependency : dependencies) {
|
||||||
Rule depRule = BakeEngine.getRule(dependency);
|
// Skip dependencies with tilde in path or compiler options
|
||||||
if (depRule != null && depRule.needsUpdate()) {
|
if (dependency.startsWith("~") || dependency.startsWith("-") || dependency.contains(":")) {
|
||||||
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()) {
|
||||||
// Vérifier les timestamps seulement si le fichier existe
|
System.out.println("Debug : Dependency rule " + dependency + " needs update");
|
||||||
if (depTimestamp > targetTimestamp) {
|
}
|
||||||
if (BakeCLI.isDebug()) {
|
return true;
|
||||||
System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update");
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Pour les règles avec des commandes, on vérifie aussi les timestamps
|
||||||
return false;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
for (String dependency : dependencies) {
|
||||||
|
// Skip dependencies with tilde in path or compiler options
|
||||||
|
if (dependency.startsWith("~") || dependency.startsWith("-") || dependency.contains(":")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
File depFile = new File(dependency);
|
||||||
|
if (!depFile.exists()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
long depTimestamp = TimestampManager.getTimestamp(depFile);
|
||||||
|
|
||||||
|
// Vérifier si le timestamp de la dépendance est dans le futur
|
||||||
|
if (depTimestamp > currentTime) {
|
||||||
|
// Avertissement similaire à make
|
||||||
|
System.out.println("bake: Warning: File '" + dependency + "' has modification time "
|
||||||
|
+ ((depTimestamp - currentTime) / 1000) + " s in the future");
|
||||||
|
if (BakeCLI.isDebug()) {
|
||||||
|
System.out.println("Debug : Dependency " + dependency + " has a timestamp in the future, needs update");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (depTimestamp > targetTimestamp) {
|
||||||
|
if (BakeCLI.isDebug()) {
|
||||||
|
System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet de récupérer la liste de toutes les règles
|
||||||
|
* @return La liste de toutes les règles
|
||||||
|
*/
|
||||||
|
private List<Rule> getAllRules() {
|
||||||
|
List<Rule> allRules = new ArrayList<>();
|
||||||
|
for (String ruleName : BakeEngine.getAllRuleNames()) {
|
||||||
|
Rule rule = BakeEngine.getRule(ruleName);
|
||||||
|
if (rule != null) {
|
||||||
|
allRules.add(rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allRules;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user