Warning, file /sdk/kde-dev-scripts/kf5/fix-ecm-install-icons.pl was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #!/usr/bin/perl -w 0002 0003 # Fix Deprecation Warnings from ECM_INSTALL_ICONS 0004 # when using the old form 0005 # ecm_install_icons(<icon_install_dir>) 0006 # 0007 # Usage: ./fix-ecm-install-icons.pl [--indent indentstr] [CMakeLists.txt files] 0008 # You can use '\t' escapes in the indentstr. The default is four spaces. 0009 # If no files are given, CMakeLists.txt from the current directory is used. 0010 # 0011 # NB: if your CMakeLists.txt uses kde4_install_icons, you should 0012 # run the adapt_cmakelists_file.pl script first 0013 0014 use strict; 0015 0016 use File::Basename; 0017 use File::Slurp::Unicode; 0018 use File::Find; 0019 use Cwd; 0020 use Cwd 'abs_path'; 0021 0022 sub findGitRepo { 0023 my $dir = abs_path(dirname(shift)); 0024 0025 while (not $dir eq '/' and !-e "$dir/.git") { 0026 $dir = dirname($dir); 0027 } 0028 0029 if ($dir eq '/') { 0030 return ""; 0031 } 0032 return $dir; 0033 } 0034 0035 my $indent = ' '; 0036 0037 if ((scalar(@ARGV) > 0) and (($ARGV[0] eq '--indent') or ($ARGV[0] eq '-i'))) { 0038 shift @ARGV; 0039 if (scalar(@ARGV) eq 0) { 0040 print "No indent string given\n"; 0041 exit 1; 0042 } 0043 $indent = $ARGV[0]; 0044 shift @ARGV; 0045 $indent =~ s/\\t/\t/g; 0046 if (not $indent =~ /^\s*$/) { 0047 print "Indent string is not whitespace\n"; 0048 exit 2; 0049 } 0050 } 0051 0052 if (scalar(@ARGV) eq 0) { 0053 @ARGV = ("CMakeLists.txt"); 0054 } 0055 0056 my $lastfile = ""; 0057 0058 my $savedir = getcwd; 0059 0060 foreach my $cmakelists (@ARGV) { 0061 my $mv = 'mv'; 0062 my $cmakecontents = read_file($cmakelists); 0063 my $cmakelistsfile = basename($cmakelists); 0064 my $cwdir = dirname($cmakelists); 0065 my $repodir = findGitRepo($cmakelists); 0066 if ($repodir) { 0067 $mv = 'git mv'; 0068 } 0069 0070 chdir($cwdir); 0071 0072 if ($cmakecontents =~ /ecm_install_icons\s*\(\s*([^\s]+)(?:\s+([^\s]+))?\s*\)/) { 0073 my $destination = $1; 0074 my $l10n_code = $2; 0075 my $replacestr = ""; 0076 my %themehash = (); 0077 0078 foreach my $file (<{*.png,*.svgz,*.mng}>) { 0079 if ($file =~ /(br|ox|cr|lo|hi)(\d+|sc)-(\w+)-([^\.]+)\.(png|svgz|mng)/) { 0080 my $th = $1; 0081 my $size = $2; 0082 my $group = $3; 0083 my $iconname = $4; 0084 my $extension = $5; 0085 0086 if ($group eq "mime") { 0087 $group = "mimetypes"; 0088 } 0089 elsif ($group eq "filesys") { 0090 $group = "places"; 0091 } 0092 elsif ($group eq "device") { 0093 $group = "devices"; 0094 } 0095 elsif ($group eq "app") { 0096 $group = "apps"; 0097 } 0098 elsif ($group eq "action") { 0099 $group = "actions"; 0100 } 0101 0102 my $newfilename = "$size-$group-$iconname.$extension"; 0103 0104 $themehash{$th} .= "\n${indent}$newfilename"; 0105 `$mv "$file" "$newfilename"`; 0106 } 0107 } 0108 0109 foreach my $key (sort keys %themehash) { 0110 $replacestr .= "ecm_install_icons(ICONS$themehash{$key}\n"; 0111 $replacestr .= "${indent}DESTINATION $destination\n"; 0112 $replacestr .= "${indent}THEME "; 0113 0114 if ($key eq "br") { 0115 $replacestr .= "breeze"; 0116 } 0117 elsif ($key eq "ox") { 0118 $replacestr .= "oxygen"; 0119 } 0120 elsif ($key eq "cr") { 0121 $replacestr .= "crystalsvg"; 0122 } 0123 elsif ($key eq "lo") { 0124 $replacestr .= "locolor"; 0125 } 0126 elsif ($key eq "hi") { 0127 $replacestr .= "hicolor"; 0128 } 0129 $replacestr .= "\n"; 0130 0131 if ($l10n_code) { 0132 $replacestr .= "${indent}LANG $l10n_code\n"; 0133 } 0134 0135 $replacestr .= ")\n"; 0136 } 0137 0138 chop($replacestr); 0139 0140 if ($replacestr ne "") { 0141 $cmakecontents =~ s/ecm_install_icons\s*\(\s*[^\s]+(?:\s+[^\s]+)?\s*\)/$replacestr/; 0142 0143 write_file($cmakelistsfile, $cmakecontents); 0144 if ($repodir) { 0145 `git add $cmakelistsfile`; 0146 } 0147 } 0148 } 0149 0150 $lastfile = $cmakelists; 0151 0152 # so relative paths work on the next iteration 0153 chdir($savedir); 0154 } 0155 0156 # Hopefully all of these files were in the same repo :) 0157 my $repodir = findGitRepo($lastfile); 0158 if ($repodir) { 0159 chdir($repodir); 0160 system("git", "status"); 0161 } 0162 # vim:et:sw=4:sts=4: