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.
|
* 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.
|
* Regex pour détecter les lignes de commande associées à une target.
|
||||||
@ -143,6 +144,18 @@ public class BakefileParser {
|
|||||||
.collect(Collectors.toList());
|
.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() {
|
public List<Rule> parse() {
|
||||||
List<Rule> rules = new ArrayList<>();
|
List<Rule> rules = new ArrayList<>();
|
||||||
Set<String> phonyTargets = new HashSet<>();
|
Set<String> phonyTargets = new HashSet<>();
|
||||||
@ -154,7 +167,7 @@ public class BakefileParser {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = Files.readAllLines(Paths.get(filename));
|
List<String> lines = Files.readAllLines(Paths.get(filename));
|
||||||
String currentTarget = null;
|
List<String> currentTargets = null;
|
||||||
List<String> dependencies = new ArrayList<>();
|
List<String> dependencies = new ArrayList<>();
|
||||||
List<String> commands = new ArrayList<>();
|
List<String> commands = new ArrayList<>();
|
||||||
|
|
||||||
@ -200,22 +213,26 @@ public class BakefileParser {
|
|||||||
varValue = replaceVariables(varValue);
|
varValue = replaceVariables(varValue);
|
||||||
variables.put(varName, varValue);
|
variables.put(varName, varValue);
|
||||||
} else if (targetMatcher.matches()) {
|
} else if (targetMatcher.matches()) {
|
||||||
if (currentTarget != null) {
|
if (currentTargets != null) {
|
||||||
String resolvedTarget = replaceVariables(currentTarget.trim());
|
// Créer une règle pour chaque cible avec les mêmes dépendances et commandes
|
||||||
rules.add(new Rule(
|
for (String target : currentTargets) {
|
||||||
resolvedTarget,
|
String resolvedTarget = replaceVariables(target.trim());
|
||||||
splitDependencies(dependencies.stream()
|
rules.add(new Rule(
|
||||||
.collect(Collectors.joining(" "))),
|
resolvedTarget,
|
||||||
replaceVariablesInList(commands),
|
splitDependencies(dependencies.stream()
|
||||||
phonyTargets.contains(resolvedTarget)
|
.collect(Collectors.joining(" "))),
|
||||||
));
|
replaceVariablesInList(commands),
|
||||||
|
phonyTargets.contains(resolvedTarget)
|
||||||
if (firstTarget == null && !phonyTargets.contains(resolvedTarget)) {
|
));
|
||||||
firstTarget = 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);
|
String depStr = targetMatcher.group(2);
|
||||||
dependencies = splitDependencies(depStr);
|
dependencies = splitDependencies(depStr);
|
||||||
commands = new ArrayList<>();
|
commands = new ArrayList<>();
|
||||||
@ -224,17 +241,20 @@ public class BakefileParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentTarget != null) {
|
if (currentTargets != null) {
|
||||||
String resolvedTarget = replaceVariables(currentTarget.trim());
|
// Créer une règle pour chaque cible avec les mêmes dépendances et commandes
|
||||||
rules.add(new Rule(
|
for (String target : currentTargets) {
|
||||||
resolvedTarget,
|
String resolvedTarget = replaceVariables(target.trim());
|
||||||
replaceVariablesInList(dependencies),
|
rules.add(new Rule(
|
||||||
replaceVariablesInList(commands),
|
resolvedTarget,
|
||||||
phonyTargets.contains(resolvedTarget)
|
replaceVariablesInList(dependencies),
|
||||||
));
|
replaceVariablesInList(commands),
|
||||||
|
phonyTargets.contains(resolvedTarget)
|
||||||
if (firstTarget == null && !phonyTargets.contains(resolvedTarget)) {
|
));
|
||||||
firstTarget = resolvedTarget;
|
|
||||||
|
if (firstTarget == null && !phonyTargets.contains(resolvedTarget)) {
|
||||||
|
firstTarget = resolvedTarget;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user