Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7903129: jextract does not handle @argfile #4

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/org/openjdk/jextract/JextractTool.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -22,6 +22,7 @@
#

# error message
argfile.read.error=reading @argfile failed: {0}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the error only occur because of arg file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. CommandLine.parse

 * @throws IOException if there is a problem reading any of the @files

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
Expand Down
Expand Up @@ -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() {
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions test/java/org/openjdk/jextract/test/toolprovider/helloargs
@@ -0,0 +1 @@
-t com.acme