@@ -117,20 +117,32 @@ fn download_sdl2() -> PathBuf {
117
117
// apply patches to sdl2 source
118
118
#[ cfg( feature = "bundled" ) ]
119
119
fn patch_sdl2 ( sdl2_source_path : & Path ) {
120
+ // vector of <(patch_file_name, patch_file_contents)>
120
121
let patches: Vec < ( & str , & ' static str ) > = vec ! [
121
- ( "SDL2-2.0.8-4234-mac-os-dylib-fix.patch" ,
122
- include_str!( "patches/SDL2-2.0.8-4234-mac-os-dylib-fix.patch" ) ) ,
122
+ // This patch fixes a CMake installation bug introduced in SDL2 2.0.4 on
123
+ // the Mac OS platform. Without this patch, the libSDL2.dylib generated
124
+ // during the SDL2 build phase will be overwritten by a symlink pointing
125
+ // to nothing. A variation of this patch was accepted upstream and
126
+ // should be included in SDL2 2.0.9.
127
+ // https://bugzilla.libsdl.org/show_bug.cgi?id=4234
128
+ ( "SDL2-2.0.8-4234-mac-os-dylib-fix.patch" , include_str!( "patches/SDL2-2.0.8-4234-mac-os-dylib-fix.patch" ) ) ,
123
129
] ;
124
130
let sdl_version = format ! ( "SDL2-{}" , LASTEST_SDL2_VERSION ) ;
125
131
126
132
for patch in & patches {
127
- // Only apply patches that apply to the current version of SDL2
133
+ // Only apply patches whose file name is prefixed with the currently
134
+ // targeted version of SDL2.
128
135
if !patch. 0 . starts_with ( & sdl_version) {
129
136
continue ;
130
137
}
131
138
let mut patch_set = unidiff:: PatchSet :: new ( ) ;
132
139
patch_set. parse ( patch. 1 ) . expect ( "Error parsing diff" ) ;
133
140
141
+ // For every modified file, copy the existing file to <file_name>_old,
142
+ // open a new copy of <file_name>. and fill the new file with a
143
+ // combination of the unmodified contents, and the patched sections.
144
+ // TOOD: This code is untested (save for the immediate application), and
145
+ // probably belongs in the unidiff (or similar) package.
134
146
for modified_file in patch_set. modified_files ( ) {
135
147
use std:: io:: { Write , BufRead } ;
136
148
@@ -183,6 +195,7 @@ fn patch_sdl2(sdl2_source_path: &Path) {
183
195
dst_buf. write_all ( b"\n " ) . unwrap ( ) ;
184
196
}
185
197
}
198
+ // For every removed file, simply delete the original.
186
199
// TODO: This is entirely untested code. There are likely bugs here, and
187
200
// this really should be part of the unidiff library, not a function
188
201
// defined here. Hopefully this gets moved somewhere else before it
@@ -194,6 +207,8 @@ fn patch_sdl2(sdl2_source_path: &Path) {
194
207
removed_file. path( ) ,
195
208
sdl2_source_path. to_string_lossy( ) ) ) ;
196
209
}
210
+ // For every new file, copy the entire contents of the patched file into
211
+ // a newly created <file_name>.
197
212
// TODO: This is entirely untested code. There are likely bugs here, and
198
213
// this really should be part of the unidiff library, not a function
199
214
// defined here. Hopefully this gets moved somewhere else before it
0 commit comments