Index: bin/build.pl
===================================================================
RCS file: /cvs/tools/solenv/bin/build.pl,v
retrieving revision 1.148
retrieving revision 1.148.8.1
diff -u -r1.148 -r1.148.8.1
--- bin/build.pl	29 Mar 2006 12:47:12 -0000	1.148
+++ bin/build.pl	20 Apr 2006 13:20:30 -0000	1.148.8.1
@@ -136,7 +136,7 @@
     $no_projects = 0;
     $only_dependent = 0;
     $build_from = '';
-    $build_from_opt = '';
+    $build_all_cont = '';
     $build_since = '';
     $dlv_switch = '';
     $child = 0;
@@ -180,6 +180,8 @@
     $chekoutmissing = 1; # chekout missing modules (links still will be broken anyway)
     $mkout = CorrectPath("$ENV{SOLARENV}/bin/mkout.pl");
     %weights_hash = (); # hash contains info about how many modules are dependent from one module
+    %weight_stored = ();
+    $grab_output = 1;
     
 ### main ###
 
@@ -231,8 +233,8 @@
         } else {
             print_error ("Cannot open file $cmd_file");
         };
-    } elsif ($show) {
-        select STDERR;
+#    } elsif ($show) {
+#        select STDOUT;
     };
 
     print $new_line;
@@ -340,6 +342,39 @@
 };
 
 #
