File: add_missing_kpart_include.pl

package info (click to toggle)
kde-dev-scripts 4%3A18.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,496 kB
  • sloc: perl: 15,466; lisp: 5,627; sh: 4,157; python: 3,892; ruby: 2,158; makefile: 16; sed: 9
file content (89 lines) | stat: -rwxr-xr-x 2,527 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl -w

# KParts was cleaned up to have one include file for each class, while in kdelibs4 #include <kparts/part.h> included many things
# Usage: add_missing_kpart_include.pl *.h *.cpp
# Recursive usage: find -iname "*.cpp" -o -iname "*.h" |xargs kde-dev-scripts/kf5/add_missing_kpart_include.pl
#
# Laurent Montel <montel@kde.org> (2014)
# David Faure <faure@kde.org> (2014)

use strict;
use File::Basename;
use lib dirname($0);
use functionUtilkde;

my @classes = (
        'BrowserArguments',
        'BrowserExtension',
        'BrowserHostExtension',
        'BrowserInterface',
        'BrowserOpenOrSaveQuestion',
        'BrowserRun',
        'Event',
        'FileInfoExtension',
        'GUIActivateEvent',
        'HistoryProvider',
        'HtmlExtension',
        'HtmlSettingsInterface',
        'ListingFilterExtension',
        'ListingNotificationExtension',
        'LiveConnectExtension',
        'MainWindow',
        'OpenUrlArguments',
        'OpenUrlEvent',
        'Part',
        'PartActivateEvent',
        'PartBase',
        'PartManager',
        'PartSelectEvent',
        'Plugin',
        'ReadOnlyPart',
        'ReadWritePart',
        'ScriptableExtension',
        'SelectorInterface',
        'StatusBarExtension',
        'TextExtension',
        'WindowArgs'
);

foreach my $file (@ARGV) {

    my %includesToBeAdded = ();
    my %fwdDecls = ();
    my $wasIncludingPartH = 0;
    my $modified;
    open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n";
    my @l = map {
        my $orig = $_;
        foreach my $class (@classes) {
            if (/class $class;/) {
                $fwdDecls{$class} = 1;
            }
            if (/KParts::$class/ && !defined $fwdDecls{$class}) {
                # include the necessary header, unless we saw a fwd decl
                $includesToBeAdded{"KParts/$class"} = 1;
                $modified = 1;
            }
        }
        # get rid of lowercase includes, to avoid duplicates
        if (/^#include .kparts\/(\w+).h/) {
            $wasIncludingPartH = 1 if ($1 eq 'part');
            $_ = "";
        }
        $modified ||= $orig ne $_;
        $_;
    } <$FILE>;

    if ($modified) {
        open (my $OUT, ">", $file);
        print $OUT @l;
        close ($OUT);
        if ($wasIncludingPartH) {
            foreach my $include (keys %includesToBeAdded) {
                functionUtilkde::addIncludeInFile($file, $include);
            }
        }
    }
}

functionUtilkde::diffFile( "@ARGV" );