Skip to content

Latest commit

 

History

History
executable file
·
1220 lines (1128 loc) · 47.3 KB

syncqt.pl

File metadata and controls

executable file
·
1220 lines (1128 loc) · 47.3 KB
 
Feb 20, 2013
Feb 20, 2013
1
#!/usr/bin/env perl
Sep 13, 2011
Sep 13, 2011
2
3
#############################################################################
##
Feb 11, 2015
Feb 11, 2015
4
5
## Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
## Contact: http://www.qt.io/licensing/
Sep 13, 2011
Sep 13, 2011
6
7
8
##
## This file is part of the build configuration tools of the Qt Toolkit.
##
Feb 11, 2015
Feb 11, 2015
9
## $QT_BEGIN_LICENSE:LGPL21$
Sep 22, 2012
Sep 22, 2012
10
11
12
13
## 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
Feb 11, 2015
Feb 11, 2015
14
15
16
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see http://www.qt.io/terms-conditions. For further
## information use the contact form at http://www.qt.io/contact-us.
Sep 22, 2012
Sep 22, 2012
17
##
Sep 13, 2011
Sep 13, 2011
18
## GNU Lesser General Public License Usage
Sep 22, 2012
Sep 22, 2012
19
## Alternatively, this file may be used under the terms of the GNU Lesser
Feb 11, 2015
Feb 11, 2015
20
21
22
23
24
25
26
27
28
## General Public License version 2.1 or version 3 as published by the Free
## Software Foundation and appearing in the file LICENSE.LGPLv21 and
## LICENSE.LGPLv3 included in the packaging of this file. Please review the
## following information to ensure the GNU Lesser General Public License
## requirements will be met: https://www.gnu.org/licenses/lgpl.html and
## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## As a special exception, The Qt Company gives you certain additional
## rights. These rights are described in The Qt Company LGPL Exception
Sep 13, 2011
Sep 13, 2011
29
30
31
32
33
34
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
## $QT_END_LICENSE$
##
#############################################################################
35
36
37
38
39
40
41
#
# Synchronizes Qt header files - internal development tool.
#
# use packages -------------------------------------------------------
use File::Basename;
use File::Path;
Jun 19, 2012
Jun 19, 2012
42
use File::Spec;
43
use Cwd;
Apr 27, 2011
Apr 27, 2011
44
use Cwd 'abs_path';
45
46
use Config;
use strict;
Jan 26, 2012
Jan 26, 2012
47
use warnings;
Jul 22, 2011
Jul 22, 2011
48
use English qw(-no_match_vars );
49
Jun 1, 2012
Jun 1, 2012
50
51
52
53
54
55
56
57
58
59
60
61
62
63
my $normalizePath_fixDrive = ($^O eq "msys" ? 1 : 0);
######################################################################
# Syntax: normalizePath(\$path)
# Params: Reference to a path that's going to be normalized.
#
# Purpose: Converts the path into a form that can be used as include
# path from C++ sources and qmake's .pro files.
# Only relevant on Windows.
# Returns: -none-
######################################################################
sub normalizePath {
my $s = shift;
$$s =~ s=\\=/=g;
Apr 20, 2013
Apr 20, 2013
64
if ($normalizePath_fixDrive && ($$s =~ m,^/([a-zA-Z])/(.*), || $$s =~ m,^([a-zA-Z]):/(.*),)) {
Jun 1, 2012
Jun 1, 2012
65
66
67
68
$$s = lc($1) . ":/$2";
}
}
Apr 27, 2011
Apr 27, 2011
69
70
# set output basedir to be where ever syncqt is run from
our $out_basedir = getcwd();
Jun 1, 2012
Jun 1, 2012
71
normalizePath(\$out_basedir);
Apr 27, 2011
Apr 27, 2011
72
73
our $basedir;
our $quoted_basedir;
74
Jun 1, 2012
Jun 1, 2012
75
76
# Make sure we use Windows line endings for chomp and friends on Windows.
$INPUT_RECORD_SEPARATOR = "\r\n" if ($^O eq "msys");
77
Apr 27, 2011
Apr 27, 2011
78
# will be defined based on the modules sync.profile
Feb 28, 2014
Feb 28, 2014
79
our (%modules, %moduleheaders, @allmoduleheadersprivate, %classnames, %deprecatedheaders);
Jul 2, 2012
Jul 2, 2012
80
our @qpa_headers = ();
81
Feb 28, 2014
Feb 28, 2014
82
83
84
# will be derived from sync.profile
our %reverse_classnames = ();
85
# global variables (modified by options)
Apr 27, 2011
Apr 27, 2011
86
my $isunix = 0;
87
88
my $module = 0;
my $showonly = 0;
Jul 21, 2011
Jul 21, 2011
89
my $verbose_level = 1;
90
91
92
93
94
95
my $remove_stale = 1;
my $force_win = 0;
my $force_relative = 0;
my $check_includes = 0;
my $copy_headers = 0;
my $create_private_headers = 1;
Sep 11, 2012
Sep 11, 2012
96
my $minimal = 0;
Mar 20, 2013
Mar 20, 2013
97
my $module_version = 0;
98
99
my @modules_to_sync ;
$force_relative = 1 if ( -d "/System/Library/Frameworks" );
Apr 27, 2011
Apr 27, 2011
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# functions ----------------------------------------------------------
######################################################################
# Syntax: showUsage()
# Params: -none-
#
# Purpose: Show the usage of the script.
# Returns: -none-
######################################################################
sub showUsage
{
print "$0 usage:\n";
Apr 27, 2011
Apr 27, 2011
114
115
print " <module directory> Specifies which module to sync header files for (required for shadow builds!)\n\n";
116
117
118
119
120
print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
Sep 11, 2012
Sep 11, 2012
121
print " -minimal Do not create CamelCase headers (default: " . ($minimal ? "yes" : "no") . ")\n";
122
print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
Mar 20, 2013
Mar 20, 2013
123
print " -version <VERSION> Specify the module's version (default: detect from qglobal.h)\n";
Jul 21, 2011
Jul 21, 2011
124
125
126
print " -quiet Only report problems, not activity (same as -verbose 0)\n";
print " -v, -verbose <level> Sets the verbosity level (max. 4) (default: $verbose_level)\n";
print " The short form increases the level by +1\n";
Apr 27, 2011
Apr 27, 2011
127
print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR>\n";
Jun 3, 2011
Jun 3, 2011
128
129
print " Create headers for <NAME> with original headers in\n";
print " <HEADERDIR> relative to <PROFILEDIR> \n";
Apr 27, 2011
Apr 27, 2011
130
print " -private Force copy private headers (default: " . ($create_private_headers ? "yes" : "no") . ")\n";
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
print " -help This help\n";
exit 0;
}
######################################################################
# Syntax: checkUnix()
# Params: -none-
#
# Purpose: Check if script runs on a Unix system or not. Cygwin
# systems are _not_ detected as Unix systems.
# Returns: 1 if a unix system, else 0.
######################################################################
sub checkUnix {
my ($r) = 0;
if ( $force_win != 0) {
return 0;
} elsif ( -f "/bin/uname" ) {
$r = 1;
(-f "\\bin\\uname") && ($r = 0);
} elsif ( -f "/usr/bin/uname" ) {
$r = 1;
(-f "\\usr\\bin\\uname") && ($r = 0);
}
if($r) {
$_ = $Config{'osname'};
$r = 0 if( /(ms)|(cyg)win/i );
}
return $r;
}
sub checkRelative {
my ($dir) = @_;
return 0 if($dir =~ /^\//);
return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
return 1;
}
Jun 3, 2013
Jun 3, 2013
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
######################################################################
# Syntax: shouldMasterInclude(iheader)
# Params: iheader, string, filename to verify inclusion
#
# Purpose: Determines if header should be in the master include file.
# Returns: 0 if file contains "#pragma qt_no_master_include" or not
# able to open, else 1.
######################################################################
sub shouldMasterInclude {
my ($iheader) = @_;
return 0 if (basename($iheader) =~ /_/);
return 0 if (basename($iheader) =~ /qconfig/);
if (open(F, "<$iheader")) {
while (<F>) {
chomp;
return 0 if (/^\#pragma qt_no_master_include$/);
}
close(F);
} else {
return 0;
}
return 1;
}
192
193
194
195
196
197
198
199
200
201
202
######################################################################
# Syntax: classNames(iheader)
# Params: iheader, string, filename to parse for classname "symlinks"
#
# Purpose: Scans through iheader to find all classnames that should be
# synced into library's include structure.
# Returns: List of all class names in a file.
######################################################################
sub classNames {
my @ret;
my ($iheader) = @_;
Apr 27, 2011
Apr 27, 2011
203
Feb 28, 2014
Feb 28, 2014
204
205
206
my $ihdrbase = basename($iheader);
my $classname = $classnames{$ihdrbase};
push @ret, split(/,/, $classname) if ($classname);
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
my $parsable = "";
if(open(F, "<$iheader")) {
while(<F>) {
my $line = $_;
chomp $line;
chop $line if ($line =~ /\r$/);
if($line =~ /^\#/) {
return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
$line = 0;
}
if($line) {
$line =~ s,//.*$,,; #remove c++ comments
$line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
$line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
Apr 10, 2012
Apr 10, 2012
223
$line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE(_[A-Z]+)*[\r\n]*$/); #qt macro
224
$line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
Dec 3, 2014
Dec 3, 2014
225
$line .= ";" if($line =~ m/^QT_WARNING_(PUSH|POP|DISABLE_\w+\(.*\))[\r\n]*$/); # qt macros
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
$parsable .= " " . $line;
}
}
close(F);
}
my $last_definition = 0;
my @namespaces;
for(my $i = 0; $i < length($parsable); $i++) {
my $definition = 0;
my $character = substr($parsable, $i, 1);
if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
for($i+=2; $i < length($parsable); $i++) {
my $end = substr($parsable, $i, 2);
if($end eq "*/") {
$last_definition = $i+2;
$i++;
last;
}
}
} elsif($character eq "{") {
my $brace_depth = 1;
my $block_start = $i + 1;
BLOCK: for($i+=1; $i < length($parsable); $i++) {
my $ignore = substr($parsable, $i, 1);
if($ignore eq "{") {
$brace_depth++;
} elsif($ignore eq "}") {
$brace_depth--;
unless($brace_depth) {
for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
my $end = substr($parsable, $i2, 1);
if($end eq ";" || $end ne " ") {
$definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
$i = $i2 if($end eq ";");
$last_definition = $i + 1;
last BLOCK;
}
}
}
}
}
} elsif($character eq ";") {
$definition = substr($parsable, $last_definition, $i - $last_definition + 1);
$last_definition = $i + 1;
} elsif($character eq "}") {
# a naked } must be a namespace ending
# if it's not a namespace, it's eaten by the loop above
pop @namespaces;
$last_definition = $i + 1;
}
if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
&& substr($parsable, $i+1, 1) eq "{") {
push @namespaces, $1;
# Eat the opening { so that the condensing loop above doesn't see it
$i++;
$last_definition = $i + 1;
}
if($definition) {
$definition =~ s=[\n\r]==g;
my @symbols;
Aug 26, 2012
Aug 26, 2012
290
my $post_kw = qr/Q_DECL_FINAL|final|sealed/; # add here macros and keywords that go after the class-name of a class definition
291
292
293
294
if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
push @symbols, $1;
} elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
push @symbols, $2;
Jul 8, 2014
Jul 8, 2014
295
} elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ <>]* +)?((?!$post_kw)[^<\s]+) ?(<[^>]*> ?)?\s*(?:$post_kw)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/o) {
296
297
298
299
300
301
push @symbols, $4;
} elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
push @symbols, "Q" . $1 . "Iterator";
push @symbols, "QMutable" . $1 . "Iterator";
}
Jan 27, 2012
Jan 27, 2012
302
our $publicclassregexp;
303
304
foreach my $symbol (@symbols) {
$symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
Jan 27, 2012
Jan 27, 2012
305
Feb 28, 2014
Feb 28, 2014
306
307
my $revhdr = $reverse_classnames{$symbol};
next if (defined($revhdr) and $revhdr ne $ihdrbase);
Dec 13, 2012
Dec 13, 2012
308
if ($symbol =~ /^Q[^:]*$/) { # no-namespace, starting with Q
Jan 27, 2012
Jan 27, 2012
309
310
311
312
push @ret, $symbol;
} elsif (defined($publicclassregexp)) {
push @ret, $symbol if ($symbol =~ $publicclassregexp);
}
313
314
315
316
317
318
}
}
}
return @ret;
}
Jul 21, 2011
Jul 21, 2011
319
320
321
322
323
324
325
326
327
sub make_path {
my ($dir, $lib, $be_verbose) = @_;
unless(-e $dir) {
mkpath $dir;
$dir = "<outbase>" . substr($dir, length($out_basedir)) if ($be_verbose < 3);
print "$lib: mkpath $dir\n" if ($be_verbose > 1);
}
}
328
329
330
331
332
333
334
335
336
337
338
######################################################################
# Syntax: syncHeader(header, iheader, copy, timestamp)
# Params: header, string, filename to create "symlink" for
# iheader, string, destination name of symlink
# copy, forces header to be a copy of iheader
# timestamp, the requested modification time if copying
#
# Purpose: Syncronizes header to iheader
# Returns: 1 if successful, else 0.
######################################################################
sub syncHeader {
Jul 21, 2011
Jul 21, 2011
339
my ($lib, $header, $iheader, $copy, $ts) = @_;
Jun 1, 2012
Jun 1, 2012
340
341
normalizePath(\$iheader);
normalizePath(\$header);
Jul 21, 2011
Jul 21, 2011
342
return copyFile($lib, $iheader, $header) if($copy);
343
344
345
unless(-e $header) {
my $header_dir = dirname($header);
Jul 21, 2011
Jul 21, 2011
346
make_path($header_dir, $lib, $verbose_level);
347
348
349
#write it
my $iheader_out = fixPaths($iheader, $header_dir);
Feb 23, 2012
Feb 23, 2012
350
open(HEADER, ">$header") || die "Could not open $header for writing: $!\n";
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
print HEADER "#include \"$iheader_out\"\n";
close HEADER;
if(defined($ts)) {
utime(time, $ts, $header) or die "$iheader, $header";
}
return 1;
}
return 0;
}
######################################################################
# Syntax: fixPaths(file, dir)
# Params: file, string, filepath to be made relative to dir
# dir, string, dirpath for point of origin
#
# Purpose: file is made relative (if possible) of dir.
# Returns: String with the above applied conversion.
######################################################################
Jun 19, 2012
Jun 19, 2012
369
370
371
372
373
374
375
376
sub cleanupPath {
my ($file) = @_;
normalizePath(\$file);
while ($file =~ s,/[^/]+/\.\./,/,) {}
return $file;
}
377
378
sub fixPaths {
my ($file, $dir) = @_;
Jun 19, 2012
Jun 19, 2012
379
380
381
382
my $out = File::Spec->abs2rel(cleanupPath($file), cleanupPath($dir));
$out =~ s,\\,/,g;
return $out;
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
}
######################################################################
# Syntax: fileContents(filename)
# Params: filename, string, filename of file to return contents
#
# Purpose: Get the contents of a file.
# Returns: String with contents of the file, or empty string if file
# doens't exist.
# Warning: Dies if it does exist but script cannot get read access.
######################################################################
sub fileContents {
my ($filename) = @_;
my $filecontents = "";
if (-e $filename) {
open(I, "< $filename") || die "Could not open $filename for reading, read block?";
local $/;
binmode I;
$filecontents = <I>;
close I;
}
return $filecontents;
}
Jun 3, 2013
Jun 3, 2013
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
######################################################################
# Syntax: writeFile(filename, contents)
# Params: filename, string, filename of file to write
# contents, string, new contents for the file
#
# Purpose: Write file with given contents. If new contents match old
# ones, do no change the file's timestamp.
# Returns: 1 if the file's contents changed.
######################################################################
sub writeFile {
my ($filename, $contents, $lib, $what) = @_;
my $oldcontents = fileContents($filename);
$oldcontents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
if ($oldcontents ne $contents) {
open(O, "> " . $filename) || die "Could not open $filename for writing: $!\n";
print O $contents;
close O;
if ($lib && $verbose_level) {
my $action = ($oldcontents eq "") ? "created" : "updated";
print "$lib: $action $what\n";
}
return 1;
}
return 0;
}
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
######################################################################
# Syntax: fileCompare(file1, file2)
# Params: file1, string, filename of first file
# file2, string, filename of second file
#
# Purpose: Determines if files are equal, and which one is newer.
# Returns: 0 if files are equal no matter the timestamp, -1 if file1
# is newer, 1 if file2 is newer.
######################################################################
sub fileCompare {
my ($file1, $file2) = @_;
my $file1contents = fileContents($file1);
my $file2contents = fileContents($file2);
if (! -e $file1) { return 1; }
if (! -e $file2) { return -1; }
return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
}
######################################################################
# Syntax: copyFile(file, ifile)
# Params: file, string, filename to create duplicate for
# ifile, string, destination name of duplicate
#
# Purpose: Keeps files in sync so changes in the newer file will be
# written to the other.
# Returns: 1 if files were synced, else 0.
# Warning: Dies if script cannot get write access.
######################################################################
sub copyFile
{
Jul 21, 2011
Jul 21, 2011
463
my ($lib, $file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# Bi-directional synchronization
open( I, "< " . $file ) || die "Could not open $file for reading";
local $/;
binmode I;
$filecontents = <I>;
close I;
if ( open(I, "< " . $ifile) ) {
local $/;
binmode I;
$ifilecontents = <I>;
close I;
$copy = fileCompare($file, $ifile);
$knowdiff = 0,
} else {
$copy = -1;
$knowdiff = 1;
}
if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
if ( $copy > 0 ) {
my $file_dir = dirname($file);
Jul 21, 2011
Jul 21, 2011
485
make_path($file_dir, $lib, $verbose_level);
486
487
488
489
490
491
492
493
494
open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
local $/;
binmode O;
print O $ifilecontents;
close O;
utime time, (stat($ifile))[9], $file;
return 1;
} elsif ( $copy < 0 ) {
my $ifile_dir = dirname($ifile);
Jul 21, 2011
Jul 21, 2011
495
make_path($ifile_dir, $lib, $verbose_level);
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
local $/;
binmode O;
print O $filecontents;
close O;
utime time, (stat($file))[9], $ifile;
return 1;
}
}
return 0;
}
######################################################################
# Syntax: findFiles(dir, match, descend)
# Params: dir, string, directory to search for name
# match, string, regular expression to match in dir
# descend, integer, 0 = non-recursive search
# 1 = recurse search into subdirectories
#
# Purpose: Finds files matching a regular expression.
# Returns: List of matching files.
#
# Examples:
# findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
# findFiles("/tmp","^#",0) - finds #* files in /tmp
######################################################################
sub findFiles {
my ($dir,$match,$descend) = @_;
my ($file,$p,@files);
local(*D);
Jun 1, 2012
Jun 1, 2012
526
normalizePath(\$dir);
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
($dir eq "") && ($dir = ".");
if ( opendir(D,$dir) ) {
if ( $dir eq "." ) {
$dir = "";
} else {
($dir =~ /\/$/) || ($dir .= "/");
}
foreach $file ( sort readdir(D) ) {
next if ( $file =~ /^\.\.?$/ );
$p = $file;
($file =~ /$match/) && (push @files, $p);
if ( $descend && -d $p && ! -l $p ) {
push @files, &findFiles($p,$match,$descend);
}
}
closedir(D);
}
return @files;
}
Aug 28, 2012
Aug 28, 2012
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
sub listSubdirs {
my @subdirs = @_;
foreach my $subdir (@subdirs) {
opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
foreach my $t (sort readdir(DIR)) {
push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
!($t eq "..") && !($t eq ".obj") &&
!($t eq ".moc") && !($t eq ".rcc") &&
!($t eq ".uic") && !($t eq "build") &&
!($t eq "doc"));
}
closedir DIR;
}
return @subdirs;
}
Apr 27, 2011
Apr 27, 2011
563
564
565
566
567
568
569
570
######################################################################
# Syntax: loadSyncProfile()
#
# Purpose: Locates the sync.profile.
# Returns: Hashmap of module name -> directory.
######################################################################
sub loadSyncProfile {
my ($srcbase, $outbase) = @_;
Jul 21, 2011
Jul 21, 2011
571
572
573
574
if ($verbose_level) {
print("<srcbase> = $$srcbase \n");
print("<outbase> = $$outbase \n");
}
Apr 27, 2011
Apr 27, 2011
575
576
577
578
579
580
581
my $syncprofile = "$$srcbase/sync.profile";
my $result;
unless ($result = do "$syncprofile") {
die "syncqt couldn't parse $syncprofile: $@" if $@;
die "syncqt couldn't execute $syncprofile: $!" unless defined $result;
}
Feb 28, 2014
Feb 28, 2014
582
583
584
585
586
587
588
for my $fn (keys %classnames) {
for my $cn (split(/,/, $classnames{$fn})) {
$reverse_classnames{$cn} = $fn;
}
}
Apr 27, 2011
Apr 27, 2011
589
590
591
return $result;
}
Jun 19, 2012
Jun 19, 2012
592
593
594
595
596
597
sub basePrettify {
my ($arg) = @_;
$$arg =~ s,^\Q$basedir\E,<srcbase>,;
$$arg =~ s,^\Q$out_basedir\E,<outbase>,;
}
Jun 19, 2012
Jun 19, 2012
598
599
600
601
602
603
sub cleanPath {
my ($arg) = @_;
while ($arg =~ s,[^/]+/\.\.(/|$),,) {}
return $arg;
}
Apr 27, 2011
Apr 27, 2011
604
605
606
607
sub locateSyncProfile
{
my ($directory) = @_;
$directory = abs_path($directory);
Feb 9, 2012
Feb 9, 2012
608
609
610
611
while (1) {
my $file = $directory."/sync.profile";
return $file if (-e $file);
my $odir = $directory;
Apr 27, 2011
Apr 27, 2011
612
$directory = dirname($directory);
Feb 9, 2012
Feb 9, 2012
613
return undef if ($directory eq $odir);
Apr 27, 2011
Apr 27, 2011
614
615
616
}
}
Jul 2, 2012
Jul 2, 2012
617
618
619
620
621
622
623
624
625
sub isQpaHeader
{
my ($header) = @_;
foreach my $qpa_header (@qpa_headers) {
return 1 if ($header =~ $qpa_header);
}
return 0;
}
Apr 27, 2011
Apr 27, 2011
626
627
# check if this is an in-source build, and if so use that as the basedir too
$basedir = locateSyncProfile($out_basedir);
May 2, 2011
May 2, 2011
628
629
if ($basedir) {
$basedir = dirname($basedir) ;
Jun 1, 2012
Jun 1, 2012
630
normalizePath(\$basedir);
May 2, 2011
May 2, 2011
631
632
$quoted_basedir = "\Q$basedir";
}
Apr 27, 2011
Apr 27, 2011
633
634
635
636
637
638
639
640
641
642
643
# --------------------------------------------------------------------
# "main" function
# --------------------------------------------------------------------
while ( @ARGV ) {
my $var = 0;
my $val = 0;
#parse
my $arg = shift @ARGV;
Apr 27, 2011
Apr 27, 2011
644
if ($arg eq "-h" || $arg eq "-help" || $arg eq "-?" || $arg eq "?") {
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
$var = "show_help";
$val = "yes";
} elsif($arg eq "-copy") {
$var = "copy";
$val = "yes";
} elsif($arg eq "-o" || $arg eq "-outdir") {
$var = "output";
$val = shift @ARGV;
} elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
$arg eq "-relative" || $arg eq "-check-includes") {
$var = substr($arg, 1);
$val = "yes";
} elsif($arg =~ /^-no-(.*)$/) {
$var = $1;
$val = "no";
#these are for commandline compat
} elsif($arg eq "-inc") {
$var = "output";
$val = shift @ARGV;
} elsif($arg eq "-module") {
$var = "module";
$val = shift @ARGV;
} elsif($arg eq "-separate-module") {
$var = "separate-module";
$val = shift @ARGV;
} elsif($arg eq "-show") {
$var = "showonly";
$val = "yes";
} elsif($arg eq "-quiet") {
Jul 21, 2011
Jul 21, 2011
674
675
676
677
$var = "verbose";
$val = "0";
} elsif($arg eq "-v") {
$var = "verbose";
678
$val = "yes";
Jul 21, 2011
Jul 21, 2011
679
680
681
} elsif($arg eq "-verbose") {
$var = "verbose";
$val = shift @ARGV;
Sep 11, 2012
Sep 11, 2012
682
683
684
} elsif($arg eq "-minimal") {
$var = "minimal";
$val = "yes";
Apr 27, 2011
Apr 27, 2011
685
686
687
} elsif($arg eq "-private") {
$var = "create_private_headers";
$val = "yes";
Mar 20, 2013
Mar 20, 2013
688
689
} elsif($arg eq "-version") {
$var = "version";
Apr 27, 2011
Apr 27, 2011
690
$val = shift @ARGV;
Apr 27, 2011
Apr 27, 2011
691
692
693
694
695
696
697
} elsif($arg =~/^-/) {
print "Unknown option: $arg\n\n" if(!$var);
showUsage();
} else {
$basedir = locateSyncProfile($arg);
die "Could not find a sync.profile for '$arg'\n" if (!$basedir);
$basedir = dirname($basedir);
Jun 1, 2012
Jun 1, 2012
698
normalizePath(\$basedir);
May 2, 2011
May 2, 2011
699
$quoted_basedir = "\Q$basedir";
Apr 27, 2011
Apr 27, 2011
700
$var = "ignore";
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
}
#do something
if(!$var || $var eq "show_help") {
print "Unknown option: $arg\n\n" if(!$var);
showUsage();
} elsif ($var eq "copy") {
if($val eq "yes") {
$copy_headers++;
} elsif($showonly) {
$copy_headers--;
}
} elsif ($var eq "showonly") {
if($val eq "yes") {
$showonly++;
} elsif($showonly) {
$showonly--;
}
Jul 21, 2011
Jul 21, 2011
719
} elsif ($var eq "verbose") {
720
if($val eq "yes") {
Jul 21, 2011
Jul 21, 2011
721
722
723
724
725
$verbose_level++;
} elsif($val eq "no" && $verbose_level) {
$verbose_level--;
} else {
$verbose_level = int($val);
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
}
} elsif ($var eq "check-includes") {
if($val eq "yes") {
$check_includes++;
} elsif($check_includes) {
$check_includes--;
}
} elsif ($var eq "remove-stale") {
if($val eq "yes") {
$remove_stale++;
} elsif($remove_stale) {
$remove_stale--;
}
} elsif ($var eq "windows") {
if($val eq "yes") {
$force_win++;
} elsif($force_win) {
$force_win--;
}
} elsif ($var eq "relative") {
if($val eq "yes") {
$force_relative++;
} elsif($force_relative) {
$force_relative--;
}
Sep 11, 2012
Sep 11, 2012
751
752
753
754
755
756
} elsif ($var eq "minimal") {
if($val eq "yes") {
$minimal++;
} elsif($minimal) {
$minimal--;
}
757
758
759
760
761
762
763
} elsif ($var eq "module") {
push @modules_to_sync, $val;
} elsif ($var eq "separate-module") {
my ($module, $prodir, $headerdir) = split(/:/, $val);
$modules{$module} = $prodir;
push @modules_to_sync, $module;
$moduleheaders{$module} = $headerdir;
Mar 20, 2013
Mar 20, 2013
764
} elsif ($var eq "version") {
Apr 27, 2011
Apr 27, 2011
765
if($val) {
Mar 20, 2013
Mar 20, 2013
766
$module_version = $val;
Apr 27, 2011
Apr 27, 2011
767
} else {
Mar 20, 2013
Mar 20, 2013
768
die "The -version option requires an argument";
Apr 27, 2011
Apr 27, 2011
769
}
770
771
772
773
774
775
776
777
778
} elsif ($var eq "output") {
my $outdir = $val;
if(checkRelative($outdir)) {
$out_basedir = getcwd();
chomp $out_basedir;
$out_basedir .= "/" . $outdir;
} else {
$out_basedir = $outdir;
}
Jun 1, 2012
Jun 1, 2012
779
normalizePath(\$out_basedir);
780
781
}
}
Apr 27, 2011
Apr 27, 2011
782
783
784
785
# if we have no $basedir we cannot be sure which sources you want, so die
die "Could not find any sync.profile for your module!\nPass <module directory> to syncqt to sync your header files.\nsyncqt failed" if (!$basedir);
Aug 4, 2011
Aug 4, 2011
786
our @ignore_headers = ();
Apr 27, 2011
Apr 27, 2011
787
788
789
790
our @ignore_for_master_contents = ();
our @ignore_for_include_check = ();
our @ignore_for_qt_begin_namespace_check = ();
our @ignore_for_qt_module_check = ();
Jun 19, 2012
Jun 19, 2012
791
our %inject_headers = ();
Apr 27, 2011
Apr 27, 2011
792
Apr 27, 2011
Apr 27, 2011
793
794
795
# load the module's sync.profile here, before we can
loadSyncProfile(\$basedir, \$out_basedir);
796
797
@modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
Aug 29, 2011
Aug 29, 2011
798
799
my %allmoduleheadersprivate = map { $_ => 1 } @allmoduleheadersprivate;
800
801
$isunix = checkUnix; #cache checkUnix
Mar 20, 2013
Mar 20, 2013
802
803
804
805
806
807
if (!$module_version) {
my $filco = fileContents($basedir."/src/corelib/global/qglobal.h");
if ($filco !~ m,.*^#[ \t]*define[ \t]+QT_VERSION_STR[ \t]+"([^"]+)".*,sm) {
die "Cannot determine Qt/Module version. Use -version.\n";
}
$module_version = $1;
Jun 19, 2012
Jun 19, 2012
808
}
809
foreach my $lib (@modules_to_sync) {
Sep 19, 2012
Sep 19, 2012
810
811
die "No such module: $lib" unless(defined $modules{$lib});
812
#iteration info
Jun 10, 2013
Jun 10, 2013
813
814
815
my $module = $modules{$lib};
my $is_qt = !($module =~ s/^!//);
my @dirs = split(/;/, $module);
Dec 4, 2012
Dec 4, 2012
816
my $dir = $dirs[0];
May 2, 2011
May 2, 2011
817
818
819
820
my $pathtoheaders = "";
$pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
Aug 29, 2011
Aug 29, 2011
821
822
823
my $allheadersprivate = 0;
$allheadersprivate = 1 if $allmoduleheadersprivate{$lib};
824
825
826
827
#information used after the syncing
my $pri_install_classes = "";
my $pri_install_files = "";
my $pri_install_pfiles = "";
May 8, 2012
May 8, 2012
828
my $pri_install_qpafiles = "";
Feb 28, 2014
Feb 28, 2014
829
my $pri_injections = "";
830
Jun 3, 2013
Jun 3, 2013
831
832
833
834
835
836
my $libcapitals = uc($lib);
my $master_contents =
"#ifndef QT_".$libcapitals."_MODULE_H\n" .
"#define QT_".$libcapitals."_MODULE_H\n" .
"#include <$lib/${lib}Depends>\n";
837
838
#remove the old files
if($remove_stale) {
Jun 19, 2012
Jun 19, 2012
839
840
841
842
843
844
845
846
847
my %injections = ();
for my $p (keys %inject_headers) {
next unless ($p =~ /^\Q$dir\E(\/|$)/);
my $sp = $p;
$sp =~ s,^\Q$basedir\E/,$out_basedir/,;
for my $n (@{$inject_headers{$p}}) {
$injections{$sp."/".$n} = 1;
}
}
848
849
850
my @subdirs = ("$out_basedir/include/$lib");
foreach my $subdir (@subdirs) {
if (opendir DIR, $subdir) {
Jul 27, 2012
Jul 27, 2012
851
foreach my $t (sort { $b cmp $a } readdir(DIR)) {
852
853
854
855
856
857
858
859
860
861
862
863
864
865
my $file = "$subdir/$t";
if(-d $file) {
push @subdirs, $file unless($t eq "." || $t eq "..");
} else {
my @files = ($file);
#push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
foreach my $file (@files) {
my $remove_file = 0;
if(open(F, "<$file")) {
while(my $line = <F>) {
chomp $line;
if($line =~ /^\#include \"([^\"]*)\"$/) {
my $include = $1;
$include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
Jun 19, 2012
Jun 19, 2012
866
$remove_file = 1 unless(-e $include or defined $injections{cleanPath($include)});
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
} else {
$remove_file = 0;
last;
}
}
close(F);
unlink $file if($remove_file);
}
}
}
}
closedir DIR;
}
}
}
#create the new ones
Dec 4, 2012
Dec 4, 2012
885
foreach my $current_dir (@dirs) {
Dec 4, 2012
Dec 4, 2012
886
887
my $thisprivate = 0;
($current_dir =~ s/^\^//) and $thisprivate = 1;
Oct 20, 2011
Oct 20, 2011
888
889
890
891
892
my @headers_paths = split(/;/, $pathtoheaders);
if (@headers_paths) {
@headers_paths = map { "$current_dir/$_" } @headers_paths;
} else {
push @headers_paths, $current_dir;
893
894
}
Oct 20, 2011
Oct 20, 2011
895
896
foreach my $headers_dir (@headers_paths) {
#calc subdirs
Aug 28, 2012
Aug 28, 2012
897
my @subdirs = listSubdirs($headers_dir);
Oct 20, 2011
Oct 20, 2011
898
899
900
901
#calc files and "copy" them
foreach my $subdir (@subdirs) {
my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
Feb 28, 2014
Feb 28, 2014
902
903
904
905
906
907
if (defined $inject_headers{$subdir}) {
foreach my $if (@{$inject_headers{$subdir}}) {
@headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
push @headers, "*".$if;
}
}
Oct 20, 2011
Oct 20, 2011
908
909
my $header_dirname = "";
foreach my $header (@headers) {
Feb 28, 2014
Feb 28, 2014
910
my $shadow = ($header =~ s/^\*//);
Oct 20, 2011
Oct 20, 2011
911
912
913
$header = 0 if($header =~ /^ui_.*.h/);
foreach (@ignore_headers) {
$header = 0 if($header eq $_);
914
}
Oct 20, 2011
Oct 20, 2011
915
916
917
918
if($header) {
my $header_copies = 0;
#figure out if it is a public header
my $public_header = $header;
May 7, 2012
May 7, 2012
919
my $qpa_header = 0;
Jul 2, 2012
Jul 2, 2012
920
if(isQpaHeader($public_header)) {
May 7, 2012
May 7, 2012
921
922
$public_header = 0;
$qpa_header = 1;
Dec 4, 2012
Dec 4, 2012
923
} elsif($allheadersprivate || $thisprivate || $public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
Oct 20, 2011
Oct 20, 2011
924
925
926
927
928
$public_header = 0;
} else {
foreach (@ignore_for_master_contents) {
$public_header = 0 if($header eq $_);
}
929
}
Oct 20, 2011
Oct 20, 2011
930
931
my $iheader = $subdir . "/" . $header;
Feb 28, 2014
Feb 28, 2014
932
$iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
Jun 10, 2013
Jun 10, 2013
933
my @classes = $public_header && (!$minimal && $is_qt) ? classNames($iheader) : ();
Oct 20, 2011
Oct 20, 2011
934
935
936
937
if($showonly) {
print "$header [$lib]\n";
foreach(@classes) {
print "SYMBOL: $_\n";
938
}
Oct 20, 2011
Oct 20, 2011
939
} else {
Feb 28, 2014
Feb 28, 2014
940
my $ts = $shadow ? 0 : (stat($iheader))[9];
Oct 20, 2011
Oct 20, 2011
941
#find out all the places it goes..
Feb 28, 2014
Feb 28, 2014
942
my $oheader;
Oct 20, 2011
Oct 20, 2011
943
if ($public_header) {
Feb 28, 2014
Feb 28, 2014
944
$oheader = "$out_basedir/include/$lib/$header";
Oct 20, 2011
Oct 20, 2011
945
946
947
948
949
950
951
952
foreach my $full_class (@classes) {
my $header_base = basename($header);
# Strip namespaces:
my $class = $full_class;
$class =~ s/^.*:://;
# if ($class =~ m/::/) {
# class =~ s,::,/,g;
# }
Nov 14, 2011
Nov 14, 2011
953
Feb 28, 2014
Feb 28, 2014
954
$header_copies++ if (!$shadow && syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
Nov 14, 2011
Nov 14, 2011
955
}
May 7, 2012
May 7, 2012
956
} elsif ($create_private_headers && !$qpa_header) {
Feb 28, 2014
Feb 28, 2014
957
$oheader = "$out_basedir/include/$lib/$module_version/$lib/private/$header";
May 7, 2012
May 7, 2012
958
} elsif ($create_private_headers) {
Feb 28, 2014
Feb 28, 2014
959
$oheader = "$out_basedir/include/$lib/$module_version/$lib/qpa/$header";
May 2, 2011
May 2, 2011
960
}
Feb 28, 2014
Feb 28, 2014
961
$header_copies++ if (!$shadow && syncHeader($lib, $oheader, $iheader, $copy_headers, $ts));
962
Feb 28, 2014
Feb 28, 2014
963
my $pri_install_iheader = fixPaths($iheader, $dir);
Feb 28, 2014
Feb 28, 2014
964
my $injection = "";
965
if($public_header) {
Jun 3, 2013
Jun 3, 2013
966
#put it into the master file
Feb 28, 2014
Feb 28, 2014
967
$master_contents .= "#include \"$public_header\"\n" if (!$shadow && shouldMasterInclude($iheader));
Jun 3, 2013
Jun 3, 2013
968
Oct 20, 2011
Oct 20, 2011
969
#deal with the install directives
Feb 28, 2014
Feb 28, 2014
970
971
972
973
974
975
976
977
978
foreach my $class (@classes) {
# Strip namespaces:
$class =~ s/^.*:://;
# if ($class =~ m/::/) {
# $class =~ s,::,/,g;
# }
my $class_header = fixPaths("$out_basedir/include/$lib/$class", $dir) . " ";
$pri_install_classes .= $class_header
unless($pri_install_classes =~ $class_header);
Feb 28, 2014
Feb 28, 2014
979
$injection .= ":$class";
980
}
Feb 28, 2014
Feb 28, 2014
981
$pri_install_files.= "$pri_install_iheader ";;
Oct 20, 2011
Oct 20, 2011
982
}
May 8, 2012
May 8, 2012
983
984
985
elsif ($qpa_header) {
$pri_install_qpafiles.= "$pri_install_iheader ";;
}
Oct 20, 2011
Oct 20, 2011
986
987
else {
$pri_install_pfiles.= "$pri_install_iheader ";;
988
}
Feb 28, 2014
Feb 28, 2014
989
990
991
$pri_injections .= fixPaths($iheader, "$out_basedir/include/$lib")
.":".fixPaths($oheader, "$out_basedir/include/$lib")
.$injection." " if ($shadow);
992
}
Jul 21, 2011
Jul 21, 2011
993
Oct 20, 2011
Oct 20, 2011
994
995
if ($verbose_level && $header_copies) {
my $new_header_dirname = dirname($iheader);
Jun 19, 2012
Jun 19, 2012
996
basePrettify(\$new_header_dirname) if ($new_header_dirname && $verbose_level < 2);
Oct 20, 2011
Oct 20, 2011
997
998
999
1000
my $header_base = basename($iheader);
if ($verbose_level < 3) {
my $line_prefix = ",";
if ($new_header_dirname ne $header_dirname) {