4
4
// License, v. 2.0. If a copy of the MPL was not distributed with this
5
5
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
7
- use std:: path :: { Path , PathBuf } ;
7
+ use std:: env ;
8
8
use std:: error:: Error ;
9
9
use std:: fs;
10
+ use std:: path:: { Path , PathBuf } ;
11
+ use std:: process:: Command ;
10
12
11
13
use rustwide:: {
12
14
cmd,
@@ -44,6 +46,7 @@ struct CargoPrusti {
44
46
prusti_home : PathBuf ,
45
47
viper_home : PathBuf ,
46
48
z3_exe : PathBuf ,
49
+ java_home : Option < PathBuf > ,
47
50
}
48
51
49
52
impl cmd:: Runnable for CargoPrusti {
@@ -52,9 +55,12 @@ impl cmd::Runnable for CargoPrusti {
52
55
}
53
56
54
57
fn prepare_command < ' w , ' pl > ( & self , cmd : cmd:: Command < ' w , ' pl > ) -> cmd:: Command < ' w , ' pl > {
58
+ let java_home = self . java_home . as_ref ( )
59
+ . map ( |p| p. to_str ( ) . unwrap ( ) )
60
+ . unwrap_or ( "/usr/lib/jvm/default-java" ) ;
55
61
cmd. env ( "VIPER_HOME" , self . viper_home . to_str ( ) . unwrap ( ) )
56
62
. env ( "Z3_EXE" , self . z3_exe . join ( "z3" ) . to_str ( ) . unwrap ( ) )
57
- . env ( "JAVA_HOME" , "/usr/lib/jvm/java-8-openjdk-amd64" )
63
+ . env ( "JAVA_HOME" , java_home )
58
64
. env ( "CARGO_PATH" , "/opt/rustwide/cargo-home/bin/cargo" )
59
65
}
60
66
}
@@ -77,6 +83,27 @@ fn get_rust_toolchain() -> RustToolchain {
77
83
rust_toolchain. toolchain
78
84
}
79
85
86
+ /// Find the Java home directory
87
+ pub fn find_java_home ( ) -> Option < PathBuf > {
88
+ Command :: new ( "java" )
89
+ . arg ( "-XshowSettings:properties" )
90
+ . arg ( "-version" )
91
+ . output ( )
92
+ . ok ( )
93
+ . and_then ( |output| {
94
+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
95
+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
96
+ for line in stdout. lines ( ) . chain ( stderr. lines ( ) ) {
97
+ if line. contains ( "java.home" ) {
98
+ let pos = line. find ( '=' ) . unwrap ( ) + 1 ;
99
+ let path = line[ pos..] . trim ( ) ;
100
+ return Some ( PathBuf :: from ( path) ) ;
101
+ }
102
+ }
103
+ None
104
+ } )
105
+ }
106
+
80
107
fn main ( ) -> Result < ( ) , Box < dyn Error > > {
81
108
color_backtrace:: install ( ) ;
82
109
setup_logs ( ) ;
@@ -85,14 +112,20 @@ fn main() -> Result<(), Box<dyn Error>> {
85
112
let host_prusti_home = Path :: new ( "target/release" ) ;
86
113
let host_viper_home = Path :: new ( "viper_tools/backends" ) ;
87
114
let host_z3_home = Path :: new ( "viper_tools/z3/bin" ) ;
115
+ let host_java_home = env:: var ( "JAVA_HOME" ) . ok ( ) . map ( |s| s. into ( ) )
116
+ . or_else ( || find_java_home ( ) )
117
+ . expect ( "Please set JAVA_HOME" ) ;
88
118
let guest_prusti_home = Path :: new ( "/opt/rustwide/prusti-home" ) ;
89
119
let guest_viper_home = Path :: new ( "/opt/rustwide/viper-home" ) ;
90
120
let guest_z3_home = Path :: new ( "/opt/rustwide/z3-home" ) ;
121
+ let guest_java_home = Path :: new ( "/opt/rustwide/java-home" ) ;
91
122
123
+ info ! ( "Using host's Java home {:?}" , host_java_home) ;
92
124
let cargo_prusti = CargoPrusti {
93
125
prusti_home : guest_prusti_home. to_path_buf ( ) ,
94
126
viper_home : guest_viper_home. to_path_buf ( ) ,
95
127
z3_exe : guest_z3_home. to_path_buf ( ) ,
128
+ java_home : Some ( guest_java_home. to_path_buf ( ) ) ,
96
129
} ;
97
130
98
131
info ! ( "Crate a new workspace..." ) ;
@@ -177,7 +210,8 @@ fn main() -> Result<(), Box<dyn Error>> {
177
210
. enable_networking ( false )
178
211
. mount ( & host_prusti_home, & guest_prusti_home, cmd:: MountKind :: ReadOnly )
179
212
. mount ( & host_viper_home, & guest_viper_home, cmd:: MountKind :: ReadOnly )
180
- . mount ( & host_z3_home, & guest_z3_home, cmd:: MountKind :: ReadOnly ) ;
213
+ . mount ( & host_z3_home, & guest_z3_home, cmd:: MountKind :: ReadOnly )
214
+ . mount ( & host_java_home, & guest_java_home, cmd:: MountKind :: ReadOnly ) ;
181
215
182
216
let mut storage = LogStorage :: new ( LevelFilter :: Info ) ;
183
217
storage. set_max_size ( 1024 * 1024 ) ;
0 commit comments