From 7af17c87d36352cd94b101b9ccf925275601e5f4 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 21 Apr 2022 21:39:32 +0200 Subject: [PATCH] Ignore Comments in Makefiles starting with # --- .../src/main/java/poseidon/SimpleMakefile.java | 2 ++ .../src/test/java/poseidon/SimpleMakefileTest.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/deploy/aws/java11Exec/src/main/java/poseidon/SimpleMakefile.java b/deploy/aws/java11Exec/src/main/java/poseidon/SimpleMakefile.java index ba6b3cf..5ff0dd7 100644 --- a/deploy/aws/java11Exec/src/main/java/poseidon/SimpleMakefile.java +++ b/deploy/aws/java11Exec/src/main/java/poseidon/SimpleMakefile.java @@ -68,6 +68,8 @@ class SimpleMakefile { String[] trimmedCommands = Arrays.stream(ruleCommands) .map(String::trim) .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); rules.put(ruleName, trimmedCommands); diff --git a/deploy/aws/java11Exec/src/test/java/poseidon/SimpleMakefileTest.java b/deploy/aws/java11Exec/src/test/java/poseidon/SimpleMakefileTest.java index 627ad05..933e5a1 100644 --- a/deploy/aws/java11Exec/src/test/java/poseidon/SimpleMakefileTest.java +++ b/deploy/aws/java11Exec/src/test/java/poseidon/SimpleMakefileTest.java @@ -37,6 +37,13 @@ public class SimpleMakefileTest { "\t@java org/example/RecursiveMath\r\n" ).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( ("run: test\n" + "\tjavac org/example/RecursiveMath.java\n" + @@ -63,6 +70,13 @@ public class SimpleMakefileTest { 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) { Map files = new HashMap<>(); files.put("Makefile", makefileB64);