From 1a3d07cb90c50137d5fcbe7912b98e93c3b96f13 Mon Sep 17 00:00:00 2001 From: Moncef STITI <moncef.stiti@etu.u-pec.fr> Date: Wed, 12 Mar 2025 22:36:26 +0100 Subject: [PATCH] BACKUP DE DEBUG --- Bakefile | 90 +++++++++++++++++++ src/fr/monlouyan/bakefile/BakefileParser.java | 5 +- .../bakefile/DependencyResolver.java | 19 ++++ src/fr/monlouyan/bakefile/Rule.java | 14 ++- tests/test-26-rule-in-rule/bake/Bakefile | 2 + tests/test-26-rule-in-rule/bake/Main.java | 5 ++ tests/test-26-rule-in-rule/make/Main.java | 5 ++ tests/test-26-rule-in-rule/make/Makefile | 2 + 8 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 Bakefile create mode 100644 tests/test-26-rule-in-rule/bake/Bakefile create mode 100644 tests/test-26-rule-in-rule/bake/Main.java create mode 100644 tests/test-26-rule-in-rule/make/Main.java create mode 100644 tests/test-26-rule-in-rule/make/Makefile diff --git a/Bakefile b/Bakefile new file mode 100644 index 0000000..93b28cc --- /dev/null +++ b/Bakefile @@ -0,0 +1,90 @@ +# Définition des variables +PACKAGE = fr.monlouyan.bakefile +ENTRY = Main +BUILDDIR = ./build/ +DOCDIR = ./doc/ +CLASSP = ./build +MANIFESTPATH = Manifest.MF +SOURCEDIR = ./src/ +TESTDIR = ./tests/ + +# Liste des fichiers source et leurs correspondances en .class +BAKECLI_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/BakeCLI.class +TIMESTAMPMANAGER_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/TimestampManager.class +BAKEFILEPARSER_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/BakefileParser.class +DEPENDENCYRESOLVER_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/DependencyResolver.class +COMMANDEXECUTOR_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/CommandExecutor.class +BAKEENGINE_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/BakeEngine.class +RULE_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/Rule.class +MAIN_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/Main.class + +# Fichiers source +BAKECLI_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/BakeCLI.java +TIMESTAMPMANAGER_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/TimestampManager.java +BAKEFILEPARSER_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/BakefileParser.java +DEPENDENCYRESOLVER_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/DependencyResolver.java +COMMANDEXECUTOR_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/CommandExecutor.java +BAKEENGINE_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/BakeEngine.java +RULE_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/Rule.java +MAIN_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/Main.java + +# Cible principale +all: init $(MAIN_CLASS) + +# Initialiser les répertoires nécessaires +init: + @mkdir -p $(BUILDDIR) + @mkdir -p $(BUILDDIR)fr/monlouyan/bakefile/ + +$(MAIN_CLASS): $(MAIN_SRC) $(BAKECLI_CLASS) $(BAKEENGINE_CLASS) + @echo "Compilation de $(MAIN_SRC)..." + @javac -cp $(CLASSP) -d $(BUILDDIR) $(MAIN_SRC) -Xlint:unchecked -Xlint:deprecation -sourcepath src + +$(RULE_CLASS): $(RULE_SRC) $(BAKECLI_CLASS) + @echo "Compilation de $(RULE_SRC)..." + @javac -cp $(CLASSP) -d $(BUILDDIR) $(RULE_SRC) -Xlint:unchecked -Xlint:deprecation -sourcepath src + +$(TIMESTAMPMANAGER_CLASS): $(TIMESTAMPMANAGER_SRC) + @echo "Compilation de $(TIMESTAMPMANAGER_SRC)..." + @javac -cp $(CLASSP) -d $(BUILDDIR) $(TIMESTAMPMANAGER_SRC) -Xlint:unchecked -Xlint:deprecation -sourcepath src + +$(DEPENDENCYRESOLVER_CLASS): $(DEPENDENCYRESOLVER_SRC) $(RULE_CLASS) + @echo "Compilation de $(DEPENDENCYRESOLVER_SRC)..." + @javac -cp $(CLASSP) -d $(BUILDDIR) $(DEPENDENCYRESOLVER_SRC) -Xlint:unchecked -Xlint:deprecation -sourcepath src + +$(COMMANDEXECUTOR_CLASS): $(COMMANDEXECUTOR_SRC) $(RULE_CLASS) $(TIMESTAMPMANAGER_CLASS) + @echo "Compilation de $(COMMANDEXECUTOR_SRC)..." + @javac -cp $(CLASSP) -d $(BUILDDIR) $(COMMANDEXECUTOR_SRC) -Xlint:unchecked -Xlint:deprecation -sourcepath src + +$(BAKEFILEPARSER_CLASS): $(BAKEFILEPARSER_SRC) $(RULE_CLASS) + @echo "Compilation de $(BAKEFILEPARSER_SRC)..." + @javac -cp $(CLASSP) -d $(BUILDDIR) $(BAKEFILEPARSER_SRC) -Xlint:unchecked -Xlint:deprecation -sourcepath src + +$(BAKEENGINE_CLASS): $(BAKEENGINE_SRC) $(BAKEFILEPARSER_CLASS) $(DEPENDENCYRESOLVER_CLASS) $(COMMANDEXECUTOR_CLASS) $(RULE_CLASS) $(BAKECLI_CLASS) + @echo "Compilation de $(BAKEENGINE_SRC)..." + @javac -cp $(CLASSP) -d $(BUILDDIR) $(BAKEENGINE_SRC) -Xlint:unchecked -Xlint:deprecation -sourcepath src + +$(BAKECLI_CLASS): $(BAKECLI_SRC) + @echo "Compilation de $(BAKECLI_SRC)..." + @javac -cp $(CLASSP) -d $(BUILDDIR) $(BAKECLI_SRC) -Xlint:unchecked -Xlint:deprecation -sourcepath src + + +# Génération de la documentation Javadoc +javadoc: + echo "Génération de la documentation Javadoc..." + javadoc -d $(DOCDIR) -sourcepath $(SOURCEDIR) -subpackages $(PACKAGE) + echo "Documentation Javadoc générée dans $(DOCDIR)" + +see-javadoc: javadoc + echo "Ouverture de la documentation Javadoc sur Firefox..." + firefox $(DOCDIR)/index.html + +# Nettoyage des fichiers générés +clean: + echo "Nettoyage des fichiers générés..." + rm -rf $(BUILDDIR) + rm -rf $(DOCDIR) + echo "Nettoyage terminé." + +# Cibles spéciales +.PHONY: all init javadoc clean \ No newline at end of file diff --git a/src/fr/monlouyan/bakefile/BakefileParser.java b/src/fr/monlouyan/bakefile/BakefileParser.java index 6f6b039..5d4d348 100644 --- a/src/fr/monlouyan/bakefile/BakefileParser.java +++ b/src/fr/monlouyan/bakefile/BakefileParser.java @@ -26,9 +26,10 @@ public class BakefileParser { /** * Regex pour détecter les targets et leurs dépendances. * Format : "nom1 nom2 nom3 : dépendance1 dépendance2" - * La nouvelle regex gère plusieurs cibles séparées par des espaces + * La nouvelle regex assure que la ligne ne commence pas par une tabulation + * et vérifie que le premier caractère non-espace n'est pas un symbole de commentaire */ - private static final Pattern TARGET_PATTERN = Pattern.compile("^([^:#]+?)\\s*:\\s*([^#]*?)\\s*(?:#.*)?$"); + private static final Pattern TARGET_PATTERN = Pattern.compile("^([^\\t:#][^:#]+?)\\s*:\\s*([^#]*?)\\s*(?:#.*)?$"); /** * Regex pour détecter les lignes de commande associées à une target. diff --git a/src/fr/monlouyan/bakefile/DependencyResolver.java b/src/fr/monlouyan/bakefile/DependencyResolver.java index b2574b4..eb01f0d 100644 --- a/src/fr/monlouyan/bakefile/DependencyResolver.java +++ b/src/fr/monlouyan/bakefile/DependencyResolver.java @@ -79,6 +79,14 @@ public class DependencyResolver { continue; } + // Ignorer les options de compilation qui pourraient avoir été mal interprétées comme des règles + if (ruleName.startsWith("-") || ruleName.contains(":")) { + if (debug) { + System.out.println("Debug: Skipping compiler option: " + ruleName); + } + continue; + } + Rule rule = ruleMap.get(ruleName); if (rule != null) { rulesToBuild.add(rule); @@ -108,6 +116,12 @@ public class DependencyResolver { if (dep.startsWith("~")) { continue; } + + // Ignorer les options de compilation qui pourraient avoir un ':' dedans + if (dep.startsWith("-") || dep.contains(":")) { + continue; + } + topologicalSort(dep, processed, buildOrder); } @@ -148,6 +162,11 @@ public class DependencyResolver { continue; } + // Ignorer les options de compilation qui pourraient avoir un ':' dedans + if (dependency.startsWith("-") || dependency.contains(":")) { + continue; + } + if (ruleMap.containsKey(dependency)) { detectCycle(dependency, visited, stack, ruleName); } diff --git a/src/fr/monlouyan/bakefile/Rule.java b/src/fr/monlouyan/bakefile/Rule.java index f2f3648..59b24b0 100644 --- a/src/fr/monlouyan/bakefile/Rule.java +++ b/src/fr/monlouyan/bakefile/Rule.java @@ -103,6 +103,12 @@ public class Rule { 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); @@ -121,8 +127,8 @@ public class Rule { // 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("~")) { + // Skip dependencies with tilde in path or compiler options + if (dependency.startsWith("~") || dependency.startsWith("-") || dependency.contains(":")) { continue; } @@ -151,8 +157,8 @@ public class Rule { long currentTime = System.currentTimeMillis(); for (String dependency : dependencies) { - // Skip dependencies with tilde in path - if (dependency.startsWith("~")) { + // Skip dependencies with tilde in path or compiler options + if (dependency.startsWith("~") || dependency.startsWith("-") || dependency.contains(":")) { continue; } diff --git a/tests/test-26-rule-in-rule/bake/Bakefile b/tests/test-26-rule-in-rule/bake/Bakefile new file mode 100644 index 0000000..ab6d903 --- /dev/null +++ b/tests/test-26-rule-in-rule/bake/Bakefile @@ -0,0 +1,2 @@ +Main.class: Main.java + javac Main.java -Xlint:unchecked \ No newline at end of file diff --git a/tests/test-26-rule-in-rule/bake/Main.java b/tests/test-26-rule-in-rule/bake/Main.java new file mode 100644 index 0000000..f3cef84 --- /dev/null +++ b/tests/test-26-rule-in-rule/bake/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} diff --git a/tests/test-26-rule-in-rule/make/Main.java b/tests/test-26-rule-in-rule/make/Main.java new file mode 100644 index 0000000..f3cef84 --- /dev/null +++ b/tests/test-26-rule-in-rule/make/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} diff --git a/tests/test-26-rule-in-rule/make/Makefile b/tests/test-26-rule-in-rule/make/Makefile new file mode 100644 index 0000000..ab6d903 --- /dev/null +++ b/tests/test-26-rule-in-rule/make/Makefile @@ -0,0 +1,2 @@ +Main.class: Main.java + javac Main.java -Xlint:unchecked \ No newline at end of file