From 2d1da343b618144df60d7e4867f3d4782cac8b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bystr=C3=B6m?= Date: Tue, 7 Sep 2021 14:05:07 +0200 Subject: [PATCH] Fixing some obvious bugs --- build.gradle | 2 +- .../tazadum/glsl/cli/options/CompilerOptions.java | 14 ++++++++++++-- .../java/com/tazadum/glsl/util/io/FileSource.java | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 8512a61..abfb21f 100755 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ allprojects { group = 'com.tazadum.glsl' - version = '1.4.0' + version = '1.4.1' } diff --git a/parser/src/main/java/com/tazadum/glsl/cli/options/CompilerOptions.java b/parser/src/main/java/com/tazadum/glsl/cli/options/CompilerOptions.java index 88b6d5f..61e572e 100755 --- a/parser/src/main/java/com/tazadum/glsl/cli/options/CompilerOptions.java +++ b/parser/src/main/java/com/tazadum/glsl/cli/options/CompilerOptions.java @@ -60,7 +60,7 @@ public void configure(OptionParser parser) { shaderIdSpec = parser.accepts("id", "Set the shader id, used for C-header generation.") .withRequiredArg().describedAs("id"); - blacklistSpec = parser.accepts("no-render", "Black lists a keyword that will be omitted from rendering.") + blacklistSpec = parser.accepts("no-render", "Omit a keyword from rendering.") .withRequiredArg().describedAs("keyword"); indentationSpec = parser.accepts("fidentation", "The number of spaces to use for output indentation") @@ -145,7 +145,7 @@ public boolean handle(OptionSet optionSet, Logger logger) { @Override public Path generateOutput(Path inputPath) { - String name = inputPath.toFile().getName(); + String name = stripExtension(inputPath.toFile().getName()); switch (outputFormat) { case SHADERTOY: case PLAIN: @@ -157,6 +157,16 @@ public Path generateOutput(Path inputPath) { } } + private String stripExtension(String name) { + if (name.endsWith(".glsl")) { + name = name.substring(0, name.length() - 5); + if (name.isEmpty()) { + return "shader"; + } + } + return name; + } + private void printFormatExpectations(Logger logger) { logger.error("Expected one of:"); diff --git a/preprocessor/src/main/java/com/tazadum/glsl/util/io/FileSource.java b/preprocessor/src/main/java/com/tazadum/glsl/util/io/FileSource.java index 27032a6..4fe927d 100755 --- a/preprocessor/src/main/java/com/tazadum/glsl/util/io/FileSource.java +++ b/preprocessor/src/main/java/com/tazadum/glsl/util/io/FileSource.java @@ -5,6 +5,7 @@ import java.io.FileReader; import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; /** * Created by erikb on 2018-09-28. @@ -40,6 +41,10 @@ public String readLine() throws IOException { @Override public Source resolve(String filePath) throws FileNotFoundException { + if (path.getParent() == null) { + return new FileSource(Paths.get(filePath)); + } + return new FileSource(path.getParent().resolve(filePath)); }