bin/syncqt
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 30 5dc02b23752f
--- a/bin/syncqt	Tue Feb 02 00:43:10 2010 +0200
+++ b/bin/syncqt	Fri Apr 16 15:50:13 2010 +0300
@@ -3,7 +3,7 @@
 #
 # Synchronizes Qt header files - internal development tool.
 #
-# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 # Contact: Nokia Corporation (qt-info@nokia.com)
 #
 ######################################################################
@@ -15,6 +15,13 @@
 use Config;
 use strict;
 
+for (my $i = 0; $i < $#ARGV; $i++) {
+    if ($ARGV[$i] eq "-base-dir" && $i < $#ARGV - 1) {
+        $ENV{"QTDIR"} = $ARGV[$i + 1];
+        last;
+    }
+}
+
 die "syncqt: QTDIR not defined" if ! $ENV{"QTDIR"}; # sanity check
 
 # global variables
@@ -61,10 +68,14 @@
 my $force_relative = 0;
 my $check_includes = 0;
 my $copy_headers = 0;
+my $create_uic_class_map = 1;
+my $create_private_headers = 1;
+my $oneway = 0;
 my @modules_to_sync ;
 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
 my $out_basedir = $basedir;
 $out_basedir =~ s=\\=/=g;
+my $out_subdir = 'include';
 
 # functions ----------------------------------------------------------
 
@@ -84,6 +95,10 @@
     print "  -windows              Force platform to Windows          (default: " . ($force_win ? "yes" : "no") . ")\n";
     print "  -showonly             Show action but not perform        (default: " . ($showonly ? "yes" : "no") . ")\n";
     print "  -outdir <PATH>        Specify output directory for sync  (default: $out_basedir)\n";
+    print "  -outsubdir <DIR>      Target subdir under outdir         (default: $out_subdir)\n";
+    print "  -public               Create only public headers         (default: " . ($create_private_headers ? "no" : "yes") . ")\n";
+    print "  -oneway               Don't sync back from outdir        (default: " . ($oneway ? "yes" : "no") . ")\n";
+    print "  -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR> Create headers for <NAME> with original headers in <HEADERDIR> relative to <PROFILEDIR> \n";
     print "  -help                 This help\n";
     exit 0;
 }
@@ -184,6 +199,8 @@
         push @ret, "QtConcurrentFilter"
     } elsif(basename($iheader) eq "qtconcurrentrun.h") {
         push @ret, "QtConcurrentRun"
+    } elsif(basename($iheader) eq "qaudio.h") {
+        push @ret, "QAudio"
     }
 
     my $parsable = "";
@@ -425,7 +442,7 @@
 #          ifile, string, destination name of duplicate
 #
 # Purpose: Keeps files in sync so changes in the newer file will be
-#          written to the other.
+#          written to the other. Don't sync back if $oneway is set.
 # Returns: 1 if files were synced, else 0.
 # Warning: Dies if script cannot get write access.
 ######################################################################
@@ -451,9 +468,10 @@
     }
 
     if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
-	if ( $copy > 0 ) {
+	if ( $copy > 0 && !$oneway) {
 	    my $file_dir = dirname($file);
 	    mkpath $file_dir, 0777 unless(-e "$file_dir");
+	    print "$file $ifile $copy\n";
 	    open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
 	    local $/;
 	    binmode O;
@@ -576,12 +594,28 @@
     } 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 "-base-dir") {
+        # skip, it's been dealt with at the top of the file
+        shift @ARGV;
+        next;
     } elsif("$arg" eq '*') {
         # workaround for windows 9x where "%*" expands to "*"
         $var = 1;
+    } elsif("$arg" eq "-outsubdir") {
+	$var = "outsubdir";
+	$val = shift @ARGV;
+    } elsif("$arg" eq "-public") {
+	$var = "public";
+	$val = "yes";
+    } elsif("$arg" eq "-oneway") {
+	$var = "oneway";
+	$val = "yes";
     }
 
     #do something
@@ -624,10 +658,23 @@
 	} elsif($force_relative) {
 	    $force_relative--;
 	}
