-
Notifications
You must be signed in to change notification settings - Fork 27
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
Fix names of overloaded methods with ref type parameters #139
Conversation
hello @berkeleybarry thanks for a contirbution and a fix! Btw, what's the purpose of those tasty files in the resources directory? |
I added the dependencies to the build.sbt so I can unit test my changes. In what undesirable way does this change the project structure? Is there some other test framework you want me to use? I haven't been part of this project so I find it entirely believable that I am violating some convention that I do not know about. I used the tasty files for generating headers with a jdk 1.8 javah. I did this so I could see what the correct C function names were. I included the tasty files, and the associated scala source so you can see an example where javah and the plugin did not match. Things will work without these resources. It might be worth adding an example with overloads and reference type parameters to the test subprojects so you can confirm that a C function with the generated name is actually called when the native method is invoked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for a great contribution; the change looks good to me!
But I left a couple of comments to bring this project into the mergable shape; a short summary of the leftovers:
- sbt-test project that demonstrates a proper work with the overloaded method, aka integration test
resources
folder cleanup- for tests we only need
classes/com/github/sbt/jni/samples/Overloads.class
classes/com/github/sbt/jni/samples/Overloads.class
is missing
- tasty files removal / move them into the sbt-test project subfolder with a corresponding README
- we don't need C / Java proxy files in the resources folder - they are not used
- for tests we only need
- build.sbt files cleanup (we need the extra salatest dep only)
- formatting (run scalafmt)
- make CI happy
@@ -42,6 +42,7 @@ object CMake extends BuildTool with ConfigureMakeInstall { | |||
s"-DCMAKE_INSTALL_PREFIX:PATH=${target.getAbsolutePath}", | |||
"-DCMAKE_BUILD_TYPE=Release", | |||
"-DSBT:BOOLEAN=true", | |||
s"-DJAVA_HOME=${scala.sys.props.get("java.home").get}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens in case java.home
for some unpredictable reason is empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know the answer to that question. I know it did not work on my laptop without providing a java home. The CMake find JNI functionality was lost without it. I think the real solution is to allow this plugin to be configurable to run as is (no JAVA_HOME set), as I modified it, or with a user-specified JAVA_HOME. That should be another PR. I just did enough to get things to work on my laptop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment was that doing .get
is unsafe. We can append it to the list of params in case it's present, why not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is modified in the update. Is there a way to make it cleaner?
class Overloads { | ||
@native | ||
def doSomething(param: A): B | ||
@native | ||
def doSomething(param: B): A | ||
@native | ||
def doSomething(param: Array[C]): A | ||
@native | ||
def doSomething(parma0: Int, param1: Array[C], param2:B, param3: Double): A | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a full test, similar to others for this proxy along with its JNI component into a separate project into the sbt-test/sbt-jni directory for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next update
plugin/src/test/scala/com/github/sbt/jni/javah/NativeMethodTests.scala
Outdated
Show resolved
Hide resolved
plugin/src/test/scala/com/github/sbt/jni/javah/NativeMethodTests.scala
Outdated
Show resolved
Hide resolved
plugin/src/test/scala/com/github/sbt/jni/javah/NativeMethodTests.scala
Outdated
Show resolved
Hide resolved
@@ -0,0 +1 @@ | |||
This directory contains a header file foe the Overloads class that was generated by the javah application of a Java 8 SDK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this does not belong to the resources folder as well as all the related tasty files. But we cat still keep tasty files in a separate folder i.e. in the plugin sbt-test directory in a new directory with a full sample-overloaded
project; similar to what we already have.
And we'd need a README to those tasty files and how to deal with them / why we need them.
return builder.toString(); | ||
} | ||
|
||
public static String mangleArguments(String arguments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to take a closer look and will appreciate some READMEs about the apporach taken with these tasty files, that's quite interesting.
I also checked that this function is backwards compatible on the https://github.com/Glavo/gjavah project tests.
But we still need to ensure sbt-tests of this project are running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on what you are getting at with your mention of READMEs. Did that line belong to the previous comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that if we want to keep these tasty files in the repository we need a direct description of what they are, how to use them to debug, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this stuff is gone. You can just compile the source in the test code to see it now.
It is not clear to me how much you want me to do here. Who are you expecting me to do the cleanup? |
Hey, I think I am as clear as it's possible; all comments should be resolved before this PR can be merged. About formatting: this project uses scalafmt; The CI should also be green. |
This is an open source project, and I am not getting paid to do contributors PR reviews as well. I am happy to help you finishing PR though. |
This is what I wanted to know.
… On Feb 22, 2023, at 1:13 PM, Grigory ***@***.***> wrote:
Who are you expecting me to do the cleanup?
This is an open source project, and I am not getting paid to do contributors PR reviews as well. I am happy to help you finishing PR though.
—
Reply to this email directly, view it on GitHub <#139 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACAEEQ4RAGVOJAIKI3M5SWDWYZ6PLANCNFSM6AAAAAAU22XM3U>.
You are receiving this because you were mentioned.
|
b04908a
to
781aca4
Compare
override def configure(target: File) = cmakeProcess( | ||
// disable producing versioned library files, not needed for fat jars | ||
val args = Seq(s"-DCMAKE_INSTALL_PREFIX:PATH=${target.getAbsolutePath}", "-DCMAKE_BUILD_TYPE=Release", "-DSBT:BOOLEAN=true") ++ scala.sys.props | ||
.get("java.home") | ||
.toSeq | ||
.map(jh => s"-DJAVA_HOME=${jh}") ++ Seq(cmakeVersion.toString, baseDirectory.getAbsolutePath) | ||
cmakeProcess(args: _*) | ||
} | ||
s"-DCMAKE_INSTALL_PREFIX:PATH=${target.getAbsolutePath}", | ||
"-DCMAKE_BUILD_TYPE=Release", | ||
"-DSBT:BOOLEAN=true", | ||
cmakeVersion.toString, | ||
baseDirectory.getAbsolutePath | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@berkeleybarry sadly I had to rollback this change. It looks like this or should be made somehow configurable for the client in a separate PR or smth else 🤔
CI definitely doesn't work with the change.
I searched for a bit, and it looks like it is not a regular practice.
May be setting an env variable may work for you?
781aca4
to
c619828
Compare
c619828
to
00605c1
Compare
What do you want to do about things running on macOS in the tests but not on my laptop (A several week old mac, probably a different cmake version, probably different jdk versions)? This is why I thought it might be wise to make -DJAVA_HOME a configuration option. You can always force it to a value that works. I can’t see enough to suggest another solution that works for all the different environments because I have limited information about the CI builds.
Before I started messing with code I tried exporting JAVA_HOME. That did not seem to work. That may depend on how you launch sbt.
I was going to write this test when the CI stuff was working for me. I suggest you pass an array of String and make sure that works.
What do you want to do about the ASM version?
… On Feb 22, 2023, at 7:53 PM, Grigory ***@***.***> wrote:
@pomadchin commented on this pull request.
In plugin/src/main/scala/com/github/sbt/jni/build/CMake.scala <#139 (comment)>:
> + override def configure(target: File) = cmakeProcess(
// disable producing versioned library files, not needed for fat jars
- val args = Seq(s"-DCMAKE_INSTALL_PREFIX:PATH=${target.getAbsolutePath}", "-DCMAKE_BUILD_TYPE=Release", "-DSBT:BOOLEAN=true") ++ scala.sys.props
- .get("java.home")
- .toSeq
- .map(jh => s"-DJAVA_HOME=${jh}") ++ Seq(cmakeVersion.toString, baseDirectory.getAbsolutePath)
- cmakeProcess(args: _*)
- }
+ s"-DCMAKE_INSTALL_PREFIX:PATH=${target.getAbsolutePath}",
+ "-DCMAKE_BUILD_TYPE=Release",
+ "-DSBT:BOOLEAN=true",
+ cmakeVersion.toString,
+ baseDirectory.getAbsolutePath
+ )
@berkeleybarry <https://github.com/berkeleybarry> sadly I had to rollback this change. It looks like this or should be made somehow configurable for the client in a separate PR or smth else 🤔
CI definitely doesn't work with the change.
I searched for a bit, and it looks like it is not a regular practice.
May be setting an env variable may work for you?
—
Reply to this email directly, view it on GitHub <#139 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACAEEQ77J6QCUEMKN4GC5VTWY3NMPANCNFSM6AAAAAAU22XM3U>.
You are receiving this because you were mentioned.
|
@berkeleybarry if you could provide more about the underlying system you have it will be much easier to debug it. I run tests on the m1 mac, with azul jdk 1.8 installed via sdkman. The only reason I had to rollback it is that I'll pass the array of strings as well, but I was definitely able to reproduce the incorrect methods generation even with the current overrides project contents. It is a really nice catch and fix, thanks! |
I don't feel bad about the java.home thing not working everywhere. I did it to solve my problem. Initially, I didn't consider it as a general solution. Once you suggested trying it as a general solution, I thought it was worth a try. The ASM thing scares me in a similar way. At least that seems to be working where it has been tested. Adding an additional build tool arguments parameter, Seq[String], seems like an easy and flexible way to solve my problem. |
For sbt, I'm running the bt shell inside IntelliJ or launching the same sbt from the command line. This is an example of how intellij launches sbt. /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/bin/java -server -Xmx1536M -Dsbt.supershell=false -Didea.managed=true -Dfile.encoding=UTF-8 "-Didea.installation.dir=/Applications/IntelliJ IDEA.app/Contents" -jar "/Users/username/Library/Application Support/JetBrains/IntelliJIdea2021.3/plugins/Scala/launcher/sbt-launch.jar" early(addPluginSbtFile="""/private/var/folders/hh/q4qgfsw13_30pqv_tsbd9m_c0000gn/T/idea.sbt""") "; set ideaPort in Global := 49201 ; idea-shell" I can get rid of a lot of the idea related arguments to run it directly on the command line This is IntelliJ IDEA 2021.3.3 (Ultimate Edition) |
I'm trying to figure out why the CI tests are failing. The simple project dies on my laptop becuse there is no CMake.txt. The plugin does not know what buildtool to use. On the CI runs the simple project on dies on Ubuntu with the error below: This looks like the JAVA_HOME is pointing to the wrong place. I can believe the change I made that makes projects with a CMake.txt file work on my laptop causes problems on the Ubuntu build machine. I have no visbility into what is hapening on ubuntu so it is kind of difficult to find something that works on both. |
Last comment i garbage. It was unsent draft and I hit some wrong buttons |
@berkeleybarry I think indeed |
200e849
to
ff4987f
Compare
JNIEXPORT jint JNICALL Java_simple_Library_00024_say___3Ljava_lang_String_2 | ||
(JNIEnv *env, jobject clazz, jobjectArray messages) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@berkeleybarry the array overload!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for a very nice fix! 🎉
Do you want to incorporate anything else into this PR?
I'm happy to merge it as is and cut a release, and anything else we can do in the follow up PRs.
I'll merge it tomorrow, so you have some time to review changes / add if anything needed.
ff4987f
to
7038a1a
Compare
84f8261
to
60eba62
Compare
I'm ok with merging it. |
This pull request is mostly a fix for incorrectly mangling class names used in identifying overloaded methods.
In order to make things run on my Mac, I did a couple of other things. I changed the ASM version for BytecodeUtil. I also set JAVA_HOME for cmake.