+# This procedure implements complete in-depth weights search
+# it's working, but very slow, so switched off in favor of the
+# last (simplified) implementation... 
+#
+#sub store_weights {
+#    my $deps_hash = shift;
+#    $weights_hash{$_} = {} foreach (keys %$deps_hash);
+#    foreach (keys %$deps_hash) {
+#        foreach my $module_deps_hash ($$deps_hash{$_}) {
+#            foreach my $dependency (keys %$module_deps_hash) {
+#                ${$weights_hash{$dependency}}{$_}++;
+#            };
+#        };
+#    };
+#    my $current_prj_preq = $$deps_hash{$CurrentPrj};
+#    foreach (keys %$current_prj_preq) {
+#        accumulate_weights($deps_hash, $_);
+#    };
+#};
+
+#sub accumulate_weights {
+#    my ($deps_hash, $module) = @_;
+#    my @prerequisites = keys %{$$deps_hash{$module}};
+#    my @is_prereq_for = keys %{$weights_hash{$module}};
+#    foreach my $prereq_module (@prerequisites) {
+##        next if (defined $weight_stored{$prereq_module});
+##        $weight_stored{$prereq_module}++;
+#        ${$weights_hash{$prereq_module}}{$_}++ foreach @is_prereq_for;
+#        accumulate_weights($deps_hash, $prereq_module);
+#    };
+#};
+
+#
 # Build everything that should be built
 #
 sub BuildAll {
@@ -347,14 +382,14 @@
         my ($Prj, $PrjDir, $orig_prj);
         GetParentDeps( $CurrentPrj, \%global_deps_hash);
         modules_classify(keys %global_deps_hash);
+        store_weights(\%global_deps_hash);
         prepare_build_from(\%global_deps_hash) if ($build_from);
         prepare_incompatible_build(\%global_deps_hash) if ($incompatible);
-        if ($build_from_opt || $build_since) {
-            prepare_build_from_opt(\%global_deps_hash);
+        if ($build_all_cont || $build_since) {
+            prepare_build_all_cont(\%global_deps_hash);
         };
         $modules_number = scalar keys %global_deps_hash;
         initialize_html_info($_) foreach (keys %global_deps_hash);
-        store_weights(\%global_deps_hash);
         if ($QuantityToBuild) {
             build_multiprocessing();
             return;
@@ -448,7 +483,10 @@
             if (!-d $log_dir) {
                  system("$perl $mkout");
             };
-            $error_code = system ("$dmake >& $log_file");
+            $error_code = system ("$dmake > $log_file 2>&1");
+            if (!$grab_output && -f $log_file) {
+                system("cat $log_file");
+            };
         } else {
             $error_code = system ("$dmake");
         };
@@ -870,7 +908,7 @@
     $Dependencies = shift;
     foreach $Prj (keys %$Dependencies) {
         my $prj_deps_hash = $$Dependencies{$Prj};
-        delete $$prj_deps_hash{$ExclPrj} if defined $$prj_deps_hash{$ExclPrj};
+        delete $$prj_deps_hash{$ExclPrj} if (defined $$prj_deps_hash{$ExclPrj});
 #        foreach (keys %$prj_deps_hash) {print ("$_ ")};
         
 #        foreach $i (0 .. $#{$$Dependencies{$Prj}}) {
@@ -987,14 +1025,16 @@
         if (scalar @candidates) {
             my $best_candidate = undef;
             my $weight = 0;
-            foreach my $candidate (@candidates) {
+            foreach my $candidate (sort @candidates) {
+#                if (defined $weights_hash{$candidate} && scalar keys %{$weights_hash{$candidate}} > $weight) {
                 if (defined $weights_hash{$candidate} && $weights_hash{$candidate} > $weight) {
                     $best_candidate = $candidate;
+#                    $weight = scalar keys %{$weights_hash{$candidate}};
                     $weight = $weights_hash{$candidate};
                 };
             };
             if (defined $best_candidate) {
-                delete $weights_hash{$best_candidate};
+#                delete $weights_hash{$best_candidate};
                 return $best_candidate;
             }
             my @sorted_candidates = sort(@candidates);
@@ -1087,7 +1127,7 @@
 
 sub usage {
     print STDERR "\nbuild\n";
-    print STDERR "Syntax:    build    [--all|-a[:prj_name]]|[--from|-f prj_name1[:prj_name2] [prj_name3 [...]]]|[--since|-c prj_name] [--with_branches|-b]|[--prepare|-p][:platform] [--dontchekoutmissingmodules]] [--deliver|-d [--dlv_switch deliver_switch]]] [-P processes] [--show|-s] [--help|-h] [--file|-F] [--ignore|-i] [--version|-V] [--mode|-m OOo[,SO[,EXT]] [--html [--html_path html_file_path]] [--job|-j] [-- job_options] \n";
+    print STDERR "Syntax:    build    [--all|-a[:prj_name]]|[--from|-f prj_name1[:prj_name2] [prj_name3 [...]]]|[--since|-c prj_name] [--with_branches|-b]|[--prepare|-p][:platform] [--dontchekoutmissingmodules]] [--deliver|-d [--dlv_switch deliver_switch]]] [-P processes] [--show|-s] [--help|-h] [--file|-F] [--ignore|-i] [--version|-V] [--mode|-m OOo[,SO[,EXT]] [--html [--html_path html_file_path] [--dontgraboutput]] [--job|-j] [-- job_options] \n";
     print STDERR "Example:    build --from sfx2\n";
     print STDERR "                     - build projects including current one from sfx2\n";
     print STDERR "Example:    build --all:sfx2\n";
@@ -1107,6 +1147,7 @@
     print STDERR "        --help       - print help info\n";
     print STDERR "        --ignore     - force tool to ignore errors\n";
     print STDERR "        --html       - generate html page with build status\n";
+    print STDERR "        --dontgraboutput - do not grab console output when generating html page\n";
     print STDERR "                       file named \$INPATH.build.html will be generated in \$SRC_ROOT\n";
     print STDERR "        --html_path  - html page path\n";
     print STDERR "        --dontchekoutmissingmodules - do not chekout missing modules when running prepape (links still will be broken)\n";
@@ -1131,7 +1172,7 @@
 # Get all options passed
 #
 sub get_options {
-    my $arg;
+    my ($arg, $dont_grab_output);
     init_logging();
     while ($arg = shift @ARGV) {
         $arg =~ /^-P$/            and $QuantityToBuild = shift @ARGV     and next;
@@ -1156,9 +1197,9 @@
                                 and $build_from = shift @ARGV         and next;
 
         $arg =~ /^--all:(\S+)$/ and $BuildAllParents = 1
-                                and $build_from_opt = $1            and next;
+                                and $build_all_cont = $1            and next;
         $arg =~ /^-a:(\S+)$/ and $BuildAllParents = 1
-                                and $build_from_opt = $1            and next;
+                                and $build_all_cont = $1            and next;
         if ($arg =~ /^--from$/ || $arg =~ /^-f$/) {
                                     $BuildAllParents = 1;
                                     get_incomp_projects();
@@ -1178,6 +1219,7 @@
         $arg =~ /^-h$/        and usage()                            and do_exit(0);
         $arg =~ /^--ignore$/        and $ignore = 1                            and next;
         $arg =~ /^--html$/        and $html = 1                            and next;
+        $arg =~ /^--dontgraboutput$/        and $dont_grab_output = 1      and next;
         $arg =~ /^--html_path$/ and $html_path = shift @ARGV  and next;
         $arg =~ /^-i$/        and $ignore = 1                            and next;
         $arg =~ /^--version$/   and do_exit(0);
@@ -1192,8 +1234,10 @@
     };
     if (!$html) {
         print_error("\"--html_path\" switch is used only with \"--html\"") if ($html_path);
+        print_error("\"--dontgraboutput\" switch is used only with \"--html\"") if ($dont_grab_output);
     };
-    print_error('Switches --with_branches and --all collision') if ($build_from && $build_from_opt);
+    $grab_output = 0 if ($dont_grab_output);
+    print_error('Switches --with_branches and --all collision') if ($build_from && $build_all_cont);
     print_error('Please prepare the workspace on one of UNIX platforms') if ($prepare && ($ENV{GUI} ne 'UNX'));
     print_error('Switches --with_branches and --since collision') if ($build_from && $build_since);
     if ($show) {
@@ -1707,7 +1751,7 @@
 #
 sub provide_consistency {
     check_dir();
-    foreach $var_ref (\$build_from, \$build_from_opt, \$build_since) {
+    foreach $var_ref (\$build_from, \$build_all_cont, \$build_since) {
         if ($$var_ref) {
             return if (-d $StandDir.$$var_ref);
             $$var_ref .= '.lnk' and return if (-d $StandDir.$$var_ref.'.lnk');
@@ -1998,9 +2042,9 @@
     foreach (keys %incompatibles) {
         $$deps_hash{$_} = $incompatibles{$_};
     };
-    if ($build_from_opt) {
-        prepare_build_from_opt($deps_hash);
-        delete $$deps_hash{$build_from_opt};
+    if ($build_all_cont) {
+        prepare_build_all_cont($deps_hash);
+        delete $$deps_hash{$build_all_cont};
     };
     @modules_built = keys %$deps_hash;
     clear_delivered() if ($prepare);
@@ -2021,9 +2065,9 @@
         my $warning_string = 'Following modules are inconsistent/missing: ' . "@missing_modules";
         push(@warnings, $warning_string);
     };
-    if ($build_from_opt) {
-        $$deps_hash{$build_from_opt} = ();
-        $build_from_opt = '';
+    if ($build_all_cont) {
+        $$deps_hash{$build_all_cont} = ();
+        $build_all_cont = '';
     };
     if ($old_output_tree) {
         push(@warnings, 'Some module(s) contain old output tree(s)!');
@@ -2062,10 +2106,10 @@
 # Removes projects which it is not necessary to build
 # with --all:prj_name or --since switch
 #
-sub prepare_build_from_opt {
+sub prepare_build_all_cont {
     my ($prj, $deps_hash, $border_prj);
     $deps_hash = shift;
-    $border_prj = $build_from_opt if ($build_from_opt);
+    $border_prj = $build_all_cont if ($build_all_cont);
     $border_prj = $build_since if ($build_since);
     while ($prj = PickPrjToBuild($deps_hash)) {
         $orig_prj = '';
@@ -2075,7 +2119,7 @@
             RemoveFromDependencies($prj, $deps_hash);
             next;
         } else {
-            if ($build_from_opt) {
+            if ($build_all_cont) {
                 $$deps_hash{$prj} = ();
             } else {
                 RemoveFromDependencies($prj, $deps_hash);
@@ -2110,8 +2154,8 @@
         } else {
             if ($option =~ /(:)/) {
                 $option = $`;
-                print_error("-from switch collision") if ($build_from_opt);
-                $build_from_opt = $';
+                print_error("-from switch collision") if ($build_all_cont);
+                $build_all_cont = $';
             };
             $incompatibles{$option}++;
         };
@@ -2374,6 +2418,9 @@
                 print_error("Cannot create log directory $log_dir") if ($@);
             };
             $error_code = system ("$job > $log_file 2>&1");
+            if (!$grab_output && -f $log_file) {
+                system("cat $log_file");
+            };
         } else {
             $error_code = system ("$job");
         }