+    } elsif ("$var" eq "public") {
+	$create_private_headers = ("$val" eq "yes" ? 0 : 1);
+    } elsif ("$var" eq "oneway") {
+	$oneway = ("$val" eq "yes" ? 1 : 0);
+    } elsif ("$var" eq "outsubdir") {
+	$out_subdir = $val;
     } elsif ("$var" eq "module") {
 	print "module :$val:\n";
 	die "No such module: $val" unless(defined $modules{$val});
 	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;
+        $create_uic_class_map = 0;
+        $create_private_headers = 0;
     } elsif ("$var" eq "output") {
 	my $outdir = $val;
 	if(checkRelative($outdir)) {
@@ -646,7 +693,7 @@
 $isunix = checkUnix; #cache checkUnix
 
 # create path
-mkpath "$out_basedir/include", 0777;
+mkpath "$out_basedir/$out_subdir", 0777;
 
 my @ignore_headers = ();
 my $class_lib_map_contents = "";
@@ -702,7 +749,7 @@
 
     #remove the old files
     if($remove_stale) {
-	my @subdirs = ("$out_basedir/include/$lib");
+	my @subdirs = ("$out_basedir/$out_subdir/$lib");
 	foreach (@subdirs) {
 	    my $subdir = "$_";
 	    if (opendir DIR, "$subdir") {
@@ -712,7 +759,7 @@
 			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");
+			#push @files, "$out_basedir/$out_subdir/Qt/$t" if(-e "$out_basedir/$out_subdir/Qt/$t");
 			foreach (@files) {
 			   my $file = $_;
 			   my $remove_file = 0;
@@ -793,22 +840,29 @@
 			#find out all the places it goes..
 			my @headers;
 			if ($public_header) {
-			    @headers = ( "$out_basedir/include/$lib/$header" );
-			    push @headers, "$out_basedir/include/Qt/$header"
+			    @headers = ( "$out_basedir/$out_subdir/$lib/$header" );
+			    push @headers, "$out_basedir/$out_subdir/Qt/$header"
 			      if ("$lib" ne "phonon" && "$subdir" =~ /^$basedir\/src/);
 
 			    foreach(@classes) {
 				my $header_base = basename($header);
 				my $class = $_;
-				if ($class =~ m/::/) {
-				    $class =~ s,::,/,g;
-				}
+				# Strip namespaces:
+				$class =~ s/^.*:://;
+#				if ($class =~ m/::/) {
+#				   class =~ s,::,/,g;
+#				}
 				$class_lib_map_contents .= "QT_CLASS_LIB($_, $lib, $header_base)\n";
-				$header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0));
+				$header_copies++ if(syncHeader("$out_basedir/$out_subdir/$lib/$class", "$out_basedir/$out_subdir/$lib/$header", 0));
+
+				# KDE-Compat headers for Phonon
+				if ($lib eq "phonon") {
+				    $header_copies++ if (syncHeader("$out_basedir/$out_subdir/phonon_compat/Phonon/$class", "$out_basedir/$out_subdir/$lib/$header", 0));
+				}
 			    }
-			} else {
-			    @headers = ( "$out_basedir/include/$lib/private/$header" );
-			    push @headers, "$out_basedir/include/Qt/private/$header"
+			} elsif ($create_private_headers) {
+			    @headers = ( "$out_basedir/$out_subdir/$lib/private/$header" );
+			    push @headers, "$out_basedir/$out_subdir/Qt/private/$header"
                               if ("$lib" ne "phonon");
 			}
 			foreach(@headers) { #sync them
@@ -824,10 +878,12 @@
 				my $pri_install_iheader = fixPaths($iheader, $current_dir);
 				foreach(@classes) {
 				    my $class = $_;
-				    if ($class =~ m/::/) {
-					$class =~ s,::,/,g;
-				    }
-				    my $class_header = fixPaths("$out_basedir/include/$lib/$class",
+				    # Strip namespaces:
+				    $class =~ s/^.*:://;
+#				    if ($class =~ m/::/) {
+#					$class =~ s,::,/,g;
+#				    }
+				    my $class_header = fixPaths("$out_basedir/$out_subdir/$lib/$class",
 								$current_dir) . " ";
 				    $pri_install_classes .= $class_header
 								unless($pri_install_classes =~ $class_header);
@@ -851,12 +907,8 @@
 
     unless($showonly) {
         my @master_includes;
-        if ($lib eq "phonon") {
-            push @master_includes, "$out_basedir/include/phonon_compat/phonon/phonon";
-            push @master_includes, "$out_basedir/include/phonon/Phonon/Phonon";
-        } else {
-            push @master_includes, "$out_basedir/include/$lib/$lib";
-        }
+	push @master_includes, "$out_basedir/$out_subdir/$lib/$lib";
+	push @master_includes, "$out_basedir/$out_subdir/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
         foreach my $master_include (@master_includes) {
             #generate the "master" include file
             $pri_install_files .= fixPaths($master_include, "$modules{$lib}") . " "; #get the master file installed too
@@ -884,7 +936,7 @@
 	$headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
 	$headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
 	$headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
-        my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
+        my $headers_pri_file = "$out_basedir/$out_subdir/$lib/headers.pri";
         if(-e "$headers_pri_file") {
             open HEADERS_PRI_FILE, "<$headers_pri_file";
             local $/;
@@ -904,7 +956,7 @@
         }
     }
 }
-unless($showonly) {
+unless($showonly || !$create_uic_class_map) {
     my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
     if(-e "$class_lib_map") {
 	open CLASS_LIB_MAP, "<$class_lib_map";
@@ -1009,7 +1061,7 @@
 					if($include) {
 					    for (keys(%modules)) {
 						my $trylib = $_;
-						if(-e "$out_basedir/include/$trylib/$include") {
+						if(-e "$out_basedir/$out_subdir/$trylib/$include") {
 						    print "WARNING: $iheader includes $include when it should include $trylib/$include\n";
 						}
 					    }