diff options
author | Jonas Häggqvist <rasher@rasher.dk> | 2008-07-20 22:20:32 +0000 |
---|---|---|
committer | Jonas Häggqvist <rasher@rasher.dk> | 2008-07-20 22:20:32 +0000 |
commit | 4077f236cedbcc24fac40874b68617a8a573b9d3 (patch) | |
tree | e71e5c50a88221acead17d91291c72a171d754fd /tools/buildzip.pl | |
parent | 95120f73ffd5f14951cbe38b39b9e5769f3644cd (diff) | |
download | rockbox-4077f236cedbcc24fac40874b68617a8a573b9d3.tar.gz rockbox-4077f236cedbcc24fac40874b68617a8a573b9d3.zip |
Buildzip.pl changes - do as much as possible with Perl, rather than using the shell. This gives a huge
speedup on Cygwin (>400%), and a slight speedup (25%) on Linux. If zips suddenly start missing files -
blame this commit.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18108 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/buildzip.pl')
-rwxr-xr-x | tools/buildzip.pl | 95 |
1 files changed, 62 insertions, 33 deletions
diff --git a/tools/buildzip.pl b/tools/buildzip.pl index e25bd6f569..9bd896be3f 100755 --- a/tools/buildzip.pl +++ b/tools/buildzip.pl | |||
@@ -8,6 +8,35 @@ | |||
8 | # $Id$ | 8 | # $Id$ |
9 | # | 9 | # |
10 | 10 | ||
11 | use File::Copy; # For move() and copy() | ||
12 | use File::Find; # For find() | ||
13 | use File::Path; # For rmtree() | ||
14 | use Cwd 'abs_path'; | ||
15 | |||
16 | sub glob_copy { | ||
17 | my ($pattern, $destination) = @_; | ||
18 | foreach my $path (glob($pattern)) { | ||
19 | copy($path, $destination); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | sub glob_unlink { | ||
24 | my ($pattern) = @_; | ||
25 | foreach my $path (glob($pattern)) { | ||
26 | unlink($path); | ||
27 | } | ||
28 | } | ||
29 | |||
30 | sub find_copyfile { | ||
31 | my ($pattern, $destination) = @_; | ||
32 | return sub { | ||
33 | $path = $_; | ||
34 | if ($path =~ $pattern && filesize($path) > 0 && !($path =~ /\.rockbox/)) { | ||
35 | copy($path, $destination); | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | |||
11 | $ROOT=".."; | 40 | $ROOT=".."; |
12 | 41 | ||
13 | my $ziptool="zip"; | 42 | my $ziptool="zip"; |
@@ -163,7 +192,7 @@ sub buildzip { | |||
163 | # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n"; | 192 | # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n"; |
164 | 193 | ||
165 | # remove old traces | 194 | # remove old traces |
166 | `rm -rf .rockbox`; | 195 | rmtree('.rockbox'); |
167 | 196 | ||
168 | mkdir ".rockbox", 0777; | 197 | mkdir ".rockbox", 0777; |
169 | 198 | ||
@@ -172,7 +201,8 @@ sub buildzip { | |||
172 | $fonts = 0; | 201 | $fonts = 0; |
173 | } | 202 | } |
174 | # create the file so the database does not try indexing a folder | 203 | # create the file so the database does not try indexing a folder |
175 | `touch .rockbox/database.ignore`; | 204 | open(IGNORE, ">.rockbox/database.ignore") || die "can't open database.ignore"; |
205 | close(IGNORE); | ||
176 | 206 | ||
177 | if($fonts) { | 207 | if($fonts) { |
178 | mkdir ".rockbox/fonts", 0777; | 208 | mkdir ".rockbox/fonts", 0777; |
@@ -212,7 +242,7 @@ sub buildzip { | |||
212 | if($swcodec) { | 242 | if($swcodec) { |
213 | mkdir ".rockbox/eqs", 0777; | 243 | mkdir ".rockbox/eqs", 0777; |
214 | 244 | ||
215 | `cp $ROOT/apps/eqs/*.cfg .rockbox/eqs/`; # equalizer presets | 245 | glob_copy("$ROOT/apps/eqs/*.cfg", '.rockbox/eqs/'); # equalizer presets |
216 | } | 246 | } |
217 | 247 | ||
218 | mkdir ".rockbox/wps", 0777; | 248 | mkdir ".rockbox/wps", 0777; |
@@ -242,8 +272,9 @@ STOP | |||
242 | else { | 272 | else { |
243 | system("$ROOT/tools/codepages -m"); | 273 | system("$ROOT/tools/codepages -m"); |
244 | } | 274 | } |
245 | $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1'; | 275 | |
246 | `$c`; | 276 | glob_copy('*.cp', '.rockbox/codepages/'); |
277 | glob_unlink('*.cp'); | ||
247 | 278 | ||
248 | if($bitmap) { | 279 | if($bitmap) { |
249 | mkdir ".rockbox/codecs", 0777; | 280 | mkdir ".rockbox/codecs", 0777; |
@@ -251,8 +282,7 @@ STOP | |||
251 | mkdir ".rockbox/backdrops", 0777; | 282 | mkdir ".rockbox/backdrops", 0777; |
252 | } | 283 | } |
253 | 284 | ||
254 | my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null'; | 285 | find(find_copyfile(qr/.*\.codec/, abs_path('.rockbox/codecs/')), 'apps/codecs'); |
255 | `$c`; | ||
256 | 286 | ||
257 | my @call = `find .rockbox/codecs -type f 2>/dev/null`; | 287 | my @call = `find .rockbox/codecs -type f 2>/dev/null`; |
258 | if(!$call[0]) { | 288 | if(!$call[0]) { |
@@ -262,8 +292,7 @@ STOP | |||
262 | } | 292 | } |
263 | } | 293 | } |
264 | 294 | ||
265 | $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;'; | 295 | find(find_copyfile(qr/\.(rock|ovl)/, abs_path('.rockbox/rocks/')), 'apps/plugins'); |
266 | print `$c`; | ||
267 | 296 | ||
268 | open VIEWERS, "$ROOT/apps/plugins/viewers.config" or | 297 | open VIEWERS, "$ROOT/apps/plugins/viewers.config" or |
269 | die "can't open viewers.config"; | 298 | die "can't open viewers.config"; |
@@ -297,7 +326,7 @@ STOP | |||
297 | if($dir ne "rocks") { | 326 | if($dir ne "rocks") { |
298 | # target is not 'rocks' but the plugins are always in that | 327 | # target is not 'rocks' but the plugins are always in that |
299 | # dir at first! | 328 | # dir at first! |
300 | `mv .rockbox/rocks/$name .rockbox/rocks/$r`; | 329 | move(".rockbox/rocks/$name", ".rockbox/rocks/$r"); |
301 | } | 330 | } |
302 | print VIEWERS $line; | 331 | print VIEWERS $line; |
303 | } | 332 | } |
@@ -310,7 +339,7 @@ STOP | |||
310 | if(-e ".rockbox/rocks/$oname") { | 339 | if(-e ".rockbox/rocks/$oname") { |
311 | # if there's an "overlay" file for the .rock, move that as | 340 | # if there's an "overlay" file for the .rock, move that as |
312 | # well | 341 | # well |
313 | `mv .rockbox/rocks/$oname .rockbox/rocks/$dir`; | 342 | move(".rockbox/rocks/$oname", ".rockbox/rocks/$dir"); |
314 | } | 343 | } |
315 | } | 344 | } |
316 | } | 345 | } |
@@ -323,33 +352,33 @@ STOP | |||
323 | foreach my $line (@rock_targetdirs) { | 352 | foreach my $line (@rock_targetdirs) { |
324 | if ($line =~ /([^,]*),(.*)/) { | 353 | if ($line =~ /([^,]*),(.*)/) { |
325 | my ($plugin, $dir)=($1, $2); | 354 | my ($plugin, $dir)=($1, $2); |
326 | `mv .rockbox/rocks/${plugin}.rock .rockbox/rocks/$dir 2> /dev/null`; | 355 | move(".rockbox/rocks/${plugin}.rock", ".rockbox/rocks/$dir/${plugin}.rock"); |
327 | } | 356 | } |
328 | } | 357 | } |
329 | 358 | ||
330 | if ($bitmap) { | 359 | if ($bitmap) { |
331 | mkdir ".rockbox/icons", 0777; | 360 | mkdir ".rockbox/icons", 0777; |
332 | `cp $viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp .rockbox/icons/viewers.bmp`; | 361 | copy("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", ".rockbox/icons/viewers.bmp"); |
333 | if ($remote_depth) { | 362 | if ($remote_depth) { |
334 | `cp $viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp .rockbox/icons/remote_viewers.bmp`; | 363 | copy("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", ".rockbox/icons/remote_viewers.bmp"); |
335 | } | 364 | } |
336 | } | 365 | } |
337 | 366 | ||
338 | `cp $ROOT/apps/tagnavi.config .rockbox/`; | 367 | copy("$ROOT/apps/tagnavi.config", ".rockbox/"); |
339 | `cp $ROOT/apps/plugins/disktidy.config .rockbox/rocks/apps/`; | 368 | copy("$ROOT/apps/plugins/disktidy.config", ".rockbox/rocks/apps/"); |
340 | 369 | ||
341 | if($bitmap) { | 370 | if($bitmap) { |
342 | `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/games/`; # sokoban levels | 371 | copy("$ROOT/apps/plugins/sokoban.levels", ".rockbox/rocks/games/sokoban.levels"); # sokoban levels |
343 | `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/games/`; # snake2 levels | 372 | copy("$ROOT/apps/plugins/snake2.levels", ".rockbox/rocks/games/snake2.levels"); # snake2 levels |
344 | } | 373 | } |
345 | 374 | ||
346 | if($image) { | 375 | if($image) { |
347 | # image is blank when this is a simulator | 376 | # image is blank when this is a simulator |
348 | if( filesize("rockbox.ucl") > 1000 ) { | 377 | if( filesize("rockbox.ucl") > 1000 ) { |
349 | `cp rockbox.ucl .rockbox/`; # UCL for flashing | 378 | copy("rockbox.ucl", ".rockbox/rockbox.ucl"); # UCL for flashing |
350 | } | 379 | } |
351 | if( filesize("rombox.ucl") > 1000) { | 380 | if( filesize("rombox.ucl") > 1000) { |
352 | `cp rombox.ucl .rockbox/`; # UCL for flashing | 381 | copy("rombox.ucl", ".rockbox/rombox.ucl"); # UCL for flashing |
353 | } | 382 | } |
354 | 383 | ||
355 | # Check for rombox.target | 384 | # Check for rombox.target |
@@ -358,7 +387,7 @@ STOP | |||
358 | my $romfile = "rombox.$2"; | 387 | my $romfile = "rombox.$2"; |
359 | if (filesize($romfile) > 1000) | 388 | if (filesize($romfile) > 1000) |
360 | { | 389 | { |
361 | `cp $romfile .rockbox/`; | 390 | copy($romfile, ".rockbox/$romfile"); |
362 | } | 391 | } |
363 | } | 392 | } |
364 | } | 393 | } |
@@ -368,15 +397,15 @@ STOP | |||
368 | "LICENSES", | 397 | "LICENSES", |
369 | "KNOWN_ISSUES" | 398 | "KNOWN_ISSUES" |
370 | )) { | 399 | )) { |
371 | `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`; | 400 | copy("$ROOT/docs/$_", ".rockbox/docs/$_.txt"); |
372 | } | 401 | } |
373 | if ($fonts) { | 402 | if ($fonts) { |
374 | `cp $ROOT/docs/profontdoc.txt .rockbox/docs/`; | 403 | copy("$ROOT/docs/profontdoc.txt", ".rockbox/docs/profontdoc.txt"); |
375 | } | 404 | } |
376 | for(("sample.colours", | 405 | for(("sample.colours", |
377 | "sample.icons" | 406 | "sample.icons" |
378 | )) { | 407 | )) { |
379 | `cp $ROOT/docs/$_ .rockbox/docs/`; | 408 | copy("$ROOT/docs/$_", ".rockbox/docs/$_"); |
380 | } | 409 | } |
381 | 410 | ||
382 | # Now do the WPS dance | 411 | # Now do the WPS dance |
@@ -388,10 +417,10 @@ STOP | |||
388 | } | 417 | } |
389 | 418 | ||
390 | # and the info file | 419 | # and the info file |
391 | system("cp rockbox-info.txt .rockbox/"); | 420 | copy("rockbox-info.txt", ".rockbox/rockbox-info.txt"); |
392 | 421 | ||
393 | # copy the already built lng files | 422 | # copy the already built lng files |
394 | `cp apps/lang/*lng .rockbox/langs/` | 423 | glob_copy('apps/lang/*lng', '.rockbox/langs/'); |
395 | 424 | ||
396 | } | 425 | } |
397 | 426 | ||
@@ -413,27 +442,27 @@ sub runone { | |||
413 | 442 | ||
414 | # create a zip file from the .rockbox dfir | 443 | # create a zip file from the .rockbox dfir |
415 | 444 | ||
416 | `rm -f $output`; | 445 | unlink($output); |
417 | if($verbose) { | 446 | if($verbose) { |
418 | print "find .rockbox | xargs $ziptool $output >/dev/null\n"; | 447 | print "$ziptool -r $output .rockbox >/dev/null\n"; |
419 | } | 448 | } |
420 | `find .rockbox | xargs $ziptool $output >/dev/null`; | 449 | system("$ziptool -r $output .rockbox >/dev/null"); |
421 | 450 | ||
422 | if($target && ($fonts != 1)) { | 451 | if($target && ($fonts != 1)) { |
423 | # On some targets, rockbox.* is inside .rockbox | 452 | # On some targets, rockbox.* is inside .rockbox |
424 | if($target !~ /(mod|ajz|wma)\z/i) { | 453 | if($target !~ /(mod|ajz|wma)\z/i) { |
425 | `cp $target .rockbox/$target`; | 454 | copy("$target", ".rockbox/$target"); |
426 | $target = ".rockbox/".$target; | 455 | $target = ".rockbox/".$target; |
427 | } | 456 | } |
428 | 457 | ||
429 | if($verbose) { | 458 | if($verbose) { |
430 | print "$ziptool $output $target\n"; | 459 | print "$ziptool $output $target >/dev/null\n"; |
431 | } | 460 | } |
432 | `$ziptool $output $target`; | 461 | system("$ziptool $output $target >/dev/null"); |
433 | } | 462 | } |
434 | 463 | ||
435 | # remove the .rockbox afterwards | 464 | # remove the .rockbox afterwards |
436 | `rm -rf .rockbox`; | 465 | rmtree('.rockbox'); |
437 | }; | 466 | }; |
438 | 467 | ||
439 | if(!$exe) { | 468 | if(!$exe) { |