summaryrefslogtreecommitdiffstats
path: root/scripts/non-module-helpers
blob: 30ba45626671f06b25f6d6a4f77db8dc9c85520c (plain)
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
90
#--------------------------------------------------------------------------------------------------
# Helper functions for standalone applications, such as examples and demos.
# -------------------------------------------------------------------------

my %module2DirectoryMapping = (
    declarative => "qtquick",
    opengl => "qtkernel",
    openvg => "qtkernel",
    dbus => "qtkernel",
    sql => "qtkernel",
    multimedia => "qtmultimedia",
    phonon => "phonon",
    network => "qtkernel",
    svg => "qtsvg",
    webkit => "qtwebkit",
    xml => "qtkernel",
    xmlpatterns => "qtxmlpatterns",
    qt3support => "qt3support",
    script => "qtscript",
    scripttools => "qtscript",
    core => "qtkernel",
    gui => "qtkernel",
    testlib => "qtkernel"
    );

# Takes a module name and returns its intended directory in modularized Qt.
sub mapModule2Directory {
    return $module2DirectoryMapping{$_[0]};
}

# Takes a directory, scans it for profiles, and tries to figure out where it should
# go, based on the usage of "QT += xxx".
# Returns undef if it couldn't find anything, or dies if there is an error.
sub findDirectoryForApplication {
    my $dir = $_[0];

    die ("$dir is not a directory") if (!-d $dir);

    my @profiles = findFiles($dir, ".*\\.pro", 0);
    return undef if (scalar(@profiles) != 1);
    my $profile = "$dir/$profiles[0]";

    my $profileFd;
    my @modules;
    my $lineSplit = 0;
    open($profileFd, "< $profile") or die ("Could not open $profile");
    while (<$profileFd>) {
        chomp;
        if (/QT\s*\+=\s*([^\\#]*)/ || ($lineSplit && m/([^\\#]*)/)) {
            push(@modules, split(/ +/, $1));
            /\\$/ and $lineSplit = 1 or $lineSplit = 0;
            next;
        } elsif (/TEMPLATE\s*=\s*subdirs/) {
            my @subdirs = findFiles($dir, ".*", 1);
            my $targetForAll;
            foreach my $subdir (@subdirs) {
                next if (! -d $subdir);
                my $subTarget;
                $subTarget = findDirectoryForApplication($subdir);
                next if (!defined($subTarget));
                if (!defined($subTarget) || (defined($targetForAll) && $targetForAll !~ $subTarget)) {
                    return undef;
                }
                $targetForAll = $subTarget;
            }
            return $targetForAll;
        }
        $lineSplit = 0;
    }
    close($profileFd);

    my $moduleDir = "qtkernel";
    foreach $module (@modules) {
        next if (!$module);
        $module =~ s/[\n\r]//g;
        my $maybeDir = mapModule2Directory($module);
        if (!defined($maybeDir)) {
            die("No mapping for module in $dir: $module\n");
        }
        if ($maybeDir !~ "qtkernel") {
            if ($maybeDir !~ $moduleDir && $moduleDir !~ "qtkernel") {
                # This means we found more than one non-qtkernel module.
                die ("Incompatible modules in $dir: " . join(" ", @modules) . ". Do this one manually.");
            } else {
                $moduleDir = $maybeDir;
            }
        }
    }
    return $moduleDir;
}