diff --git a/bakefile.jar b/bakefile.jar index d445db8..589b110 100644 Binary files a/bakefile.jar and b/bakefile.jar differ diff --git a/src/fr/monlouyan/bakefile/BakefileParser.java b/src/fr/monlouyan/bakefile/BakefileParser.java index 4bf89c2..61bf21d 100644 --- a/src/fr/monlouyan/bakefile/BakefileParser.java +++ b/src/fr/monlouyan/bakefile/BakefileParser.java @@ -80,7 +80,13 @@ public class BakefileParser { } currentTarget = targetMatcher.group(1); - dependencies = new ArrayList<>(Arrays.asList(targetMatcher.group(2).trim().split("\\s+"))); + String depStr = targetMatcher.group(2).trim(); + dependencies = depStr.isEmpty() ? new ArrayList<>() : new ArrayList<>(Arrays.asList(depStr.split("\\s+"))); + + if (currentTarget.equals("clean")) { + phonyTargets.add(currentTarget); + } + commands = new ArrayList<>(); } else if (commandMatcher.matches()) { commands.add(commandMatcher.group(1)); diff --git a/src/fr/monlouyan/bakefile/CommandExecutor.java b/src/fr/monlouyan/bakefile/CommandExecutor.java index 65b6645..d3ed16d 100644 --- a/src/fr/monlouyan/bakefile/CommandExecutor.java +++ b/src/fr/monlouyan/bakefile/CommandExecutor.java @@ -38,12 +38,39 @@ public class CommandExecutor { if (debug) System.out.println("Debug: Executing " + command); ProcessBuilder pb = new ProcessBuilder("sh", "-c", command); Process process = pb.start(); + + // Lire et afficher la sortie standard (stdout) + new Thread(() -> { + try (var reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()))) { + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + + // Lire et afficher la sortie d'erreur (stderr) + new Thread(() -> { + try (var reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getErrorStream()))) { + String line; + while ((line = reader.readLine()) != null) { + System.err.println(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + + // Attendre la fin du processus int exitCode = process.waitFor(); - + if (exitCode != 0) { - System.err.println("Error executing " + rule.getName()); - System.exit(1); + System.err.println("bake: *** [" + rule.getName() + "] Error " + exitCode); + System.exit(exitCode); } + } catch (IOException | InterruptedException e) { e.printStackTrace(); System.exit(1); diff --git a/src/fr/monlouyan/bakefile/Rule.java b/src/fr/monlouyan/bakefile/Rule.java index 6fa61b6..0b1b01c 100644 --- a/src/fr/monlouyan/bakefile/Rule.java +++ b/src/fr/monlouyan/bakefile/Rule.java @@ -104,7 +104,8 @@ public class Rule { for (String dependency : dependencies) { File depFile = new File(dependency); - if (!depFile.exists()) { + + if (!depFile.exists() && !dependency.isEmpty()) { System.out.println("bake: *** No rule to make target '" + dependency + "', needed by '" + name + "'. Stop."); System.exit(1); } diff --git a/tests/C/test-01-from-nothing/Bakefile b/tests/C/test-01-from-nothing/Bakefile index 35bfebb..2d7c69f 100644 --- a/tests/C/test-01-from-nothing/Bakefile +++ b/tests/C/test-01-from-nothing/Bakefile @@ -1,4 +1,5 @@ -FLAGS = -ansi -pedabtic - main: main.c - gcc -o main main.c \ No newline at end of file + gcc -o main main.c + +clean: + rm main \ No newline at end of file diff --git a/tests/C/test-01-from-nothing/Makefile b/tests/C/test-01-from-nothing/Makefile new file mode 100644 index 0000000..4845081 --- /dev/null +++ b/tests/C/test-01-from-nothing/Makefile @@ -0,0 +1,5 @@ +main: main.c + gcc -o main main.c + +clean: + rm main \ No newline at end of file diff --git a/tests/bakefile.jar b/tests/bakefile.jar index d445db8..589b110 100644 Binary files a/tests/bakefile.jar and b/tests/bakefile.jar differ