Ignore Comments in Makefiles starting with #
This commit is contained in:

committed by
Sebastian Serth

parent
a545614040
commit
7af17c87d3
@@ -68,6 +68,8 @@ class SimpleMakefile {
|
|||||||
String[] trimmedCommands = Arrays.stream(ruleCommands)
|
String[] trimmedCommands = Arrays.stream(ruleCommands)
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
.map(s -> s.startsWith("@") ? s.substring(1) : s)
|
.map(s -> s.startsWith("@") ? s.substring(1) : s)
|
||||||
|
.map(s -> s.contains("#") ? s.substring(0, s.indexOf("#")) : s)
|
||||||
|
.filter(s -> !s.isEmpty())
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
|
|
||||||
rules.put(ruleName, trimmedCommands);
|
rules.put(ruleName, trimmedCommands);
|
||||||
|
@@ -37,6 +37,13 @@ public class SimpleMakefileTest {
|
|||||||
"\t@java org/example/RecursiveMath\r\n"
|
"\t@java org/example/RecursiveMath\r\n"
|
||||||
).getBytes(StandardCharsets.UTF_8));
|
).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
static final String SuccessfulMakefileWithComment = Base64.getEncoder().encodeToString(
|
||||||
|
("run:\r\n" +
|
||||||
|
"\t@javac org/example/RecursiveMath.java\r\n" +
|
||||||
|
"\t@java org/example/RecursiveMath\r\n" +
|
||||||
|
"\t#exit\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" +
|
||||||
@@ -63,6 +70,13 @@ public class SimpleMakefileTest {
|
|||||||
parseRunCommandOfMakefile(SuccessfulMakefileWithAtSymbol);
|
parseRunCommandOfMakefile(SuccessfulMakefileWithAtSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We remove [any comments with #](https://www.gnu.org/software/make/manual/make.html#Recipe-Syntax)
|
||||||
|
// as they are normally ignored / echoed with most shells.
|
||||||
|
@Test
|
||||||
|
public void sucessfullMakeWithComment() {
|
||||||
|
parseRunCommandOfMakefile(SuccessfulMakefileWithComment);
|
||||||
|
}
|
||||||
|
|
||||||
private void parseRunCommandOfMakefile(String makefileB64) {
|
private void parseRunCommandOfMakefile(String makefileB64) {
|
||||||
Map<String, String> files = new HashMap<>();
|
Map<String, String> files = new HashMap<>();
|
||||||
files.put("Makefile", makefileB64);
|
files.put("Makefile", makefileB64);
|
||||||
|
Reference in New Issue
Block a user