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

7903666: Jextract should report issues with missing dependencies #214

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -119,6 +119,30 @@ jextract -t org.jextract @includes.txt point.h

It is easy to see how this mechanism allows developers to look into the set of symbols seen by `jextract` while parsing, and then process the generated include file, so as to prevent code generation for otherwise unused symbols.

Users should exercise caution when filtering symbols, as it is relatively easy to filter out a declaration that is depended on by one or more declarations:

```c
// test.h
struct A {
int x;
}
struct A aVar;
```

Here, we could run `jextract` and filter out `A`, like so:

```
jextract --include-var aVar test.h
```

However, doing so would lead to broken generated code, as the layout of the global variable `aVar` depends on the layout of the excluded struct `A`.

In such cases, `jextract` will report the missing dependency and terminate without generating any bindings:

```
ERROR: aVar depends on A which has been excluded
```

#### Tracing support

It is sometimes useful to inspect the parameters passed to a native call, especially when diagnosing application
22 changes: 11 additions & 11 deletions src/main/java/org/openjdk/jextract/JextractTool.java
Original file line number Diff line number Diff line change
@@ -46,15 +46,12 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -71,11 +68,12 @@ public final class JextractTool {

// error codes
private static final int SUCCESS = 0;
private static final int OPTION_ERROR = 1;
private static final int INPUT_ERROR = 2;
private static final int CLANG_ERROR = 3;
private static final int RUNTIME_ERROR = 4;
private static final int OUTPUT_ERROR = 5;
private static final int FAILURE = 1;
private static final int OPTION_ERROR = 2;
private static final int INPUT_ERROR = 3;
private static final int CLANG_ERROR = 4;
private static final int FATAL_ERROR = 5;
private static final int OUTPUT_ERROR = 6;

private final Logger logger;

@@ -502,7 +500,7 @@ private int run(String[] args) {
return CLANG_ERROR;
} catch (RuntimeException re) {
logger.fatal(re);
return RUNTIME_ERROR;
return FATAL_ERROR;
}

try {
@@ -519,10 +517,12 @@ private int run(String[] args) {
}
} catch (RuntimeException re) {
logger.fatal(re);
return RUNTIME_ERROR;
return FATAL_ERROR;
}

return SUCCESS;
return logger.hasErrors() ?
FAILURE :
SUCCESS;
}

/**
11 changes: 6 additions & 5 deletions test/lib/testlib/JextractToolRunner.java
Original file line number Diff line number Diff line change
@@ -67,11 +67,12 @@ public class JextractToolRunner {

// (private) exit codes from jextract tool. Copied from JextractTool.
protected static final int SUCCESS = 0;
protected static final int OPTION_ERROR = 1;
protected static final int INPUT_ERROR = 2;
protected static final int CLANG_ERROR = 3;
protected static final int RUNTIME_ERROR = 4;
protected static final int OUTPUT_ERROR = 5;
protected static final int FAILURE = 1;
protected static final int OPTION_ERROR = 2;
protected static final int INPUT_ERROR = 3;
protected static final int CLANG_ERROR = 4;
protected static final int RUNTIME_ERROR = 5;
protected static final int OUTPUT_ERROR = 6;

private static String safeFileName(String filename) {
int ext = filename.lastIndexOf('.');
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ public void before() {
"--include-struct", "C",
"--include-function", "n",
outputH.toString());
result.checkFailure(FAILURE);
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe result.checkFailure() here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops - yes!


@Test(dataProvider = "cases")