diff --git a/src/main/java/org/openjdk/jextract/JextractTool.java b/src/main/java/org/openjdk/jextract/JextractTool.java index 8d7de280..611c744f 100644 --- a/src/main/java/org/openjdk/jextract/JextractTool.java +++ b/src/main/java/org/openjdk/jextract/JextractTool.java @@ -26,6 +26,7 @@ package org.openjdk.jextract; import org.openjdk.jextract.impl.ClangException; +import org.openjdk.jextract.impl.CommandLine; import org.openjdk.jextract.impl.IncludeHelper; import org.openjdk.jextract.impl.OutputFactory; import org.openjdk.jextract.impl.Parser; @@ -44,6 +45,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.text.MessageFormat; +import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; @@ -172,6 +174,16 @@ public static void main(String[] args) { } private int run(String[] args) { + try { + args = CommandLine.parse(Arrays.asList(args)).toArray(new String[0]); + } catch (IOException ioexp) { + err.println(format("argfile.read.error", ioexp)); + if (JextractTool.DEBUG) { + ioexp.printStackTrace(err); + } + return OPTION_ERROR; + } + OptionParser parser = new OptionParser(false); parser.accepts("C", format("help.C")).withRequiredArg(); parser.accepts("I", format("help.I")).withRequiredArg(); diff --git a/src/main/resources/org/openjdk/jextract/impl/resources/Messages.properties b/src/main/resources/org/openjdk/jextract/impl/resources/Messages.properties index 7d143e21..3ce8b590 100644 --- a/src/main/resources/org/openjdk/jextract/impl/resources/Messages.properties +++ b/src/main/resources/org/openjdk/jextract/impl/resources/Messages.properties @@ -22,6 +22,7 @@ # # error message +argfile.read.error=reading @argfile failed: {0} cannot.read.header.file=cannot read header file: {0} not.a.file=not a file: {0} l.option.value.invalid=option value for -l option should be a name or an absolute path diff --git a/test/java/org/openjdk/jextract/test/toolprovider/JextractToolProviderTest.java b/test/java/org/openjdk/jextract/test/toolprovider/JextractToolProviderTest.java index 65e05edf..ad329ae1 100644 --- a/test/java/org/openjdk/jextract/test/toolprovider/JextractToolProviderTest.java +++ b/test/java/org/openjdk/jextract/test/toolprovider/JextractToolProviderTest.java @@ -39,6 +39,14 @@ public void testHelp() { run("-?").checkSuccess(); } + // error for non-existent args file + @Test + public void testNonExistentArgsFile() { + run("@non_existent_args") + .checkFailure(OPTION_ERROR) + .checkContainsOutput("reading @argfile failed"); + } + // error for non-existent header file @Test public void testNonExistentHeader() { @@ -95,6 +103,20 @@ public void testOutputClass() { } } + @Test + public void testArgsFile() { + Path helloOutput = getOutputFilePath("hellogen"); + run("-d", helloOutput.toString(), + "@" + getInputFilePath("helloargs").toString(), + getInputFilePath("hello.h").toString()).checkSuccess(); + try(TestUtils.Loader loader = TestUtils.classLoader(helloOutput)) { + Class cls = loader.loadClass("com.acme.hello_h"); + assertNotNull(cls); + } finally { + TestUtils.deleteDir(helloOutput); + } + } + private void testTargetPackage(String targetPkgOption) { Path helloOutput = getOutputFilePath("hellogen"); Path helloH = getInputFilePath("hello.h"); diff --git a/test/java/org/openjdk/jextract/test/toolprovider/helloargs b/test/java/org/openjdk/jextract/test/toolprovider/helloargs new file mode 100644 index 00000000..ab9e15a7 --- /dev/null +++ b/test/java/org/openjdk/jextract/test/toolprovider/helloargs @@ -0,0 +1 @@ +-t com.acme