Correction de bug
This commit is contained in:
parent
f8caea69c6
commit
77e954fff0
@ -17,9 +17,10 @@ public class BakefileParser {
|
||||
|
||||
/**
|
||||
* Regex pour détecter les targets et leurs dépendances.
|
||||
* Format : "nom : dépendance1 dépendance2"
|
||||
* Format : "nom1 nom2 nom3 : dépendance1 dépendance2"
|
||||
* La nouvelle regex gère plusieurs cibles séparées par des espaces
|
||||
*/
|
||||
private static final Pattern TARGET_PATTERN = Pattern.compile("^(\\S+)\\s*:\\s*([^#]*?)\\s*(?:#.*)?$");
|
||||
private static final Pattern TARGET_PATTERN = Pattern.compile("^([^:#]+?)\\s*:\\s*([^#]*?)\\s*(?:#.*)?$");
|
||||
|
||||
/**
|
||||
* Regex pour détecter les lignes de commande associées à une target.
|
||||
@ -143,6 +144,18 @@ public class BakefileParser {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<String> splitTargets(String targetStr) {
|
||||
if (targetStr == null || targetStr.trim().isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String resolvedStr = replaceVariables(targetStr.trim());
|
||||
return Arrays.stream(resolvedStr.split("\\s+"))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Rule> parse() {
|
||||
List<Rule> rules = new ArrayList<>();
|
||||
Set<String> phonyTargets = new HashSet<>();
|
||||
@ -154,7 +167,7 @@ public class BakefileParser {
|
||||
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(Paths.get(filename));
|
||||
String currentTarget = null;
|
||||
List<String> currentTargets = null;
|
||||
List<String> dependencies = new ArrayList<>();
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
@ -200,22 +213,26 @@ public class BakefileParser {
|
||||
varValue = replaceVariables(varValue);
|
||||
variables.put(varName, varValue);
|
||||
} else if (targetMatcher.matches()) {
|
||||
if (currentTarget != null) {
|
||||
String resolvedTarget = replaceVariables(currentTarget.trim());
|
||||
rules.add(new Rule(
|
||||
resolvedTarget,
|
||||
splitDependencies(dependencies.stream()
|
||||
.collect(Collectors.joining(" "))),
|
||||
replaceVariablesInList(commands),
|
||||
phonyTargets.contains(resolvedTarget)
|
||||
));
|
||||
|
||||
if (firstTarget == null && !phonyTargets.contains(resolvedTarget)) {
|
||||
firstTarget = resolvedTarget;
|
||||
if (currentTargets != null) {
|
||||
// Créer une règle pour chaque cible avec les mêmes dépendances et commandes
|
||||
for (String target : currentTargets) {
|
||||
String resolvedTarget = replaceVariables(target.trim());
|
||||
rules.add(new Rule(
|
||||
resolvedTarget,
|
||||
splitDependencies(dependencies.stream()
|
||||
.collect(Collectors.joining(" "))),
|
||||
replaceVariablesInList(commands),
|
||||
phonyTargets.contains(resolvedTarget)
|
||||
));
|
||||
|
||||
if (firstTarget == null && !phonyTargets.contains(resolvedTarget)) {
|
||||
firstTarget = resolvedTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentTarget = targetMatcher.group(1);
|
||||
String targetStr = targetMatcher.group(1);
|
||||
currentTargets = splitTargets(targetStr);
|
||||
String depStr = targetMatcher.group(2);
|
||||
dependencies = splitDependencies(depStr);
|
||||
commands = new ArrayList<>();
|
||||
@ -224,17 +241,20 @@ public class BakefileParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTarget != null) {
|
||||
String resolvedTarget = replaceVariables(currentTarget.trim());
|
||||
rules.add(new Rule(
|
||||
resolvedTarget,
|
||||
replaceVariablesInList(dependencies),
|
||||
replaceVariablesInList(commands),
|
||||
phonyTargets.contains(resolvedTarget)
|
||||
));
|
||||
|
||||
if (firstTarget == null && !phonyTargets.contains(resolvedTarget)) {
|
||||
firstTarget = resolvedTarget;
|
||||
if (currentTargets != null) {
|
||||
// Créer une règle pour chaque cible avec les mêmes dépendances et commandes
|
||||
for (String target : currentTargets) {
|
||||
String resolvedTarget = replaceVariables(target.trim());
|
||||
rules.add(new Rule(
|
||||
resolvedTarget,
|
||||
replaceVariablesInList(dependencies),
|
||||
replaceVariablesInList(commands),
|
||||
phonyTargets.contains(resolvedTarget)
|
||||
));
|
||||
|
||||
if (firstTarget == null && !phonyTargets.contains(resolvedTarget)) {
|
||||
firstTarget = resolvedTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user