2011-11-11 08:57:44 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#############################################################################
|
|
|
|
##
|
2016-01-15 07:08:27 +00:00
|
|
|
## Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
## Contact: https://www.qt.io/licensing/
|
2011-11-11 08:57:44 +00:00
|
|
|
##
|
|
|
|
## This file is part of the porting tools of the Qt Toolkit.
|
|
|
|
##
|
2016-01-15 07:08:27 +00:00
|
|
|
## $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
## Commercial License Usage
|
|
|
|
## Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
## accordance with the commercial license agreement provided with the
|
|
|
|
## Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
## a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 07:08:27 +00:00
|
|
|
## and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
## information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
##
|
2011-11-11 08:57:44 +00:00
|
|
|
## GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
## Alternatively, this file may be used under the terms of the GNU Lesser
|
2016-01-15 07:08:27 +00:00
|
|
|
## General Public License version 3 as published by the Free Software
|
|
|
|
## Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
|
|
## packaging of this file. Please review the following information to
|
|
|
|
## ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
2015-01-28 08:44:43 +00:00
|
|
|
##
|
2016-01-15 07:08:27 +00:00
|
|
|
## GNU General Public License Usage
|
|
|
|
## Alternatively, this file may be used under the terms of the GNU
|
|
|
|
## General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
## Public license version 3 or any later version approved by the KDE Free
|
|
|
|
## Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
|
|
## included in the packaging of this file. Please review the following
|
|
|
|
## information to ensure the GNU General Public License requirements will
|
|
|
|
## be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
|
|
## https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-11-11 08:57:44 +00:00
|
|
|
##
|
|
|
|
## $QT_END_LICENSE$
|
|
|
|
##
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
use Cwd;
|
|
|
|
use File::Find;
|
|
|
|
use File::Spec;
|
2011-11-22 11:20:04 +00:00
|
|
|
use IO::File;
|
|
|
|
use Getopt::Long;
|
2011-11-11 08:57:44 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
my $dry_run = 0;
|
2011-11-22 11:20:04 +00:00
|
|
|
my $help = 0;
|
|
|
|
my $stripModule = 0;
|
2011-11-11 08:57:44 +00:00
|
|
|
my $fixedFileCount = 0;
|
2011-11-22 11:20:04 +00:00
|
|
|
my $fileCount = 0;
|
|
|
|
my $verbose = 0;
|
2015-04-17 09:59:53 +00:00
|
|
|
my $qtdir;
|
|
|
|
my $qtIncludeDir;
|
2011-11-22 11:20:04 +00:00
|
|
|
|
|
|
|
my $USAGE=<<EOF;
|
|
|
|
This script replaces all Qt 4 style includes with Qt 5 includes.
|
|
|
|
|
|
|
|
Usage: $0 [options]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--dry-run : Do not replace anything, just print what would be replaced
|
|
|
|
--strip-modules : Strip the module headers for writing portable code
|
|
|
|
--verbose : Verbose
|
|
|
|
--qtdir <directory> : Point to Qt 5's qtbase directory
|
|
|
|
EOF
|
|
|
|
|
|
|
|
if (!GetOptions('dry-run' => \$dry_run, 'help' => \$help,
|
|
|
|
'strip-modules' => \$stripModule, 'verbose' => \$verbose, 'qtdir:s' => \$qtdir)
|
|
|
|
|| $help) {
|
|
|
|
print $USAGE;
|
|
|
|
exit (1);
|
2011-11-11 08:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my %headerSubst = ();
|
|
|
|
my $cwd = getcwd();
|
|
|
|
|
|
|
|
sub fixHeaders
|
|
|
|
{
|
|
|
|
my $fileName = $File::Find::name;
|
|
|
|
my $relFileName = File::Spec->abs2rel($fileName, $cwd);
|
|
|
|
|
|
|
|
# only check sources, also ignore symbolic links and directories
|
2011-11-22 11:20:04 +00:00
|
|
|
return unless -f $fileName && $fileName =~ /(\.h|\.cpp|\/C|\.cc|\.CC)$/;
|
2011-11-11 08:57:44 +00:00
|
|
|
|
2011-11-22 11:20:04 +00:00
|
|
|
my $inFile = new IO::File('<' . $fileName) or die ('Unable to open ' . $fileName . ': ' . $!);
|
|
|
|
$fileCount++;
|
|
|
|
my @affectedClasses;
|
|
|
|
my @outLines;
|
2011-11-11 08:57:44 +00:00
|
|
|
|
2011-11-22 11:20:04 +00:00
|
|
|
while (my $line = <$inFile>) {
|
2011-11-11 08:57:44 +00:00
|
|
|
if ($line =~ /^#(\s*)include(\s*)<.*?\/(.*?)>(.*)/) {
|
|
|
|
my $newHeader = $headerSubst{$3};
|
|
|
|
if ($newHeader) {
|
2011-11-22 11:20:04 +00:00
|
|
|
$line = '#' . $1 . 'include' . $2 . '<' . $newHeader . '>' . $4 . "\n";
|
|
|
|
push(@affectedClasses, $3);
|
2011-11-11 08:57:44 +00:00
|
|
|
}
|
|
|
|
} elsif ($line =~ /^#(\s*)include(\s*)<QtGui>(.*)/) {
|
2011-11-22 11:20:04 +00:00
|
|
|
$line = '#' . $1 . 'include' . $2 . '<QtWidgets>' . $3 . "\n";
|
|
|
|
push(@affectedClasses, 'QtGui');
|
2011-11-11 08:57:44 +00:00
|
|
|
}
|
2011-11-22 11:20:04 +00:00
|
|
|
push(@outLines, $line);
|
|
|
|
}
|
|
|
|
$inFile->close();
|
|
|
|
|
|
|
|
if (scalar(@affectedClasses)) {
|
|
|
|
$fixedFileCount++;
|
|
|
|
print $relFileName, ': ', join(', ', @affectedClasses), "\n" if ($verbose || $dry_run);
|
|
|
|
if (!$dry_run) {
|
|
|
|
my $outFile = new IO::File('>' . $fileName) or die ('Unable to open ' . $fileName . ': ' . $!);
|
|
|
|
map { print $outFile $_; } @outLines;
|
|
|
|
$outFile->close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print $relFileName, ": no modification.\n" if ($verbose || $dry_run);
|
2011-11-11 08:57:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub findQtHeaders
|
|
|
|
{
|
2015-04-17 09:59:53 +00:00
|
|
|
my ($dirName,$includeDir) = @_;
|
2011-11-11 08:57:44 +00:00
|
|
|
|
|
|
|
local (*DIR);
|
|
|
|
|
2015-04-17 09:59:53 +00:00
|
|
|
my $moduleIncludeDir = $includeDir . '/' . $dirName;
|
|
|
|
opendir(DIR, $moduleIncludeDir) || die ('Unable to open ' . $moduleIncludeDir . ': ' . $!);
|
2011-11-11 08:57:44 +00:00
|
|
|
my @headers = readdir(DIR);
|
|
|
|
closedir(DIR);
|
|
|
|
|
|
|
|
foreach my $header (@headers) {
|
2015-04-17 09:59:53 +00:00
|
|
|
next if (-d ($moduleIncludeDir . '/' . $header) || $header =~ /\.pri$/);
|
2011-11-22 11:20:04 +00:00
|
|
|
$headerSubst{$header} = $stripModule ? $header : ($dirName . '/' . $header);
|
2011-11-11 08:57:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-22 11:20:04 +00:00
|
|
|
# -------- MAIN
|
2011-11-11 08:57:44 +00:00
|
|
|
|
2015-04-17 09:59:53 +00:00
|
|
|
if ($qtdir) {
|
|
|
|
$qtIncludeDir = $qtdir . '/include';
|
|
|
|
} else {
|
|
|
|
$qtIncludeDir = `qmake -query QT_INSTALL_HEADERS`;
|
|
|
|
chop($qtIncludeDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
die "The location of the Qt 5 include files could not be determined.\n"
|
|
|
|
."Please ensure qmake can be found in PATH or pass the command line option --qtdir.\n"
|
|
|
|
unless -d $qtIncludeDir;
|
2011-11-11 08:57:44 +00:00
|
|
|
|
2015-04-17 09:59:53 +00:00
|
|
|
findQtHeaders('QtCore', $qtIncludeDir);
|
|
|
|
findQtHeaders('QtConcurrent', $qtIncludeDir);
|
|
|
|
findQtHeaders('QtWidgets', $qtIncludeDir);
|
|
|
|
findQtHeaders('QtPrintSupport', $qtIncludeDir);
|
2011-11-11 08:57:44 +00:00
|
|
|
|
2015-04-17 09:59:53 +00:00
|
|
|
if (-d $qtIncludeDir . '/include/QtMultimedia') {
|
|
|
|
findQtHeaders('QtMultimedia', $qtIncludeDir);
|
|
|
|
findQtHeaders('QtMultimediaWidgets', $qtIncludeDir);
|
|
|
|
} elsif (-d $qtIncludeDir . '/../qtmultimedia' ) {
|
2011-11-11 08:57:44 +00:00
|
|
|
# This is the case if QTDIR points to a source tree instead of an installed Qt
|
2015-04-17 09:59:53 +00:00
|
|
|
findQtHeaders('QtMultimedia', $qtIncludeDir . '/../qtmultimedia');
|
|
|
|
findQtHeaders('QtMultimediaWidgets', $qtIncludeDir . '/../qtmultimedia');
|
2011-11-11 08:57:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 12:08:08 +00:00
|
|
|
# Support porting from "Qt 4.99" QtDeclarative to QtQuick (QQuickItem et al)
|
2015-04-17 09:59:53 +00:00
|
|
|
if (-d $qtIncludeDir . '/include/QtQuick') {
|
|
|
|
findQtHeaders('QtQuick', $qtIncludeDir);
|
|
|
|
} elsif (-d $qtIncludeDir . '/../qtdeclarative' ) {
|
2011-12-05 12:08:08 +00:00
|
|
|
# This is the case if QTDIR points to a source tree instead of an installed Qt
|
2015-04-17 09:59:53 +00:00
|
|
|
findQtHeaders('QtQuick', $qtIncludeDir . '/../qtdeclarative');
|
2011-12-05 12:08:08 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 08:57:44 +00:00
|
|
|
# special case
|
2011-11-22 11:20:04 +00:00
|
|
|
$headerSubst{'QtGui'} = 'QtWidgets/QtWidgets';
|
2011-11-11 08:57:44 +00:00
|
|
|
|
|
|
|
find({ wanted => \&fixHeaders, no_chdir => 1}, $cwd);
|
|
|
|
|
2011-11-22 11:20:04 +00:00
|
|
|
print 'Done. ', ($dry_run ? 'Checked' : 'Modified'), ' ', $fixedFileCount, ' of ', $fileCount, " file(s).\n";
|