Amélioration de la gestion des dépendances et ajout de la sortie des erreurs lors de l'exécution des commandes

This commit is contained in:
Louay DARDOURI 2025-02-06 12:31:07 +01:00
parent ad19cecc45
commit eb8eea428d
7 changed files with 48 additions and 8 deletions

Binary file not shown.

@ -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));

@ -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);

@ -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);
}

@ -1,4 +1,5 @@
FLAGS = -ansi -pedabtic
main: main.c
gcc -o main main.c
gcc -o main main.c
clean:
rm main

@ -0,0 +1,5 @@
main: main.c
gcc -o main main.c
clean:
rm main

Binary file not shown.