Ignore @ Symbols in Makefiles

This commit is contained in:
Maximilian Paß
2022-04-21 18:58:06 +02:00
parent a95db653ca
commit 4cd53d24bc
2 changed files with 23 additions and 15 deletions

View File

@ -65,7 +65,10 @@ class SimpleMakefile {
}
String[] ruleCommands = makeRuleMatcher.group("commands").split("\n");
String[] trimmedCommands = Arrays.stream(ruleCommands).map(String::trim).toArray(String[]::new);
String[] trimmedCommands = Arrays.stream(ruleCommands)
.map(String::trim)
.map(s -> s.startsWith("@") ? s.substring(1) : s)
.toArray(String[]::new);
rules.put(ruleName, trimmedCommands);
}

View File

@ -31,6 +31,12 @@ public class SimpleMakefileTest {
"\techo Hi\r\n"
).getBytes(StandardCharsets.UTF_8));
static final String SuccessfulMakefileWithAtSymbol = Base64.getEncoder().encodeToString(
("run:\r\n" +
"\t@javac org/example/RecursiveMath.java\r\n" +
"\t@java org/example/RecursiveMath\r\n"
).getBytes(StandardCharsets.UTF_8));
static final String NotSupportedMakefile = Base64.getEncoder().encodeToString(
("run: test\n" +
"\tjavac org/example/RecursiveMath.java\n" +
@ -42,25 +48,24 @@ public class SimpleMakefileTest {
@Test
public void sucessfullMake() {
Map<String, String> files = new HashMap<>();
files.put("Makefile", SuccessfulMakefile);
files.put("org/example/RecursiveMath.java", RecursiveMathContent);
try {
String command = "make run";
SimpleMakefile makefile = new SimpleMakefile(files);
String cmd = makefile.parseCommand(command);
assertEquals("javac org/example/RecursiveMath.java && java org/example/RecursiveMath", cmd);
} catch (NoMakefileFoundException | InvalidMakefileException | NoMakeCommandException ignored) {
fail();
}
parseRunCommandOfMakefile(SuccessfulMakefile);
}
@Test
public void sucessfullMakeWithCR() {
parseRunCommandOfMakefile(SuccessfulWindowsMakefile);
}
// We remove [the @ Symbol](https://www.gnu.org/software/make/manual/make.html#Echoing)
// as the command itself is never written to stdout with this implementation.
@Test
public void sucessfullMakeWithAtSymbol() {
parseRunCommandOfMakefile(SuccessfulMakefileWithAtSymbol);
}
private void parseRunCommandOfMakefile(String makefileB64) {
Map<String, String> files = new HashMap<>();
files.put("Makefile", SuccessfulWindowsMakefile);
files.put("Makefile", makefileB64);
files.put("org/example/RecursiveMath.java", RecursiveMathContent);
try {