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:
BIN
bakefile.jar
BIN
bakefile.jar
Binary file not shown.
@@ -80,7 +80,13 @@ public class BakefileParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentTarget = targetMatcher.group(1);
|
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<>();
|
commands = new ArrayList<>();
|
||||||
} else if (commandMatcher.matches()) {
|
} else if (commandMatcher.matches()) {
|
||||||
commands.add(commandMatcher.group(1));
|
commands.add(commandMatcher.group(1));
|
||||||
|
@@ -38,12 +38,39 @@ public class CommandExecutor {
|
|||||||
if (debug) System.out.println("Debug: Executing " + command);
|
if (debug) System.out.println("Debug: Executing " + command);
|
||||||
ProcessBuilder pb = new ProcessBuilder("sh", "-c", command);
|
ProcessBuilder pb = new ProcessBuilder("sh", "-c", command);
|
||||||
Process process = pb.start();
|
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();
|
int exitCode = process.waitFor();
|
||||||
|
|
||||||
if (exitCode != 0) {
|
if (exitCode != 0) {
|
||||||
System.err.println("Error executing " + rule.getName());
|
System.err.println("bake: *** [" + rule.getName() + "] Error " + exitCode);
|
||||||
System.exit(1);
|
System.exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
@@ -104,7 +104,8 @@ public class Rule {
|
|||||||
|
|
||||||
for (String dependency : dependencies) {
|
for (String dependency : dependencies) {
|
||||||
File depFile = new File(dependency);
|
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.out.println("bake: *** No rule to make target '" + dependency + "', needed by '" + name + "'. Stop.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
FLAGS = -ansi -pedabtic
|
|
||||||
|
|
||||||
main: main.c
|
main: main.c
|
||||||
gcc -o main main.c
|
gcc -o main main.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm main
|
5
tests/C/test-01-from-nothing/Makefile
Normal file
5
tests/C/test-01-from-nothing/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
main: main.c
|
||||||
|
gcc -o main main.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm main
|
Binary file not shown.
Reference in New Issue
Block a user