source: trunk/bin/syncqt@ 397

Last change on this file since 397 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

  • Property svn:executable set to *
File size: 36.1 KB
Line 
1#!/usr/bin/perl -w
2######################################################################
3#
4# Synchronizes Qt header files - internal Trolltech tool.
5#
6# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
7# Contact: Qt Software Information ([email protected])
8#
9######################################################################
10
11# use packages -------------------------------------------------------
12use File::Basename;
13use File::Path;
14use Cwd;
15use Config;
16use strict;
17
18die "syncqt: QTDIR not defined" if ! $ENV{"QTDIR"}; # sanity check
19
20# global variables
21my $isunix = 0;
22my $basedir = $ENV{"QTDIR"};
23$basedir =~ s=\\=/=g;
24my %modules = ( # path to module name map
25 "QtGui" => "$basedir/src/gui",
26 "QtOpenGL" => "$basedir/src/opengl",
27 "QtCore" => "$basedir/src/corelib",
28 "QtXml" => "$basedir/src/xml",
29 "QtXmlPatterns" => "$basedir/src/xmlpatterns",
30 "QtSql" => "$basedir/src/sql",
31 "QtNetwork" => "$basedir/src/network",
32 "QtSvg" => "$basedir/src/svg",
33 "QtScript" => "$basedir/src/script",
34 "QtScriptTools" => "$basedir/src/scripttools",
35 "Qt3Support" => "$basedir/src/qt3support",
36 "ActiveQt" => "$basedir/src/activeqt/container;$basedir/src/activeqt/control;$basedir/src/activeqt/shared",
37 "QtTest" => "$basedir/src/testlib",
38 "QtAssistant" => "$basedir/tools/assistant/compat/lib",
39 "QtHelp" => "$basedir/tools/assistant/lib",
40 "QtDesigner" => "$basedir/tools/designer/src/lib",
41 "QtUiTools" => "$basedir/tools/designer/src/uitools",
42 "QtDBus" => "$basedir/src/dbus",
43 "QtWebKit" => "$basedir/src/3rdparty/webkit/WebCore",
44 "phonon" => "$basedir/src/phonon",
45);
46my %moduleheaders = ( # restrict the module headers to those found in relative path
47 "QtWebKit" => "../WebKit/qt/Api",
48 "phonon" => "../3rdparty/phonon/phonon",
49);
50
51#$modules{"QtCore"} .= ";$basedir/mkspecs/" . $ENV{"MKSPEC"} if defined $ENV{"MKSPEC"};
52
53# global variables (modified by options)
54my $module = 0;
55my $showonly = 0;
56my $remove_stale = 1;
57my $force_win = 0;
58my $force_relative = 0;
59my $check_includes = 0;
60my $copy_headers = 0;
61my @modules_to_sync ;
62$force_relative = 1 if ( -d "/System/Library/Frameworks" );
63my $out_basedir = $basedir;
64$out_basedir =~ s=\\=/=g;
65
66# functions ----------------------------------------------------------
67
68######################################################################
69# Syntax: showUsage()
70# Params: -none-
71#
72# Purpose: Show the usage of the script.
73# Returns: -none-
74######################################################################
75sub showUsage
76{
77 print "$0 usage:\n";
78 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
79 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
80 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
81 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
82 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
83 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
84 print " -help This help\n";
85 exit 0;
86}
87
88######################################################################
89# Syntax: checkUnix()
90# Params: -none-
91#
92# Purpose: Check if script runs on a Unix system or not. Cygwin
93# systems are _not_ detected as Unix systems.
94# Returns: 1 if a unix system, else 0.
95######################################################################
96sub checkUnix {
97 my ($r) = 0;
98 if ( $force_win != 0) {
99 return 0;
100 } elsif ( -f "/bin/uname" ) {
101 $r = 1;
102 (-f "\\bin\\uname") && ($r = 0);
103 } elsif ( -f "/usr/bin/uname" ) {
104 $r = 1;
105 (-f "\\usr\\bin\\uname") && ($r = 0);
106 }
107 if($r) {
108 $_ = $Config{'osname'};
109 $r = 0 if( /(ms)|(cyg)win/i );
110 }
111 return $r;
112}
113
114sub checkRelative {
115 my ($dir) = @_;
116 return 0 if($dir =~ /^\//);
117 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
118 return 1;
119}
120
121######################################################################
122# Syntax: shouldMasterInclude(iheader)
123# Params: iheader, string, filename to verify inclusion
124#
125# Purpose: Determines if header should be in the master include file.
126# Returns: 0 if file contains "#pragma qt_no_master_include" or not
127# able to open, else 1.
128######################################################################
129sub shouldMasterInclude {
130 my ($iheader) = @_;
131 return 0 if(basename($iheader) =~ /_/);
132 return 0 if(basename($iheader) =~ /qconfig/);
133 if(open(F, "<$iheader")) {
134 while(<F>) {
135 chomp;
136 return 0 if(/^\#pragma qt_no_master_include$/);
137 }
138 close(F);
139 } else {
140 return 0;
141 }
142 return 1;
143}
144
145######################################################################
146# Syntax: classNames(iheader)
147# Params: iheader, string, filename to parse for classname "symlinks"
148#
149# Purpose: Scans through iheader to find all classnames that should be
150# synced into library's include structure.
151# Returns: List of all class names in a file.
152######################################################################
153sub classNames {
154 my @ret;
155 my ($iheader) = @_;
156 if(basename($iheader) eq "qglobal.h") {
157 push @ret, "QtGlobal";
158 } elsif(basename($iheader) eq "qendian.h") {
159 push @ret, "QtEndian";
160 } elsif(basename($iheader) eq "qconfig.h") {
161 push @ret, "QtConfig";
162 } elsif(basename($iheader) eq "qplugin.h") {
163 push @ret, "QtPlugin";
164 } elsif(basename($iheader) eq "qalgorithms.h") {
165 push @ret, "QtAlgorithms";
166 } elsif(basename($iheader) eq "qcontainerfwd.h") {
167 push @ret, "QtContainerFwd";
168 } elsif(basename($iheader) eq "qdebug.h") {
169 push @ret, "QtDebug";
170 } elsif(basename($iheader) eq "qevent.h") {
171 push @ret, "QtEvents";
172 } elsif(basename($iheader) eq "qnamespace.h") {
173 push @ret, "Qt"
174 } elsif(basename($iheader) eq "qssl.h") {
175 push @ret, "QSsl";
176 } elsif(basename($iheader) eq "qtest.h") {
177 push @ret, "QTest"
178 } elsif(basename($iheader) eq "qtconcurrentmap.h") {
179 push @ret, "QtConcurrentMap"
180 } elsif(basename($iheader) eq "qtconcurrentfilter.h") {
181 push @ret, "QtConcurrentFilter"
182 } elsif(basename($iheader) eq "qtconcurrentrun.h") {
183 push @ret, "QtConcurrentRun"
184 }
185
186 my $parsable = "";
187 if(open(F, "<$iheader")) {
188 while(<F>) {
189 my $line = $_;
190 chomp $line;
191 chop $line if ($line =~ /\r$/);
192 if($line =~ /^\#/) {
193 if($line =~ /\\$/) {
194 while($line = <F>) {
195 chomp $line;
196 last unless($line =~ /\\$/);
197 }
198 }
199 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
200 push(@ret, "$1") if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
201 $line = 0;
202 }
203 if($line) {
204 $line =~ s,//.*$,,; #remove c++ comments
205 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
206 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
207 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro
208 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
209 $parsable .= " " . $line;
210 }
211 }
212 close(F);
213 }
214
215 my $last_definition = 0;
216 my @namespaces;
217 for(my $i = 0; $i < length($parsable); $i++) {
218 my $definition = 0;
219 my $character = substr($parsable, $i, 1);
220 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
221 for($i+=2; $i < length($parsable); $i++) {
222 my $end = substr($parsable, $i, 2);
223 if($end eq "*/") {
224 $last_definition = $i+2;
225 $i++;
226 last;
227 }
228 }
229 } elsif($character eq "{") {
230 my $brace_depth = 1;
231 my $block_start = $i + 1;
232 BLOCK: for($i+=1; $i < length($parsable); $i++) {
233 my $ignore = substr($parsable, $i, 1);
234 if($ignore eq "{") {
235 $brace_depth++;
236 } elsif($ignore eq "}") {
237 $brace_depth--;
238 unless($brace_depth) {
239 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
240 my $end = substr($parsable, $i2, 1);
241 if($end eq ";" || $end ne " ") {
242 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
243 $i = $i2 if($end eq ";");
244 $last_definition = $i + 1;
245 last BLOCK;
246 }
247 }
248 }
249 }
250 }
251 } elsif($character eq ";") {
252 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
253 $last_definition = $i + 1;
254 } elsif($character eq "}") {
255 # a naked } must be a namespace ending
256 # if it's not a namespace, it's eaten by the loop above
257 pop @namespaces;
258 $last_definition = $i + 1;
259 }
260
261 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
262 && substr($parsable, $i+1, 1) eq "{") {
263 push @namespaces, $1;
264
265 # Eat the opening { so that the condensing loop above doesn't see it
266 $i++;
267 $last_definition = $i + 1;
268 }
269
270 if($definition) {
271 $definition =~ s=[\n\r]==g;
272 my @symbols;
273 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
274 push @symbols, $1;
275 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
276 push @symbols, $2;
277 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
278 push @symbols, $4;
279 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
280 push @symbols, "Q" . $1 . "Iterator";
281 push @symbols, "QMutable" . $1 . "Iterator";
282 }
283
284 foreach (@symbols) {
285 my $symbol = $_;
286 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
287 push @ret, $symbol
288 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
289 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
290 }
291 }
292 }
293 return @ret;
294}
295
296######################################################################
297# Syntax: syncHeader(header, iheader, copy)
298# Params: header, string, filename to create "symlink" for
299# iheader, string, destination name of symlink
300# copy, forces header to be a copy of iheader
301#
302# Purpose: Syncronizes header to iheader
303# Returns: 1 if successful, else 0.
304######################################################################
305sub syncHeader {
306 my ($header, $iheader, $copy) = @_;
307 $iheader =~ s=\\=/=g;
308 $header =~ s=\\=/=g;
309 return copyFile($iheader, $header) if($copy);
310
311 my $iheader_no_basedir = $iheader;
312 $iheader_no_basedir =~ s,^$basedir/?,,;
313 unless(-e "$header") {
314 my $header_dir = dirname($header);
315 mkpath $header_dir, 0777;
316
317 #write it
318 my $iheader_out = fixPaths($iheader, $header_dir);
319 open HEADER, ">$header" || die "Could not open $header for writing!\n";
320 print HEADER "#include \"$iheader_out\"\n";
321 close HEADER;
322 return 1;
323 }
324 return 0;
325}
326
327######################################################################
328# Syntax: fixPaths(file, dir)
329# Params: file, string, filepath to be made relative to dir
330# dir, string, dirpath for point of origin
331#
332# Purpose: file is made relative (if possible) of dir.
333# Returns: String with the above applied conversion.
334######################################################################
335sub fixPaths {
336 my ($file, $dir) = @_;
337 $dir =~ s=^$basedir/=$out_basedir/= if(!($basedir eq $out_basedir));
338 $file =~ s=\\=/=g;
339 $file =~ s/\+/\\+/g;
340 $dir =~ s=\\=/=g;
341 $dir =~ s/\+/\\+/g;
342
343 #setup
344 my $ret = $file;
345 my $file_dir = dirname($file);
346 if($file_dir eq ".") {
347 $file_dir = getcwd();
348 $file_dir =~ s=\\=/=g;
349 }
350 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:,g;
351 if($dir eq ".") {
352 $dir = getcwd();
353 $dir =~ s=\\=/=g;
354 }
355 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
356 return basename($file) if("$file_dir" eq "$dir");
357
358 #guts
359 my $match_dir = 0;
360 for(my $i = 1; $i < length($file_dir); $i++) {
361 my $slash = index($file_dir, "/", $i);
362 last if($slash == -1);
363 my $tmp = substr($file_dir, 0, $slash);
364 last unless($dir =~ m,^$tmp/,);
365 $match_dir = $tmp;
366 $i = $slash;
367 }
368 if($match_dir) {
369 my $after = substr($dir, length($match_dir));
370 my $count = ($after =~ tr,/,,);
371 my $dots = "";
372 for(my $i = 0; $i < $count; $i++) {
373 $dots .= "../";
374 }
375 $ret =~ s,^$match_dir,$dots,;
376 }
377 $ret =~ s,/+,/,g;
378 return $ret;
379}
380
381######################################################################
382# Syntax: fileContents(filename)
383# Params: filename, string, filename of file to return contents
384#
385# Purpose: Get the contents of a file.
386# Returns: String with contents of the file, or empty string if file
387# doens't exist.
388# Warning: Dies if it does exist but script cannot get read access.
389######################################################################
390sub fileContents {
391 my ($filename) = @_;
392 my $filecontents = "";
393 if (-e $filename) {
394 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
395 local $/;
396 binmode I;
397 $filecontents = <I>;
398 close I;
399 }
400 return $filecontents;
401}
402
403######################################################################
404# Syntax: fileCompare(file1, file2)
405# Params: file1, string, filename of first file
406# file2, string, filename of second file
407#
408# Purpose: Determines if files are equal, and which one is newer.
409# Returns: 0 if files are equal no matter the timestamp, -1 if file1
410# is newer, 1 if file2 is newer.
411######################################################################
412sub fileCompare {
413 my ($file1, $file2) = @_;
414 my $file1contents = fileContents($file1);
415 my $file2contents = fileContents($file2);
416 if (! -e $file1) { return 1; }
417 if (! -e $file2) { return -1; }
418 return $file1contents ne $file2contents ? (stat("$file2"))[9] <=> (stat("$file1"))[9] : 0;
419}
420
421######################################################################
422# Syntax: copyFile(file, ifile)
423# Params: file, string, filename to create duplicate for
424# ifile, string, destination name of duplicate
425#
426# Purpose: Keeps files in sync so changes in the newer file will be
427# written to the other.
428# Returns: 1 if files were synced, else 0.
429# Warning: Dies if script cannot get write access.
430######################################################################
431sub copyFile
432{
433 my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
434 # Bi-directional synchronization
435 open( I, "< " . $file ) || die "Could not open $file for reading";
436 local $/;
437 binmode I;
438 $filecontents = <I>;
439 close I;
440 if ( open(I, "< " . $ifile) ) {
441 local $/;
442 binmode I;
443 $ifilecontents = <I>;
444 close I;
445 $copy = fileCompare($file, $ifile);
446 $knowdiff = 0,
447 } else {
448 $copy = -1;
449 $knowdiff = 1;
450 }
451
452 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
453 if ( $copy > 0 ) {
454 my $file_dir = dirname($file);
455 mkpath $file_dir, 0777 unless(-e "$file_dir");
456 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
457 local $/;
458 binmode O;
459 print O $ifilecontents;
460 close O;
461 return 1;
462 } elsif ( $copy < 0 ) {
463 my $ifile_dir = dirname($ifile);
464 mkpath $ifile_dir, 0777 unless(-e "$ifile_dir");
465 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
466 local $/;
467 binmode O;
468 print O $filecontents;
469 close O;
470 return 1;
471 }
472 }
473 return 0;
474}
475
476######################################################################
477# Syntax: symlinkFile(file, ifile)
478# Params: file, string, filename to create "symlink" for
479# ifile, string, destination name of symlink
480#
481# Purpose: File is symlinked to ifile (or copied if filesystem doesn't
482# support symlink).
483# Returns: 1 on success, else 0.
484######################################################################
485sub symlinkFile
486{
487 my ($file,$ifile) = @_;
488
489 if ($isunix) {
490 print "symlink created for $file ";
491 if ( $force_relative && ($ifile =~ /^$basedir/)) {
492 my $t = getcwd();
493 my $c = -1;
494 my $p = "../";
495 $t =~ s-^$basedir/--;
496 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
497 $file =~ s-^$basedir/-$p-;
498 print " ($file)\n";
499 }
500 print "\n";
501 return symlink($file, $ifile);
502 }
503 return copyFile($file, $ifile);
504}
505
506######################################################################
507# Syntax: findFiles(dir, match, descend)
508# Params: dir, string, directory to search for name
509# match, string, regular expression to match in dir
510# descend, integer, 0 = non-recursive search
511# 1 = recurse search into subdirectories
512#
513# Purpose: Finds files matching a regular expression.
514# Returns: List of matching files.
515#
516# Examples:
517# findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
518# findFiles("/tmp","^#",0) - finds #* files in /tmp
519######################################################################
520sub findFiles {
521 my ($dir,$match,$descend) = @_;
522 my ($file,$p,@files);
523 local(*D);
524 $dir =~ s=\\=/=g;
525 ($dir eq "") && ($dir = ".");
526 if ( opendir(D,$dir) ) {
527 if ( $dir eq "." ) {
528 $dir = "";
529 } else {
530 ($dir =~ /\/$/) || ($dir .= "/");
531 }
532 foreach $file ( readdir(D) ) {
533 next if ( $file =~ /^\.\.?$/ );
534 $p = $file;
535 ($file =~ /$match/) && (push @files, $p);
536 if ( $descend && -d $p && ! -l $p ) {
537 push @files, &findFiles($p,$match,$descend);
538 }
539 }
540 closedir(D);
541 }
542 return @files;
543}
544
545# --------------------------------------------------------------------
546# "main" function
547# --------------------------------------------------------------------
548
549while ( @ARGV ) {
550 my $var = 0;
551 my $val = 0;
552
553 #parse
554 my $arg = shift @ARGV;
555 if ("$arg" eq "-h" || "$arg" eq "-help" || "$arg" eq "?") {
556 $var = "show_help";
557 $val = "yes";
558 } elsif("$arg" eq "-copy") {
559 $var = "copy";
560 $val = "yes";
561 } elsif("$arg" eq "-o" || "$arg" eq "-outdir") {
562 $var = "output";
563 $val = shift @ARGV;
564 } elsif("$arg" eq "-showonly" || "$arg" eq "-remove-stale" || "$arg" eq "-windows" ||
565 "$arg" eq "-relative" || "$arg" eq "-check-includes") {
566 $var = substr($arg, 1);
567 $val = "yes";
568 } elsif("$arg" =~ /^-no-(.*)$/) {
569 $var = $1;
570 $val = "no";
571 #these are for commandline compat
572 } elsif("$arg" eq "-inc") {
573 $var = "output";
574 $val = shift @ARGV;
575 } elsif("$arg" eq "-module") {
576 $var = "module";
577 $val = shift @ARGV;
578 } elsif("$arg" eq "-show") {
579 $var = "showonly";
580 $val = "yes";
581 } elsif("$arg" eq '*') {
582 # workaround for windows 9x where "%*" expands to "*"
583 $var = 1;
584 }
585
586 #do something
587 if(!$var || "$var" eq "show_help") {
588 print "Unknown option: $arg\n\n" if(!$var);
589 showUsage();
590 } elsif ("$var" eq "copy") {
591 if("$val" eq "yes") {
592 $copy_headers++;
593 } elsif($showonly) {
594 $copy_headers--;
595 }
596 } elsif ("$var" eq "showonly") {
597 if("$val" eq "yes") {
598 $showonly++;
599 } elsif($showonly) {
600 $showonly--;
601 }
602 } elsif ("$var" eq "check-includes") {
603 if("$val" eq "yes") {
604 $check_includes++;
605 } elsif($check_includes) {
606 $check_includes--;
607 }
608 } elsif ("$var" eq "remove-stale") {
609 if("$val" eq "yes") {
610 $remove_stale++;
611 } elsif($remove_stale) {
612 $remove_stale--;
613 }
614 } elsif ("$var" eq "windows") {
615 if("$val" eq "yes") {
616 $force_win++;
617 } elsif($force_win) {
618 $force_win--;
619 }
620 } elsif ("$var" eq "relative") {
621 if("$val" eq "yes") {
622 $force_relative++;
623 } elsif($force_relative) {
624 $force_relative--;
625 }
626 } elsif ("$var" eq "module") {
627 print "module :$val:\n";
628 die "No such module: $val" unless(defined $modules{$val});
629 push @modules_to_sync, $val;
630 } elsif ("$var" eq "output") {
631 my $outdir = $val;
632 if(checkRelative($outdir)) {
633 $out_basedir = getcwd();
634 chomp $out_basedir;
635 $out_basedir .= "/" . $outdir;
636 } else {
637 $out_basedir = $outdir;
638 }
639 # \ -> /
640 $out_basedir =~ s=\\=/=g;
641 }
642}
643@modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
644
645$isunix = checkUnix; #cache checkUnix
646
647# create path
648mkpath "$out_basedir/include", 0777;
649
650my @ignore_headers = ();
651my $class_lib_map_contents = "";
652my @ignore_for_master_contents = ( "qt.h", "qpaintdevicedefs.h" );
653my @ignore_for_include_check = ( "qatomic.h" );
654my @ignore_for_qt_begin_header_check = ( "qiconset.h", "qconfig.h", "qconfig-dist.h", "qconfig-large.h", "qconfig-medium.h", "qconfig-minimal.h", "qconfig-small.h", "qfeatures.h", "qt_windows.h" );
655my @ignore_for_qt_begin_namespace_check = ( "qconfig.h", "qconfig-dist.h", "qconfig-large.h", "qconfig-medium.h", "qconfig-minimal.h", "qconfig-small.h", "qfeatures.h", "qatomic_arch.h", "qatomic_windowsce.h", "qt_windows.h", "qatomic_macosx.h" );
656my @ignore_for_qt_module_check = ( "$modules{QtCore}/arch", "$modules{QtCore}/global", "$modules{QtSql}/drivers", "$modules{QtTest}", "$modules{QtAssistant}", "$modules{QtDesigner}", "$modules{QtUiTools}", "$modules{QtDBus}", "$modules{phonon}" );
657
658foreach (@modules_to_sync) {
659 #iteration info
660 my $lib = $_;
661 my $dir = "$modules{$lib}";
662 my $pathtoheaders = "";
663 $pathtoheaders = "$moduleheaders{$lib}" if ($moduleheaders{$lib});
664
665 #information used after the syncing
666 my $pri_install_classes = "";
667 my $pri_install_files = "";
668
669 my $libcapitals = $lib;
670 $libcapitals =~ y/a-z/A-Z/;
671 my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
672
673 #get dependencies
674 if(-e "$dir/" . basename($dir) . ".pro") {
675 if(open(F, "<$dir/" . basename($dir) . ".pro")) {
676 while(<F>) {
677 my $line = $_;
678 chomp $line;
679 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
680 foreach(split(/ /, "$1")) {
681 $master_contents .= "#include <QtCore/QtCore>\n" if("$_" eq "core");
682 $master_contents .= "#include <QtGui/QtGui>\n" if("$_" eq "gui");
683 $master_contents .= "#include <QtNetwork/QtNetwork>\n" if("$_" eq "network");
684 $master_contents .= "#include <QtSvg/QtSvg>\n" if("$_" eq "svg");
685 $master_contents .= "#include <QtScript/QtScript>\n" if("$_" eq "script");
686 $master_contents .= "#include <QtScriptTools/QtScriptTools>\n" if("$_" eq "scripttools");
687 $master_contents .= "#include <Qt3Support/Qt3Support>\n" if("$_" eq "qt3support");
688 $master_contents .= "#include <QtSql/QtSql>\n" if("$_" eq "sql");
689 $master_contents .= "#include <QtXml/QtXml>\n" if("$_" eq "xml");
690 $master_contents .= "#include <QtXmlPatterns/QtXmlPatterns>\n" if("$_" eq "xmlpatterns");
691 $master_contents .= "#include <QtOpenGL/QtOpenGL>\n" if("$_" eq "opengl");
692 }
693 }
694 }
695 close(F);
696 }
697 }
698
699 #remove the old files
700 if($remove_stale) {
701 my @subdirs = ("$out_basedir/include/$lib");
702 foreach (@subdirs) {
703 my $subdir = "$_";
704 if (opendir DIR, "$subdir") {
705 while(my $t = readdir(DIR)) {
706 my $file = "$subdir/$t";
707 if(-d "$file") {
708 push @subdirs, "$file" unless($t eq "." || $t eq "..");
709 } else {
710 my @files = ("$file");
711 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
712 foreach (@files) {
713 my $file = $_;
714 my $remove_file = 0;
715 if(open(F, "<$file")) {
716 while(<F>) {
717 my $line = $_;
718 chomp $line;
719 if($line =~ /^\#include \"([^\"]*)\"$/) {
720 my $include = $1;
721 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
722 $remove_file = 1 unless(-e "$include");
723 } else {
724 $remove_file = 0;
725 last;
726 }
727 }
728 close(F);
729 unlink "$file" if($remove_file);
730 }
731 }
732 }
733 }
734 closedir DIR;
735 }
736
737 }
738 }
739
740 #create the new ones
741 foreach (split(/;/, $dir)) {
742 my $current_dir = "$_";
743 my $headers_dir = $current_dir;
744 $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
745 #calc subdirs
746 my @subdirs = ($headers_dir);
747 foreach (@subdirs) {
748 my $subdir = "$_";
749 opendir DIR, "$subdir" or next;
750 while(my $t = readdir(DIR)) {
751 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
752 !($t eq "..") && !($t eq ".obj") &&
753 !($t eq ".moc") && !($t eq ".rcc") &&
754 !($t eq ".uic") && !($t eq "build"));
755 }
756 closedir DIR;
757 }
758
759 #calc files and "copy" them
760 foreach (@subdirs) {
761 my $subdir = "$_";
762 my @headers = findFiles("$subdir", "^[-a-z0-9_]*\\.h\$" , 0);
763 foreach (@headers) {
764 my $header = "$_";
765 $header = 0 if("$header" =~ /^ui_.*.h/);
766 foreach (@ignore_headers) {
767 $header = 0 if("$header" eq "$_");
768 }
769 if($header) {
770 my $header_copies = 0;
771 #figure out if it is a public header
772 my $public_header = $header;
773 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
774 $public_header = 0;
775 } else {
776 foreach (@ignore_for_master_contents) {
777 $public_header = 0 if("$header" eq "$_");
778 }
779 }
780
781 my $iheader = $subdir . "/" . $header;
782 my @classes = $public_header ? classNames($iheader) : ();
783 if($showonly) {
784 print "$header [$lib]\n";
785 foreach(@classes) {
786 print "SYMBOL: $_\n";
787 }
788 } else {
789 #find out all the places it goes..
790 my @headers;
791 if ($public_header) {
792 @headers = ( "$out_basedir/include/$lib/$header" );
793 push @headers, "$out_basedir/include/Qt/$header"
794 if ("$lib" ne "phonon" && "$subdir" =~ /^$basedir\/src/);
795
796 foreach(@classes) {
797 my $header_base = basename($header);
798 my $class = $_;
799 if ($class =~ m/::/) {
800 $class =~ s,::,/,g;
801 $class = "../" . $class;
802 }
803 $class_lib_map_contents .= "QT_CLASS_LIB($_, $lib, $header_base)\n";
804 $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", $header, 0));
805 }
806 } else {
807 @headers = ( "$out_basedir/include/$lib/private/$header" );
808 push @headers, "$out_basedir/include/Qt/private/$header"
809 if ("$lib" ne "phonon");
810 }
811 foreach(@headers) { #sync them
812 $header_copies++ if(syncHeader($_, $iheader, $copy_headers));
813 }
814
815 if($public_header) {
816 #put it into the master file
817 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
818
819 #deal with the install directives
820 if($public_header) {
821 my $pri_install_iheader = fixPaths($iheader, $current_dir);
822 foreach(@classes) {
823 my $class = $_;
824 if ($class =~ m/::/) {
825 $class =~ s,::,/,g;
826 $class = "../" . $class;
827 }
828 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
829 $current_dir) . " ";
830 $pri_install_classes .= $class_header
831 unless($pri_install_classes =~ $class_header);
832 }
833 $pri_install_files.= "$pri_install_iheader ";;
834 }
835 }
836 }
837 print "header created for $iheader ($header_copies)\n" if($header_copies > 0);
838 }
839 }
840 }
841 }
842
843 # close the master include:
844 $master_contents .= "#endif\n";
845
846 unless($showonly) {
847 #generate the "master" include file
848 my $master_include = "$out_basedir/include/$lib/$lib";
849 $pri_install_files .= fixPaths($master_include, "$modules{$lib}") . " "; #get the master file installed too
850 if(-e "$master_include") {
851 open MASTERINCLUDE, "<$master_include";
852 local $/;
853 binmode MASTERINCLUDE;
854 my $oldmaster = <MASTERINCLUDE>;
855 close MASTERINCLUDE;
856 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
857 $master_include = 0 if($oldmaster eq $master_contents);
858 }
859 if($master_include && $master_contents) {
860 my $master_dir = dirname($master_include);
861 mkpath $master_dir, 0777;
862 print "header (master) created for $lib\n";
863 open MASTERINCLUDE, ">$master_include";
864 print MASTERINCLUDE "$master_contents";
865 close MASTERINCLUDE;
866 }
867
868 #handle the headers.pri for each module
869 my $headers_pri_contents = "";
870 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
871 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
872 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
873 if(-e "$headers_pri_file") {
874 open HEADERS_PRI_FILE, "<$headers_pri_file";
875 local $/;
876 binmode HEADERS_PRI_FILE;
877 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
878 close HEADERS_PRI_FILE;
879 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
880 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
881 }
882 if($headers_pri_file && $master_contents) {
883 my $headers_pri_dir = dirname($headers_pri_file);
884 mkpath $headers_pri_dir, 0777;
885 print "headers.pri file created for $lib\n";
886 open HEADERS_PRI_FILE, ">$headers_pri_file";
887 print HEADERS_PRI_FILE "$headers_pri_contents";
888 close HEADERS_PRI_FILE;
889 }
890 }
891}
892unless($showonly) {
893 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
894 if(-e "$class_lib_map") {
895 open CLASS_LIB_MAP, "<$class_lib_map";
896 local $/;
897 binmode CLASS_LIB_MAP;
898 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
899 close CLASS_LIB_MAP;
900 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
901 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
902 }
903 if($class_lib_map) {
904 my $class_lib_map_dir = dirname($class_lib_map);
905 mkpath $class_lib_map_dir, 0777;
906 open CLASS_LIB_MAP, ">$class_lib_map";
907 print CLASS_LIB_MAP "$class_lib_map_contents";
908 close CLASS_LIB_MAP;
909 }
910}
911
912if($check_includes) {
913 for (keys(%modules)) {
914 #iteration info
915 my $lib = $_;
916 my $dir = "$modules{$lib}";
917 foreach (split(/;/, $dir)) {
918 my $current_dir = "$_";
919 #calc subdirs
920 my @subdirs = ($current_dir);
921 foreach (@subdirs) {
922 my $subdir = "$_";
923 opendir DIR, "$subdir";
924 while(my $t = readdir(DIR)) {
925 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
926 !($t eq "..") && !($t eq ".obj") &&
927 !($t eq ".moc") && !($t eq ".rcc") &&
928 !($t eq ".uic") && !($t eq "build"));
929 }
930 closedir DIR;
931 }
932
933 foreach (@subdirs) {
934 my $subdir = "$_";
935 my $header_skip_qt_module_test = 0;
936 foreach(@ignore_for_qt_module_check) {
937 foreach (split(/;/, $_)) {
938 $header_skip_qt_module_test = 1 if ("$subdir" =~ /^$_/);
939 }
940 }
941 my @headers = findFiles("$subdir", "^[-a-z0-9_]*\\.h\$" , 0);
942 foreach (@headers) {
943 my $header = "$_";
944 my $header_skip_qt_begin_header_test = 0;
945 my $header_skip_qt_begin_namespace_test = 0;
946 $header = 0 if("$header" =~ /^ui_.*.h/);
947 foreach (@ignore_headers) {
948 $header = 0 if("$header" eq "$_");
949 }
950 if($header) {
951 my $public_header = $header;
952 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
953 $public_header = 0;
954 } else {
955 foreach (@ignore_for_master_contents) {
956 $public_header = 0 if("$header" eq "$_");
957 }
958 if($public_header) {
959 foreach (@ignore_for_include_check) {
960 $public_header = 0 if("$header" eq "$_");
961 }
962 foreach(@ignore_for_qt_begin_header_check) {
963 $header_skip_qt_begin_header_test = 1 if ("$header" eq "$_");
964 }
965 foreach(@ignore_for_qt_begin_namespace_check) {
966 $header_skip_qt_begin_namespace_test = 1 if ("$header" eq "$_");
967 }
968 }
969 }
970
971 my $iheader = $subdir . "/" . $header;
972 if($public_header) {
973 if(open(F, "<$iheader")) {
974 my $qt_module_found = 0;
975 my $qt_begin_header_found = 0;
976 my $qt_end_header_found = 0;
977 my $qt_begin_namespace_found = 0;
978 my $qt_end_namespace_found = 0;
979 my $line;
980 while($line = <F>) {
981 chomp $line;
982 my $output_line = 1;
983 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
984 last;
985 } elsif($line =~ /^ *\# *include/) {
986 my $include = $line;
987 if($line =~ /<.*>/) {
988 $include =~ s,.*<(.*)>.*,$1,;
989 } elsif($line =~ /".*"/) {
990 $include =~ s,.*"(.*)".*,$1,;
991 } else {
992 $include = 0;
993 }
994 if($include) {
995 for (keys(%modules)) {
996 my $trylib = $_;
997 if(-e "$out_basedir/include/$trylib/$include") {
998 print "WARNING: $iheader includes $include when it should include $trylib/$include\n";
999 }
1000 }
1001 }
1002 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1003 $qt_begin_header_found = 1;
1004 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1005 $qt_end_header_found = 1;
1006 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1007 $qt_begin_namespace_found = 1;
1008 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1009 $qt_end_namespace_found = 1;
1010 } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1011 $qt_module_found = 1;
1012 }
1013 }
1014 if ($header_skip_qt_begin_header_test == 0) {
1015 if ($qt_begin_header_found == 0) {
1016 print "WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1017 }
1018
1019 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1020 print "WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1021 }
1022 }
1023
1024 if ($header_skip_qt_begin_namespace_test == 0) {
1025 if ($qt_begin_namespace_found == 0) {
1026 print "WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1027 }
1028
1029 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1030 print "WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1031 }
1032 }
1033
1034 if ($header_skip_qt_module_test == 0) {
1035 if ($qt_module_found == 0) {
1036 print "WARNING: $iheader does not include QT_MODULE\n";
1037 }
1038 }
1039 close(F);
1040 }
1041 }
1042 }
1043 }
1044 }
1045 }
1046 }
1047}
1048
1049exit 0;
Note: See TracBrowser for help on using the repository browser.