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

rPackages.rJava: set JAVA_HOME, fixes darwin #355931

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

b-rodrigues
Copy link
Contributor

@b-rodrigues b-rodrigues commented Nov 14, 2024

Sets JAVA_HOME as it was empty. This was not an issue on linux, but caused rPackages.rJava not to load on Darwin.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@b-rodrigues
Copy link
Contributor Author

@ofborg build rPackages.rJava

@Kupac
Copy link
Contributor

Kupac commented Nov 14, 2024

Other than that, it works on x86_64-linux.

It's a bit weird that it doesn't work on darwin despite the explicit export JAVA_HOME. Is that the traditional way to set enc vars on darwin? do the other packages that manupulate JAVA_HOME work on darwin?

[ins] r$> library(rJava)

[ins] r$> example(.jcompare)

.jcmprr$> ## Don't show: 
.jcmprr$> .jinit()

.jcmprr$> ## End(Don't show)
.jcmprr$> s <- .jnew("java/lang/String", "foo")

.jcmprr$> .jequals(s, "foo") # TRUE
[1] TRUE

.jcmprr$> .jequals(s, "foo", strict=TRUE) # FALSE - "foo" is not a Java object
[1] FALSE

.jcmprr$> t <- s

.jcmprr$> .jequals(s, t, strict=TRUE) # TRUE
[1] TRUE

.jcmprr$> s=="foo" # TRUE
[1] TRUE

.jcmprr$> ## Don't show: 
.jcmprr$>  
.jcmprr$> 	stopifnot( 
.jcmpr+ 		.jequals(s, "foo"), 
.jcmpr+ 		!.jequals(s, "foo", strict=TRUE), 
.jcmpr+ 		.jequals(s, t, strict=TRUE), 
.jcmpr+ 		s == "foo"
.jcmpr+ 	)

.jcmprr$> ## End(Don't show)
.jcmprr$> 
.jcmprr$> Double <- J("java.lang.Double")

.jcmprr$> d1 <- new( Double, 0.0 ) 

.jcmprr$> d2 <- new( Double, 1.0 )

.jcmprr$> d3 <- new( Double, 0.0 )

.jcmprr$> d1 < d2
[1] TRUE

.jcmprr$> d1 <= d3
[1] TRUE

.jcmprr$> d1 >= d3
[1] TRUE

.jcmprr$> d1 > d2
[1] FALSE

.jcmprr$> # cannot compare a Double and a String
.jcmprr$> try( d1 < "foo" )
Error in .jcall("RJavaComparator", "I", "compare", .jcast(a), .jcast(b)) : 
  NotComparableException: objects of class java.lang.Double and java.lang.String are not comparable

.jcmprr$> # but can compare a Double and an Integer
.jcmprr$> d1 < 10L
[1] TRUE

.jcmprr$> ## Don't show: 
.jcmprr$> 	stopifnot( 
.jcmpr+ 		d1 < d2       ,
.jcmpr+ 		d1 <= d3      ,
.jcmpr+ 		d1 >= d3      ,
.jcmpr+ 		! (d1 > d2 )  , 
.jcmpr+ 		inherits( try( d1 < "foo", silent = TRUE ), "try-error" ), 
.jcmpr+ 		d1 < 10L )

.jcmprr$> ## End(Don't show)
.jcmprr$> 
.jcmprr$> 
.jcmprr$> 
.jcmprr$> 
.jcmprr$> 

[ins] r$> Sys.getenv("JAVA_HOME")
[1] "/nix/store/3vhlpdyqkrwk9arf84iaxk935r71rxvx-openjdk-21.0.5+11"

@TomaSajt
Copy link
Contributor

TomaSajt commented Nov 14, 2024

I'm surprised it even worked with the env-var only being set at build time.
(I haven't looked at the code, maybe its expected to work like that)

@ofborg ofborg bot added 6.topic: darwin Running or building packages on Darwin 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Nov 15, 2024
@jbedo jbedo merged commit 5083ec8 into NixOS:master Nov 18, 2024
26 checks passed
Copy link
Contributor

@Kupac Kupac left a comment

Choose a reason for hiding this comment

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

Sorry, forgot to click submit review... Anyway it's merged now and after all, it's working.

Comment on lines +1289 to +1292
substituteInPlace R/zzz.R.in \
--replace-fail ".onLoad <- function(libname, pkgname) {" \
".onLoad <- function(libname, pkgname) {
Sys.setenv(\"JAVA_HOME\" = Sys.getenv(\"JAVA_HOME\", unset = \"${pkgs.jdk}\"))"
Copy link
Contributor

Choose a reason for hiding this comment

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

This belongs to postPatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin 6.topic: R 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants