Ignore @ Symbols in Makefiles
This commit is contained in:
@ -65,7 +65,10 @@ class SimpleMakefile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String[] ruleCommands = makeRuleMatcher.group("commands").split("\n");
|
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);
|
rules.put(ruleName, trimmedCommands);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,12 @@ public class SimpleMakefileTest {
|
|||||||
"\techo Hi\r\n"
|
"\techo Hi\r\n"
|
||||||
).getBytes(StandardCharsets.UTF_8));
|
).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(
|
static final String NotSupportedMakefile = Base64.getEncoder().encodeToString(
|
||||||
("run: test\n" +
|
("run: test\n" +
|
||||||
"\tjavac org/example/RecursiveMath.java\n" +
|
"\tjavac org/example/RecursiveMath.java\n" +
|
||||||
@ -42,25 +48,24 @@ public class SimpleMakefileTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sucessfullMake() {
|
public void sucessfullMake() {
|
||||||
Map<String, String> files = new HashMap<>();
|
parseRunCommandOfMakefile(SuccessfulMakefile);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sucessfullMakeWithCR() {
|
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<>();
|
Map<String, String> files = new HashMap<>();
|
||||||
files.put("Makefile", SuccessfulWindowsMakefile);
|
files.put("Makefile", makefileB64);
|
||||||
files.put("org/example/RecursiveMath.java", RecursiveMathContent);
|
files.put("org/example/RecursiveMath.java", RecursiveMathContent);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user