1 | #!/usr/bin/php |
---|
2 | <?php |
---|
3 | |
---|
4 | // Usage: "port file all | php ports_using_cd.php" |
---|
5 | // Author: Ryan Schmidt <ryandesign@macports.org> |
---|
6 | // License: public domain |
---|
7 | |
---|
8 | $total_ports = 0; |
---|
9 | $bad_ports = $bad_maintainers = array(); |
---|
10 | while (!feof(STDIN)) { |
---|
11 | $portfile = trim(fgets(STDIN)); |
---|
12 | if (!file_exists($portfile)) continue; |
---|
13 | ++$total_ports; |
---|
14 | |
---|
15 | $contents = file_get_contents($portfile); |
---|
16 | |
---|
17 | // Censor some parts of the portfile. Replace non-space characters with "#". |
---|
18 | // Don't just remove the affected bits because we want to maintain line numbers. |
---|
19 | $search = array(); |
---|
20 | $search[] = '%^(\\s*#)(.*)$%me'; // comments |
---|
21 | $search[] = '%(\\W)((?:system|ui_(?:error|info|msg))\\s+".*?[^\\\\]")%se'; // system and ui_* calls |
---|
22 | $search[] = '%(\\W)(\\w+\\.cmd\\s+cd\\s.*?[^\\\\]\\n)%se'; // configure.cmd, build.cmd, etc. |
---|
23 | $replace = '\'\\1\' . preg_replace(\'%\\S%\', \'#\', \'\\2\')'; |
---|
24 | $contents = preg_replace($search, $replace, $contents); |
---|
25 | |
---|
26 | // Examine each line for the offending command. |
---|
27 | $lines = preg_split("%\n%", $contents); |
---|
28 | foreach ($lines as $line_num => $line) { |
---|
29 | if (preg_match('%(^|\\s)cd\\s%', $line)) { |
---|
30 | if (!in_array($portfile, $bad_ports)) $bad_ports[] = $portfile; |
---|
31 | echo $portfile . ':' . $line_num . ' ' . $line . "\n"; |
---|
32 | } |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | if ($total_ports > 0) { |
---|
37 | if (empty($bad_ports)) { |
---|
38 | fwrite(STDERR, "None of these $total_ports ports are using the 'cd' command.\n"); |
---|
39 | } else { |
---|
40 | fwrite(STDERR, "\nOf these $total_ports ports, " . count($bad_ports) . " are using the 'cd' command, maintained by:\n"); |
---|
41 | foreach ($bad_ports as $bad_port) { |
---|
42 | fwrite(STDERR, '.'); |
---|
43 | $maintainers = exec("port info --maintainer " . escapeshellarg(dirname($bad_port))); |
---|
44 | $maintainers = preg_replace('%^maintainer: %', '', $maintainers); |
---|
45 | $maintainers = preg_split('%, %', $maintainers); |
---|
46 | foreach ($maintainers as $maintainer) { |
---|
47 | if (!isset($bad_maintainers[$maintainer])) { |
---|
48 | $bad_maintainers[$maintainer] = 1; |
---|
49 | } else { |
---|
50 | ++$bad_maintainers[$maintainer]; |
---|
51 | } |
---|
52 | } |
---|
53 | } |
---|
54 | ksort($bad_maintainers); |
---|
55 | fwrite(STDERR, "\n"); |
---|
56 | foreach ($bad_maintainers as $bad_maintainer => $num_bad_ports) { |
---|
57 | fwrite(STDERR, $bad_maintainer . ' (' . $num_bad_ports . ')' . "\n"); |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | ?> |
---|