1414use std:: env;
1515use std:: path:: PathBuf ;
1616
17+ #[ cfg( feature = "bundled" ) ]
18+ use std:: path:: Path ;
19+ #[ cfg( feature = "bundled" ) ]
20+ use std:: { fs, io} ;
21+
1722#[ cfg( feature = "bundled" ) ]
1823fn vsomeip_includes ( ) -> PathBuf {
1924 let crate_root =
@@ -100,35 +105,54 @@ mod build {
100105 use std:: path:: { Path , PathBuf } ;
101106 use std:: process:: Command ;
102107
108+ use crate :: copy_dir_all;
109+
103110 pub fn build ( ) {
104111 let submodule_folder = "vsomeip" ;
105112
106113 let crate_root = env:: var ( "CARGO_MANIFEST_DIR" )
107114 . expect ( "CARGO_MANIFEST_DIR environment variable is not set" ) ;
108115
109116 let patch_folder = PathBuf :: from ( & crate_root) . join ( "patches" ) ;
117+ println ! ( "debug: patch_folder: {}" , patch_folder. display( ) ) ;
110118
111119 let submodule_git = PathBuf :: from ( & crate_root) . join ( format ! ( "{}/.git" , submodule_folder) ) ;
112120 println ! ( "debug: submodule_git: {:?}" , submodule_git) ;
113121
114122 // Make sure that the Git submodule is checked out
115123 if !Path :: new ( & submodule_git) . exists ( ) {
116- let _ = Command :: new ( "git" )
124+ let submodule_checkout = Command :: new ( "git" )
117125 . arg ( "-C" )
118126 . arg ( submodule_folder)
119127 . arg ( "submodule" )
120128 . arg ( "update" )
121129 . arg ( "--init" )
122130 . status ( ) ;
131+
132+ println ! ( "debug: submodule_checkout: {:?}" , submodule_checkout) ;
123133 }
124134
125- println ! ( "debug: trying to apply patch" ) ;
135+ let out_dir = env:: var_os ( "OUT_DIR" ) . unwrap ( ) ;
136+ let submodule_to_patch = PathBuf :: from ( & crate_root) . join ( submodule_folder) ;
137+ let vsomeip_build_dir = PathBuf :: from ( out_dir) . join ( "vsomeip" ) . join ( "vsomeip_build" ) ;
138+ let copy_res = copy_dir_all ( & submodule_to_patch, & vsomeip_build_dir) ;
139+ println ! (
140+ "debug: copying vsomeip to output directory to build: {:?}" ,
141+ copy_res
142+ ) ;
143+
144+ println ! (
145+ "debug: trying to apply patch to: {}" ,
146+ vsomeip_build_dir. display( )
147+ ) ;
126148 let disable_test_patch = patch_folder. join ( "disable_tests.patch" ) ;
127149 let disable_test_patch_str = format ! ( "{}" , disable_test_patch. display( ) ) ;
128- let output = Command :: new ( "git" )
129- . arg ( "-C" )
130- . arg ( submodule_folder)
131- . arg ( "apply" )
150+ println ! ( "disable_test_patch_str: {}" , disable_test_patch_str) ;
151+ let output = Command :: new ( "patch" )
152+ . arg ( "-d" )
153+ . arg ( & vsomeip_build_dir)
154+ . arg ( "-p1" )
155+ . arg ( "-i" )
132156 . arg ( disable_test_patch_str)
133157 . output ( )
134158 . expect ( "Failed to apply patch" ) ;
@@ -145,15 +169,14 @@ mod build {
145169 let vsomeip_install_path =
146170 env:: var ( "VSOMEIP_INSTALL_PATH" ) . unwrap_or ( vsomeip_install_path_default) ;
147171
148- let vsomeip_project_root = PathBuf :: from ( & crate_root) . join ( "vsomeip" ) ;
149172 println ! ( "debug: vsomeip_project_root set" ) ;
150173 println ! (
151174 "debug: vsomeip_project_root: {}" ,
152- vsomeip_project_root . display( )
175+ vsomeip_build_dir . display( )
153176 ) ;
154177 println ! ( "debug: vsomeip_install_path: {}" , vsomeip_install_path) ;
155178
156- let vsomeip_cmake_build = Config :: new ( vsomeip_project_root )
179+ let vsomeip_cmake_build = Config :: new ( vsomeip_build_dir )
157180 . define ( "CMAKE_INSTALL_PREFIX" , vsomeip_install_path. clone ( ) )
158181 . define ( "ENABLE_SIGNAL_HANDLING" , "1" )
159182 . build_target ( "install" )
@@ -163,40 +186,6 @@ mod build {
163186 "debug: vsomeip_cmake_build: {}" ,
164187 vsomeip_cmake_build. display( )
165188 ) ;
166-
167- // Remove the changes made
168- let stash_output = Command :: new ( "git" )
169- . arg ( "-C" )
170- . arg ( submodule_folder)
171- . arg ( "stash" )
172- . output ( )
173- . expect ( "Failed to stash changes" ) ;
174- println ! ( "debug: stash output: {:?}" , stash_output) ;
175-
176- if !stash_output. status . success ( ) {
177- panic ! (
178- "Failed to stash changes: {}" ,
179- String :: from_utf8_lossy( & stash_output. stderr)
180- ) ;
181- }
182-
183- // Remove the stash entry
184- let stash_output = Command :: new ( "git" )
185- . arg ( "-C" )
186- . arg ( submodule_folder)
187- . arg ( "stash" )
188- . arg ( "drop" )
189- . arg ( "stash@{0}" )
190- . output ( )
191- . expect ( "Failed to stash changes" ) ;
192- println ! ( "debug: stash output: {:?}" , stash_output) ;
193-
194- if !stash_output. status . success ( ) {
195- panic ! (
196- "Failed to stash changes: {}" ,
197- String :: from_utf8_lossy( & stash_output. stderr)
198- ) ;
199- }
200189 }
201190}
202191mod bindings {
@@ -347,3 +336,18 @@ mod bindings {
347336 fixed_line
348337 }
349338}
339+
340+ #[ cfg( feature = "bundled" ) ]
341+ fn copy_dir_all ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
342+ fs:: create_dir_all ( & dst) ?;
343+ for entry in fs:: read_dir ( src) ? {
344+ let entry = entry?;
345+ let ty = entry. file_type ( ) ?;
346+ if ty. is_dir ( ) {
347+ copy_dir_all ( entry. path ( ) , dst. as_ref ( ) . join ( entry. file_name ( ) ) ) ?;
348+ } else {
349+ fs:: copy ( entry. path ( ) , dst. as_ref ( ) . join ( entry. file_name ( ) ) ) ?;
350+ }
351+ }
352+ Ok ( ( ) )
353+ }
0 commit comments