@@ -31,25 +31,24 @@ fn main() -> Result<(), J4rsBuildError> {
31
31
let source_jar_location = PathBuf :: from ( format ! (
32
32
"../java/target/j4rs-{VERSION}-jar-with-dependencies.jar"
33
33
) ) ;
34
- if Path :: new ( & source_jar_location) . exists ( ) {
34
+ if source_jar_location. exists ( ) {
35
35
println ! (
36
36
"cargo:rerun-if-changed={}" ,
37
37
source_jar_location. to_string_lossy( )
38
38
) ;
39
39
}
40
+ generate_src ( & out_dir) ?;
40
41
41
- let target_os_res = env:: var ( "CARGO_CFG_TARGET_OS" ) ;
42
- let target_os = target_os_res. as_ref ( ) . map ( |x| & * * x) . unwrap_or ( "unknown" ) ;
43
- if target_os == "android" {
44
- generate_src ( & out_dir) ?;
42
+ if env:: var ( "CARGO_CFG_TARGET_OS" ) . as_deref ( ) == Ok ( "android" ) {
43
+ // skip the rest of setup on android
45
44
return Ok ( ( ) ) ;
46
45
}
47
46
48
47
// Copy the needed jar files if they are available
49
48
// (that is, if the build is done with the full source-code - not in crates.io)
50
49
copy_jars_from_java ( & source_jar_location) ?;
51
- copy_jars_to_exec_directory ( & out_dir ) ? ;
52
- generate_src ( & out_dir) ?;
50
+
51
+ copy_jars_to_target_directory ( & out_dir) ?;
53
52
54
53
Ok ( ( ) )
55
54
}
@@ -75,9 +74,7 @@ pub(crate) fn java_fx_version() -> &'static str {{
75
74
fn copy_jars_from_java ( jar_source_path : & Path ) -> Result < ( ) , J4rsBuildError > {
76
75
if jar_source_path. exists ( ) {
77
76
// Find the destination file
78
- let home = env:: var ( "CARGO_MANIFEST_DIR" ) ?;
79
- let jassets_path_buf = Path :: new ( & home) . join ( "jassets" ) ;
80
- let jassets_path = jassets_path_buf. to_str ( ) . unwrap ( ) . to_owned ( ) ;
77
+ let jassets_path = Path :: new ( & env:: var ( "CARGO_MANIFEST_DIR" ) ?) . join ( "jassets" ) ;
81
78
82
79
let destination_jar_file =
83
80
Path :: new ( & jassets_path) . join ( format ! ( "j4rs-{VERSION}-jar-with-dependencies.jar" ) ) ;
@@ -92,8 +89,9 @@ fn copy_jars_from_java(jar_source_path: &Path) -> Result<(), J4rsBuildError> {
92
89
if do_copy {
93
90
fs_extra:: remove_items ( & [ & jassets_path] ) ?;
94
91
95
- let _ = fs:: create_dir_all ( & jassets_path_buf)
96
- . map_err ( |error| panic ! ( "Cannot create dir '{jassets_path_buf:?}': {error:?}" ) ) ;
92
+ fs:: create_dir_all ( & jassets_path)
93
+ . map_err ( |error| panic ! ( "Cannot create dir '{jassets_path:?}': {error:?}" ) )
94
+ . ok ( ) ;
97
95
98
96
fs_extra:: copy_items ( & [ jar_source_path] , jassets_path, & CopyOptions :: new ( ) ) ?;
99
97
}
@@ -105,22 +103,17 @@ fn are_same_files(path1: &Path, path2: &Path) -> Result<bool, J4rsBuildError> {
105
103
Ok ( std:: fs:: read ( path1) ? == std:: fs:: read ( path2) ?)
106
104
}
107
105
108
- // Copies the jars to the exec directory.
109
- fn copy_jars_to_exec_directory ( out_dir : & str ) -> Result < ( ) , J4rsBuildError > {
110
- let mut exec_dir_path_buf = PathBuf :: from ( out_dir) ;
111
- exec_dir_path_buf. pop ( ) ;
112
- exec_dir_path_buf. pop ( ) ;
113
- exec_dir_path_buf. pop ( ) ;
114
-
115
- let jassets_output_dir = exec_dir_path_buf. to_str ( ) . unwrap ( ) ;
106
+ // Copies the jars to CARGO_TARGET_DIR/*/jassets
107
+ fn copy_jars_to_target_directory ( out_dir : & str ) -> Result < ( ) , J4rsBuildError > {
108
+ let mut target_dir = PathBuf :: from ( out_dir) ;
109
+ target_dir. pop ( ) ;
110
+ target_dir. pop ( ) ;
111
+ target_dir. pop ( ) ;
116
112
117
- let home = env:: var ( "CARGO_MANIFEST_DIR" ) ?;
118
- let jassets_path_buf = Path :: new ( & home) . join ( "jassets" ) ;
119
- let jassets_path = jassets_path_buf. to_str ( ) . unwrap ( ) . to_owned ( ) ;
113
+ let jassets_path = Path :: new ( & env:: var ( "CARGO_MANIFEST_DIR" ) ?) . join ( "jassets" ) ;
114
+ let jassets_jar_file = jassets_path. join ( format ! ( "j4rs-{VERSION}-jar-with-dependencies.jar" ) ) ;
120
115
121
- let jassets_jar_file =
122
- Path :: new ( & jassets_path) . join ( format ! ( "j4rs-{VERSION}-jar-with-dependencies.jar" ) ) ;
123
- let jassets_output_file = Path :: new ( & jassets_output_dir)
116
+ let jassets_output_file = target_dir
124
117
. join ( "jassets" )
125
118
. join ( format ! ( "j4rs-{VERSION}-jar-with-dependencies.jar" ) ) ;
126
119
@@ -132,8 +125,8 @@ fn copy_jars_to_exec_directory(out_dir: &str) -> Result<(), J4rsBuildError> {
132
125
} ;
133
126
134
127
if do_copy {
135
- fs_extra:: remove_items ( & [ format ! ( "{jassets_output_dir}/ jassets") ] ) ?;
136
- fs_extra:: copy_items ( & [ jassets_path] , jassets_output_dir , & CopyOptions :: new ( ) ) ?;
128
+ fs_extra:: remove_items ( & [ target_dir . join ( " jassets") ] ) ?;
129
+ fs_extra:: copy_items ( & [ jassets_path] , target_dir , & CopyOptions :: new ( ) ) ?;
137
130
}
138
131
139
132
Ok ( ( ) )
0 commit comments