X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=OSX%2Fupdate-info-plist.pl;h=3e0fb8f5ee703f905c1e371d82e4e563b4eb3951;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hp=c5233ae7a370afe3e3cee024a6b636f5f15a6c47;hpb=2762a7d7cf8d83e68b8f635941f6609119d630ae;p=xscreensaver diff --git a/OSX/update-info-plist.pl b/OSX/update-info-plist.pl index c5233ae7..3e0fb8f5 100755 --- a/OSX/update-info-plist.pl +++ b/OSX/update-info-plist.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright © 2006-2013 Jamie Zawinski +# Copyright © 2006-2017 Jamie Zawinski # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that @@ -27,11 +27,12 @@ use IO::Compress::Gzip qw(gzip $GzipError); my ($exec_dir, $progname) = ($0 =~ m@^(.*?)/([^/]+)$@); -my $version = q{ $Revision: 1.26 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; +my ($version) = ('$Revision: 1.47 $' =~ m/\s(\d[.\d]+)\s/s); $ENV{PATH} = "/usr/local/bin:$ENV{PATH}"; # for seticon +$ENV{PATH} = "/opt/local/bin:$ENV{PATH}"; # for macports wget -my $thumbdir = $ENV{HOME} . '/www/xscreensaver/screenshots/'; +my $thumbdir = 'build/screenshots'; @@ -43,13 +44,24 @@ sub convert_plist($$) { if ($data && (!$is_binary_p) != (!$to_binary_p)) { print STDERR "$progname: converting plist\n" if ($verbose > 2); my $which = ($to_binary_p ? 'binary1' : 'xml1'); - my $cmd = "plutil -convert $which -s -o - -"; - my $pid = open3 (my $in, my $out, undef, $cmd) || error ("pipe: $cmd: $!"); + my @cmd = ('plutil', '-convert', $which, '-s', '-o', '-', '-'); + my $pid = open3 (my $in, my $out, undef, @cmd) || + error ("pipe: $cmd[0]: $!"); + error ("$cmd[0]: $!") unless $pid; print $in $data; close $in; local $/ = undef; # read entire file $data = <$out>; close $out; + waitpid ($pid, 0); + if ($?) { + my $exit_value = $? >> 8; + my $signal_num = $? & 127; + my $dumped_core = $? & 128; + error ("$cmd[0]: core dumped!") if ($dumped_core); + error ("$cmd[0]: signal $signal_num!") if ($signal_num); + error ("$cmd[0]: exited with $exit_value!") if ($exit_value); + } } return $data; } @@ -85,6 +97,7 @@ sub read_saver_xml($) { return () if ($name eq 'XScreenSaver'); return () if ($name eq 'SaverTester'); + return () if ($name eq 'XScreenSaverUpdater'); my $file = "$app_dir/Contents/Resources/" . lc($name) . ".xml"; my $file2 = "$app_dir/" . lc($name) . ".xml"; @@ -111,20 +124,11 @@ sub read_saver_xml($) { } -sub update_saver_xml($$) { - my ($app_dir, $vers) = @_; - my ($filename, $body, $was_compressed_p) = read_saver_xml ($app_dir); - my $obody = $body; - - return () unless defined ($filename); - - $body =~ m@]*?[ \t]_label=\"([^\"]+)\"@m || - error ("$filename: no name label"); - my $name = $1; +# This is duplicated in hacks/check-configs.pl for Android +# +sub munge_blurb($$$$) { + my ($filename, $name, $vers, $desc) = @_; - $body =~ m@<_description>(.*?)@s || - error ("$filename: no description tag"); - my $desc = $1; $desc =~ s/^([ \t]*\n)+//s; $desc =~ s/\s*$//s; @@ -132,13 +136,15 @@ sub update_saver_xml($$) { $desc =~ s@@@gs; $desc =~ s/^.* version \d[^\n]*\n//s; $desc =~ s/^From the XScreenSaver.*\n//m; - $desc =~ s@^http://www\.jwz\.org/xscreensaver.*\n@@m; + $desc =~ s@^https://www\.jwz\.org/xscreensaver.*\n@@m; $desc =~ s/\nCopyright [^ \r\n\t]+ (\d{4})(-\d{4})? (.*)\.$/\nWritten $3; $1./s; $desc =~ s/^\n+//s; - error ("$filename: description contains bad characters") - if ($desc =~ m/([^\t\n -~]|[<>])/); + error ("$filename: description contains markup: $1") + if ($desc =~ m/([<>&][^<>&\s]*)/s); + error ("$filename: description contains ctl chars: $1") + if ($desc =~ m/([\000-\010\013-\037])/s); error ("$filename: can't extract authors") unless ($desc =~ m@^(.*)\nWritten by[ \t]+(.+)$@s); @@ -177,13 +183,13 @@ sub update_saver_xml($$) { $desc . "\n" . "\n" . "From the XScreenSaver collection: " . - "http://www.jwz.org/xscreensaver/\n" . - "Copyright \251 $year by $authors.\n"); + "https://www.jwz.org/xscreensaver/\n" . + "Copyright \302\251 $year by $authors.\n"); my $desc2 = ("$name $vers,\n" . # Info.plist "\302\251 $year $authors.\n" . "From the XScreenSaver collection:\n" . - "http://www.jwz.org/xscreensaver/\n" . + "https://www.jwz.org/xscreensaver/\n" . "\n" . $desc . "\n"); @@ -191,12 +197,41 @@ sub update_saver_xml($$) { # unwrap lines, but only when it's obviously ok: leave blank lines, # and don't unwrap if that would compress leading whitespace on a line. # - $desc2 =~ s/^(From |http:)/\n$1/gm; + $desc2 =~ s/^(From |https?:)/\n$1/gm; 1 while ($desc2 =~ s/([^\s])[ \t]*\n([^\s])/$1 $2/gs); - $desc2 =~ s/\n\n(From |http:)/\n$1/gs; + $desc2 =~ s/\n\n(From |https?:)/\n$1/gs; + + return ($desc1, $desc2); +} + + +sub update_saver_xml($$) { + my ($app_dir, $vers) = @_; + my ($filename, $body, $was_compressed_p) = read_saver_xml ($app_dir); + my $obody = $body; + + return () unless defined ($filename); + + $body =~ m@]*?[ \t]_label=\"([^\"]+)\"@m || + error ("$filename: no name label"); + my $name = $1; + + $body =~ m@<_description>(.*?)@s || + error ("$filename: no description tag"); + my $desc = $1; + + error ("$filename: description contains non-ASCII and is not UTF-8: $1") + if ($body !~ m/\Q)(.*?)()@$1$desc1$3@s; + # NSXMLParser doesn't seem to work properly on Latin1 XML documents, + # so we convert these to UTF8 when embedding them in the .saver bundle. + $body =~ s@encoding="ISO-8859-1"@encoding="UTF-8"@gsi; + if ($obody eq $body && $was_compressed_p) { print STDERR "$progname: $filename: unchanged\n" if ($verbose > 1); } else { @@ -283,11 +318,9 @@ sub set_icon($) { my ($app_dir) = @_; $app_dir =~ s@/+$@@s; - # "seticon" is from osxutils, http://osxutils.sourceforge.net/ - my $icon = ($app_dir =~ m/\.saver$/ ? 'XScreenSaver' : 'SaverRunner'); $icon = "$app_dir/../../../$icon.icns"; - my @cmd = ("seticon", "-d", $icon, $app_dir); + my @cmd = ("$app_dir/../../../seticon.pl", "-d", $icon, $app_dir); print STDERR "$progname: exec: " . join(' ', @cmd) . "\n" if ($verbose > 1); system (@cmd); @@ -299,8 +332,70 @@ sub set_thumb($) { return unless ($app_dir =~ m@\.saver/?$@s); - my @cmd = ("$exec_dir/update-thumbnail.pl", $thumbdir, $app_dir); - push @cmd, "-" . ("v" x $verbose) if ($verbose); + my $name = $app_dir; + $name =~ s@^.*/@@s; + $name =~ s@\..*?$@@s; + $name = lc($name); + + $name = 'rd-bomb' if ($name eq 'rdbomb'); # sigh + + if (! -f "$thumbdir/$name.png") { + system ("make", "$thumbdir/$name.png"); + my $exit = $? >> 8; + exit ($exit) if $exit; + error ("unable to download $name.png") + unless (-f "$thumbdir/$name.png"); + } + + $app_dir =~ s@/+$@@s; + $app_dir .= "/Contents/Resources"; + error ("$app_dir does not exist") unless (-d $app_dir); + + system ("cp", "-p", "$thumbdir/$name.png", "$app_dir/thumbnail.png"); + my $exit = $? >> 8; + exit ($exit) if $exit; +} + + +sub enable_gc($) { + my ($app_dir) = @_; + + return unless ($app_dir =~ m@\.saver/?$@s); + my ($dir, $name) = ($app_dir =~ m@^(.*)/([^/]+)\.saver$@s); + error ("unparsable: $app_dir") unless $name; + my $exe = "$app_dir/Contents/MacOS/$name"; + my @cmd = ("$dir/enable_gc", $exe); + print STDERR "$progname: exec: " . join(' ', @cmd) . "\n" + if ($verbose > 1); + system (@cmd); + my $exit = $? >> 8; + exit ($exit) if $exit; +} + + +sub fix_coretext($) { + my ($app_dir) = @_; + + # In MacOS 10.8, they moved CoreText.framework from + # /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ + # to /System/Library/Frameworks/ which means that executables compiled + # on 10.8 and newer won't run on 10.7 and older because they can't find + # the library. Fortunately, 10.8 and later leave a symlink behind, so + # the old location still works. So we need our executables to contain + # an LC_LOAD_DYLIB pointing at the old directory instead of the new + # one. + # + return if ($app_dir =~ m@-iphone@s); + my ($dir, $name) = ($app_dir =~ m@^(.*)/([^/]+)\.(app|saver)$@s); + error ("unparsable: $app_dir") unless $name; + my $exe = "$app_dir/Contents/MacOS/$name"; + + my $new = ("/System/Library/Frameworks/CoreText.framework/" . + "Versions/A/CoreText"); + my $old = ("/System/Library/Frameworks/ApplicationServices.framework/" . + "Frameworks/CoreText.framework/Versions/A/CoreText"); + my @cmd = ("install_name_tool", "-change", $new, $old, $exe); + print STDERR "$progname: exec: " . join(' ', @cmd) . "\n" if ($verbose > 1); system (@cmd); @@ -340,7 +435,7 @@ sub update($) { $copyright =~ s/\b\d{4}-(\d{4})\b/$1/; # Lose the Wikipedia URLs. - $info_str =~ s@http:.*?\b(wikipedia|mathworld)\b[^\s]+[ \t]*\n?@@gm; + $info_str =~ s@https?:.*?\b(wikipedia|mathworld)\b[^\s]+[ \t]*\n?@@gm; $info_str =~ s/(\n\n)\n+/$1/gs; $info_str =~ s/(^\s+|\s+$)//gs; @@ -350,6 +445,9 @@ sub update($) { "CFBundleLongVersionString",$copyright); $plist = set_plist_key ($filename, $plist, "CFBundleGetInfoString", $info_str); + $plist = set_plist_key ($filename, $plist, + "CFBundleIdentifier", + "org.jwz.xscreensaver." . $app_name); if ($oplist eq $plist) { print STDERR "$progname: $filename: unchanged\n" if ($verbose > 1); @@ -368,8 +466,13 @@ sub update($) { } } - set_icon ($app_dir); + # MacOS 10.12: codesign says "resource fork, Finder information, or + # similar detritus not allowed" if any bundle has an Icon\r file. + # set_icon ($app_dir); + set_thumb ($app_dir); +# enable_gc ($app_dir); + fix_coretext ($app_dir) }