1cdf0e10cSrcweir: 2cdf0e10cSrcweir eval 'exec perl -S $0 ${1+"$@"}' 3cdf0e10cSrcweir if 0; 47e90fac2SAndrew Rist#************************************************************** 57e90fac2SAndrew Rist# 67e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 77e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 87e90fac2SAndrew Rist# distributed with this work for additional information 97e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 107e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 117e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 127e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 137e90fac2SAndrew Rist# 147e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 157e90fac2SAndrew Rist# 167e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 177e90fac2SAndrew Rist# software distributed under the License is distributed on an 187e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 197e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 207e90fac2SAndrew Rist# specific language governing permissions and limitations 217e90fac2SAndrew Rist# under the License. 227e90fac2SAndrew Rist# 237e90fac2SAndrew Rist#************************************************************** 247e90fac2SAndrew Rist 25cdf0e10cSrcweir# 26cdf0e10cSrcweir# build - build entire project 27cdf0e10cSrcweir# 28cdf0e10cSrcweir use strict; 29cdf0e10cSrcweir use Config; 30cdf0e10cSrcweir use POSIX; 31cdf0e10cSrcweir use Cwd qw (cwd); 32cdf0e10cSrcweir use File::Path; 33cdf0e10cSrcweir use File::Temp qw(tmpnam tempdir); 34cdf0e10cSrcweir use File::Find; 35cdf0e10cSrcweir use Socket; 36cdf0e10cSrcweir use IO::Socket::INET; 37cdf0e10cSrcweir use IO::Select; 38cdf0e10cSrcweir use Fcntl; 39cdf0e10cSrcweir use POSIX qw(:errno_h); 40cdf0e10cSrcweir use Sys::Hostname; 41cdf0e10cSrcweir 42cdf0e10cSrcweir use lib ("$ENV{SOLARENV}/bin/modules"); 43cdf0e10cSrcweir use SourceConfig; 44cdf0e10cSrcweir use RepositoryHelper; 45cdf0e10cSrcweir use Cwd 'chdir'; 46cdf0e10cSrcweir 47cdf0e10cSrcweir my $in_so_env = 0; 48cdf0e10cSrcweir if (defined $ENV{COMMON_ENV_TOOLS}) { 49cdf0e10cSrcweir unshift(@INC, "$ENV{COMMON_ENV_TOOLS}/modules"); 50cdf0e10cSrcweir $in_so_env++; 51cdf0e10cSrcweir }; 52cdf0e10cSrcweir if (defined $ENV{CWS_WORK_STAMP}) { 53cdf0e10cSrcweir require GenInfoParser; import GenInfoParser; 54cdf0e10cSrcweir require IO::Handle; import IO::Handle; 55cdf0e10cSrcweir }; 56cdf0e10cSrcweir my $verbose_mode = 0; 57cdf0e10cSrcweir if (defined $ENV{verbose} || defined $ENV{VERBOSE}) { 58cdf0e10cSrcweir $verbose_mode = ($ENV{verbose} =~ /^t\S*$/i); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir my $enable_multiprocessing = 1; 61cdf0e10cSrcweir ### for XML file format 62cdf0e10cSrcweir eval { require XMLBuildListParser; import XMLBuildListParser; }; 63cdf0e10cSrcweir my $enable_xml = 0; 64cdf0e10cSrcweir my @modes_array = (); 65cdf0e10cSrcweir if (!$@) { 66cdf0e10cSrcweir $enable_xml = 1; 67cdf0e10cSrcweir @modes_array = split('\s' , $ENV{BUILD_TYPE}); 68cdf0e10cSrcweir }; 69cdf0e10cSrcweir#### script id ##### 70cdf0e10cSrcweir 71cdf0e10cSrcweir ( my $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/; 72cdf0e10cSrcweir my $id_str = ' $Revision: 275224 $ '; 73cdf0e10cSrcweir my $script_rev = 0; 74cdf0e10cSrcweir $id_str =~ /Revision:\s+(\S+)\s+\$/ 75cdf0e10cSrcweir ? ($script_rev = $1) : ($script_rev = "-"); 76cdf0e10cSrcweir 77cdf0e10cSrcweir print "$script_name -- version: $script_rev\n"; 78cdf0e10cSrcweir 79cdf0e10cSrcweir######################### 80cdf0e10cSrcweir# # 81cdf0e10cSrcweir# Globale Variablen # 82cdf0e10cSrcweir# # 83cdf0e10cSrcweir######################### 84cdf0e10cSrcweir 85cdf0e10cSrcweir my $modules_number++; 86cdf0e10cSrcweir my $perl = 'perl'; 87cdf0e10cSrcweir my $remove_command = 'rm -rf'; 88cdf0e10cSrcweir my $nul = '> /dev/null'; 89cdf0e10cSrcweir 90cdf0e10cSrcweir my $processes_to_run = 0; 91cdf0e10cSrcweir# delete $pid when not needed 92cdf0e10cSrcweir my %projects_deps_hash = (); # hash of projects with no dependencies, 93cdf0e10cSrcweir # that could be built now 94cdf0e10cSrcweir my %broken_build = (); # hash of hashes of the modules, 95cdf0e10cSrcweir # where build was broken (error occurred) 96cdf0e10cSrcweir my %folders_hashes = (); 97cdf0e10cSrcweir my %running_children = (); 98cdf0e10cSrcweir my $dependencies_hash = 0; 99cdf0e10cSrcweir my $cmd_file = ''; 100cdf0e10cSrcweir my $build_all_parents = 0; 101cdf0e10cSrcweir my $show = 0; 102cdf0e10cSrcweir my $checkparents = 0; 103cdf0e10cSrcweir my $deliver = 0; 104cdf0e10cSrcweir my $pre_custom_job = ''; 105cdf0e10cSrcweir my $custom_job = ''; 106cdf0e10cSrcweir my $post_custom_job = ''; 107cdf0e10cSrcweir my %local_deps_hash = (); 108cdf0e10cSrcweir my %path_hash = (); 109cdf0e10cSrcweir my %platform_hash = (); 110cdf0e10cSrcweir my %alive_dependencies = (); 111cdf0e10cSrcweir my %global_deps_hash = (); # hash of dependencies of the all modules 112cdf0e10cSrcweir my %global_deps_hash_backup = (); # backup hash of external dependencies of the all modules 113cdf0e10cSrcweir my %module_deps_hash_backup = (); # backup hash of internal dependencies for aech module 114cdf0e10cSrcweir my @broken_module_names = (); # array of modules, which cannot be built further 115cdf0e10cSrcweir my @dmake_args = (); 116cdf0e10cSrcweir my %dead_parents = (); 117cdf0e10cSrcweir my $initial_module = ''; 118cdf0e10cSrcweir my $all_dependent = 1; # a flag indicating if the hash has independent keys 119cdf0e10cSrcweir my $build_from_with_branches = ''; 120cdf0e10cSrcweir my $build_all_cont = ''; 121cdf0e10cSrcweir my $build_since = ''; 122cdf0e10cSrcweir my $dlv_switch = ''; 123cdf0e10cSrcweir my $child = 0; 124cdf0e10cSrcweir my %processes_hash = (); 125cdf0e10cSrcweir my %module_announced = (); 126cdf0e10cSrcweir my $prepare = ''; # prepare for following incompatible build 127cdf0e10cSrcweir my $ignore = ''; 128cdf0e10cSrcweir my $html = ''; 129cdf0e10cSrcweir my @ignored_errors = (); 130cdf0e10cSrcweir my %incompatibles = (); 131cdf0e10cSrcweir my %skip_modules = (); 132cdf0e10cSrcweir my %exclude_branches = (); 133cdf0e10cSrcweir my $only_platform = ''; # the only platform to prepare 134cdf0e10cSrcweir my $only_common = ''; # the only common output tree to delete when preparing 135cdf0e10cSrcweir my %build_modes = (); 136cdf0e10cSrcweir my $maximal_processes = 0; # the max number of the processes run 137cdf0e10cSrcweir my %modules_types = (); # modules types ('mod', 'img', 'lnk') hash 138cdf0e10cSrcweir my %platforms = (); # platforms available or being working with 139cdf0e10cSrcweir my %platforms_to_copy = (); # copy output trees for the platforms when --prepare 140cdf0e10cSrcweir my $tmp_dir = get_tmp_dir(); # temp directory for checkout and other actions 141cdf0e10cSrcweir# $dmake_batch = undef; # 142cdf0e10cSrcweir my @possible_build_lists = ('build.lst', 'build.xlist'); # build lists names 143cdf0e10cSrcweir my %build_list_paths = (); # build lists names 144cdf0e10cSrcweir my %build_lists_hash = (); # hash of arrays $build_lists_hash{$module} = \($path, $xml_list_object) 145cdf0e10cSrcweir my $pre_job = 'announce'; # job to add for not-single module build 146cdf0e10cSrcweir my $post_job = ''; # -"- 147cdf0e10cSrcweir my @warnings = (); # array of warnings to be shown at the end of the process 148cdf0e10cSrcweir my @errors = (); # array of errors to be shown at the end of the process 149cdf0e10cSrcweir my %html_info = (); # hash containing all necessary info for generating of html page 150cdf0e10cSrcweir my %module_by_hash = (); # hash containing all modules names as values and correspondent hashes as keys 151cdf0e10cSrcweir my %build_in_progress = (); # hash of modules currently being built 152cdf0e10cSrcweir my %build_is_finished = (); # hash of already built modules 153cdf0e10cSrcweir my %modules_with_errors = (); # hash of modules with build errors 154cdf0e10cSrcweir my %build_in_progress_shown = (); # hash of modules being built, 155cdf0e10cSrcweir # and shown last time (to keep order) 156cdf0e10cSrcweir my $build_time = time; 157cdf0e10cSrcweir my $html_last_updated = 0; 158cdf0e10cSrcweir my %jobs_hash = (); 159cdf0e10cSrcweir my $html_path = undef; 160cdf0e10cSrcweir my $build_finished = 0; 161cdf0e10cSrcweir my $html_file = ''; 162cdf0e10cSrcweir my %had_error = (); # hack for misteriuos windows problems - try run dmake 2 times if first time there was an error 163cdf0e10cSrcweir my $mkout = correct_path("$ENV{SOLARENV}/bin/mkout.pl"); 164cdf0e10cSrcweir my %weights_hash = (); # hash contains info about how many modules are dependent from one module 165cdf0e10cSrcweir# %weight_stored = (); 166cdf0e10cSrcweir my $grab_output = 1; 167cdf0e10cSrcweir my $stop_build_on_error = 0; # for multiprocessing mode: do not build further module if there is an error 168cdf0e10cSrcweir my $interactive = 0; # for interactive mode... (for testing purpose enabled by default) 169cdf0e10cSrcweir my $parent_process = 1; 170cdf0e10cSrcweir my $server_mode = 0; 171cdf0e10cSrcweir my $setenv_string = ''; # string for configuration of the client environment 172cdf0e10cSrcweir my $ports_string = ''; # string with possible ports for server 173cdf0e10cSrcweir my @server_ports = (); 174cdf0e10cSrcweir my $html_port = 0; 175cdf0e10cSrcweir my $server_socket_obj = undef; # socket object for server 176cdf0e10cSrcweir my $html_socket_obj = undef; # socket object for server 177cdf0e10cSrcweir my %clients_jobs = (); 178cdf0e10cSrcweir my %clients_times = (); 179cdf0e10cSrcweir my $client_timeout = 0; # time for client to build (in sec)... 180cdf0e10cSrcweir # The longest time period after that 181cdf0e10cSrcweir # the server considered as an error/client crash 182cdf0e10cSrcweir my %lost_client_jobs = (); # hash containing lost jobs 183cdf0e10cSrcweir my %job_jobdir = (); # hash containing job-dir pairs 184cdf0e10cSrcweir my $reschedule_queue = 0; 185cdf0e10cSrcweir my %module_build_queue = (); 186cdf0e10cSrcweir my %reversed_dependencies = (); 187cdf0e10cSrcweir my %module_paths = (); # hash with absolute module paths 188cdf0e10cSrcweir my %active_modules = (); 189cdf0e10cSrcweir my $generate_config = 0; 190cdf0e10cSrcweir my %add_to_config = (); 191cdf0e10cSrcweir my %remove_from_config = (); 192cdf0e10cSrcweir my $clear_config = 0; 193cdf0e10cSrcweir my $finisched_children = 0; 194cdf0e10cSrcweir my $debug = 0; 195cdf0e10cSrcweir my %module_deps_hash_pids = (); 196cdf0e10cSrcweir my @argv = @ARGV; 197cdf0e10cSrcweir my $source_config_file; 198cdf0e10cSrcweir my @modules_built = (); 199cdf0e10cSrcweir my $deliver_command = $ENV{DELIVER}; 200cdf0e10cSrcweir my %prj_platform = (); 201cdf0e10cSrcweir my $check_error_string = ''; 202cdf0e10cSrcweir my $dmake = ''; 203cdf0e10cSrcweir my $dmake_args = ''; 204cdf0e10cSrcweir my $echo = ''; 205cdf0e10cSrcweir my $new_line = "\n"; 206cdf0e10cSrcweir my $incompatible = 0; 207cdf0e10cSrcweir my $local_host_ip = 'localhost'; 208cdf0e10cSrcweir### main ### 209cdf0e10cSrcweir 210cdf0e10cSrcweir get_options(); 211cdf0e10cSrcweir 212cdf0e10cSrcweir# my $temp_html_file = correct_path($tmp_dir. '/' . $ENV{INPATH}. '.build.html'); 213cdf0e10cSrcweir get_build_modes(); 214cdf0e10cSrcweir my %deliver_env = (); 215cdf0e10cSrcweir if ($prepare) { 216cdf0e10cSrcweir get_platforms(\%platforms); 217cdf0e10cSrcweir 218cdf0e10cSrcweir $deliver_env{'BUILD_SOSL'}++; 219cdf0e10cSrcweir $deliver_env{'COMMON_OUTDIR'}++; 220cdf0e10cSrcweir $deliver_env{'GUI'}++; 221cdf0e10cSrcweir $deliver_env{'INPATH'}++; 222cdf0e10cSrcweir $deliver_env{'OFFENV_PATH'}++; 223cdf0e10cSrcweir $deliver_env{'OUTPATH'}++; 224cdf0e10cSrcweir $deliver_env{'L10N_framework'}++; 225cdf0e10cSrcweir }; 226cdf0e10cSrcweir my $workspace_path = get_workspace_path(); # This also sets $initial_module 227149f2bc0SAndre Fischer my @additional_repositories = (); 228149f2bc0SAndre Fischer 229149f2bc0SAndre Fischer # Collect additional repository directories from the ADDITIONAL_REPOSITORIES 230149f2bc0SAndre Fischer # environment variable (typically set by configure). 231*3e9d7d56SAndre Fischer foreach my $additional_repository (split(" ", $ENV{ADDITIONAL_REPOSITORIES})) 232149f2bc0SAndre Fischer { 233149f2bc0SAndre Fischer next if $additional_repository eq ""; 234149f2bc0SAndre Fischer # The repository path is expected to be relative to the workspace_path. 235149f2bc0SAndre Fischer # For support of absolute paths we need functionality to distinguish between 236149f2bc0SAndre Fischer # relative and absolute paths (provided by File::Spec). 237149f2bc0SAndre Fischer my $path = Cwd::realpath(correct_path($workspace_path . "/" . $additional_repository)); 238149f2bc0SAndre Fischer if ( -d $path) 239149f2bc0SAndre Fischer { 240149f2bc0SAndre Fischer push @additional_repositories, $path; 241149f2bc0SAndre Fischer } 242149f2bc0SAndre Fischer } 243149f2bc0SAndre Fischer 244149f2bc0SAndre Fischer my $source_config = SourceConfig -> new($workspace_path, @additional_repositories); 245cdf0e10cSrcweir check_partial_gnumake_build($initial_module); 246cdf0e10cSrcweir 247cdf0e10cSrcweir if ($html) { 248cdf0e10cSrcweir if (defined $html_path) { 249cdf0e10cSrcweir $html_file = correct_path($html_path . '/' . $ENV{INPATH}. '.build.html'); 250cdf0e10cSrcweir } else { 251cdf0e10cSrcweir my $log_directory = Cwd::realpath(correct_path($workspace_path . '/..')) . '/log'; 252cdf0e10cSrcweir if ((!-d $log_directory) && (!mkdir($log_directory))) { 253cdf0e10cSrcweir print_error("Cannot create $log_directory for writing html file\n"); 254cdf0e10cSrcweir }; 255cdf0e10cSrcweir $html_file = $log_directory . '/' . $ENV{INPATH}. '.build.html'; 256cdf0e10cSrcweir print "\nPath to html status page: $html_file\n"; 257cdf0e10cSrcweir }; 258cdf0e10cSrcweir }; 259cdf0e10cSrcweir 260cdf0e10cSrcweir if ($generate_config && ($clear_config || (scalar keys %remove_from_config)||(scalar keys %add_to_config))) { 261cdf0e10cSrcweir generate_config_file(); 262cdf0e10cSrcweir exit 0; 263cdf0e10cSrcweir } 264cdf0e10cSrcweir get_module_and_buildlist_paths(); 265cdf0e10cSrcweir provide_consistency() if (defined $ENV{CWS_WORK_STAMP} && defined($ENV{COMMON_ENV_TOOLS})); 266cdf0e10cSrcweir 267cdf0e10cSrcweir $deliver_command .= ' -verbose' if ($html); 268cdf0e10cSrcweir $deliver_command .= ' '. $dlv_switch if ($dlv_switch); 269cdf0e10cSrcweir $ENV{mk_tmp}++; 270cdf0e10cSrcweir 271cdf0e10cSrcweir get_commands(); 272cdf0e10cSrcweir unlink ($cmd_file); 273cdf0e10cSrcweir if ($cmd_file) { 274cdf0e10cSrcweir if (open (CMD_FILE, ">>$cmd_file")) { 275cdf0e10cSrcweir select CMD_FILE; 276cdf0e10cSrcweir $echo = 'echo '; 277cdf0e10cSrcweir if ($ENV{GUI} ne 'UNX') { 278cdf0e10cSrcweir $new_line = "echo.\n"; 279cdf0e10cSrcweir print "\@$echo off\npushd\n"; 280cdf0e10cSrcweir } else { 281cdf0e10cSrcweir $new_line = $echo."\"\"\n"; 282cdf0e10cSrcweir }; 283cdf0e10cSrcweir } else { 284cdf0e10cSrcweir print_error ("Cannot open file $cmd_file"); 285cdf0e10cSrcweir }; 286cdf0e10cSrcweir# } elsif ($show) { 287cdf0e10cSrcweir# select STDOUT; 288cdf0e10cSrcweir }; 289cdf0e10cSrcweir 290cdf0e10cSrcweir print $new_line; 291cdf0e10cSrcweir get_server_ports(); 292cdf0e10cSrcweir start_interactive() if ($interactive); 293cdf0e10cSrcweir 294cdf0e10cSrcweir if ($checkparents) { 295cdf0e10cSrcweir get_parent_deps( $initial_module, \%global_deps_hash ); 296cdf0e10cSrcweir } else { 297cdf0e10cSrcweir build_all(); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir if (scalar keys %broken_build) { 300cdf0e10cSrcweir cancel_build(); 301cdf0e10cSrcweir# } elsif (!$custom_job && $post_custom_job) { 302cdf0e10cSrcweir# do_post_custom_job(correct_path($workspace_path.$initial_module)); 303cdf0e10cSrcweir }; 304cdf0e10cSrcweir print_warnings(); 305cdf0e10cSrcweir if (scalar keys %active_modules) { 306cdf0e10cSrcweir foreach (keys %dead_parents) { 307cdf0e10cSrcweir delete $dead_parents{$_} if (!defined $active_modules{$_}); 308cdf0e10cSrcweir }; 309cdf0e10cSrcweir }; 310cdf0e10cSrcweir if (scalar keys %dead_parents) { 311cdf0e10cSrcweir print $new_line.$new_line; 312cdf0e10cSrcweir print $echo."WARNING! Project(s):\n"; 313cdf0e10cSrcweir foreach (keys %dead_parents) { 314cdf0e10cSrcweir print $echo."$_\n"; 315cdf0e10cSrcweir }; 316cdf0e10cSrcweir print $new_line; 317cdf0e10cSrcweir print $echo."not found and couldn't be built. dependencies on that module(s) ignored. Maybe you should correct build lists.\n"; 318cdf0e10cSrcweir print $new_line; 319cdf0e10cSrcweir do_exit(1) if ($checkparents); 320cdf0e10cSrcweir }; 321cdf0e10cSrcweir if (($ENV{GUI} ne 'UNX') && $cmd_file) { 322cdf0e10cSrcweir print "popd\n"; 323cdf0e10cSrcweir }; 324cdf0e10cSrcweir $ENV{mk_tmp} = ''; 325cdf0e10cSrcweir if ($cmd_file) { 326cdf0e10cSrcweir close CMD_FILE; 327cdf0e10cSrcweir print STDOUT "Script $cmd_file generated\n"; 328cdf0e10cSrcweir }; 329cdf0e10cSrcweir if ($ignore && scalar @ignored_errors) { 330cdf0e10cSrcweir print STDERR "\nERROR: next directories could not be built:\n"; 331cdf0e10cSrcweir foreach (@ignored_errors) { 332cdf0e10cSrcweir print STDERR "\t$_\n"; 333cdf0e10cSrcweir }; 334cdf0e10cSrcweir print STDERR "\nERROR: please check these directories and build the corresponding module(s) anew!!\n\n"; 335cdf0e10cSrcweir do_exit(1); 336cdf0e10cSrcweir }; 337cdf0e10cSrcweir do_exit(0); 338cdf0e10cSrcweir 339cdf0e10cSrcweir 340cdf0e10cSrcweir######################### 341cdf0e10cSrcweir# # 342cdf0e10cSrcweir# Procedures # 343cdf0e10cSrcweir# # 344cdf0e10cSrcweir######################### 345cdf0e10cSrcweir 346cdf0e10cSrcweirsub print_warnings { 347cdf0e10cSrcweir if (scalar @warnings) { 348cdf0e10cSrcweir print STDERR "\nWARNING(S):\n"; 349cdf0e10cSrcweir print STDERR $_ foreach (@warnings); 350cdf0e10cSrcweir }; 351cdf0e10cSrcweir}; 352cdf0e10cSrcweir 353cdf0e10cSrcweirsub rename_file { 354cdf0e10cSrcweir my ($old_file_name, $new_file_name, $throw_error) = @_; 355cdf0e10cSrcweir 356cdf0e10cSrcweir if(-e $old_file_name) { 357cdf0e10cSrcweir rename($old_file_name, $new_file_name) or system("mv", $old_file_name, $new_file_name); 358cdf0e10cSrcweir if (-e $old_file_name) { 359cdf0e10cSrcweir system("rm -rf $old_file_name") if (!unlink $old_file_name); 360cdf0e10cSrcweir }; 361cdf0e10cSrcweir } elsif ($throw_error) { 362cdf0e10cSrcweir print_error("No such file $old_file_name"); 363cdf0e10cSrcweir }; 364cdf0e10cSrcweir}; 365cdf0e10cSrcweir 366cdf0e10cSrcweirsub generate_config_file { 367cdf0e10cSrcweir $source_config->add_active_modules([keys %add_to_config], 1) if (scalar %add_to_config); 368cdf0e10cSrcweir $source_config->remove_activated_modules([keys %remove_from_config], 1) if (scalar %remove_from_config); 369cdf0e10cSrcweir $source_config->remove_all_activated_modules() if ($clear_config); 370cdf0e10cSrcweir}; 371cdf0e10cSrcweir 372cdf0e10cSrcweir 373cdf0e10cSrcweirsub start_interactive { 374cdf0e10cSrcweir my $pid = open(HTML_PIPE, "-|"); 375cdf0e10cSrcweir print "Pipe is open\n"; 376cdf0e10cSrcweir 377cdf0e10cSrcweir if ($pid) { # parent 378cdf0e10cSrcweir # make file handle non-blocking 379cdf0e10cSrcweir my $flags = ''; 380cdf0e10cSrcweir fcntl(HTML_PIPE, F_GETFL, $flags); 381cdf0e10cSrcweir $flags |= O_NONBLOCK; 382cdf0e10cSrcweir fcntl(HTML_PIPE, F_SETFL, $flags); 383cdf0e10cSrcweir } else { # child 384cdf0e10cSrcweir $parent_process = 0; 385cdf0e10cSrcweir start_html_listener(); 386cdf0e10cSrcweir }; 387cdf0e10cSrcweir}; 388cdf0e10cSrcweir 389cdf0e10cSrcweirsub start_html_listener { 390cdf0e10cSrcweir $html_port = $server_ports[$#server_ports]; 391cdf0e10cSrcweir do { 392cdf0e10cSrcweir $html_port++ 393cdf0e10cSrcweir } while (start_server_on_port($html_port, \$html_socket_obj)); 394cdf0e10cSrcweir print "html_port:$html_port html_socket_obj: $html_socket_obj\n"; 395cdf0e10cSrcweir my $new_socket_obj; 396cdf0e10cSrcweir do { 397cdf0e10cSrcweir $new_socket_obj = accept_html_connection(); 398cdf0e10cSrcweir if (defined $new_socket_obj) { 399cdf0e10cSrcweir my $html_message; 400cdf0e10cSrcweir $html_message = <$new_socket_obj>; 401cdf0e10cSrcweir chomp $html_message; 402cdf0e10cSrcweir print $html_message . "\n"; 403cdf0e10cSrcweir my $socket_message = ''; 404cdf0e10cSrcweir for my $action ('rebuild', 'delete') { 405cdf0e10cSrcweir if ($html_message =~ /$action=(\S+)/) { 406cdf0e10cSrcweir print $new_socket_obj "Module $1 is scheduled for $action"; 407cdf0e10cSrcweir }; 408cdf0e10cSrcweir }; 409cdf0e10cSrcweir close($new_socket_obj); 410cdf0e10cSrcweir } else { 411cdf0e10cSrcweir sleep(10); 412cdf0e10cSrcweir }; 413cdf0e10cSrcweir } while(1); 414cdf0e10cSrcweir}; 415cdf0e10cSrcweir 416cdf0e10cSrcweirsub start_html_message_trigger { 417cdf0e10cSrcweir my $child_id=fork(); ### VG: for windows there is a "simulation of the "fork"", no new procs... One can use Win32::Process::Create 418cdf0e10cSrcweir 419cdf0e10cSrcweir if ($child_id) { 420cdf0e10cSrcweir # parent 421cdf0e10cSrcweir# print "started listener trigger\n"; 422cdf0e10cSrcweir } else { 423cdf0e10cSrcweir my $buffer_size = 1024; 424cdf0e10cSrcweir my $buffer; 425cdf0e10cSrcweir my $rv; 426cdf0e10cSrcweir my $full_buffer = ''; 427cdf0e10cSrcweir my %modules_to_rebuild = (); 428cdf0e10cSrcweir my $paddr; 429cdf0e10cSrcweir while ($rv = sysread(HTML_PIPE, $buffer, $buffer_size)) { 430cdf0e10cSrcweir $full_buffer .= $buffer; 431cdf0e10cSrcweir }; 432cdf0e10cSrcweir if (length $full_buffer) { 433cdf0e10cSrcweir print "**********Got message $full_buffer\n"; 434cdf0e10cSrcweir socket(SOCKET, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "socket: $!"; 435cdf0e10cSrcweir if (connect(SOCKET, $paddr)) { 436cdf0e10cSrcweir $full_buffer .= "\n"; 437cdf0e10cSrcweir syswrite SOCKET, $full_buffer, length $full_buffer; 438cdf0e10cSrcweir# close SOCKET or die "Child close socket: $!"; 439cdf0e10cSrcweir } else { 440cdf0e10cSrcweir die "Child connect: $!"; 441cdf0e10cSrcweir }; 442cdf0e10cSrcweir } 443cdf0e10cSrcweir _exit(0); 444cdf0e10cSrcweir }; 445cdf0e10cSrcweir}; 446cdf0e10cSrcweir 447cdf0e10cSrcweirsub get_html_orders { 448cdf0e10cSrcweir return if (!$interactive); 449cdf0e10cSrcweir my $buffer_size = 1024; 450cdf0e10cSrcweir my $buffer; 451cdf0e10cSrcweir my $rv; 452cdf0e10cSrcweir my $full_buffer = ''; 453cdf0e10cSrcweir my %modules_to_rebuild = (); 454cdf0e10cSrcweir my %modules_to_delete = (); 455cdf0e10cSrcweir while ($rv = sysread(HTML_PIPE, $buffer, $buffer_size)) { 456cdf0e10cSrcweir $full_buffer .= $buffer; 457cdf0e10cSrcweir }; 458cdf0e10cSrcweir# }; 459cdf0e10cSrcweir my @html_messages = split(/\n/, $full_buffer); 460cdf0e10cSrcweir foreach (@html_messages) { 461cdf0e10cSrcweir if (/^html_port:(\d+)/) { 462cdf0e10cSrcweir $html_port = $1; 463cdf0e10cSrcweir print "Html port is: $html_port\n"; 464cdf0e10cSrcweir next; 465cdf0e10cSrcweir };# GET /rebuild=officenames HTTP/1.0 466cdf0e10cSrcweir print "Message: $_\n"; 467cdf0e10cSrcweir chomp; 468cdf0e10cSrcweir if (/GET\s+\/delete=(\S+)[:(\S+)]*\s*HTTP/) { 469cdf0e10cSrcweir $modules_to_delete{$1} = $2; 470cdf0e10cSrcweir print "$1 scheduled for removal from build for \n"; 471cdf0e10cSrcweir } 472cdf0e10cSrcweir if (/GET\s+\/rebuild=(\S+)[:(\S+)]*\s*HTTP/) { 473cdf0e10cSrcweir if (defined $global_deps_hash{$1}) { 474cdf0e10cSrcweir print "!!! /tarModule $1 has not been built. Html order ignored\n"; 475cdf0e10cSrcweir } else { 476cdf0e10cSrcweir $modules_to_rebuild{$1} = $2; 477cdf0e10cSrcweir print "Scheduled $1 for rebuild\n"; 478cdf0e10cSrcweir } 479cdf0e10cSrcweir } 480cdf0e10cSrcweir }; 481cdf0e10cSrcweir if (scalar keys %modules_to_delete) { 482cdf0e10cSrcweir $reschedule_queue++; 483cdf0e10cSrcweir schedule_delete(\%modules_to_delete); 484cdf0e10cSrcweir generate_html_file(); 485cdf0e10cSrcweir }; 486cdf0e10cSrcweir if (scalar keys %modules_to_rebuild) { 487cdf0e10cSrcweir $reschedule_queue++; 488cdf0e10cSrcweir schedule_rebuild(\%modules_to_rebuild); 489cdf0e10cSrcweir generate_html_file(); 490cdf0e10cSrcweir }; 491cdf0e10cSrcweir}; 492cdf0e10cSrcweir 493cdf0e10cSrcweirsub schedule_delete { 494cdf0e10cSrcweir my $modules_to_delete = shift; 495cdf0e10cSrcweir foreach (keys %$modules_to_delete) { 496cdf0e10cSrcweir print "Schedule module $_ for delete\n"; 497cdf0e10cSrcweir delete ($global_deps_hash{$_}); 498cdf0e10cSrcweir delete ($global_deps_hash_backup{$_}); 499cdf0e10cSrcweir if (scalar keys %{$module_deps_hash_pids{$projects_deps_hash{$_}}}) { 500cdf0e10cSrcweir kill 9, keys %{$module_deps_hash_pids{$projects_deps_hash{$_}}}; 501cdf0e10cSrcweir handle_dead_children(0); 502cdf0e10cSrcweir }; 503cdf0e10cSrcweir remove_from_dependencies($_, \%global_deps_hash); 504cdf0e10cSrcweir remove_from_dependencies($_, \%global_deps_hash_backup); 505cdf0e10cSrcweir delete $reversed_dependencies{$_}; 506cdf0e10cSrcweir delete $build_is_finished{$_} if defined $build_is_finished{$_}; 507cdf0e10cSrcweir delete $modules_with_errors{$_} if defined $modules_with_errors{$_}; 508cdf0e10cSrcweir delete $module_announced{$_} if defined $module_announced{$_}; 509cdf0e10cSrcweir delete $html_info{$_} if defined $html_info{$_}; 510cdf0e10cSrcweir delete $projects_deps_hash{$_} if defined $projects_deps_hash{$_}; 511cdf0e10cSrcweir }; 512cdf0e10cSrcweir}; 513cdf0e10cSrcweir 514cdf0e10cSrcweirsub schedule_rebuild { 515cdf0e10cSrcweir my $modules_to_rebuild = shift; 516cdf0e10cSrcweir foreach (keys %$modules_to_rebuild) { 517cdf0e10cSrcweir if (defined $$modules_to_rebuild{$_}) { 518cdf0e10cSrcweir print "Schedule directory for rebuild"; 519cdf0e10cSrcweir } else { 520cdf0e10cSrcweir print "Schedule complete $_ module for rebuild\n"; 521cdf0e10cSrcweir if (scalar keys %{$module_deps_hash_pids{$projects_deps_hash{$_}}}) { 522cdf0e10cSrcweir kill 9, keys %{$module_deps_hash_pids{$projects_deps_hash{$_}}}; 523cdf0e10cSrcweir handle_dead_children(0); 524cdf0e10cSrcweir }; 525cdf0e10cSrcweir delete $build_is_finished{$_} if defined $build_is_finished{$_}; 526cdf0e10cSrcweir delete $modules_with_errors{$_} if defined $modules_with_errors{$_}; 527cdf0e10cSrcweir delete $module_announced{$_}; 528cdf0e10cSrcweir initialize_html_info($_); 529cdf0e10cSrcweir 530cdf0e10cSrcweir foreach my $waiter (keys %{$reversed_dependencies{$_}}) { 531cdf0e10cSrcweir # for rebuild_all_dependent - refacture "if" condition 532cdf0e10cSrcweir ${$global_deps_hash{$waiter}}{$_}++ if (!defined $build_is_finished{$waiter}); 533cdf0e10cSrcweir }; 534cdf0e10cSrcweir delete $projects_deps_hash{$_} if defined $projects_deps_hash{$_}; 535cdf0e10cSrcweir my %single_module_dep_hash = (); 536cdf0e10cSrcweir foreach my $module (keys %{$global_deps_hash_backup{$_}}) { 537cdf0e10cSrcweir if (defined ${$global_deps_hash_backup{$_}}{$module} && (!defined $build_is_finished{$module})) { 538cdf0e10cSrcweir $single_module_dep_hash{$module}++; 539cdf0e10cSrcweir }; 540cdf0e10cSrcweir }; 541cdf0e10cSrcweir $global_deps_hash{$_} = \%single_module_dep_hash; 542cdf0e10cSrcweir }; 543cdf0e10cSrcweir }; 544cdf0e10cSrcweir}; 545cdf0e10cSrcweir 546cdf0e10cSrcweir 547cdf0e10cSrcweir# 548cdf0e10cSrcweir# procedure retrieves build list path 549cdf0e10cSrcweir# (all possibilities are taken into account) 550cdf0e10cSrcweir# 551cdf0e10cSrcweirsub get_build_list_path { 552cdf0e10cSrcweir my $module = shift; 553cdf0e10cSrcweir return $build_list_paths{$module} if (defined $build_list_paths{$module}); 554cdf0e10cSrcweir my @possible_dirs = ($module, $module. '.lnk', $module. '.link'); 555cdf0e10cSrcweir return $build_list_paths{$module} if (defined $build_list_paths{$module}); 556cdf0e10cSrcweir foreach (@possible_dirs) { 557cdf0e10cSrcweir my $possible_dir_path = $module_paths{$_}.'/prj/'; 558cdf0e10cSrcweir if (-d $possible_dir_path) { 559cdf0e10cSrcweir foreach my $build_list (@possible_build_lists) { 560cdf0e10cSrcweir my $possible_build_list_path = correct_path($possible_dir_path . $build_list); 561cdf0e10cSrcweir if (-f $possible_build_list_path) { 562cdf0e10cSrcweir $build_list_paths{$module} = $possible_build_list_path; 563cdf0e10cSrcweir return $possible_build_list_path; 564cdf0e10cSrcweir }; 565cdf0e10cSrcweir } 566cdf0e10cSrcweir print_error("There's no build list for $module"); 567cdf0e10cSrcweir }; 568cdf0e10cSrcweir }; 569cdf0e10cSrcweir $dead_parents{$module}++; 570cdf0e10cSrcweir $build_list_paths{$module} = correct_path(retrieve_build_list($module)) if (!defined $build_list_paths{$module}); 571cdf0e10cSrcweir return $build_list_paths{$module}; 572cdf0e10cSrcweir}; 573cdf0e10cSrcweir 574cdf0e10cSrcweir# 575cdf0e10cSrcweir# Get dependencies hash of the current and all parent projects 576cdf0e10cSrcweir# 577cdf0e10cSrcweirsub get_parent_deps { 578cdf0e10cSrcweir my $prj_dir = shift; 579cdf0e10cSrcweir my $deps_hash = shift; 580cdf0e10cSrcweir my @unresolved_parents = ($prj_dir); 581cdf0e10cSrcweir my %skipped_branches = (); 582cdf0e10cSrcweir while (my $module = pop(@unresolved_parents)) { 583cdf0e10cSrcweir next if (defined $$deps_hash{$module}); 584cdf0e10cSrcweir my %parents_deps_hash = (); 585cdf0e10cSrcweir foreach (get_parents_array($module)) { 586cdf0e10cSrcweir if (defined $exclude_branches{$_}) { 587cdf0e10cSrcweir $skipped_branches{$_}++; 588cdf0e10cSrcweir next; 589cdf0e10cSrcweir }; 590cdf0e10cSrcweir $parents_deps_hash{$_}++; 591cdf0e10cSrcweir } 592cdf0e10cSrcweir $$deps_hash{$module} = \%parents_deps_hash; 593cdf0e10cSrcweir foreach my $parent (keys %parents_deps_hash) { 594cdf0e10cSrcweir if (!defined($$deps_hash{$parent}) && (!defined $exclude_branches{$module})) { 595cdf0e10cSrcweir push (@unresolved_parents, $parent); 596cdf0e10cSrcweir }; 597cdf0e10cSrcweir }; 598cdf0e10cSrcweir }; 599cdf0e10cSrcweir check_deps_hash($deps_hash); 600cdf0e10cSrcweir foreach (keys %skipped_branches) { 601cdf0e10cSrcweir print $echo . "Skipping module's $_ branch\n"; 602cdf0e10cSrcweir delete $exclude_branches{$_}; 603cdf0e10cSrcweir }; 604cdf0e10cSrcweir my @missing_branches = keys %exclude_branches; 605cdf0e10cSrcweir if (scalar @missing_branches) { 606cdf0e10cSrcweir print_error("For $prj_dir branche(s): \"@missing_branches\" not found\n"); 607cdf0e10cSrcweir }; 608cdf0e10cSrcweir}; 609cdf0e10cSrcweir 610cdf0e10cSrcweirsub store_weights { 611cdf0e10cSrcweir my $deps_hash = shift; 612cdf0e10cSrcweir foreach (keys %$deps_hash) { 613cdf0e10cSrcweir foreach my $module_deps_hash ($$deps_hash{$_}) { 614cdf0e10cSrcweir foreach my $dependency (keys %$module_deps_hash) { 615cdf0e10cSrcweir $weights_hash{$dependency}++; 616cdf0e10cSrcweir }; 617cdf0e10cSrcweir }; 618cdf0e10cSrcweir }; 619cdf0e10cSrcweir}; 620cdf0e10cSrcweir 621cdf0e10cSrcweir# 622cdf0e10cSrcweir# This procedure builds comlete dependency for each module, ie if the deps look like: 623cdf0e10cSrcweir# mod1 -> mod2 -> mod3 -> mod4,mod5, 624cdf0e10cSrcweir# than mod1 get mod3,mod4,mod5 as eplicit list of deps, not only mod2 as earlier 625cdf0e10cSrcweir# 626cdf0e10cSrcweirsub expand_dependencies { 627cdf0e10cSrcweir my $deps_hash = shift; 628cdf0e10cSrcweir 629cdf0e10cSrcweir foreach my $module1 (keys %$deps_hash) { 630cdf0e10cSrcweir foreach my $module2 (keys %$deps_hash) { 631cdf0e10cSrcweir next if ($module1 eq $module2); 632cdf0e10cSrcweir if (defined ${$$deps_hash{$module2}}{$module1}) { 633cdf0e10cSrcweir ${$$deps_hash{$module2}}{$_}++ foreach (keys %{$$deps_hash{$module1}}) 634cdf0e10cSrcweir }; 635cdf0e10cSrcweir }; 636cdf0e10cSrcweir }; 637cdf0e10cSrcweir}; 638cdf0e10cSrcweir 639cdf0e10cSrcweir# 640cdf0e10cSrcweir# This procedure fills the second hash with reversed dependencies, 641cdf0e10cSrcweir# ie, with info about modules "waiting" for the module 642cdf0e10cSrcweir# 643cdf0e10cSrcweirsub reverse_dependensies { 644cdf0e10cSrcweir my ($deps_hash, $reversed) = @_; 645cdf0e10cSrcweir foreach my $module (keys %$deps_hash) { 646cdf0e10cSrcweir foreach (keys %{$$deps_hash{$module}}) { 647cdf0e10cSrcweir if (defined $$reversed{$_}) { 648cdf0e10cSrcweir ${$$reversed{$_}}{$module}++ 649cdf0e10cSrcweir } else { 650cdf0e10cSrcweir my %single_module_dep_hash = ($module => 1); 651cdf0e10cSrcweir $$reversed{$_} = \%single_module_dep_hash; 652cdf0e10cSrcweir }; 653cdf0e10cSrcweir }; 654cdf0e10cSrcweir }; 655cdf0e10cSrcweir}; 656cdf0e10cSrcweir 657cdf0e10cSrcweir# 658cdf0e10cSrcweir# Build everything that should be built 659cdf0e10cSrcweir# 660cdf0e10cSrcweirsub build_all { 661cdf0e10cSrcweir if ($build_all_parents) { 662cdf0e10cSrcweir my ($prj, $prj_dir, $orig_prj); 663cdf0e10cSrcweir get_parent_deps( $initial_module, \%global_deps_hash); 664cdf0e10cSrcweir if (scalar keys %active_modules) { 665cdf0e10cSrcweir $active_modules{$initial_module}++; 666cdf0e10cSrcweir $modules_types{$initial_module} = 'mod'; 667cdf0e10cSrcweir }; 668cdf0e10cSrcweir modules_classify(keys %global_deps_hash); 669cdf0e10cSrcweir expand_dependencies (\%global_deps_hash); 670cdf0e10cSrcweir prepare_incompatible_build(\%global_deps_hash) if ($incompatible && (!$build_from_with_branches)); 671cdf0e10cSrcweir if ($build_from_with_branches) { 672cdf0e10cSrcweir my %reversed_full_deps_hash = (); 673cdf0e10cSrcweir reverse_dependensies(\%global_deps_hash, \%reversed_full_deps_hash); 674cdf0e10cSrcweir prepare_build_from_with_branches(\%global_deps_hash, \%reversed_full_deps_hash); 675cdf0e10cSrcweir } 676cdf0e10cSrcweir if ($build_all_cont || $build_since) { 677cdf0e10cSrcweir store_weights(\%global_deps_hash); 678cdf0e10cSrcweir prepare_build_all_cont(\%global_deps_hash); 679cdf0e10cSrcweir %weights_hash = (); 680cdf0e10cSrcweir }; 681cdf0e10cSrcweir if ($generate_config) { 682cdf0e10cSrcweir %add_to_config = %global_deps_hash; 683cdf0e10cSrcweir generate_config_file(); 684cdf0e10cSrcweir exit 0; 685cdf0e10cSrcweir } elsif ($incompatible) { 686cdf0e10cSrcweir my @missing_modules = (); 687cdf0e10cSrcweir foreach (sort keys %global_deps_hash) { 688cdf0e10cSrcweir push(@missing_modules, $_) if (!defined $active_modules{$_}); 689cdf0e10cSrcweir }; 690cdf0e10cSrcweir if (scalar @missing_modules) { 691cdf0e10cSrcweir push(@warnings, "The modules: \"@missing_modules\" should be have been built, but they are not activated and have been skipped. Be aware, that can cause compatibility problems. Maybe you should verify your $source_config_file.\n"); 692cdf0e10cSrcweir }; 693cdf0e10cSrcweir }; 694cdf0e10cSrcweir foreach my $module (keys %dead_parents, keys %skip_modules) { 695cdf0e10cSrcweir remove_from_dependencies($module, \%global_deps_hash); 696cdf0e10cSrcweir delete ($global_deps_hash{$module}) if (defined $global_deps_hash{$module}); 697cdf0e10cSrcweir }; 698cdf0e10cSrcweir store_weights(\%global_deps_hash); 699cdf0e10cSrcweir backup_deps_hash(\%global_deps_hash, \%global_deps_hash_backup); 700cdf0e10cSrcweir reverse_dependensies(\%global_deps_hash_backup, \%reversed_dependencies); 701cdf0e10cSrcweir $modules_number = scalar keys %global_deps_hash; 702cdf0e10cSrcweir initialize_html_info($_) foreach (keys %global_deps_hash); 703cdf0e10cSrcweir if ($processes_to_run) { 704cdf0e10cSrcweir build_multiprocessing(); 705cdf0e10cSrcweir return; 706cdf0e10cSrcweir }; 707cdf0e10cSrcweir if ($server_mode) { 708cdf0e10cSrcweir run_server(); 709cdf0e10cSrcweir }; 710cdf0e10cSrcweir while ($prj = pick_prj_to_build(\%global_deps_hash)) { 711cdf0e10cSrcweir if (!defined $dead_parents{$prj}) { 712cdf0e10cSrcweir if (scalar keys %broken_build) { 713cdf0e10cSrcweir print $echo . "Skipping project $prj because of error(s)\n"; 714cdf0e10cSrcweir remove_from_dependencies($prj, \%global_deps_hash); 715cdf0e10cSrcweir $build_is_finished{$prj}++; 716cdf0e10cSrcweir next; 717cdf0e10cSrcweir }; 718cdf0e10cSrcweir 719cdf0e10cSrcweir $prj_dir = $module_paths{$prj}; 720cdf0e10cSrcweir get_module_dep_hash($prj, \%local_deps_hash); 721cdf0e10cSrcweir my $info_hash = $html_info{$prj}; 722cdf0e10cSrcweir $$info_hash{DIRS} = check_deps_hash(\%local_deps_hash, $prj); 723cdf0e10cSrcweir $module_by_hash{\%local_deps_hash} = $prj; 724cdf0e10cSrcweir build_dependent(\%local_deps_hash); 725cdf0e10cSrcweir print $check_error_string; 726cdf0e10cSrcweir }; 727cdf0e10cSrcweir 728cdf0e10cSrcweir remove_from_dependencies($prj, \%global_deps_hash); 729cdf0e10cSrcweir $build_is_finished{$prj}++; 730cdf0e10cSrcweir }; 731cdf0e10cSrcweir } else { 732cdf0e10cSrcweir store_build_list_content($initial_module); 733cdf0e10cSrcweir get_module_dep_hash($initial_module, \%local_deps_hash); 734cdf0e10cSrcweir initialize_html_info($initial_module); 735cdf0e10cSrcweir my $info_hash = $html_info{$initial_module}; 736cdf0e10cSrcweir $$info_hash{DIRS} = check_deps_hash(\%local_deps_hash, $initial_module); 737cdf0e10cSrcweir $module_by_hash{\%local_deps_hash} = $initial_module; 738cdf0e10cSrcweir if ($server_mode) { 739cdf0e10cSrcweir run_server(); 740cdf0e10cSrcweir } else { 741cdf0e10cSrcweir build_dependent(\%local_deps_hash); 742cdf0e10cSrcweir }; 743cdf0e10cSrcweir }; 744cdf0e10cSrcweir}; 745cdf0e10cSrcweir 746cdf0e10cSrcweirsub backup_deps_hash { 747cdf0e10cSrcweir my $source_hash = shift; 748cdf0e10cSrcweir my $backup_hash = shift; 749cdf0e10cSrcweir foreach my $key (keys %$source_hash) { 750cdf0e10cSrcweir my %values_hash = %{$$source_hash{$key}}; 751cdf0e10cSrcweir $$backup_hash{$key} = \%values_hash; 752cdf0e10cSrcweir }; 753cdf0e10cSrcweir}; 754cdf0e10cSrcweir 755cdf0e10cSrcweirsub initialize_html_info { 756cdf0e10cSrcweir my $module = shift; 757cdf0e10cSrcweir return if (defined $dead_parents{$module}); 758cdf0e10cSrcweir $html_info{$module} = { 'DIRS' => [], 759cdf0e10cSrcweir 'ERRORFUL' => [], 760cdf0e10cSrcweir 'SUCCESSFUL' => [], 761cdf0e10cSrcweir 'BUILD_TIME' => 0}; 762cdf0e10cSrcweir} 763cdf0e10cSrcweir 764cdf0e10cSrcweir# 765cdf0e10cSrcweir# Do job 766cdf0e10cSrcweir# 767cdf0e10cSrcweirsub dmake_dir { 768cdf0e10cSrcweir my ($new_job_name, $error_code); 769cdf0e10cSrcweir my $job_name = shift; 770cdf0e10cSrcweir $jobs_hash{$job_name}->{START_TIME} = time(); 771cdf0e10cSrcweir $jobs_hash{$job_name}->{STATUS} = 'building'; 772cdf0e10cSrcweir if ($job_name =~ /(\s)/o && (!-d $job_name)) { 773cdf0e10cSrcweir $error_code = do_custom_job($job_name, \%local_deps_hash); 774cdf0e10cSrcweir } else { 775cdf0e10cSrcweir html_store_job_info(\%local_deps_hash, $job_name); 776cdf0e10cSrcweir print_error("$job_name not found!!\n") if (!-d $job_name); 777cdf0e10cSrcweir if (!-d $job_name) { 778cdf0e10cSrcweir $new_job_name = $job_name; 779cdf0e10cSrcweir $new_job_name =~ s/_simple//g; 780cdf0e10cSrcweir if ((-d $new_job_name)) { 781cdf0e10cSrcweir print("\nTrying $new_job_name, $job_name not found!!\n"); 782cdf0e10cSrcweir $job_name = $new_job_name; 783cdf0e10cSrcweir } else { 784cdf0e10cSrcweir print_error("\n$job_name not found!!\n"); 785cdf0e10cSrcweir } 786cdf0e10cSrcweir } 787cdf0e10cSrcweir if ($cmd_file) { 788cdf0e10cSrcweir print "cd $job_name\n"; 789cdf0e10cSrcweir print $check_error_string; 790cdf0e10cSrcweir print $echo.$job_name."\n"; 791cdf0e10cSrcweir print "$dmake\n"; 792cdf0e10cSrcweir print $check_error_string; 793cdf0e10cSrcweir } else { 794cdf0e10cSrcweir print "\n" if ( ! $show ); 795cdf0e10cSrcweir print "Entering $job_name\n"; 796cdf0e10cSrcweir }; 797cdf0e10cSrcweir remove_from_dependencies($job_name, \%local_deps_hash) if (!$child); 798cdf0e10cSrcweir return if ($cmd_file || $show); 799cdf0e10cSrcweir $error_code = run_job($dmake, $job_name); 800cdf0e10cSrcweir html_store_job_info(\%local_deps_hash, $job_name, $error_code) if (!$child); 801cdf0e10cSrcweir }; 802cdf0e10cSrcweir 803cdf0e10cSrcweir if ($error_code && $ignore) { 804cdf0e10cSrcweir push(@ignored_errors, $job_name); 805cdf0e10cSrcweir $error_code = 0; 806cdf0e10cSrcweir }; 807cdf0e10cSrcweir if ($child) { 808cdf0e10cSrcweir my $oldfh = select STDERR; 809cdf0e10cSrcweir $| = 1; 810cdf0e10cSrcweir select $oldfh; 811cdf0e10cSrcweir $| =1; 812cdf0e10cSrcweir if ($error_code) { 813cdf0e10cSrcweir _exit($error_code >> 8); 814cdf0e10cSrcweir } else { 815cdf0e10cSrcweir _exit($? >> 8) if ($? && ($? != -1)); 816cdf0e10cSrcweir }; 817cdf0e10cSrcweir _exit(0); 818cdf0e10cSrcweir } elsif ($error_code && ($error_code != -1)) { 819cdf0e10cSrcweir $broken_build{$job_name} = $error_code; 820cdf0e10cSrcweir return $error_code; 821cdf0e10cSrcweir }; 822cdf0e10cSrcweir}; 823cdf0e10cSrcweir 824cdf0e10cSrcweir# 825cdf0e10cSrcweir# Procedure stores information about build list (and) 826cdf0e10cSrcweir# build list object in build_lists_hash 827cdf0e10cSrcweir# 828cdf0e10cSrcweirsub store_build_list_content { 829cdf0e10cSrcweir my $module = shift; 830cdf0e10cSrcweir my $build_list_path = get_build_list_path($module); 831cdf0e10cSrcweir return undef if (!defined $build_list_path); 832cdf0e10cSrcweir return if (!$build_list_path); 833cdf0e10cSrcweir my $xml_list = undef; 834cdf0e10cSrcweir if ($build_list_path =~ /\.xlist$/o) { 835cdf0e10cSrcweir print_error("XMLBuildListParser.pm couldn\'t be found, so XML format for build lists is not enabled") if (!defined $enable_xml); 836cdf0e10cSrcweir $xml_list = XMLBuildListParser->new(); 837cdf0e10cSrcweir if (!$xml_list->loadXMLFile($build_list_path)) { 838cdf0e10cSrcweir print_error("Cannot use $build_list_path"); 839cdf0e10cSrcweir }; 840cdf0e10cSrcweir $build_lists_hash{$module} = $xml_list; 841cdf0e10cSrcweir } else { 842cdf0e10cSrcweir if (open (BUILD_LST, $build_list_path)) { 843cdf0e10cSrcweir my @build_lst = <BUILD_LST>; 844cdf0e10cSrcweir $build_lists_hash{$module} = \@build_lst; 845cdf0e10cSrcweir close BUILD_LST; 846cdf0e10cSrcweir return; 847cdf0e10cSrcweir } 848cdf0e10cSrcweir $dead_parents{$module}++; 849cdf0e10cSrcweir }; 850cdf0e10cSrcweir} 851cdf0e10cSrcweir# 852cdf0e10cSrcweir# Get string (list) of parent projects to build 853cdf0e10cSrcweir# 854cdf0e10cSrcweirsub get_parents_array { 855cdf0e10cSrcweir my $module = shift; 856cdf0e10cSrcweir store_build_list_content($module); 857cdf0e10cSrcweir my $build_list_ref = $build_lists_hash{$module}; 858cdf0e10cSrcweir 859cdf0e10cSrcweir if (ref($build_list_ref) eq 'XMLBuildListParser') { 860cdf0e10cSrcweir return $build_list_ref->getModuleDependencies(\@modes_array); 861cdf0e10cSrcweir }; 862cdf0e10cSrcweir foreach (@$build_list_ref) { 863cdf0e10cSrcweir if ($_ =~ /#/) { 864cdf0e10cSrcweir if ($`) { 865cdf0e10cSrcweir $_ = $`; 866cdf0e10cSrcweir } else { 867cdf0e10cSrcweir next; 868cdf0e10cSrcweir }; 869cdf0e10cSrcweir }; 870cdf0e10cSrcweir s/\r\n//; 871cdf0e10cSrcweir if ($_ =~ /\:+\s+/) { 872cdf0e10cSrcweir return pick_for_build_type($'); 873cdf0e10cSrcweir }; 874cdf0e10cSrcweir }; 875cdf0e10cSrcweir return (); 876cdf0e10cSrcweir}; 877cdf0e10cSrcweir 878cdf0e10cSrcweir# 879cdf0e10cSrcweir# get folders' platform infos 880cdf0e10cSrcweir# 881cdf0e10cSrcweirsub get_prj_platform { 882cdf0e10cSrcweir my $build_list_ref = shift; 883cdf0e10cSrcweir my ($prj_alias, $line); 884cdf0e10cSrcweir foreach(@$build_list_ref) { 885cdf0e10cSrcweir s/\r\n//; 886cdf0e10cSrcweir $line++; 887cdf0e10cSrcweir if ($_ =~ /\snmake\s/) { 888cdf0e10cSrcweir if ($' =~ /\s*-\s+(\w+)[,\S+]*\s+(\S+)/ ) { 889cdf0e10cSrcweir my $platform = $1; 890cdf0e10cSrcweir my $alias = $2; 891cdf0e10cSrcweir print_error ("There is no correct alias set in the line $line!") if ($alias eq 'NULL'); 892cdf0e10cSrcweir mark_platform($alias, $platform); 893cdf0e10cSrcweir } else { 894cdf0e10cSrcweir print_error("Misspelling in line: \n$_"); 895cdf0e10cSrcweir }; 896cdf0e10cSrcweir }; 897cdf0e10cSrcweir }; 898cdf0e10cSrcweir}; 899cdf0e10cSrcweir 900cdf0e10cSrcweir# 901cdf0e10cSrcweir# Procedure populate the dependencies hash with 902cdf0e10cSrcweir# information from XML build list object 903cdf0e10cSrcweir# 904cdf0e10cSrcweirsub get_deps_from_object { 905cdf0e10cSrcweir my ($module, $build_list_object, $dependencies_hash) = @_; 906cdf0e10cSrcweir 907cdf0e10cSrcweir foreach my $dir ($build_list_object->getJobDirectories("make", $ENV{GUI})) { 908cdf0e10cSrcweir $path_hash{$dir} = $module_paths{$module}; 909cdf0e10cSrcweir $path_hash{$dir} .= $dir if ($dir ne '/'); 910cdf0e10cSrcweir my %deps_hash = (); 911cdf0e10cSrcweir 912cdf0e10cSrcweir foreach my $dep ($build_list_object->getJobDependencies($dir, "make", $ENV{GUI})) { 913cdf0e10cSrcweir $deps_hash{$dep}++; 914cdf0e10cSrcweir }; 915cdf0e10cSrcweir $$dependencies_hash{$dir} = \%deps_hash; 916cdf0e10cSrcweir }; 917cdf0e10cSrcweir}; 918cdf0e10cSrcweir 919cdf0e10cSrcweir# 920cdf0e10cSrcweir# this function wraps the get_module_dep_hash and backups the resultung hash 921cdf0e10cSrcweir# 922cdf0e10cSrcweirsub get_module_dep_hash { 923cdf0e10cSrcweir my ($module, $module_dep_hash) = @_; 924cdf0e10cSrcweir if (defined $module_deps_hash_backup{$module}) { 925cdf0e10cSrcweir backup_deps_hash($module_deps_hash_backup{$module}, $module_dep_hash); 926cdf0e10cSrcweir } else { 927cdf0e10cSrcweir get_deps_hash($module, $module_dep_hash); 928cdf0e10cSrcweir my %values_hash = (); 929cdf0e10cSrcweir backup_deps_hash($module_dep_hash, \%values_hash); 930cdf0e10cSrcweir $module_deps_hash_backup{$module} = \%values_hash; 931cdf0e10cSrcweir } 932cdf0e10cSrcweir}; 933cdf0e10cSrcweir 934cdf0e10cSrcweir# 935cdf0e10cSrcweir# Getting hashes of all internal dependencies and additional 936cdf0e10cSrcweir# information for given project 937cdf0e10cSrcweir# 938cdf0e10cSrcweirsub get_deps_hash { 939cdf0e10cSrcweir my ($dummy, $module_to_build); 940cdf0e10cSrcweir my %dead_dependencies = (); 941cdf0e10cSrcweir $module_to_build = shift; 942cdf0e10cSrcweir my $dependencies_hash = shift; 943cdf0e10cSrcweir if ($custom_job) { 944cdf0e10cSrcweir if ($modules_types{$module_to_build} ne 'lnk') { 945cdf0e10cSrcweir add_prerequisite_job($dependencies_hash, $module_to_build, $pre_custom_job); 946cdf0e10cSrcweir add_prerequisite_job($dependencies_hash, $module_to_build, $pre_job); 947cdf0e10cSrcweir add_dependent_job($dependencies_hash, $module_to_build, $custom_job); 948cdf0e10cSrcweir add_dependent_job($dependencies_hash, $module_to_build, $post_job); 949cdf0e10cSrcweir add_dependent_job($dependencies_hash, $module_to_build, $post_custom_job); 950cdf0e10cSrcweir }; 951cdf0e10cSrcweir return; 952cdf0e10cSrcweir }; 953cdf0e10cSrcweir if ( defined $modules_types{$module_to_build} && $modules_types{$module_to_build} ne 'mod') { 954cdf0e10cSrcweir add_prerequisite_job($dependencies_hash, $module_to_build, $pre_job); 955cdf0e10cSrcweir return; 956cdf0e10cSrcweir }; 957cdf0e10cSrcweir 958cdf0e10cSrcweir my $build_list_ref = $build_lists_hash{$module_to_build}; 959cdf0e10cSrcweir# delete $build_lists_hash{$module_to_build}; 960cdf0e10cSrcweir if (ref($build_list_ref) eq 'XMLBuildListParser') { 961cdf0e10cSrcweir get_deps_from_object($module_to_build, $build_list_ref, $dependencies_hash); 962cdf0e10cSrcweir } else { 963cdf0e10cSrcweir get_prj_platform($build_list_ref); 964cdf0e10cSrcweir foreach (@$build_list_ref) { 965cdf0e10cSrcweir if ($_ =~ /#/o) { 966cdf0e10cSrcweir next if (!$`); 967cdf0e10cSrcweir $_ = $`; 968cdf0e10cSrcweir }; 969cdf0e10cSrcweir s/\r\n//; 970cdf0e10cSrcweir if ($_ =~ /\s+nmake\s+/o) { 971cdf0e10cSrcweir my ($platform, $dependencies, $dir, $dir_alias); 972cdf0e10cSrcweir my %deps_hash = (); 973cdf0e10cSrcweir $dependencies = $'; 974cdf0e10cSrcweir $dummy = $`; 975cdf0e10cSrcweir $dummy =~ /(\S+)\s+(\S*)/o; 976cdf0e10cSrcweir $dir = $2; 977cdf0e10cSrcweir $dependencies =~ /(\w+)/o; 978cdf0e10cSrcweir $platform = $1; 979cdf0e10cSrcweir $dependencies = $'; 980cdf0e10cSrcweir while ($dependencies =~ /,(\w+)/o) { 981cdf0e10cSrcweir $dependencies = $'; 982cdf0e10cSrcweir }; 983cdf0e10cSrcweir $dependencies =~ /\s+(\S+)\s+/o; 984cdf0e10cSrcweir $dir_alias = $1; 985cdf0e10cSrcweir if (!check_platform($platform)) { 986cdf0e10cSrcweir next if (defined $platform_hash{$dir_alias}); 987cdf0e10cSrcweir $dead_dependencies{$dir_alias}++; 988cdf0e10cSrcweir next; 989cdf0e10cSrcweir }; 990cdf0e10cSrcweir delete $dead_dependencies{$dir_alias} if (defined $dead_dependencies{$dir_alias}); 991cdf0e10cSrcweir print_error("Directory alias $dir_alias is defined at least twice!! Please, correct build.lst in module $module_to_build") if (defined $$dependencies_hash{$dir_alias}); 992cdf0e10cSrcweir $platform_hash{$dir_alias}++; 993cdf0e10cSrcweir $dependencies = $'; 994cdf0e10cSrcweir print_error("$module_to_build/prj/build.lst has wrongly written dependencies string:\n$_\n") if (!$dependencies); 995cdf0e10cSrcweir $deps_hash{$_}++ foreach (get_dependency_array($dependencies)); 996cdf0e10cSrcweir $$dependencies_hash{$dir_alias} = \%deps_hash; 997cdf0e10cSrcweir my $local_dir = ''; 998cdf0e10cSrcweir if ($dir =~ /(\\|\/)/o) { 999cdf0e10cSrcweir $local_dir = "/$'"; 1000cdf0e10cSrcweir }; 1001cdf0e10cSrcweir $path_hash{$dir_alias} = correct_path($module_paths{$module_to_build} . $local_dir); 1002cdf0e10cSrcweir } elsif ($_ !~ /^\s*$/ && $_ !~ /^\w*\s/o) { 1003cdf0e10cSrcweir chomp; 1004cdf0e10cSrcweir push(@errors, $_); 1005cdf0e10cSrcweir }; 1006cdf0e10cSrcweir }; 1007cdf0e10cSrcweir if (scalar @errors) { 1008cdf0e10cSrcweir my $message = "$module_to_build/prj/build.lst has wrongly written string(s):\n"; 1009cdf0e10cSrcweir $message .= "$_\n" foreach(@errors); 1010cdf0e10cSrcweir if ($processes_to_run) { 1011cdf0e10cSrcweir $broken_build{$module_to_build} = $message; 1012cdf0e10cSrcweir $dependencies_hash = undef; 1013cdf0e10cSrcweir return; 1014cdf0e10cSrcweir } else { 1015cdf0e10cSrcweir print_error($message); 1016cdf0e10cSrcweir }; 1017cdf0e10cSrcweir }; 1018cdf0e10cSrcweir foreach my $alias (keys %dead_dependencies) { 1019cdf0e10cSrcweir next if defined $alive_dependencies{$alias}; 1020cdf0e10cSrcweir# if (!IsHashNative($alias)) { 1021cdf0e10cSrcweir remove_from_dependencies($alias, $dependencies_hash); 1022cdf0e10cSrcweir delete $dead_dependencies{$alias}; 1023cdf0e10cSrcweir# }; 1024cdf0e10cSrcweir }; 1025cdf0e10cSrcweir }; 1026cdf0e10cSrcweir resolve_aliases($dependencies_hash, \%path_hash); 1027cdf0e10cSrcweir if (!$prepare) { 1028cdf0e10cSrcweir add_prerequisite_job($dependencies_hash, $module_to_build, $pre_custom_job); 1029cdf0e10cSrcweir add_prerequisite_job($dependencies_hash, $module_to_build, $pre_job); 1030cdf0e10cSrcweir add_dependent_job($dependencies_hash, $module_to_build, $custom_job); 1031cdf0e10cSrcweir add_dependent_job($dependencies_hash, $module_to_build, $post_job) if ($module_to_build ne $initial_module); 1032cdf0e10cSrcweir add_dependent_job($dependencies_hash, $module_to_build, $post_custom_job); 1033cdf0e10cSrcweir }; 1034cdf0e10cSrcweir store_weights($dependencies_hash); 1035cdf0e10cSrcweir}; 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir# 1038cdf0e10cSrcweir# procedure adds which is independent from anothers, but anothers are dependent from it 1039cdf0e10cSrcweir# 1040cdf0e10cSrcweirsub add_prerequisite_job { 1041cdf0e10cSrcweir my ($dependencies_hash, $module, $job) = @_; 1042cdf0e10cSrcweir return if (!$job); 1043cdf0e10cSrcweir $job = "$module $job"; 1044cdf0e10cSrcweir foreach (keys %$dependencies_hash) { 1045cdf0e10cSrcweir my $deps_hash = $$dependencies_hash{$_}; 1046cdf0e10cSrcweir $$deps_hash{$job}++; 1047cdf0e10cSrcweir }; 1048cdf0e10cSrcweir $$dependencies_hash{$job} = {}; 1049cdf0e10cSrcweir}; 1050cdf0e10cSrcweir 1051cdf0e10cSrcweir# 1052cdf0e10cSrcweir# procedure adds a job wich is dependent from all already registered jobs 1053cdf0e10cSrcweir# 1054cdf0e10cSrcweirsub add_dependent_job { 1055cdf0e10cSrcweir # $post_job is dependent from all jobs 1056cdf0e10cSrcweir my ($dependencies_hash, $module, $job) = @_; 1057cdf0e10cSrcweir return if (!$job); 1058cdf0e10cSrcweir my %deps_hash = (); 1059cdf0e10cSrcweir $deps_hash{$_}++ foreach (keys %$dependencies_hash); 1060cdf0e10cSrcweir $$dependencies_hash{"$module $job"} = \%deps_hash; 1061cdf0e10cSrcweir}; 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir# 1064cdf0e10cSrcweir# this procedure converts aliases to absolute paths 1065cdf0e10cSrcweir# 1066cdf0e10cSrcweirsub resolve_aliases { 1067cdf0e10cSrcweir my ($dependencies_hash, $path_hash) = @_; 1068cdf0e10cSrcweir foreach my $dir_alias (keys %$dependencies_hash) { 1069cdf0e10cSrcweir my $aliases_hash_ref = $$dependencies_hash{$dir_alias}; 1070cdf0e10cSrcweir my %paths_hash = (); 1071cdf0e10cSrcweir foreach (keys %$aliases_hash_ref) { 1072cdf0e10cSrcweir $paths_hash{$$path_hash{$_}}++; 1073cdf0e10cSrcweir }; 1074cdf0e10cSrcweir delete $$dependencies_hash{$dir_alias}; 1075cdf0e10cSrcweir $$dependencies_hash{$$path_hash{$dir_alias}} = \%paths_hash; 1076cdf0e10cSrcweir }; 1077cdf0e10cSrcweir}; 1078cdf0e10cSrcweir 1079cdf0e10cSrcweir# 1080cdf0e10cSrcweir# mark platform in order to prove if alias has been used according to specs 1081cdf0e10cSrcweir# 1082cdf0e10cSrcweirsub mark_platform { 1083cdf0e10cSrcweir my $prj_alias = shift; 1084cdf0e10cSrcweir if (exists $prj_platform{$prj_alias}) { 1085cdf0e10cSrcweir $prj_platform{$prj_alias} = 'all'; 1086cdf0e10cSrcweir } else { 1087cdf0e10cSrcweir $prj_platform{$prj_alias} = shift; 1088cdf0e10cSrcweir }; 1089cdf0e10cSrcweir}; 1090cdf0e10cSrcweir 1091cdf0e10cSrcweir# 1092cdf0e10cSrcweir# Convert path from abstract (with '\' and/or '/' delimiters) 1093cdf0e10cSrcweir# to system-independent 1094cdf0e10cSrcweir# 1095cdf0e10cSrcweirsub correct_path { 1096cdf0e10cSrcweir $_ = shift; 1097cdf0e10cSrcweir s/\\/\//g; 1098cdf0e10cSrcweir return $_; 1099cdf0e10cSrcweir}; 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir 1102cdf0e10cSrcweirsub check_dmake { 1103cdf0e10cSrcweir#print "Checking dmake..."; 1104cdf0e10cSrcweir if (open(DMAKEVERSION, "dmake -V |")) { 1105cdf0e10cSrcweir# if (open(DMAKEVERSION, "dmake -V |")) { 1106cdf0e10cSrcweir my @dmake_version = <DMAKEVERSION>; 1107cdf0e10cSrcweir close DMAKEVERSION; 1108cdf0e10cSrcweir# if ($dmake_version[0] =~ /^dmake\s\-\sCopyright\s\(c\)/) { 1109cdf0e10cSrcweir# print " Using version $1\n" if ($dmake_version[0] =~ /Version\s(\d+\.*\d*)/); 1110cdf0e10cSrcweir# }; 1111cdf0e10cSrcweir return; 1112cdf0e10cSrcweir }; 1113cdf0e10cSrcweir my $error_message = 'dmake: Command not found.'; 1114cdf0e10cSrcweir $error_message .= ' Please rerun bootstrap' if (!defined $ENV{COMMON_ENV_TOOLS}); 1115cdf0e10cSrcweir print_error($error_message); 1116cdf0e10cSrcweir}; 1117cdf0e10cSrcweir 1118cdf0e10cSrcweir# 1119cdf0e10cSrcweir# Get platform-dependent commands 1120cdf0e10cSrcweir# 1121cdf0e10cSrcweirsub get_commands { 1122cdf0e10cSrcweir my $arg = ''; 1123cdf0e10cSrcweir # Setting alias for dmake 1124cdf0e10cSrcweir $dmake = 'dmake'; 1125cdf0e10cSrcweir check_dmake(); 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir if ($cmd_file) { 1128cdf0e10cSrcweir if ($ENV{GUI} eq 'UNX') { 1129cdf0e10cSrcweir $check_error_string = "if \"\$?\" != \"0\" exit\n"; 1130cdf0e10cSrcweir } else { 1131cdf0e10cSrcweir $check_error_string = "if \"\%?\" != \"0\" quit\n"; 1132cdf0e10cSrcweir }; 1133cdf0e10cSrcweir }; 1134cdf0e10cSrcweir 1135cdf0e10cSrcweir $dmake_args = join(' ', 'dmake', @dmake_args); 1136cdf0e10cSrcweir 1137cdf0e10cSrcweir while ($arg = pop(@dmake_args)) { 1138cdf0e10cSrcweir $dmake .= ' '.$arg; 1139cdf0e10cSrcweir }; 1140cdf0e10cSrcweir $dmake .= ' verbose=true' if ($html); 1141cdf0e10cSrcweir}; 1142cdf0e10cSrcweir 1143cdf0e10cSrcweir# 1144cdf0e10cSrcweir# Procedure retrieves list of projects to be built from build.lst 1145cdf0e10cSrcweir# 1146cdf0e10cSrcweirsub get_workspace_path { 1147cdf0e10cSrcweir if (!defined $ENV{GUI}) { 1148cdf0e10cSrcweir $ENV{mk_tmp} = ''; 1149cdf0e10cSrcweir die "No environment set\n"; 1150cdf0e10cSrcweir }; 1151cdf0e10cSrcweir my $repository_helper = RepositoryHelper->new(); 1152cdf0e10cSrcweir my $workspace_path = $repository_helper->get_repository_root(); 1153cdf0e10cSrcweir my $initial_dir = $repository_helper->get_initial_directory(); 1154cdf0e10cSrcweir if ($workspace_path eq $initial_dir) { 1155cdf0e10cSrcweir print_error('Found no project to build'); 1156cdf0e10cSrcweir }; 1157cdf0e10cSrcweir $initial_module = substr($initial_dir, length($workspace_path) + 1); 1158cdf0e10cSrcweir if ($initial_module =~ /(\\|\/)/) { 1159cdf0e10cSrcweir $initial_module = $`; 1160cdf0e10cSrcweir }; 1161cdf0e10cSrcweir $module_paths{$initial_module} = $workspace_path . "/$initial_module"; 1162cdf0e10cSrcweir return $workspace_path; 1163cdf0e10cSrcweir}; 1164cdf0e10cSrcweir 1165cdf0e10cSrcweir# 1166cdf0e10cSrcweir# Picks project which can be built now from hash and then deletes it from hash 1167cdf0e10cSrcweir# 1168cdf0e10cSrcweirsub pick_prj_to_build { 1169cdf0e10cSrcweir my $deps_hash = shift; 1170cdf0e10cSrcweir get_html_orders(); 1171cdf0e10cSrcweir my $prj = find_indep_prj($deps_hash); 1172cdf0e10cSrcweir if ($prj) { 1173cdf0e10cSrcweir delete $$deps_hash{$prj}; 1174cdf0e10cSrcweir generate_html_file(); 1175cdf0e10cSrcweir }; 1176cdf0e10cSrcweir return $prj; 1177cdf0e10cSrcweir}; 1178cdf0e10cSrcweir 1179cdf0e10cSrcweir# 1180cdf0e10cSrcweir# Make a decision if the project should be built on this platform 1181cdf0e10cSrcweir# 1182cdf0e10cSrcweirsub check_platform { 1183cdf0e10cSrcweir my $platform = shift; 1184cdf0e10cSrcweir return 1 if ($platform eq 'all'); 1185cdf0e10cSrcweir return 1 if (($ENV{GUI} eq 'WIN') && ($platform eq 'w')); 1186cdf0e10cSrcweir return 1 if (($ENV{GUI} eq 'UNX') && ($platform eq 'u')); 1187cdf0e10cSrcweir return 1 if (($ENV{GUI} eq 'OS2') && ($platform eq 'p')); 1188cdf0e10cSrcweir return 1 if (($ENV{GUI} eq 'WNT') && 1189cdf0e10cSrcweir (($platform eq 'w') || ($platform eq 'n'))); 1190cdf0e10cSrcweir return 0; 1191cdf0e10cSrcweir}; 1192cdf0e10cSrcweir 1193cdf0e10cSrcweir# 1194cdf0e10cSrcweir# Remove project to build ahead from dependencies and make an array 1195cdf0e10cSrcweir# of all from given project dependent projects 1196cdf0e10cSrcweir# 1197cdf0e10cSrcweirsub remove_from_dependencies { 1198cdf0e10cSrcweir my ($exclude_prj, $i, $prj, $dependencies); 1199cdf0e10cSrcweir $exclude_prj = shift; 1200cdf0e10cSrcweir my $exclude_prj_orig = ''; 1201cdf0e10cSrcweir $exclude_prj_orig = $` if (($exclude_prj =~ /\.lnk$/o) || ($exclude_prj =~ /\.link$/o)); 1202cdf0e10cSrcweir $dependencies = shift; 1203cdf0e10cSrcweir foreach $prj (keys %$dependencies) { 1204cdf0e10cSrcweir my $prj_deps_hash = $$dependencies{$prj}; 1205cdf0e10cSrcweir delete $$prj_deps_hash{$exclude_prj} if (defined $$prj_deps_hash{$exclude_prj}); 1206cdf0e10cSrcweir }; 1207cdf0e10cSrcweir}; 1208cdf0e10cSrcweir 1209cdf0e10cSrcweir 1210cdf0e10cSrcweir# 1211cdf0e10cSrcweir# Check the hash for consistency 1212cdf0e10cSrcweir# 1213cdf0e10cSrcweirsub check_deps_hash { 1214cdf0e10cSrcweir my ($deps_hash_ref, $module) = @_; 1215cdf0e10cSrcweir my @possible_order; 1216cdf0e10cSrcweir my $module_path = $module_paths{$module} if (defined $module); 1217cdf0e10cSrcweir return if (!scalar keys %$deps_hash_ref); 1218cdf0e10cSrcweir my %deps_hash = (); 1219cdf0e10cSrcweir my $consistent; 1220cdf0e10cSrcweir backup_deps_hash($deps_hash_ref, \%deps_hash); 1221cdf0e10cSrcweir my $string; 1222cdf0e10cSrcweir my $log_name; 1223cdf0e10cSrcweir my $build_number = 0; 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir do { 1226cdf0e10cSrcweir $consistent = ''; 1227cdf0e10cSrcweir foreach my $key (sort keys %deps_hash) { 1228cdf0e10cSrcweir my $local_deps_ref = $deps_hash{$key}; 1229cdf0e10cSrcweir if (!scalar keys %$local_deps_ref) { 1230cdf0e10cSrcweir if (defined $module) { 1231cdf0e10cSrcweir $build_number++; 1232cdf0e10cSrcweir $string = undef; 1233cdf0e10cSrcweir if ($key =~ /(\s)/o) { 1234cdf0e10cSrcweir $string = $key; 1235cdf0e10cSrcweir } else { 1236cdf0e10cSrcweir if (length($key) == length($module_path)) { 1237cdf0e10cSrcweir $string = './'; 1238cdf0e10cSrcweir } else { 1239cdf0e10cSrcweir $string = substr($key, length($module_path) + 1); 1240cdf0e10cSrcweir $string =~ s/\\/\//go; 1241cdf0e10cSrcweir }; 1242cdf0e10cSrcweir }; 1243cdf0e10cSrcweir $log_name = $string; 1244cdf0e10cSrcweir if ($log_name eq "$module $custom_job") { 1245cdf0e10cSrcweir $log_name = "custom_job"; 1246cdf0e10cSrcweir }; 1247cdf0e10cSrcweir if ($log_name eq "$module $pre_custom_job") { 1248cdf0e10cSrcweir $log_name = "pre_custom_job"; 1249cdf0e10cSrcweir }; 1250cdf0e10cSrcweir if ($log_name eq "$module $post_custom_job") { 1251cdf0e10cSrcweir $log_name = "post_custom_job"; 1252cdf0e10cSrcweir }; 1253cdf0e10cSrcweir $log_name =~ s/\\|\//\./g; 1254cdf0e10cSrcweir $log_name =~ s/\s/_/g; 1255cdf0e10cSrcweir $log_name = $module if ($log_name =~ /^\.+$/); 1256cdf0e10cSrcweir $log_name .= '.txt'; 1257cdf0e10cSrcweir push(@possible_order, $key); 1258cdf0e10cSrcweir $jobs_hash{$key} = { SHORT_NAME => $string, 1259cdf0e10cSrcweir BUILD_NUMBER => $build_number, 1260cdf0e10cSrcweir STATUS => 'waiting', 1261cdf0e10cSrcweir LOG_PATH => '../' . $source_config->get_module_repository($module) . "/$module/$ENV{INPATH}/misc/logs/$log_name", 1262cdf0e10cSrcweir LONG_LOG_PATH => correct_path($module_paths{$module} . "/$ENV{INPATH}/misc/logs/$log_name"), 1263cdf0e10cSrcweir START_TIME => 0, 1264cdf0e10cSrcweir FINISH_TIME => 0, 1265cdf0e10cSrcweir CLIENT => '-' 1266cdf0e10cSrcweir }; 1267cdf0e10cSrcweir }; 1268cdf0e10cSrcweir remove_from_dependencies($key, \%deps_hash); 1269cdf0e10cSrcweir delete $deps_hash{$key}; 1270cdf0e10cSrcweir $consistent++; 1271cdf0e10cSrcweir }; 1272cdf0e10cSrcweir }; 1273cdf0e10cSrcweir } while ($consistent && (scalar keys %deps_hash)); 1274cdf0e10cSrcweir return \@possible_order if ($consistent); 1275cdf0e10cSrcweir print STDERR "Fatal error:"; 1276cdf0e10cSrcweir foreach (keys %deps_hash) { 1277cdf0e10cSrcweir print STDERR "\n\t$_ depends on: "; 1278cdf0e10cSrcweir foreach my $i (keys %{$deps_hash{$_}}) { 1279cdf0e10cSrcweir print STDERR (' ', $i); 1280cdf0e10cSrcweir }; 1281cdf0e10cSrcweir }; 1282cdf0e10cSrcweir if ($child) { 1283cdf0e10cSrcweir my $oldfh = select STDERR; 1284cdf0e10cSrcweir $| = 1; 1285cdf0e10cSrcweir _do_exit(1); 1286cdf0e10cSrcweir } else { 1287cdf0e10cSrcweir print_error("There are dead or circular dependencies\n"); 1288cdf0e10cSrcweir }; 1289cdf0e10cSrcweir}; 1290cdf0e10cSrcweir 1291cdf0e10cSrcweir# 1292cdf0e10cSrcweir# Find project with no dependencies left. 1293cdf0e10cSrcweir# 1294cdf0e10cSrcweirsub find_indep_prj { 1295cdf0e10cSrcweir my ($dependencies, $i); 1296cdf0e10cSrcweir my @candidates = (); 1297cdf0e10cSrcweir $all_dependent = 1; 1298cdf0e10cSrcweir handle_dead_children(0) if ($processes_to_run); 1299cdf0e10cSrcweir my $children = children_number(); 1300cdf0e10cSrcweir return '' if (!$server_mode && $children && ($children >= $processes_to_run)); 1301cdf0e10cSrcweir $dependencies = shift; 1302cdf0e10cSrcweir if (scalar keys %$dependencies) { 1303cdf0e10cSrcweir foreach my $job (keys %$dependencies) { 1304cdf0e10cSrcweir if (!scalar keys %{$$dependencies{$job}}) { 1305cdf0e10cSrcweir push(@candidates, $job); 1306cdf0e10cSrcweir last if (!$processes_to_run); 1307cdf0e10cSrcweir }; 1308cdf0e10cSrcweir }; 1309cdf0e10cSrcweir if (scalar @candidates) { 1310cdf0e10cSrcweir $all_dependent = 0; 1311cdf0e10cSrcweir my $best_candidate = undef; 1312cdf0e10cSrcweir my $best_weight = 0; 1313cdf0e10cSrcweir if (scalar @candidates > 1) { 1314cdf0e10cSrcweir foreach my $candidate (@candidates) { 1315cdf0e10cSrcweir my $candidate_weight = get_waiters_number($candidate); 1316cdf0e10cSrcweir if ($candidate_weight > $best_weight) { 1317cdf0e10cSrcweir $best_candidate = $candidate; 1318cdf0e10cSrcweir $best_weight = $candidate_weight; 1319cdf0e10cSrcweir }; 1320cdf0e10cSrcweir }; 1321cdf0e10cSrcweir if (defined $best_candidate) { 1322cdf0e10cSrcweir return $best_candidate; 1323cdf0e10cSrcweir } 1324cdf0e10cSrcweir } 1325cdf0e10cSrcweir my @sorted_candidates = sort(@candidates); 1326cdf0e10cSrcweir return $sorted_candidates[0]; 1327cdf0e10cSrcweir }; 1328cdf0e10cSrcweir }; 1329cdf0e10cSrcweir return ''; 1330cdf0e10cSrcweir}; 1331cdf0e10cSrcweir 1332cdf0e10cSrcweirsub get_waiters_number { 1333cdf0e10cSrcweir my $module = shift; 1334cdf0e10cSrcweir if (defined $weights_hash{$module}) { 1335cdf0e10cSrcweir return $weights_hash{$module}; 1336cdf0e10cSrcweir }; 1337cdf0e10cSrcweir if (defined $reversed_dependencies{$module}) { 1338cdf0e10cSrcweir return scalar keys %{$reversed_dependencies{$module}}; 1339cdf0e10cSrcweir }; 1340cdf0e10cSrcweir return 0; 1341cdf0e10cSrcweir}; 1342cdf0e10cSrcweir 1343cdf0e10cSrcweir# 1344cdf0e10cSrcweir# Check if given entry is HASH-native, that is not a user-defined data 1345cdf0e10cSrcweir# 1346cdf0e10cSrcweir#sub IsHashNative { 1347cdf0e10cSrcweir# my $prj = shift; 1348cdf0e10cSrcweir# return 1 if ($prj =~ /^HASH\(0x[\d | a | b | c | d | e | f]{6,}\)/); 1349cdf0e10cSrcweir# return 0; 1350cdf0e10cSrcweir#}; 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir# 1353cdf0e10cSrcweir# Getting array of dependencies from the string given 1354cdf0e10cSrcweir# 1355cdf0e10cSrcweirsub get_dependency_array { 1356cdf0e10cSrcweir my ($dep_string, @dependencies, $parent_prj, $prj, $string); 1357cdf0e10cSrcweir @dependencies = (); 1358cdf0e10cSrcweir $dep_string = shift; 1359cdf0e10cSrcweir $string = $dep_string; 1360cdf0e10cSrcweir $prj = shift; 1361cdf0e10cSrcweir while ($dep_string !~ /^NULL/o) { 1362cdf0e10cSrcweir print_error("Project $prj has wrongly written dependencies string:\n $string") if (!$dep_string); 1363cdf0e10cSrcweir $dep_string =~ /(\S+)\s*/o; 1364cdf0e10cSrcweir $parent_prj = $1; 1365cdf0e10cSrcweir $dep_string = $'; 1366cdf0e10cSrcweir if ($parent_prj =~ /\.(\w+)$/o) { 1367cdf0e10cSrcweir $parent_prj = $`; 1368cdf0e10cSrcweir if (($prj_platform{$parent_prj} ne $1) && 1369cdf0e10cSrcweir ($prj_platform{$parent_prj} ne 'all')) { 1370cdf0e10cSrcweir print_error ("$parent_prj\.$1 is a wrongly dependency identifier!\nCheck if it is platform dependent"); 1371cdf0e10cSrcweir }; 1372cdf0e10cSrcweir $alive_dependencies{$parent_prj}++ if (check_platform($1)); 1373cdf0e10cSrcweir push(@dependencies, $parent_prj); 1374cdf0e10cSrcweir } else { 1375cdf0e10cSrcweir if ((exists($prj_platform{$parent_prj})) && 1376cdf0e10cSrcweir ($prj_platform{$parent_prj} ne 'all') ) { 1377cdf0e10cSrcweir print_error("$parent_prj is a wrongly used dependency identifier!\nCheck if it is platform dependent"); 1378cdf0e10cSrcweir }; 1379cdf0e10cSrcweir push(@dependencies, $parent_prj); 1380cdf0e10cSrcweir }; 1381cdf0e10cSrcweir }; 1382cdf0e10cSrcweir return @dependencies; 1383cdf0e10cSrcweir}; 1384cdf0e10cSrcweir 1385cdf0e10cSrcweir 1386cdf0e10cSrcweir# 1387cdf0e10cSrcweir# Getting current directory list 1388cdf0e10cSrcweir# 1389cdf0e10cSrcweirsub get_directory_list { 1390cdf0e10cSrcweir my $path = shift; 1391cdf0e10cSrcweir opendir(CurrentDirList, $path); 1392cdf0e10cSrcweir my @directory_list = readdir(CurrentDirList); 1393cdf0e10cSrcweir closedir(CurrentDirList); 1394cdf0e10cSrcweir return @directory_list; 1395cdf0e10cSrcweir}; 1396cdf0e10cSrcweir 1397cdf0e10cSrcweirsub print_error { 1398cdf0e10cSrcweir my $message = shift; 1399cdf0e10cSrcweir my $force = shift; 1400cdf0e10cSrcweir $modules_number -= scalar keys %global_deps_hash; 1401cdf0e10cSrcweir $modules_number -= 1; 1402cdf0e10cSrcweir print STDERR "\nERROR: $message\n"; 1403cdf0e10cSrcweir $ENV{mk_tmp} = ''; 1404cdf0e10cSrcweir if ($cmd_file) { 1405cdf0e10cSrcweir close CMD_FILE; 1406cdf0e10cSrcweir unlink ($cmd_file); 1407cdf0e10cSrcweir }; 1408cdf0e10cSrcweir if (!$child) { 1409cdf0e10cSrcweir $ENV{mk_tmp} = ''; 1410cdf0e10cSrcweir close CMD_FILE if ($cmd_file); 1411cdf0e10cSrcweir unlink ($cmd_file); 1412cdf0e10cSrcweir do_exit(1); 1413cdf0e10cSrcweir }; 1414cdf0e10cSrcweir do_exit(1) if (defined $force); 1415cdf0e10cSrcweir}; 1416cdf0e10cSrcweir 1417cdf0e10cSrcweirsub usage { 1418cdf0e10cSrcweir print STDERR "\nbuild\n"; 1419cdf0e10cSrcweir print STDERR "Syntax: build [--all|-a[:prj_name]]|[--from|-f prj_name1[:prj_name2] [prj_name3 [...]]]|[--since|-c prj_name] [--with_branches prj_name1[:prj_name2] [--skip prj_name1[:prj_name2] [prj_name3 [...]] [prj_name3 [...]|-b]|[--prepare|-p][:platform] [--deliver|-d [--dlv_switch deliver_switch]]] [-P processes|--server [--setenvstring \"string\"] [--client_timeout MIN] [--port port1[:port2:...:portN]]] [--show|-s] [--help|-h] [--file|-F] [--ignore|-i] [--version|-V] [--mode|-m OOo[,SO[,EXT]] [--html [--html_path html_file_path] [--dontgraboutput]] [--pre_job=pre_job_sring] [--job=job_string|-j] [--post_job=post_job_sring] [--stoponerror] [--genconf [--removeall|--clear|--remove|--add [module1,module2[,...,moduleN]]]] [--exclude_branch_from prj_name1[:prj_name2] [prj_name3 [...]]] [--interactive]\n"; 1420cdf0e10cSrcweir print STDERR "Example1: build --from sfx2\n"; 1421cdf0e10cSrcweir print STDERR " - build all projects dependent from sfx2, starting with sfx2, finishing with the current module\n"; 1422cdf0e10cSrcweir print STDERR "Example2: build --all:sfx2\n"; 1423cdf0e10cSrcweir print STDERR " - the same as --all, but skip all projects that have been already built when using \"--all\" switch before sfx2\n"; 1424cdf0e10cSrcweir print STDERR "Example3: build --all --server\n"; 1425cdf0e10cSrcweir print STDERR " - build all projects in server mode, use first available port from default range 7890-7894 (running clients required!!)\n"; 1426cdf0e10cSrcweir print STDERR "Example4(for unixes):\n"; 1427cdf0e10cSrcweir print STDERR " build --all --pre_job=echo\\ Starting\\ job\\ in\\ \\\$PWD --job=some_script.sh --post_job=echo\\ Job\\ in\\ \\\$PWD\\ is\\ made\n"; 1428cdf0e10cSrcweir print STDERR " - go through all projects, echo \"Starting job in \$PWD\" in each module, execute script some_script.sh, and finally echo \"Job in \$PWD is made\"\n"; 1429cdf0e10cSrcweir print STDERR "\nSwitches:\n"; 1430cdf0e10cSrcweir print STDERR " --all - build all projects from very beginning till current one\n"; 1431cdf0e10cSrcweir print STDERR " --from - build all projects dependent from the specified (including it) till current one\n"; 1432cdf0e10cSrcweir print STDERR " --exclude_branch_from - exclude module(s) and its branch from the build\n"; 1433cdf0e10cSrcweir print STDERR " --mode OOo - build only projects needed for OpenOffice.org\n"; 1434cdf0e10cSrcweir print STDERR " --prepare - clear all projects for incompatible build from prj_name till current one [for platform] (cws version)\n"; 1435cdf0e10cSrcweir print STDERR " --with_branches- the same as \"--from\" but with build all projects in neighbour branches\n"; 1436cdf0e10cSrcweir print STDERR " --skip - do not build certain module(s)\n"; 1437cdf0e10cSrcweir print STDERR " --since - build all projects beginning from the specified till current one (the same as \"--all:prj_name\", but skipping prj_name)\n"; 1438cdf0e10cSrcweir print STDERR " --checkmodules - check if all required parent projects are availlable\n"; 1439cdf0e10cSrcweir print STDERR " --show - show what is going to be built\n"; 1440cdf0e10cSrcweir print STDERR " --file - generate command file file_name\n"; 1441cdf0e10cSrcweir print STDERR " --deliver - only deliver, no build (usable for \'-all\' and \'-from\' keys)\n"; 1442cdf0e10cSrcweir print STDERR " -P - start multiprocessing build, with number of processes passed\n"; 1443cdf0e10cSrcweir print STDERR " --server - start build in server mode (clients required)\n"; 1444cdf0e10cSrcweir print STDERR " --setenvstring - string for configuration of the client environment\n"; 1445cdf0e10cSrcweir print STDERR " --port - set server port, default is 7890. You may pass several ports, the server will be started on the first available\n"; 1446cdf0e10cSrcweir print STDERR " otherwise the server will be started on first available port from the default range 7890-7894\n"; 1447cdf0e10cSrcweir print STDERR " --client_timeout - time frame after which the client/job is considered to be lost. Default is 120 min\n"; 1448cdf0e10cSrcweir print STDERR " --dlv_switch - use deliver with the switch specified\n"; 1449cdf0e10cSrcweir print STDERR " --help - print help info\n"; 1450cdf0e10cSrcweir print STDERR " --ignore - force tool to ignore errors\n"; 1451cdf0e10cSrcweir print STDERR " --html - generate html page with build status\n"; 1452cdf0e10cSrcweir print STDERR " file named $ENV{INPATH}.build.html will be generated in $ENV{SOLARSRC}\n"; 1453cdf0e10cSrcweir print STDERR " --html_path - set html page path\n"; 1454cdf0e10cSrcweir print STDERR " --dontgraboutput - do not grab console output when generating html page\n"; 1455cdf0e10cSrcweir print STDERR " --genconf - generate/modify workspace configuration file\n"; 1456cdf0e10cSrcweir print STDERR " --add - add active module(s) to configuration file\n"; 1457cdf0e10cSrcweir print STDERR " --remove - removeactive modules(s) from configuration file\n"; 1458cdf0e10cSrcweir print STDERR " --removeall|--clear - remove all active modules(s) from configuration file\n"; 1459cdf0e10cSrcweir 1460cdf0e10cSrcweir print STDERR " --stoponerror - stop build when error occurs (for mp builds)\n"; 1461cdf0e10cSrcweir print STDERR " --interactive - start interactive build process (process can be managed via html page)\n"; 1462cdf0e10cSrcweir print STDERR " Custom jobs:\n"; 1463cdf0e10cSrcweir print STDERR " --job=job_string - execute custom job in (each) module. job_string is a shell script/command to be executed instead of regular dmake jobs\n"; 1464cdf0e10cSrcweir print STDERR " --pre_job=pre_job_string - execute preliminary job in (each) module. pre_job_string is a shell script/command to be executed before regular job in the module\n"; 1465cdf0e10cSrcweir print STDERR " --post_job=job_string - execute a postprocess job in (each) module. post_job_string is a shell script/command to be executed after regular job in the module\n"; 1466cdf0e10cSrcweir print STDERR "Default: - build current project\n"; 1467cdf0e10cSrcweir print STDERR "Unknown switches passed to dmake\n"; 1468cdf0e10cSrcweir}; 1469cdf0e10cSrcweir 1470cdf0e10cSrcweir# 1471cdf0e10cSrcweir# Get all options passed 1472cdf0e10cSrcweir# 1473cdf0e10cSrcweirsub get_options { 1474cdf0e10cSrcweir my ($arg, $dont_grab_output); 1475cdf0e10cSrcweir while ($arg = shift @ARGV) { 1476cdf0e10cSrcweir $arg =~ /^-P$/ and $processes_to_run = shift @ARGV and next; 1477cdf0e10cSrcweir $arg =~ /^-P(\d+)$/ and $processes_to_run = $1 and next; 1478cdf0e10cSrcweir $arg =~ /^--all$/ and $build_all_parents = 1 and next; 1479cdf0e10cSrcweir $arg =~ /^-a$/ and $build_all_parents = 1 and next; 1480cdf0e10cSrcweir $arg =~ /^--show$/ and $show = 1 and next; 1481cdf0e10cSrcweir $arg =~ /^--checkmodules$/ and $checkparents = 1 and $ignore = 1 and next; 1482cdf0e10cSrcweir $arg =~ /^-s$/ and $show = 1 and next; 1483cdf0e10cSrcweir $arg =~ /^--deliver$/ and $deliver = 1 and next; 1484cdf0e10cSrcweir $arg =~ /^(--job=)/ and $custom_job = $' and next; 1485cdf0e10cSrcweir $arg =~ /^(--pre_job=)/ and $pre_custom_job = $' and next; 1486cdf0e10cSrcweir $arg =~ /^(--post_job=)/ and $post_custom_job = $' and next; 1487cdf0e10cSrcweir $arg =~ /^-d$/ and $deliver = 1 and next; 1488cdf0e10cSrcweir $arg =~ /^--dlv_switch$/ and $dlv_switch = shift @ARGV and next; 1489cdf0e10cSrcweir $arg =~ /^--file$/ and $cmd_file = shift @ARGV and next; 1490cdf0e10cSrcweir $arg =~ /^-F$/ and $cmd_file = shift @ARGV and next; 1491cdf0e10cSrcweir $arg =~ /^--skip$/ and get_modules_passed(\%skip_modules) and next; 1492cdf0e10cSrcweir 1493cdf0e10cSrcweir if ($arg =~ /^--with_branches$/ || $arg =~ /^-b$/) { 1494cdf0e10cSrcweir $build_from_with_branches = 1; 1495cdf0e10cSrcweir $build_all_parents = 1; 1496cdf0e10cSrcweir get_modules_passed(\%incompatibles); 1497cdf0e10cSrcweir next; 1498cdf0e10cSrcweir }; 1499cdf0e10cSrcweir $arg =~ /^--all:(\S+)$/ and $build_all_parents = 1 1500cdf0e10cSrcweir and $build_all_cont = $1 and next; 1501cdf0e10cSrcweir $arg =~ /^-a:(\S+)$/ and $build_all_parents = 1 1502cdf0e10cSrcweir and $build_all_cont = $1 and next; 1503cdf0e10cSrcweir if ($arg =~ /^--from$/ || $arg =~ /^-f$/) { 1504cdf0e10cSrcweir $build_all_parents = 1; 1505cdf0e10cSrcweir get_modules_passed(\%incompatibles); 1506cdf0e10cSrcweir next; 1507cdf0e10cSrcweir }; 1508cdf0e10cSrcweir if ($arg =~ /^--exclude_branch_from$/) { 1509cdf0e10cSrcweir get_modules_passed(\%exclude_branches); 1510cdf0e10cSrcweir next; 1511cdf0e10cSrcweir }; 1512cdf0e10cSrcweir $arg =~ /^--prepare$/ and $prepare = 1 and next; 1513cdf0e10cSrcweir $arg =~ /^-p$/ and $prepare = 1 and next; 1514cdf0e10cSrcweir $arg =~ /^--prepare:/ and $prepare = 1 and $only_platform = $' and next; 1515cdf0e10cSrcweir $arg =~ /^-p:/ and $prepare = 1 and $only_platform = $' and next; 1516cdf0e10cSrcweir $arg =~ /^--since$/ and $build_all_parents = 1 1517cdf0e10cSrcweir and $build_since = shift @ARGV and next; 1518cdf0e10cSrcweir $arg =~ /^-c$/ and $build_all_parents = 1 1519cdf0e10cSrcweir and $build_since = shift @ARGV and next; 1520cdf0e10cSrcweir $arg =~ /^-s$/ and $build_all_parents = 1 1521cdf0e10cSrcweir and $build_since = shift @ARGV and next; 1522cdf0e10cSrcweir $arg =~ /^--help$/ and usage() and do_exit(0); 1523cdf0e10cSrcweir $arg =~ /^-h$/ and usage() and do_exit(0); 1524cdf0e10cSrcweir $arg =~ /^--ignore$/ and $ignore = 1 and next; 1525cdf0e10cSrcweir $arg =~ /^--genconf$/ and $generate_config = 1 and next; 1526cdf0e10cSrcweir if ($arg =~ /^--add$/) { 1527cdf0e10cSrcweir get_list_of_modules(\%add_to_config); 1528cdf0e10cSrcweir next; 1529cdf0e10cSrcweir }; 1530cdf0e10cSrcweir if ($arg =~ /^--remove$/) { 1531cdf0e10cSrcweir get_list_of_modules(\%remove_from_config); 1532cdf0e10cSrcweir if (!scalar %remove_from_config) { 1533cdf0e10cSrcweir print_error('No module list supplied!!'); 1534cdf0e10cSrcweir }; 1535cdf0e10cSrcweir next; 1536cdf0e10cSrcweir }; 1537cdf0e10cSrcweir ($arg =~ /^--clear$/ || $arg =~ /^--removeall$/) and $clear_config = 1 and next; 1538cdf0e10cSrcweir $arg =~ /^--html$/ and $html = 1 and next; 1539cdf0e10cSrcweir $arg =~ /^--dontgraboutput$/ and $dont_grab_output = 1 and next; 1540cdf0e10cSrcweir $arg =~ /^--html_path$/ and $html_path = shift @ARGV and next; 1541cdf0e10cSrcweir $arg =~ /^-i$/ and $ignore = 1 and next; 1542cdf0e10cSrcweir $arg =~ /^--server$/ and $server_mode = 1 and next; 1543cdf0e10cSrcweir $arg =~ /^--client_timeout$/ and $client_timeout = (shift @ARGV)*60 and next; 1544cdf0e10cSrcweir $arg =~ /^--setenvstring$/ and $setenv_string = shift @ARGV and next; 1545cdf0e10cSrcweir $arg =~ /^--port$/ and $ports_string = shift @ARGV and next; 1546cdf0e10cSrcweir $arg =~ /^--version$/ and do_exit(0); 1547cdf0e10cSrcweir $arg =~ /^-V$/ and do_exit(0); 1548cdf0e10cSrcweir $arg =~ /^-m$/ and get_modes() and next; 1549cdf0e10cSrcweir $arg =~ /^--mode$/ and get_modes() and next; 1550cdf0e10cSrcweir $arg =~ /^--stoponerror$/ and $stop_build_on_error = 1 and next; 1551cdf0e10cSrcweir $arg =~ /^--interactive$/ and $interactive = 1 and next; 1552cdf0e10cSrcweir if ($arg =~ /^--$/) { 1553cdf0e10cSrcweir push (@dmake_args, get_dmake_args()) if (!$custom_job); 1554cdf0e10cSrcweir next; 1555cdf0e10cSrcweir }; 1556cdf0e10cSrcweir push (@dmake_args, $arg); 1557cdf0e10cSrcweir }; 1558cdf0e10cSrcweir if (!$html) { 1559cdf0e10cSrcweir print_error("\"--html_path\" switch is used only with \"--html\"") if ($html_path); 1560cdf0e10cSrcweir print_error("\"--dontgraboutput\" switch is used only with \"--html\"") if ($dont_grab_output); 1561cdf0e10cSrcweir }; 1562cdf0e10cSrcweir if ((scalar keys %exclude_branches) && !$build_all_parents) { 1563cdf0e10cSrcweir print_error("\"--exclude_branch_from\" is not applicable for one module builds!!"); 1564cdf0e10cSrcweir }; 1565cdf0e10cSrcweir $grab_output = 0 if ($dont_grab_output); 1566cdf0e10cSrcweir print_error('Switches --with_branches and --all collision') if ($build_from_with_branches && $build_all_cont); 1567cdf0e10cSrcweir print_error('Switch --skip is for building multiple modules only!!') if ((scalar keys %skip_modules) && (!$build_all_parents)); 1568cdf0e10cSrcweir# print_error('Please prepare the workspace on one of UNIX platforms') if ($prepare && ($ENV{GUI} ne 'UNX')); 1569cdf0e10cSrcweir print_error('Switches --with_branches and --since collision') if ($build_from_with_branches && $build_since); 1570cdf0e10cSrcweir if ($show) { 1571cdf0e10cSrcweir $processes_to_run = 0; 1572cdf0e10cSrcweir $cmd_file = ''; 1573cdf0e10cSrcweir }; 1574cdf0e10cSrcweir print_error('Switches --job and --deliver collision') if ($custom_job && $deliver); 1575cdf0e10cSrcweir $custom_job = 'deliver' if $deliver; 1576cdf0e10cSrcweir $post_job = 'deliver' if (!$custom_job); 1577cdf0e10cSrcweir $incompatible = scalar keys %incompatibles; 1578cdf0e10cSrcweir if ($prepare) { 1579cdf0e10cSrcweir print_error("--prepare is for use with --from switch only!\n") if (!$incompatible); 1580cdf0e10cSrcweir }; 1581cdf0e10cSrcweir if ($processes_to_run) { 1582cdf0e10cSrcweir if ($ignore && !$html) { 1583cdf0e10cSrcweir print_error("Cannot ignore errors in multiprocessing build"); 1584cdf0e10cSrcweir }; 1585cdf0e10cSrcweir if (!$enable_multiprocessing) { 1586cdf0e10cSrcweir print_error("Cannot load Win32::Process module for multiprocessing build"); 1587cdf0e10cSrcweir }; 1588cdf0e10cSrcweir if ($server_mode) { 1589cdf0e10cSrcweir print_error("Switches -P and --server collision"); 1590cdf0e10cSrcweir }; 1591cdf0e10cSrcweir } elsif ($stop_build_on_error) { 1592cdf0e10cSrcweir print_error("Switch --stoponerror is only for multiprocessing builds"); 1593cdf0e10cSrcweir }; 1594cdf0e10cSrcweir if ($server_mode) { 1595cdf0e10cSrcweir $html++; 1596cdf0e10cSrcweir $client_timeout = 60 * 60 * 2 if (!$client_timeout); 1597cdf0e10cSrcweir } else { 1598cdf0e10cSrcweir print_error("--ports switch is for server mode only!!") if ($ports_string); 1599cdf0e10cSrcweir print_error("--setenvstring switch is for server mode only!!") if ($setenv_string); 1600cdf0e10cSrcweir print_error("--client_timeout switch is for server mode only!!") if ($client_timeout); 1601cdf0e10cSrcweir }; 1602cdf0e10cSrcweir 1603cdf0e10cSrcweir if (!$generate_config) { 1604cdf0e10cSrcweir my $error_message = ' switch(es) should be used only with "--genconf"'; 1605cdf0e10cSrcweir print_error('"--removeall" ("--clear")' . $error_message) if ($clear_config); 1606cdf0e10cSrcweir if ((scalar %add_to_config) || (scalar %remove_from_config)) { 1607cdf0e10cSrcweir print_error('"--add" or/and "--remove"' . $error_message); 1608cdf0e10cSrcweir }; 1609cdf0e10cSrcweir } elsif ((!scalar %add_to_config) && !$clear_config && (!scalar %remove_from_config) && !$build_all_parents){ 1610cdf0e10cSrcweir print_error('Please supply necessary switch for "--genconf" (--add|--remove|--removeall). --add can be used with --from and such'); 1611cdf0e10cSrcweir }; 1612cdf0e10cSrcweir 1613cdf0e10cSrcweir if ($only_platform) { 1614cdf0e10cSrcweir $only_common = 'common'; 1615cdf0e10cSrcweir $only_common .= '.pro' if ($only_platform =~ /\.pro$/); 1616cdf0e10cSrcweir }; 1617cdf0e10cSrcweir if ($interactive) { 1618cdf0e10cSrcweir $html++; # enable html page generation... 1619cdf0e10cSrcweir my $local_host_name = hostname(); 1620cdf0e10cSrcweir $local_host_ip = inet_ntoa(scalar(gethostbyname($local_host_name)) || 'localhost'); 1621cdf0e10cSrcweir } 1622cdf0e10cSrcweir # Default build modes(for OpenOffice.org) 1623cdf0e10cSrcweir $ENV{BUILD_TYPE} = 'OOo EXT' if (!defined $ENV{BUILD_TYPE}); 1624cdf0e10cSrcweir @ARGV = @dmake_args; 1625cdf0e10cSrcweir foreach $arg (@dmake_args) { 1626cdf0e10cSrcweir $arg =~ /^verbose=(\S+)$/i and $verbose_mode = ($1 =~ /^t\S*$/i); 1627cdf0e10cSrcweir } 1628cdf0e10cSrcweir}; 1629cdf0e10cSrcweir 1630cdf0e10cSrcweirsub get_module_and_buildlist_paths { 1631cdf0e10cSrcweir if ($build_all_parents || $checkparents) { 1632cdf0e10cSrcweir $source_config_file = $source_config->get_config_file_path(); 1633cdf0e10cSrcweir $active_modules{$_}++ foreach ($source_config->get_active_modules()); 1634cdf0e10cSrcweir my %active_modules_copy = %active_modules; 1635cdf0e10cSrcweir foreach ($source_config->get_all_modules()) { 1636cdf0e10cSrcweir delete $active_modules_copy{$_} if defined($active_modules_copy{$_}); 1637cdf0e10cSrcweir next if ($_ eq $initial_module); 1638cdf0e10cSrcweir $module_paths{$_} = $source_config->get_module_path($_); 1639cdf0e10cSrcweir $build_list_paths{$_} = $source_config->get_module_build_list($_) 1640cdf0e10cSrcweir } 1641cdf0e10cSrcweir $dead_parents{$_}++ foreach (keys %active_modules_copy); 1642cdf0e10cSrcweir }; 1643cdf0e10cSrcweir}; 1644cdf0e10cSrcweir 1645cdf0e10cSrcweir 1646cdf0e10cSrcweirsub get_dmake_args { 1647cdf0e10cSrcweir my $arg; 1648cdf0e10cSrcweir my @job_args = (); 1649cdf0e10cSrcweir while ($arg = shift @ARGV) { 1650cdf0e10cSrcweir next if ($arg =~ /^--$/); 1651cdf0e10cSrcweir push (@job_args, $arg); 1652cdf0e10cSrcweir }; 1653cdf0e10cSrcweir return @job_args; 1654cdf0e10cSrcweir}; 1655cdf0e10cSrcweir 1656cdf0e10cSrcweir# 1657cdf0e10cSrcweir# get all options without '-' 1658cdf0e10cSrcweir# 1659cdf0e10cSrcweirsub get_switch_options { 1660cdf0e10cSrcweir my $string = ''; 1661cdf0e10cSrcweir my $option = ''; 1662cdf0e10cSrcweir while ($option = shift @ARGV) { 1663cdf0e10cSrcweir if (!($option =~ /^-+/)) { 1664cdf0e10cSrcweir $string .= '-' . $option; 1665cdf0e10cSrcweir $string .= ' '; 1666cdf0e10cSrcweir } else { 1667cdf0e10cSrcweir unshift(@ARGV, $option); 1668cdf0e10cSrcweir last; 1669cdf0e10cSrcweir }; 1670cdf0e10cSrcweir }; 1671cdf0e10cSrcweir $string =~ s/\s$//; 1672cdf0e10cSrcweir return $string; 1673cdf0e10cSrcweir}; 1674cdf0e10cSrcweir 1675cdf0e10cSrcweir# 1676cdf0e10cSrcweir# cancel build when one of children has error exit code 1677cdf0e10cSrcweir# 1678cdf0e10cSrcweirsub cancel_build { 1679cdf0e10cSrcweir# close_server_socket(); 1680cdf0e10cSrcweir my $broken_modules_number = scalar @broken_module_names; 1681cdf0e10cSrcweir my $message_part = 'build '; 1682cdf0e10cSrcweir if (scalar keys %incompatibles) { 1683cdf0e10cSrcweir my @incompatible_modules = keys %incompatibles; 1684cdf0e10cSrcweir if ($stop_build_on_error) { 1685cdf0e10cSrcweir $message_part .= "--from @incompatible_modules:@broken_module_names\n"; 1686cdf0e10cSrcweir } else { 1687cdf0e10cSrcweir $message_part .= "--from @broken_module_names\n"; 1688cdf0e10cSrcweir }; 1689cdf0e10cSrcweir } else { 1690cdf0e10cSrcweir if ($processes_to_run) { 1691cdf0e10cSrcweir $message_part .= "--from "; 1692cdf0e10cSrcweir } else { 1693cdf0e10cSrcweir $message_part .= "--all:"; 1694cdf0e10cSrcweir }; 1695cdf0e10cSrcweir $message_part .= "@broken_module_names\n"; 1696cdf0e10cSrcweir 1697cdf0e10cSrcweir }; 1698cdf0e10cSrcweir if ($broken_modules_number && $build_all_parents) { 1699cdf0e10cSrcweir print STDERR "\n"; 1700cdf0e10cSrcweir print STDERR $broken_modules_number; 1701cdf0e10cSrcweir print STDERR " module(s): "; 1702cdf0e10cSrcweir foreach (@broken_module_names) { 1703cdf0e10cSrcweir print STDERR "\n\t$_"; 1704cdf0e10cSrcweir }; 1705cdf0e10cSrcweir print STDERR "\nneed(s) to be rebuilt\n\nReason(s):\n\n"; 1706cdf0e10cSrcweir foreach (keys %broken_build) { 1707cdf0e10cSrcweir print STDERR "ERROR: error " . $broken_build{$_} . " occurred while making $_\n"; 1708cdf0e10cSrcweir }; 170982d47efdSHerbert Dürr print STDERR "\nWhen you have fixed the errors in " . 1710b67eb7e5SHerbert Dürr (length(@broken_module_names)==1 ? "that module" : "these modules") . 1711b67eb7e5SHerbert Dürr " you can resume the build by running:\n\n\t" . $message_part; 1712cdf0e10cSrcweir } else { 1713cdf0e10cSrcweir while (children_number()) { 1714cdf0e10cSrcweir handle_dead_children(1); 1715cdf0e10cSrcweir } 1716cdf0e10cSrcweir foreach (keys %broken_build) { 1717cdf0e10cSrcweir print STDERR "ERROR: error " . $broken_build{$_} . " occurred while making $_\n"; 1718cdf0e10cSrcweir }; 1719cdf0e10cSrcweir }; 1720cdf0e10cSrcweir print "\n"; 1721cdf0e10cSrcweir do_exit(1); 1722cdf0e10cSrcweir}; 1723cdf0e10cSrcweir 1724cdf0e10cSrcweir# 1725cdf0e10cSrcweir# Function for storing errors in multiprocessing AllParents build 1726cdf0e10cSrcweir# 1727cdf0e10cSrcweirsub store_error { 1728cdf0e10cSrcweir my ($pid, $error_code) = @_; 1729cdf0e10cSrcweir return 0 if (!$error_code); 1730cdf0e10cSrcweir my $child_nick = $processes_hash{$pid}; 1731cdf0e10cSrcweir if ($ENV{GUI} eq 'WNT') { 1732cdf0e10cSrcweir if (!defined $had_error{$child_nick}) { 1733cdf0e10cSrcweir $had_error{$child_nick}++; 1734cdf0e10cSrcweir return 1; 1735cdf0e10cSrcweir }; 1736cdf0e10cSrcweir }; 1737cdf0e10cSrcweir $modules_with_errors{$folders_hashes{$child_nick}}++; 1738cdf0e10cSrcweir $broken_build{$child_nick} = $error_code; 1739cdf0e10cSrcweir if ($stop_build_on_error) { 1740cdf0e10cSrcweir clear_from_child($pid); 1741cdf0e10cSrcweir # Let all children finish their work 1742cdf0e10cSrcweir while (children_number()) { 1743cdf0e10cSrcweir handle_dead_children(1); 1744cdf0e10cSrcweir }; 1745cdf0e10cSrcweir cancel_build(); 1746cdf0e10cSrcweir }; 1747cdf0e10cSrcweir return 0; 1748cdf0e10cSrcweir}; 1749cdf0e10cSrcweir 1750cdf0e10cSrcweir# 1751cdf0e10cSrcweir# child handler (clears (or stores info about) the terminated child) 1752cdf0e10cSrcweir# 1753cdf0e10cSrcweirsub handle_dead_children { 1754cdf0e10cSrcweir my $running_children = children_number(); 1755cdf0e10cSrcweir return if (!$running_children); 1756cdf0e10cSrcweir my $force_wait = shift; 1757cdf0e10cSrcweir my $try_once_more = 0; 1758cdf0e10cSrcweir do { 1759cdf0e10cSrcweir my $pid = 0; 1760cdf0e10cSrcweir if (children_number() >= $processes_to_run || 1761cdf0e10cSrcweir ($force_wait && ($running_children == children_number()))) { 1762cdf0e10cSrcweir $pid = wait(); 1763cdf0e10cSrcweir } else { 1764cdf0e10cSrcweir $pid = waitpid( -1, &WNOHANG); 1765cdf0e10cSrcweir }; 1766cdf0e10cSrcweir if ($pid > 0) { 1767cdf0e10cSrcweir $try_once_more = store_error($pid, $?); 1768cdf0e10cSrcweir if ($try_once_more) { 1769cdf0e10cSrcweir give_second_chance($pid); 1770cdf0e10cSrcweir } else { 1771cdf0e10cSrcweir clear_from_child($pid); 1772cdf0e10cSrcweir }; 1773cdf0e10cSrcweir $finisched_children++; 1774cdf0e10cSrcweir }; 1775cdf0e10cSrcweir } while(children_number() >= $processes_to_run); 1776cdf0e10cSrcweir}; 1777cdf0e10cSrcweir 1778cdf0e10cSrcweirsub give_second_chance { 1779cdf0e10cSrcweir my $pid = shift; 1780cdf0e10cSrcweir # A malicious hack for misterious windows problems - try 2 times 1781cdf0e10cSrcweir # to run dmake in the same directory if errors occurs 1782cdf0e10cSrcweir my $child_nick = $processes_hash{$pid}; 1783cdf0e10cSrcweir $running_children{$folders_hashes{$child_nick}}--; 1784cdf0e10cSrcweir delete $processes_hash{$pid}; 1785cdf0e10cSrcweir start_child($child_nick, $folders_hashes{$child_nick}); 1786cdf0e10cSrcweir}; 1787cdf0e10cSrcweir 1788cdf0e10cSrcweirsub clear_from_child { 1789cdf0e10cSrcweir my $pid = shift; 1790cdf0e10cSrcweir my $child_nick = $processes_hash{$pid}; 1791cdf0e10cSrcweir my $error_code = 0; 1792cdf0e10cSrcweir if (defined $broken_build{$child_nick}) { 1793cdf0e10cSrcweir $error_code = $broken_build{$child_nick}; 1794cdf0e10cSrcweir } else { 1795cdf0e10cSrcweir remove_from_dependencies($child_nick, 1796cdf0e10cSrcweir $folders_hashes{$child_nick}); 1797cdf0e10cSrcweir }; 1798cdf0e10cSrcweir foreach (keys %module_deps_hash_pids) { 1799cdf0e10cSrcweir delete ${$module_deps_hash_pids{$_}}{$pid} if defined (${$module_deps_hash_pids{$_}}{$pid}); 1800cdf0e10cSrcweir }; 1801cdf0e10cSrcweir my $module = $module_by_hash{$folders_hashes{$child_nick}}; 1802cdf0e10cSrcweir html_store_job_info($folders_hashes{$child_nick}, $child_nick, $error_code); 1803cdf0e10cSrcweir $running_children{$folders_hashes{$child_nick}}--; 1804cdf0e10cSrcweir delete $processes_hash{$pid}; 1805cdf0e10cSrcweir $verbose_mode && print 'Running processes: ' . children_number() . "\n"; 1806cdf0e10cSrcweir}; 1807cdf0e10cSrcweir 1808cdf0e10cSrcweir# 1809cdf0e10cSrcweir# Build the entire project according to queue of dependencies 1810cdf0e10cSrcweir# 1811cdf0e10cSrcweirsub build_dependent { 1812cdf0e10cSrcweir $dependencies_hash = shift; 1813cdf0e10cSrcweir my $pid = 0; 1814cdf0e10cSrcweir my $child_nick = ''; 1815cdf0e10cSrcweir $running_children{$dependencies_hash} = 0 if (!defined $running_children{$dependencies_hash}); 1816cdf0e10cSrcweir while ($child_nick = pick_prj_to_build($dependencies_hash)) { 1817cdf0e10cSrcweir if ($processes_to_run) { 1818cdf0e10cSrcweir do { 1819cdf0e10cSrcweir if (defined $modules_with_errors{$dependencies_hash} && !$ignore) { 1820cdf0e10cSrcweir return 0 if ($build_all_parents); 1821cdf0e10cSrcweir last; 1822cdf0e10cSrcweir }; 1823cdf0e10cSrcweir # start current child & all 1824cdf0e10cSrcweir # that could be started now 1825cdf0e10cSrcweir if ($child_nick) { 1826cdf0e10cSrcweir start_child($child_nick, $dependencies_hash); 1827cdf0e10cSrcweir return 1 if ($build_all_parents); 1828cdf0e10cSrcweir } else { 1829cdf0e10cSrcweir return 0 if ($build_all_parents); 1830cdf0e10cSrcweir if (scalar keys %$dependencies_hash) { 1831cdf0e10cSrcweir handle_dead_children(1); 1832cdf0e10cSrcweir }; 1833cdf0e10cSrcweir }; 1834cdf0e10cSrcweir $child_nick = pick_prj_to_build($dependencies_hash); 1835cdf0e10cSrcweir } while (scalar keys %$dependencies_hash || $child_nick); 1836cdf0e10cSrcweir while (children_number()) { 1837cdf0e10cSrcweir handle_dead_children(1); 1838cdf0e10cSrcweir }; 1839cdf0e10cSrcweir 1840cdf0e10cSrcweir if (defined $modules_with_errors{$dependencies_hash}) { 1841cdf0e10cSrcweir cancel_build(); 1842cdf0e10cSrcweir } 1843cdf0e10cSrcweir mp_success_exit(); 1844cdf0e10cSrcweir } else { 1845cdf0e10cSrcweir if (dmake_dir($child_nick)) { 1846cdf0e10cSrcweir push(@broken_module_names, $module_by_hash{$dependencies_hash}); 1847cdf0e10cSrcweir cancel_build(); 1848cdf0e10cSrcweir }; 1849cdf0e10cSrcweir }; 1850cdf0e10cSrcweir $child_nick = ''; 1851cdf0e10cSrcweir }; 1852cdf0e10cSrcweir}; 1853cdf0e10cSrcweir 1854cdf0e10cSrcweirsub children_number { 1855cdf0e10cSrcweir return scalar keys %processes_hash; 1856cdf0e10cSrcweir}; 1857cdf0e10cSrcweir 1858cdf0e10cSrcweirsub start_child { 1859cdf0e10cSrcweir my ($job_dir, $dependencies_hash) = @_; 1860cdf0e10cSrcweir $jobs_hash{$job_dir}->{START_TIME} = time(); 1861cdf0e10cSrcweir $jobs_hash{$job_dir}->{STATUS} = 'building'; 1862cdf0e10cSrcweir if ($job_dir =~ /(\s)/o) { 1863cdf0e10cSrcweir my $error_code = undef; 1864cdf0e10cSrcweir if ($job_dir !~ /\sdeliver$/o) { 1865cdf0e10cSrcweir $error_code = do_custom_job($job_dir, $dependencies_hash); 1866cdf0e10cSrcweir return; 1867cdf0e10cSrcweir } 1868cdf0e10cSrcweir }; 1869cdf0e10cSrcweir $build_in_progress{$module_by_hash{$dependencies_hash}}++; 1870cdf0e10cSrcweir html_store_job_info($dependencies_hash, $job_dir); 1871cdf0e10cSrcweir my $pid = undef; 1872cdf0e10cSrcweir my $children_running; 1873cdf0e10cSrcweir my $oldfh = select STDOUT; 1874cdf0e10cSrcweir $| = 1; 1875cdf0e10cSrcweir if ($pid = fork) { # parent 1876cdf0e10cSrcweir select $oldfh; 1877cdf0e10cSrcweir $processes_hash{$pid} = $job_dir; 1878cdf0e10cSrcweir $children_running = children_number(); 1879cdf0e10cSrcweir $verbose_mode && print 'Running processes: ', $children_running, "\n"; 1880cdf0e10cSrcweir $maximal_processes = $children_running if ($children_running > $maximal_processes); 1881cdf0e10cSrcweir $folders_hashes{$job_dir} = $dependencies_hash; 1882cdf0e10cSrcweir store_pid($dependencies_hash, $pid); 1883cdf0e10cSrcweir $running_children{$dependencies_hash}++; 1884cdf0e10cSrcweir } elsif (defined $pid) { # child 1885cdf0e10cSrcweir select $oldfh; 1886cdf0e10cSrcweir $child = 1; 1887cdf0e10cSrcweir dmake_dir($job_dir); 1888cdf0e10cSrcweir do_exit(1); 1889cdf0e10cSrcweir }; 1890cdf0e10cSrcweir}; 1891cdf0e10cSrcweir 1892cdf0e10cSrcweirsub store_pid { 1893cdf0e10cSrcweir my ($deps_hash, $pid) = @_; 1894cdf0e10cSrcweir if (!defined $module_deps_hash_pids{$deps_hash}) { 1895cdf0e10cSrcweir my %module_hash_pids = (); 1896cdf0e10cSrcweir $module_deps_hash_pids{$deps_hash} = \%module_hash_pids; 1897cdf0e10cSrcweir }; 1898cdf0e10cSrcweir ${$module_deps_hash_pids{$deps_hash}}{$pid}++; 1899cdf0e10cSrcweir}; 1900cdf0e10cSrcweir 1901cdf0e10cSrcweir# 1902cdf0e10cSrcweir# Build everything that should be built multiprocessing version 1903cdf0e10cSrcweir# 1904cdf0e10cSrcweirsub build_multiprocessing { 1905cdf0e10cSrcweir my $prj; 1906cdf0e10cSrcweir do { 1907cdf0e10cSrcweir my $got_module = 0; 1908cdf0e10cSrcweir $finisched_children = 0; 1909cdf0e10cSrcweir while ($prj = pick_prj_to_build(\%global_deps_hash)) { 1910cdf0e10cSrcweir if (!defined $projects_deps_hash{$prj}) { 1911cdf0e10cSrcweir $projects_deps_hash{$prj} = {}; 1912cdf0e10cSrcweir get_module_dep_hash($prj, $projects_deps_hash{$prj}); 1913cdf0e10cSrcweir my $info_hash = $html_info{$prj}; 1914cdf0e10cSrcweir $$info_hash{DIRS} = check_deps_hash($projects_deps_hash{$prj}, $prj); 1915cdf0e10cSrcweir $module_by_hash{$projects_deps_hash{$prj}} = $prj; 1916cdf0e10cSrcweir } 1917cdf0e10cSrcweir $module_build_queue{$prj}++; 1918cdf0e10cSrcweir $got_module++; 1919cdf0e10cSrcweir }; 1920cdf0e10cSrcweir if (!$got_module) { 1921cdf0e10cSrcweir cancel_build() if ((!scalar keys %module_build_queue) && !children_number()); 1922cdf0e10cSrcweir if (!$finisched_children) { 1923cdf0e10cSrcweir# print "#### 1979: Starting waiting for dead child\n"; 1924cdf0e10cSrcweir handle_dead_children(1); 1925cdf0e10cSrcweir }; 1926cdf0e10cSrcweir }; 1927cdf0e10cSrcweir build_actual_queue(\%module_build_queue); 1928cdf0e10cSrcweir } while (scalar keys %global_deps_hash); 1929cdf0e10cSrcweir # Let the last module be built till the end 1930cdf0e10cSrcweir while (scalar keys %module_build_queue) { 1931cdf0e10cSrcweir build_actual_queue(\%module_build_queue); 1932cdf0e10cSrcweir# print "#### 1988: Starting waiting for dead child\n"; 1933cdf0e10cSrcweir handle_dead_children(1); 1934cdf0e10cSrcweir }; 1935cdf0e10cSrcweir # Let all children finish their work 1936cdf0e10cSrcweir while (children_number()) { 1937cdf0e10cSrcweir handle_dead_children(1); 1938cdf0e10cSrcweir }; 1939cdf0e10cSrcweir cancel_build() if (scalar keys %broken_build); 1940cdf0e10cSrcweir mp_success_exit(); 1941cdf0e10cSrcweir}; 1942cdf0e10cSrcweir 1943cdf0e10cSrcweirsub mp_success_exit { 1944cdf0e10cSrcweir# close_server_socket(); 1945cdf0e10cSrcweir# if (!$custom_job && $post_custom_job) { 1946cdf0e10cSrcweir# do_post_custom_job(correct_path($workspace_path.$initial_module)); 1947cdf0e10cSrcweir# }; 1948cdf0e10cSrcweir print "\nMultiprocessing build is finished\n"; 1949cdf0e10cSrcweir print "Maximal number of processes run: $maximal_processes\n"; 1950cdf0e10cSrcweir do_exit(0); 1951cdf0e10cSrcweir}; 1952cdf0e10cSrcweir 1953cdf0e10cSrcweir# 1954cdf0e10cSrcweir# Here the built queue is built as long as possible 1955cdf0e10cSrcweir# 1956cdf0e10cSrcweirsub build_actual_queue { 1957cdf0e10cSrcweir my $build_queue = shift; 1958cdf0e10cSrcweir my $finished_projects = 0; 1959cdf0e10cSrcweir do { 1960cdf0e10cSrcweir my @sorted_queue = sort {(scalar keys %{$projects_deps_hash{$a}}) <=> (scalar keys %{$projects_deps_hash{$b}})} keys %$build_queue; 1961cdf0e10cSrcweir my $started_children = 0; 1962cdf0e10cSrcweir foreach my $prj (keys %$build_queue) { 1963cdf0e10cSrcweir get_html_orders(); 1964cdf0e10cSrcweir if ($reschedule_queue) { 1965cdf0e10cSrcweir $reschedule_queue = 0; 1966cdf0e10cSrcweir foreach (keys %$build_queue) { 1967cdf0e10cSrcweir # Remove the module from the build queue if there is a dependency emerged 1968cdf0e10cSrcweir if ((defined $global_deps_hash{$_}) && (scalar keys %{$global_deps_hash{$_}})) { 1969cdf0e10cSrcweir delete $$build_queue{$_}; 1970cdf0e10cSrcweir }; 1971cdf0e10cSrcweir delete $$build_queue{$_} if (!defined $global_deps_hash_backup{$_}) 1972cdf0e10cSrcweir }; 1973cdf0e10cSrcweir return; 1974cdf0e10cSrcweir }; 1975cdf0e10cSrcweir if (defined $modules_with_errors{$projects_deps_hash{$prj}} && !$ignore) { 1976cdf0e10cSrcweir push (@broken_module_names, $prj); 1977cdf0e10cSrcweir delete $$build_queue{$prj}; 1978cdf0e10cSrcweir next; 1979cdf0e10cSrcweir }; 1980cdf0e10cSrcweir $started_children += build_dependent($projects_deps_hash{$prj}); 1981cdf0e10cSrcweir if ((!scalar keys %{$projects_deps_hash{$prj}}) && 1982cdf0e10cSrcweir !$running_children{$projects_deps_hash{$prj}}) { 1983cdf0e10cSrcweir if (!defined $modules_with_errors{$projects_deps_hash{$prj}} || $ignore) 1984cdf0e10cSrcweir { 1985cdf0e10cSrcweir remove_from_dependencies($prj, \%global_deps_hash); 1986cdf0e10cSrcweir $build_is_finished{$prj}++; 1987cdf0e10cSrcweir delete $$build_queue{$prj}; 1988cdf0e10cSrcweir $finished_projects++; 1989cdf0e10cSrcweir }; 1990cdf0e10cSrcweir }; 1991cdf0e10cSrcweir }; 1992cdf0e10cSrcweir # trigger wait 1993cdf0e10cSrcweir if (!$started_children) { 1994cdf0e10cSrcweir if ($finished_projects) { 1995cdf0e10cSrcweir return; 1996cdf0e10cSrcweir } else { 1997cdf0e10cSrcweir handle_dead_children(1); 1998cdf0e10cSrcweir }; 1999cdf0e10cSrcweir }; 2000cdf0e10cSrcweir } while (scalar keys %$build_queue); 2001cdf0e10cSrcweir}; 2002cdf0e10cSrcweir 2003cdf0e10cSrcweirsub run_job { 2004cdf0e10cSrcweir my ($job, $path, $registered_name) = @_; 2005cdf0e10cSrcweir my $job_to_do = $job; 2006cdf0e10cSrcweir my $error_code = 0; 2007cdf0e10cSrcweir print "$registered_name\n"; 2008cdf0e10cSrcweir return 0 if ( $show ); 2009cdf0e10cSrcweir $job_to_do = $deliver_command if ($job eq 'deliver'); 2010cdf0e10cSrcweir $registered_name = $path if (!defined $registered_name); 2011cdf0e10cSrcweir chdir $path; 2012cdf0e10cSrcweir getcwd(); 2013cdf0e10cSrcweir 2014cdf0e10cSrcweir if ($html) { 2015cdf0e10cSrcweir my $log_file = $jobs_hash{$registered_name}->{LONG_LOG_PATH}; 2016cdf0e10cSrcweir my $log_dir = File::Basename::dirname($log_file); 2017cdf0e10cSrcweir if (!-d $log_dir) { 2018cdf0e10cSrcweir system("$perl $mkout"); 2019cdf0e10cSrcweir }; 2020cdf0e10cSrcweir $error_code = system ("$job_to_do > $log_file 2>&1"); 2021cdf0e10cSrcweir if (!$grab_output && -f $log_file) { 2022cdf0e10cSrcweir system("cat $log_file"); 2023cdf0e10cSrcweir }; 2024cdf0e10cSrcweir } else { 2025cdf0e10cSrcweir $error_code = system ("$job_to_do"); 2026cdf0e10cSrcweir }; 2027cdf0e10cSrcweir return $error_code; 2028cdf0e10cSrcweir}; 2029cdf0e10cSrcweir 2030cdf0e10cSrcweirsub do_custom_job { 2031cdf0e10cSrcweir my ($module_job, $dependencies_hash) = @_; 2032cdf0e10cSrcweir $module_job =~ /(\s)/o; 2033cdf0e10cSrcweir my $module = $`; 2034cdf0e10cSrcweir my $job = $'; 2035cdf0e10cSrcweir html_store_job_info($dependencies_hash, $module_job); 2036cdf0e10cSrcweir my $error_code = 0; 2037cdf0e10cSrcweir if ($job eq $pre_job) { 2038cdf0e10cSrcweir announce_module($module); 2039cdf0e10cSrcweir# html_store_job_info($dependencies_hash, $job_dir); 2040cdf0e10cSrcweir remove_from_dependencies($module_job, $dependencies_hash); 2041cdf0e10cSrcweir } else { 2042cdf0e10cSrcweir $error_code = run_job($job, $module_paths{$module}, $module_job); 2043cdf0e10cSrcweir if ($error_code) { 2044cdf0e10cSrcweir # give windows one more chance 2045cdf0e10cSrcweir if ($ENV{GUI} eq 'WNT') { 2046cdf0e10cSrcweir $error_code = run_job($job, $module_paths{$module}, $module_job); 2047cdf0e10cSrcweir }; 2048cdf0e10cSrcweir }; 2049cdf0e10cSrcweir if ($error_code && $ignore) { 2050cdf0e10cSrcweir push(@ignored_errors, $module_job); 2051cdf0e10cSrcweir $error_code = 0; 2052cdf0e10cSrcweir }; 2053cdf0e10cSrcweir if ($error_code) { 2054cdf0e10cSrcweir $modules_with_errors{$dependencies_hash}++; 2055cdf0e10cSrcweir# $broken_build{$module_job} = $error_code; 2056cdf0e10cSrcweir } else { 2057cdf0e10cSrcweir remove_from_dependencies($module_job, $dependencies_hash); 2058cdf0e10cSrcweir }; 2059cdf0e10cSrcweir }; 2060cdf0e10cSrcweir html_store_job_info($dependencies_hash, $module_job, $error_code); 2061cdf0e10cSrcweir return $error_code; 2062cdf0e10cSrcweir}; 2063cdf0e10cSrcweir 2064cdf0e10cSrcweir# 2065cdf0e10cSrcweir# Print announcement for module just started 2066cdf0e10cSrcweir# 2067cdf0e10cSrcweirsub announce_module { 2068cdf0e10cSrcweir my $prj = shift; 2069cdf0e10cSrcweir $build_in_progress{$prj}++; 2070cdf0e10cSrcweir print_announce($prj); 2071cdf0e10cSrcweir}; 2072cdf0e10cSrcweir 2073cdf0e10cSrcweirsub print_announce { 2074cdf0e10cSrcweir my $prj = shift; 2075cdf0e10cSrcweir return if (defined $module_announced{$prj}); 2076cdf0e10cSrcweir my $prj_type = ''; 2077cdf0e10cSrcweir $prj_type = $modules_types{$prj} if (defined $modules_types{$prj}); 2078cdf0e10cSrcweir my $text; 2079cdf0e10cSrcweir if ($prj_type eq 'lnk') { 2080cdf0e10cSrcweir if (!defined $active_modules{$prj}) { 2081cdf0e10cSrcweir $text = "Skipping module $prj\n"; 2082cdf0e10cSrcweir } else { 2083cdf0e10cSrcweir $text = "Skipping link to $prj\n"; 2084cdf0e10cSrcweir }; 2085cdf0e10cSrcweir $build_is_finished{$prj}++; 2086cdf0e10cSrcweir } elsif ($prj_type eq 'img') { 2087cdf0e10cSrcweir $text = "Skipping incomplete $prj\n"; 2088cdf0e10cSrcweir $build_is_finished{$prj}++; 2089cdf0e10cSrcweir } elsif ($custom_job) { 2090cdf0e10cSrcweir $text = "Running custom job \"$custom_job\" in module $prj\n"; 2091cdf0e10cSrcweir } else { 2092cdf0e10cSrcweir $text = "Building module $prj\n"; 2093cdf0e10cSrcweir }; 2094cdf0e10cSrcweir my $announce_string = $new_line; 2095cdf0e10cSrcweir $announce_string .= $echo . "=============\n"; 2096cdf0e10cSrcweir $announce_string .= $echo . $text; 2097cdf0e10cSrcweir $announce_string .= $echo . "=============\n"; 2098cdf0e10cSrcweir print $announce_string; 2099cdf0e10cSrcweir $module_announced{$prj}++; 2100cdf0e10cSrcweir}; 2101cdf0e10cSrcweir 2102cdf0e10cSrcweirsub are_all_dependent { 2103cdf0e10cSrcweir my $build_queue = shift; 2104cdf0e10cSrcweir my $folder = ''; 2105cdf0e10cSrcweir my $first_candidate = undef; 2106cdf0e10cSrcweir foreach my $prj (keys %$build_queue) { 2107cdf0e10cSrcweir $folder = find_indep_prj($projects_deps_hash{$prj}); 2108cdf0e10cSrcweir $first_candidate = $folder if (!defined $first_candidate); 2109cdf0e10cSrcweir }; 2110cdf0e10cSrcweir $folder = $first_candidate; 2111cdf0e10cSrcweir return '' if ($first_candidate); 2112cdf0e10cSrcweir return '1'; 2113cdf0e10cSrcweir}; 2114cdf0e10cSrcweir 2115cdf0e10cSrcweir 2116cdf0e10cSrcweir# 2117cdf0e10cSrcweir# Procedure defines if the local directory is a 2118cdf0e10cSrcweir# complete module, an image or a link 2119cdf0e10cSrcweir# return values: lnk link 2120cdf0e10cSrcweir# img incomplete (image) 2121cdf0e10cSrcweir# mod complete (module) 2122cdf0e10cSrcweir# 2123cdf0e10cSrcweirsub modules_classify { 2124cdf0e10cSrcweir my @modules = @_; 2125cdf0e10cSrcweir foreach my $module (sort @modules) { 2126cdf0e10cSrcweir if (!defined $module_paths{$module}) { 2127cdf0e10cSrcweir $modules_types{$module} = 'img'; 2128cdf0e10cSrcweir next; 2129cdf0e10cSrcweir }; 2130cdf0e10cSrcweir if (( $module_paths{$module} =~ /\.lnk$/) || ($module_paths{$module} =~ /\.link$/) 2131cdf0e10cSrcweir || (!defined $active_modules{$module})) { 2132cdf0e10cSrcweir $modules_types{$module} = 'lnk'; 2133cdf0e10cSrcweir next; 2134cdf0e10cSrcweir }; 2135cdf0e10cSrcweir $modules_types{$module} = 'mod'; 2136cdf0e10cSrcweir }; 2137cdf0e10cSrcweir}; 2138cdf0e10cSrcweir 2139cdf0e10cSrcweir# 2140cdf0e10cSrcweir# This procedure provides consistency for cws 2141cdf0e10cSrcweir# and optimized build (ie in case of --with_branches, -all:prj_name 2142cdf0e10cSrcweir# and -since switches) 2143cdf0e10cSrcweir# 2144cdf0e10cSrcweirsub provide_consistency { 2145cdf0e10cSrcweir check_dir(); 2146cdf0e10cSrcweir foreach my $var_ref (\$build_all_cont, \$build_since) { 2147cdf0e10cSrcweir if ($$var_ref) { 2148cdf0e10cSrcweir return if (defined $module_paths{$$var_ref}); 2149cdf0e10cSrcweir print_error("Cannot find module '$$var_ref'", 9); 2150cdf0e10cSrcweir return; 2151cdf0e10cSrcweir }; 2152cdf0e10cSrcweir }; 2153cdf0e10cSrcweir}; 2154cdf0e10cSrcweir 2155cdf0e10cSrcweir# 2156cdf0e10cSrcweir# Get the workspace list ('stand.lst'), either from 'localini' 2157cdf0e10cSrcweir# or, if this is not possible, from 'globalini. 2158cdf0e10cSrcweir# (Heiner's proprietary :) 2159cdf0e10cSrcweir# 2160cdf0e10cSrcweirsub get_workspace_lst 2161cdf0e10cSrcweir{ 2162cdf0e10cSrcweir my $home = $ENV{HOME}; 2163cdf0e10cSrcweir my $inifile = $ENV{HOME}. '/localini/stand.lst'; 2164cdf0e10cSrcweir if (-f $inifile) { 2165cdf0e10cSrcweir return $inifile; 2166cdf0e10cSrcweir }; 2167cdf0e10cSrcweir return ''; 2168cdf0e10cSrcweir} 2169cdf0e10cSrcweir 2170cdf0e10cSrcweir# 2171cdf0e10cSrcweir# Procedure clears up module for incompatible build 2172cdf0e10cSrcweir# 2173cdf0e10cSrcweirsub ensure_clear_module { 2174cdf0e10cSrcweir my $module = shift; 2175cdf0e10cSrcweir if ($modules_types{$module} eq 'mod') { 2176cdf0e10cSrcweir clear_module($module); 2177cdf0e10cSrcweir return; 2178cdf0e10cSrcweir }; 2179cdf0e10cSrcweir if ($modules_types{$module} eq 'lnk' && (File::Basename::basename($module_paths{$module}) ne $module)) { 2180cdf0e10cSrcweir if(rename($module_paths{$module}, File::Basename::dirname($module_paths{$module}) ."/$module")) { 2181cdf0e10cSrcweir $module_paths{$module} = File::Basename::dirname($module_paths{$module}) ."/$module"; 2182cdf0e10cSrcweir clear_module($module); 2183cdf0e10cSrcweir } else { 2184cdf0e10cSrcweir print_error("Cannot rename link to $module. Please rename it manually"); 2185cdf0e10cSrcweir }; 2186cdf0e10cSrcweir }; 2187cdf0e10cSrcweir}; 2188cdf0e10cSrcweir 2189cdf0e10cSrcweir# 2190cdf0e10cSrcweir# Procedure removes output tree from the module (without common trees) 2191cdf0e10cSrcweir# 2192cdf0e10cSrcweirsub clear_module { 2193cdf0e10cSrcweir my $module = shift; 2194cdf0e10cSrcweir print "Removing module's $module output trees...\n"; 2195cdf0e10cSrcweir print "\n" and return if ($show); 2196cdf0e10cSrcweir opendir DIRHANDLE, $module_paths{$module}; 2197cdf0e10cSrcweir my @dir_content = readdir(DIRHANDLE); 2198cdf0e10cSrcweir closedir(DIRHANDLE); 2199cdf0e10cSrcweir foreach (@dir_content) { 2200cdf0e10cSrcweir next if (/^\.+$/); 2201cdf0e10cSrcweir my $dir = correct_path($module_paths{$module}.'/'.$_); 2202cdf0e10cSrcweir if ((!-d $dir.'/.svn') && is_output_tree($dir)) { 2203cdf0e10cSrcweir #print "I would delete $dir\n"; 2204cdf0e10cSrcweir rmtree("$dir", 0, 1); 2205cdf0e10cSrcweir if (-d $dir) { 2206cdf0e10cSrcweir system("$remove_command $dir"); 2207cdf0e10cSrcweir if (-d $dir) { 2208cdf0e10cSrcweir push(@warnings, "Cannot delete $dir"); 2209cdf0e10cSrcweir#print_error("Cannot delete $dir"); 2210cdf0e10cSrcweir } else { 2211cdf0e10cSrcweir print STDERR (">>> Removed $dir by force\n"); 2212cdf0e10cSrcweir }; 2213cdf0e10cSrcweir }; 2214cdf0e10cSrcweir }; 2215cdf0e10cSrcweir }; 2216cdf0e10cSrcweir}; 2217cdf0e10cSrcweir 2218cdf0e10cSrcweir# 2219cdf0e10cSrcweir# Figure out if the directory is an output tree 2220cdf0e10cSrcweir# 2221cdf0e10cSrcweirsub is_output_tree { 2222cdf0e10cSrcweir my $dir = shift; 2223cdf0e10cSrcweir $dir =~ /([\w\d\.]+)$/; 2224cdf0e10cSrcweir $_ = $1; 2225cdf0e10cSrcweir return '1' if (defined $platforms{$_}); 2226cdf0e10cSrcweir if ($only_common) { 2227cdf0e10cSrcweir return '1' if ($_ eq $only_common); 2228cdf0e10cSrcweir } else { 2229cdf0e10cSrcweir if (scalar keys %platforms < scalar keys %platforms_to_copy) { 2230cdf0e10cSrcweir return ''; 2231cdf0e10cSrcweir }; 2232cdf0e10cSrcweir return '1' if (/^common$/); 2233cdf0e10cSrcweir return '1' if (/^common\.pro$/); 2234cdf0e10cSrcweir }; 2235cdf0e10cSrcweir return ''; 2236cdf0e10cSrcweir}; 2237cdf0e10cSrcweirsub get_tmp_dir { 2238cdf0e10cSrcweir my $tmp_dir; 2239cdf0e10cSrcweir if( defined($ENV{TMPDIR}) ) { 2240cdf0e10cSrcweir $tmp_dir = $ENV{TMPDIR} . '/'; 2241cdf0e10cSrcweir } elsif( defined($ENV{TMP}) ) { 2242cdf0e10cSrcweir $tmp_dir = $ENV{TMP} . '/'; 2243cdf0e10cSrcweir } else { 2244cdf0e10cSrcweir $tmp_dir = '/tmp/'; 2245cdf0e10cSrcweir } 2246cdf0e10cSrcweir $tmp_dir = tempdir ( DIR => $tmp_dir ); 2247cdf0e10cSrcweir if (!-d $tmp_dir) { 2248cdf0e10cSrcweir print_error("Cannot create temporary directory for checkout in $tmp_dir") if ($@); 2249cdf0e10cSrcweir }; 2250cdf0e10cSrcweir return $tmp_dir; 2251cdf0e10cSrcweir}; 2252cdf0e10cSrcweir 2253cdf0e10cSrcweirsub retrieve_build_list { 2254cdf0e10cSrcweir my $module = shift; 2255cdf0e10cSrcweir my $old_fh = select(STDOUT); 2256cdf0e10cSrcweir 2257cdf0e10cSrcweir # Try to get global depencies from solver's build.lst if such exists 2258cdf0e10cSrcweir my $solver_inc_dir = "$ENV{SOLARVER}/$ENV{OUTPATH}"; 2259cdf0e10cSrcweir $solver_inc_dir .= $ENV{PROEXT} if (defined $ENV{PROEXT}); 2260cdf0e10cSrcweir $solver_inc_dir .= '/inc'; 2261cdf0e10cSrcweir $solver_inc_dir .= $ENV{UPDMINOREXT} if (defined $ENV{UPDMINOREXT}); 2262cdf0e10cSrcweir $solver_inc_dir .= "/$module"; 2263cdf0e10cSrcweir $solver_inc_dir = correct_path($solver_inc_dir); 2264cdf0e10cSrcweir $dead_parents{$module}++; 2265cdf0e10cSrcweir print "Fetching dependencies for module $module from solver..."; 2266cdf0e10cSrcweir foreach my $onelist (@possible_build_lists) { 2267cdf0e10cSrcweir my $build_list_candidate = "$solver_inc_dir/$onelist"; 2268cdf0e10cSrcweir if (-e $build_list_candidate) { 2269cdf0e10cSrcweir print " ok\n"; 2270cdf0e10cSrcweir select($old_fh); 2271cdf0e10cSrcweir return $build_list_candidate; 2272cdf0e10cSrcweir }; 2273cdf0e10cSrcweir } 2274cdf0e10cSrcweir print(" failed\n"); 2275cdf0e10cSrcweir print_error("incomplete dependencies!\n"); 2276cdf0e10cSrcweir return undef; 2277cdf0e10cSrcweir}; 2278cdf0e10cSrcweir 2279cdf0e10cSrcweirsub fix_permissions { 2280cdf0e10cSrcweir my $file = $File::Find::name; 2281cdf0e10cSrcweir return unless -f $file; 2282cdf0e10cSrcweir chmod '0664', $file; 2283cdf0e10cSrcweir}; 2284cdf0e10cSrcweir 2285cdf0e10cSrcweirsub prepare_build_from_with_branches { 2286cdf0e10cSrcweir my ($full_deps_hash, $reversed_full_deps_hash) = @_; 2287cdf0e10cSrcweir foreach my $prerequisite (keys %$full_deps_hash) { 2288cdf0e10cSrcweir foreach my $dependent_module (keys %incompatibles) { 2289cdf0e10cSrcweir if (defined ${$$reversed_full_deps_hash{$prerequisite}}{$dependent_module}) { 2290cdf0e10cSrcweir remove_from_dependencies($prerequisite, $full_deps_hash); 2291cdf0e10cSrcweir delete $$full_deps_hash{$prerequisite}; 2292cdf0e10cSrcweir# print "Removed $prerequisite\n"; 2293cdf0e10cSrcweir last; 2294cdf0e10cSrcweir }; 2295cdf0e10cSrcweir }; 2296cdf0e10cSrcweir }; 2297cdf0e10cSrcweir}; 2298cdf0e10cSrcweir 2299cdf0e10cSrcweir# 2300cdf0e10cSrcweir# Removes projects which it is not necessary to build 2301cdf0e10cSrcweir# in incompatible build 2302cdf0e10cSrcweir# 2303cdf0e10cSrcweirsub prepare_incompatible_build { 2304cdf0e10cSrcweir my ($prj, $deps_hash, @missing_modules); 2305cdf0e10cSrcweir $deps_hash = shift; 2306cdf0e10cSrcweir foreach my $module (keys %incompatibles) { 2307cdf0e10cSrcweir if (!defined $$deps_hash{$module}) { 2308cdf0e10cSrcweir print_error("The module $initial_module is independent from $module\n"); 2309cdf0e10cSrcweir } 2310cdf0e10cSrcweir $incompatibles{$module} = $$deps_hash{$module}; 2311cdf0e10cSrcweir delete $$deps_hash{$module}; 2312cdf0e10cSrcweir } 2313cdf0e10cSrcweir while ($prj = pick_prj_to_build($deps_hash)) { 2314cdf0e10cSrcweir remove_from_dependencies($prj, $deps_hash); 2315cdf0e10cSrcweir remove_from_dependencies($prj, \%incompatibles); 2316cdf0e10cSrcweir }; 2317cdf0e10cSrcweir foreach (keys %incompatibles) { 2318cdf0e10cSrcweir $$deps_hash{$_} = $incompatibles{$_}; 2319cdf0e10cSrcweir }; 2320cdf0e10cSrcweir if ($build_all_cont) { 2321cdf0e10cSrcweir prepare_build_all_cont($deps_hash); 2322cdf0e10cSrcweir delete $$deps_hash{$build_all_cont}; 2323cdf0e10cSrcweir }; 2324cdf0e10cSrcweir @modules_built = keys %$deps_hash; 2325cdf0e10cSrcweir %add_to_config = %$deps_hash; 2326cdf0e10cSrcweir if ($prepare) { 2327cdf0e10cSrcweir if ((!(defined $ENV{UPDATER} && (!defined $ENV{CWS_WORK_STAMP}))) || (defined $ENV{CWS_WORK_STAMP})) { 2328cdf0e10cSrcweir $source_config->add_active_modules([keys %add_to_config], 0); 2329cdf0e10cSrcweir } 2330cdf0e10cSrcweir clear_delivered(); 2331cdf0e10cSrcweir } 2332790d3a29SHerbert Dürr my @old_output_trees = (); 2333cdf0e10cSrcweir foreach $prj (sort keys %$deps_hash) { 2334cdf0e10cSrcweir if ($prepare) { 2335cdf0e10cSrcweir ensure_clear_module($prj); 2336cdf0e10cSrcweir } else { 2337cdf0e10cSrcweir next if ($show); 2338cdf0e10cSrcweir if ($modules_types{$prj} ne 'mod') { 2339cdf0e10cSrcweir push(@missing_modules, $prj); 2340cdf0e10cSrcweir } elsif (-d $module_paths{$prj}. '/'. $ENV{INPATH}) { 2341790d3a29SHerbert Dürr push(@old_output_trees, $prj); 2342cdf0e10cSrcweir }; 2343cdf0e10cSrcweir }; 2344cdf0e10cSrcweir }; 2345cdf0e10cSrcweir if (scalar @missing_modules) { 2346cdf0e10cSrcweir my $warning_string = 'Following modules are inconsistent/missing: ' . "@missing_modules"; 2347cdf0e10cSrcweir push(@warnings, $warning_string); 2348cdf0e10cSrcweir }; 2349cdf0e10cSrcweir if ($build_all_cont) { 2350cdf0e10cSrcweir $$deps_hash{$build_all_cont} = (); 2351cdf0e10cSrcweir $build_all_cont = ''; 2352cdf0e10cSrcweir }; 2353790d3a29SHerbert Dürr if( scalar @old_output_trees) { 2354790d3a29SHerbert Dürr my $warning_string = 'Some modules contain old output trees! Please check: ' . "@old_output_trees"; 2355790d3a29SHerbert Dürr push(@warnings, $warning_string); 2356cdf0e10cSrcweir }; 2357cdf0e10cSrcweir if (!$generate_config && scalar @warnings) { 2358cdf0e10cSrcweir print "WARNING(S):\n"; 2359cdf0e10cSrcweir print STDERR "$_\n" foreach (@warnings); 2360cdf0e10cSrcweir print "\nATTENTION: If you are performing an incompatible build, please break the build with Ctrl+C and prepare the workspace with \"--prepare\" switch!\n\n" if (!$prepare); 2361cdf0e10cSrcweir sleep(10); 2362cdf0e10cSrcweir }; 2363cdf0e10cSrcweir if ($prepare) { 2364cdf0e10cSrcweir print "\nPreparation finished"; 2365cdf0e10cSrcweir if (scalar @warnings) { 2366cdf0e10cSrcweir print " with WARNINGS!!\n\n"; 2367cdf0e10cSrcweir } else {print " successfully\n\n";} 2368cdf0e10cSrcweir } 2369cdf0e10cSrcweir do_exit(0) if ($prepare); 2370cdf0e10cSrcweir}; 2371cdf0e10cSrcweir 2372cdf0e10cSrcweir# 2373cdf0e10cSrcweir# Removes projects which it is not necessary to build 2374cdf0e10cSrcweir# with --all:prj_name or --since switch 2375cdf0e10cSrcweir# 2376cdf0e10cSrcweirsub prepare_build_all_cont { 2377cdf0e10cSrcweir my ($prj, $deps_hash, $border_prj); 2378cdf0e10cSrcweir $deps_hash = shift; 2379cdf0e10cSrcweir $border_prj = $build_all_cont if ($build_all_cont); 2380cdf0e10cSrcweir $border_prj = $build_since if ($build_since); 2381cdf0e10cSrcweir while ($prj = pick_prj_to_build($deps_hash)) { 2382cdf0e10cSrcweir my $orig_prj = ''; 2383cdf0e10cSrcweir $orig_prj = $` if ($prj =~ /\.lnk$/o); 2384cdf0e10cSrcweir $orig_prj = $` if ($prj =~ /\.link$/o); 2385cdf0e10cSrcweir if (($border_prj ne $prj) && 2386cdf0e10cSrcweir ($border_prj ne $orig_prj)) { 2387cdf0e10cSrcweir remove_from_dependencies($prj, $deps_hash); 2388cdf0e10cSrcweir next; 2389cdf0e10cSrcweir } else { 2390cdf0e10cSrcweir if ($build_all_cont) { 2391cdf0e10cSrcweir $$deps_hash{$prj} = (); 2392cdf0e10cSrcweir } else { 2393cdf0e10cSrcweir remove_from_dependencies($prj, $deps_hash); 2394cdf0e10cSrcweir }; 2395cdf0e10cSrcweir return; 2396cdf0e10cSrcweir }; 2397cdf0e10cSrcweir }; 2398cdf0e10cSrcweir}; 2399cdf0e10cSrcweir 2400cdf0e10cSrcweirsub get_modes { 2401cdf0e10cSrcweir my $option = ''; 2402cdf0e10cSrcweir while ($option = shift @ARGV) { 2403cdf0e10cSrcweir if ($option =~ /^-+/) { 2404cdf0e10cSrcweir unshift(@ARGV, $option); 2405cdf0e10cSrcweir return; 2406cdf0e10cSrcweir } else { 2407cdf0e10cSrcweir if ($option =~ /,/) { 2408cdf0e10cSrcweir $build_modes{$`}++; 2409cdf0e10cSrcweir unshift(@ARGV, $') if ($'); 2410cdf0e10cSrcweir } else {$build_modes{$option}++;}; 2411cdf0e10cSrcweir }; 2412cdf0e10cSrcweir }; 2413cdf0e10cSrcweir $build_modes{$option}++; 2414cdf0e10cSrcweir}; 2415cdf0e10cSrcweir 2416cdf0e10cSrcweirsub get_list_of_modules { 2417cdf0e10cSrcweir my $option = ''; 2418cdf0e10cSrcweir my $hash_ref = shift; 2419cdf0e10cSrcweir while ($option = shift @ARGV) { 2420cdf0e10cSrcweir if ($option =~ /^-+/) { 2421cdf0e10cSrcweir unshift(@ARGV, $option); 2422cdf0e10cSrcweir return; 2423cdf0e10cSrcweir } else { 2424cdf0e10cSrcweir if ($option =~ /,/) { 2425cdf0e10cSrcweir foreach (split /,/, $option) { 2426cdf0e10cSrcweir next if (!$_); 2427cdf0e10cSrcweir $$hash_ref{$_}++; 2428cdf0e10cSrcweir }; 2429cdf0e10cSrcweir } else { 2430cdf0e10cSrcweir $$hash_ref{$option}++; 2431cdf0e10cSrcweir }; 2432cdf0e10cSrcweir }; 2433cdf0e10cSrcweir }; 2434cdf0e10cSrcweir# if (!scalar %$hash_ref) { 2435cdf0e10cSrcweir# print_error('No module list supplied!!'); 2436cdf0e10cSrcweir# }; 2437cdf0e10cSrcweir}; 2438cdf0e10cSrcweir 2439cdf0e10cSrcweirsub get_modules_passed { 2440cdf0e10cSrcweir my $hash_ref = shift; 2441cdf0e10cSrcweir my $option = ''; 2442cdf0e10cSrcweir while ($option = shift @ARGV) { 2443cdf0e10cSrcweir if ($option =~ /^-+/) { 2444cdf0e10cSrcweir unshift(@ARGV, $option); 2445cdf0e10cSrcweir return; 2446cdf0e10cSrcweir } else { 2447cdf0e10cSrcweir if ($option =~ /(:)/) { 2448cdf0e10cSrcweir $option = $`; 2449cdf0e10cSrcweir print_error("\'--from\' switch collision") if ($build_all_cont); 2450cdf0e10cSrcweir $build_all_cont = $'; 2451cdf0e10cSrcweir }; 2452cdf0e10cSrcweir $$hash_ref{$option}++; 2453cdf0e10cSrcweir }; 2454cdf0e10cSrcweir }; 2455cdf0e10cSrcweir}; 2456cdf0e10cSrcweir 2457cdf0e10cSrcweirsub get_workspace_platforms { 2458cdf0e10cSrcweir my $workspace_patforms = shift; 2459cdf0e10cSrcweir my $solver_path = $ENV{SOLARVERSION}; 2460cdf0e10cSrcweir opendir(SOLVERDIR, $solver_path); 2461cdf0e10cSrcweir my @dir_list = readdir(SOLVERDIR); 2462cdf0e10cSrcweir close SOLVERDIR; 2463cdf0e10cSrcweir foreach (@dir_list) { 2464cdf0e10cSrcweir next if /^common/; 2465cdf0e10cSrcweir next if /^\./; 2466cdf0e10cSrcweir if (open(LS, "ls $solver_path/$_/inc/*minor.mk 2>$nul |")) { 2467cdf0e10cSrcweir foreach my $string (<LS>) { 2468cdf0e10cSrcweir chomp $string; 2469cdf0e10cSrcweir if ($string =~ /minor.mk$/) { 2470cdf0e10cSrcweir $$workspace_patforms{$_}++ 2471cdf0e10cSrcweir }; 2472cdf0e10cSrcweir }; 2473cdf0e10cSrcweir close LS; 2474cdf0e10cSrcweir }; 2475cdf0e10cSrcweir }; 2476cdf0e10cSrcweir}; 2477cdf0e10cSrcweir 2478cdf0e10cSrcweirsub get_platforms { 2479cdf0e10cSrcweir my $platforms_ref = shift; 2480cdf0e10cSrcweir if ($only_platform) { 2481cdf0e10cSrcweir foreach (split(',', $only_platform)) { 2482cdf0e10cSrcweir $$platforms_ref{$_}++; 2483cdf0e10cSrcweir } 2484cdf0e10cSrcweir $platforms_ref = \%platforms_to_copy; 2485cdf0e10cSrcweir }; 2486cdf0e10cSrcweir 2487cdf0e10cSrcweir my $workspace_lst = get_workspace_lst(); 2488cdf0e10cSrcweir if ($workspace_lst) { 2489cdf0e10cSrcweir my $workspace_db; 2490cdf0e10cSrcweir eval { $workspace_db = GenInfoParser->new(); }; 2491cdf0e10cSrcweir if (!$@) { 2492cdf0e10cSrcweir my $success = $workspace_db->load_list($workspace_lst); 2493cdf0e10cSrcweir if ( !$success ) { 2494cdf0e10cSrcweir print_error("Can't load workspace list '$workspace_lst'.", 4); 2495cdf0e10cSrcweir } 2496cdf0e10cSrcweir my $access_path = $ENV{WORK_STAMP} . '/Environments'; 2497cdf0e10cSrcweir my @platforms_available = $workspace_db->get_keys($access_path); 2498cdf0e10cSrcweir my $solver = $ENV{SOLARVERSION}; 2499cdf0e10cSrcweir foreach (@platforms_available) { 2500cdf0e10cSrcweir my $s_path = $solver . '/' . $_; 2501cdf0e10cSrcweir $$platforms_ref{$_}++ if (-d $s_path); 2502cdf0e10cSrcweir }; 2503cdf0e10cSrcweir } else { 2504cdf0e10cSrcweir get_workspace_platforms(\%platforms); 2505cdf0e10cSrcweir }; 2506cdf0e10cSrcweir }; 2507cdf0e10cSrcweir 2508cdf0e10cSrcweir if (!scalar keys %platforms) { 2509cdf0e10cSrcweir # An Auses wish - fallback to INPATH for new platforms 2510cdf0e10cSrcweir if (defined $ENV{INPATH}) { 2511cdf0e10cSrcweir $$platforms_ref{$ENV{INPATH}}++; 2512cdf0e10cSrcweir } else { 2513cdf0e10cSrcweir print_error("There is no platform found!!") ; 2514cdf0e10cSrcweir }; 2515cdf0e10cSrcweir }; 2516cdf0e10cSrcweir}; 2517cdf0e10cSrcweir 2518cdf0e10cSrcweir# 2519cdf0e10cSrcweir# This procedure clears solver from delivered 2520cdf0e10cSrcweir# by the modules to be build 2521cdf0e10cSrcweir# 2522cdf0e10cSrcweirsub clear_delivered { 2523cdf0e10cSrcweir my $message = 'Clearing up delivered'; 2524cdf0e10cSrcweir my %backup_vars; 2525cdf0e10cSrcweir my $deliver_delete_switches = '-delete'; 2526cdf0e10cSrcweir if (scalar keys %platforms < scalar keys %platforms_to_copy) { 2527cdf0e10cSrcweir $message .= ' without common trees'; 2528cdf0e10cSrcweir $deliver_delete_switches .= ' -dontdeletecommon'; 2529cdf0e10cSrcweir $only_common = ''; 2530cdf0e10cSrcweir }; 2531cdf0e10cSrcweir print "$message\n"; 2532cdf0e10cSrcweir 2533cdf0e10cSrcweir foreach my $platform (keys %platforms) { 2534cdf0e10cSrcweir print "\nRemoving files delivered for $platform\n"; 2535cdf0e10cSrcweir my %solar_vars = (); 2536cdf0e10cSrcweir read_ssolar_vars($platform, \%solar_vars); 2537cdf0e10cSrcweir if (scalar keys %solar_vars) { 2538cdf0e10cSrcweir foreach (keys %solar_vars) { 2539cdf0e10cSrcweir if (!defined $backup_vars{$_}) { 2540cdf0e10cSrcweir $backup_vars{$_} = $ENV{$_}; 2541cdf0e10cSrcweir }; 2542cdf0e10cSrcweir $ENV{$_} = $solar_vars{$_}; 2543cdf0e10cSrcweir }; 2544cdf0e10cSrcweir }; 2545cdf0e10cSrcweir my $undeliver = "$deliver_command $deliver_delete_switches $nul"; 2546cdf0e10cSrcweir# my $current_dir = getcwd(); 2547cdf0e10cSrcweir foreach my $module (sort @modules_built) { 2548cdf0e10cSrcweir if (chdir($module_paths{$module})) { 2549cdf0e10cSrcweir print "Removing delivered from module $module\n"; 2550cdf0e10cSrcweir next if ($show); 2551cdf0e10cSrcweir if (system($undeliver)) { 2552cdf0e10cSrcweir $ENV{$_} = $backup_vars{$_} foreach (keys %backup_vars); 2553cdf0e10cSrcweir print_error("Cannot run: $undeliver"); 2554cdf0e10cSrcweir } 2555cdf0e10cSrcweir } else { 2556cdf0e10cSrcweir push(@warnings, "Could not remove delivered files from the module $module. Your build can become inconsistent.\n"); 2557cdf0e10cSrcweir }; 2558cdf0e10cSrcweir }; 2559cdf0e10cSrcweir# chdir $current_dir; 2560cdf0e10cSrcweir# getcwd(); 2561cdf0e10cSrcweir }; 2562cdf0e10cSrcweir $ENV{$_} = $backup_vars{$_} foreach (keys %backup_vars); 2563cdf0e10cSrcweir}; 2564cdf0e10cSrcweir 2565cdf0e10cSrcweir# 2566cdf0e10cSrcweir# Run setsolar for given platform and 2567cdf0e10cSrcweir# write all variables needed in %solar_vars hash 2568cdf0e10cSrcweir# 2569cdf0e10cSrcweirsub read_ssolar_vars { 2570cdf0e10cSrcweir my ($setsolar, $tmp_file); 2571cdf0e10cSrcweir $setsolar = $ENV{ENV_ROOT} . '/etools/setsolar.pl'; 2572cdf0e10cSrcweir my ($platform, $solar_vars) = @_; 2573cdf0e10cSrcweir $setsolar = '/net/jumbo2.germany/buildenv/r/etools/setsolar.pl' if ! -e $setsolar; 2574cdf0e10cSrcweir $tmp_file = $ENV{HOME} . "/.solar.env.$$.tmp"; 2575cdf0e10cSrcweir if (!-e $setsolar) { 2576cdf0e10cSrcweir print STDERR "There is no setsolar found. Falling back to current platform settings\n"; 2577cdf0e10cSrcweir return; 2578cdf0e10cSrcweir } 2579cdf0e10cSrcweir my $pro = ""; 2580cdf0e10cSrcweir if ($platform =~ /\.pro$/) { 2581cdf0e10cSrcweir $pro = "-pro"; 2582cdf0e10cSrcweir $platform = $`; 2583cdf0e10cSrcweir }; 2584cdf0e10cSrcweir 2585cdf0e10cSrcweir my ($verswitch, $source_root, $cwsname); 2586cdf0e10cSrcweir $verswitch = "-ver $ENV{UPDMINOR}" if (defined $ENV{UPDMINOR}); 2587cdf0e10cSrcweir $source_root = '-sourceroot' if (defined $ENV{SOURCE_ROOT_USED}); 2588cdf0e10cSrcweir my $cws_name = "-cwsname $ENV{CWS_WORK_STAMP}" if (defined $ENV{CWS_WORK_STAMP}); 2589cdf0e10cSrcweir 2590cdf0e10cSrcweir my $param = "-$ENV{WORK_STAMP} $verswitch $source_root $cws_name $pro $platform"; 2591cdf0e10cSrcweir my $ss_command = "$perl $setsolar -file $tmp_file $param $nul"; 2592cdf0e10cSrcweir if (system($ss_command)) { 2593cdf0e10cSrcweir unlink $tmp_file; 2594cdf0e10cSrcweir print_error("Cannot run command:\n$ss_command"); 2595cdf0e10cSrcweir }; 2596cdf0e10cSrcweir get_solar_vars($solar_vars, $tmp_file); 2597cdf0e10cSrcweir}; 2598cdf0e10cSrcweir 2599cdf0e10cSrcweir# 2600cdf0e10cSrcweir# read variables to hash 2601cdf0e10cSrcweir# 2602cdf0e10cSrcweirsub get_solar_vars { 2603cdf0e10cSrcweir my ($solar_vars, $file) = @_; 2604cdf0e10cSrcweir my ($var, $value); 2605cdf0e10cSrcweir open SOLARTABLE, "<$file" or die "can�t open solarfile $file"; 2606cdf0e10cSrcweir while(<SOLARTABLE>) { 2607cdf0e10cSrcweir s/\r\n//o; 2608cdf0e10cSrcweir next if(!/^\w+\s+(\w+)/o); 2609cdf0e10cSrcweir next if (!defined $deliver_env{$1}); 2610cdf0e10cSrcweir $var = $1; 2611cdf0e10cSrcweir /\'(\S+)\'$/o; 2612cdf0e10cSrcweir $value = $1; 2613cdf0e10cSrcweir $$solar_vars{$var} = $value; 2614cdf0e10cSrcweir }; 2615cdf0e10cSrcweir close SOLARTABLE; 2616cdf0e10cSrcweir unlink $file; 2617cdf0e10cSrcweir} 2618cdf0e10cSrcweir 2619cdf0e10cSrcweir# 2620cdf0e10cSrcweir# Procedure renames <module>.lnk (.link) into <module> 2621cdf0e10cSrcweir# 2622cdf0e10cSrcweirsub get_current_module { 2623cdf0e10cSrcweir my $module_name = shift; 2624cdf0e10cSrcweir my $link_name = $module_name . '.lnk'; 2625cdf0e10cSrcweir $link_name .= '.link' if (-e $workspace_path.$module_name . '.link'); 2626cdf0e10cSrcweir chdir $workspace_path; 2627cdf0e10cSrcweir getcwd(); 2628cdf0e10cSrcweir print "\nBreaking link to module $module_name"; 2629cdf0e10cSrcweir my $result = rename $link_name, $module_name; 2630cdf0e10cSrcweir if ( ! $result ) { 2631cdf0e10cSrcweir print_error("Cannot rename $module_name: $!\n"); 2632cdf0e10cSrcweir } 2633cdf0e10cSrcweir if ( $initial_module eq $link_name) { 2634cdf0e10cSrcweir $initial_module = $module_name; 2635cdf0e10cSrcweir } 2636cdf0e10cSrcweir chdir $module_name; 2637cdf0e10cSrcweir getcwd(); 2638cdf0e10cSrcweir}; 2639cdf0e10cSrcweir 2640cdf0e10cSrcweirsub check_dir { 2641cdf0e10cSrcweir my $start_dir = getcwd(); 2642cdf0e10cSrcweir my @dir_entries = split(/[\\\/]/, $ENV{PWD}); 2643cdf0e10cSrcweir my $current_module = $dir_entries[$#dir_entries]; 2644cdf0e10cSrcweir if (($current_module =~ /(\.lnk)$/) || ($current_module =~ /(\.link)$/)) { 2645cdf0e10cSrcweir $current_module = $`; 2646cdf0e10cSrcweir # we're dealing with a link => fallback to SOLARSRC under UNIX 2647cdf0e10cSrcweir $workspace_path = $ENV{SOLARSRC}.'/'; 2648cdf0e10cSrcweir get_current_module($current_module); 2649cdf0e10cSrcweir return; 2650cdf0e10cSrcweir } else { 2651cdf0e10cSrcweir chdir $start_dir; 2652cdf0e10cSrcweir getcwd(); 2653cdf0e10cSrcweir }; 2654cdf0e10cSrcweir}; 2655cdf0e10cSrcweir 2656cdf0e10cSrcweir# 2657cdf0e10cSrcweir# Store all available build modi in %build_modes 2658cdf0e10cSrcweir# 2659cdf0e10cSrcweirsub get_build_modes { 2660cdf0e10cSrcweir return if (scalar keys %build_modes); 2661cdf0e10cSrcweir if (defined $ENV{BUILD_TYPE}) { 2662cdf0e10cSrcweir if ($ENV{BUILD_TYPE} =~ /\s+/o) { 2663cdf0e10cSrcweir my @build_modes = split (/\s+/, $ENV{BUILD_TYPE}); 2664cdf0e10cSrcweir $build_modes{$_}++ foreach (@build_modes); 2665cdf0e10cSrcweir } else { 2666cdf0e10cSrcweir $build_modes{$ENV{BUILD_TYPE}}++; 2667cdf0e10cSrcweir }; 2668cdf0e10cSrcweir return; 2669cdf0e10cSrcweir }; 2670cdf0e10cSrcweir}; 2671cdf0e10cSrcweir 2672cdf0e10cSrcweir# 2673cdf0e10cSrcweir# pick only the modules, that should be built for 2674cdf0e10cSrcweir# build types from %build_modes 2675cdf0e10cSrcweir# 2676cdf0e10cSrcweirsub pick_for_build_type { 2677cdf0e10cSrcweir my $modules = shift; 2678cdf0e10cSrcweir my @mod_array = split(/\s+/, $modules); 2679cdf0e10cSrcweir print_error("Wrongly written dependencies string:\n $modules\n") if ($mod_array[$#mod_array] ne 'NULL'); 2680cdf0e10cSrcweir pop @mod_array; 2681cdf0e10cSrcweir my @modules_to_build; 2682cdf0e10cSrcweir foreach (@mod_array) { 2683cdf0e10cSrcweir if (/(\w+):(\S+)/o) { 2684cdf0e10cSrcweir push(@modules_to_build, $2) if (defined $build_modes{$1}); 2685cdf0e10cSrcweir next; 2686cdf0e10cSrcweir }; 2687cdf0e10cSrcweir push(@modules_to_build, $_); 2688cdf0e10cSrcweir }; 2689cdf0e10cSrcweir return @modules_to_build; 2690cdf0e10cSrcweir}; 2691cdf0e10cSrcweir 2692cdf0e10cSrcweirsub do_exit { 2693cdf0e10cSrcweir# close_server_socket(); 2694cdf0e10cSrcweir my $exit_code = shift; 2695cdf0e10cSrcweir $build_finished++; 2696cdf0e10cSrcweir generate_html_file(1); 2697cdf0e10cSrcweir if ( $^O eq 'os2' ) 2698cdf0e10cSrcweir { 2699cdf0e10cSrcweir # perl 5.10 returns 'resource busy' for rmtree 2700cdf0e10cSrcweir rmdir(correct_path($tmp_dir)) if ($tmp_dir); 2701cdf0e10cSrcweir } 2702cdf0e10cSrcweir rmtree(correct_path($tmp_dir), 0, 0) if ($tmp_dir); 2703cdf0e10cSrcweir print STDERR "Cannot delete $tmp_dir. Please remove it manually\n" if (-d $tmp_dir); 2704cdf0e10cSrcweir exit($exit_code); 2705cdf0e10cSrcweir}; 2706cdf0e10cSrcweir 2707cdf0e10cSrcweir# 2708cdf0e10cSrcweir# Procedure sorts module in user-frendly order 2709cdf0e10cSrcweir# 2710cdf0e10cSrcweirsub sort_modules_appearance { 2711cdf0e10cSrcweir foreach (keys %dead_parents) { 2712cdf0e10cSrcweir delete $build_is_finished{$_} if (defined $build_is_finished{$_}); 2713cdf0e10cSrcweir delete $build_in_progress{$_} if (defined $build_in_progress{$_}); 2714cdf0e10cSrcweir }; 2715cdf0e10cSrcweir foreach (keys %build_is_finished) { 2716cdf0e10cSrcweir delete $build_in_progress{$_} if (defined $build_in_progress{$_}); 2717cdf0e10cSrcweir delete $build_in_progress_shown{$_} if (defined $build_in_progress_shown{$_}); 2718cdf0e10cSrcweir }; 2719cdf0e10cSrcweir my @modules_order = sort keys %modules_with_errors; 2720cdf0e10cSrcweir foreach (keys %modules_with_errors) { 2721cdf0e10cSrcweir delete $build_in_progress{$_} if (defined $build_in_progress{$_}); 2722cdf0e10cSrcweir delete $build_is_finished{$_} if (defined $build_is_finished{$_}); 2723cdf0e10cSrcweir delete $build_in_progress_shown{$_} if (defined $build_in_progress_shown{$_}); 2724cdf0e10cSrcweir }; 2725cdf0e10cSrcweir $build_in_progress_shown{$_}++ foreach (keys %build_in_progress); 2726cdf0e10cSrcweir push(@modules_order, $_) foreach (sort { $build_in_progress_shown{$b} <=> $build_in_progress_shown{$a} } keys %build_in_progress_shown); 2727cdf0e10cSrcweir push(@modules_order, $_) foreach (sort keys %build_is_finished); 2728cdf0e10cSrcweir foreach(sort keys %html_info) { 2729cdf0e10cSrcweir next if (defined $build_is_finished{$_} || defined $build_in_progress{$_} || defined $modules_with_errors{$_}); 2730cdf0e10cSrcweir push(@modules_order, $_); 2731cdf0e10cSrcweir }; 2732cdf0e10cSrcweir return @modules_order; 2733cdf0e10cSrcweir}; 2734cdf0e10cSrcweir 2735cdf0e10cSrcweirsub generate_html_file { 2736cdf0e10cSrcweir return if (!$html); 2737cdf0e10cSrcweir my $force_update = shift; 2738cdf0e10cSrcweir $force_update++ if ($debug); 2739cdf0e10cSrcweir $html_last_updated = time; 2740cdf0e10cSrcweir my @modules_order = sort_modules_appearance(); 2741cdf0e10cSrcweir my ($successes_percent, $errors_percent) = get_progress_percentage(scalar keys %html_info, scalar keys %build_is_finished, scalar keys %modules_with_errors); 2742cdf0e10cSrcweir my $build_duration = get_time_line(time - $build_time); 2743cdf0e10cSrcweir my $temp_html_file = File::Temp::tmpnam($tmp_dir); 2744cdf0e10cSrcweir my $title; 2745cdf0e10cSrcweir $title = $ENV{CWS_WORK_STAMP} . ': ' if (defined $ENV{CWS_WORK_STAMP}); 2746cdf0e10cSrcweir $title .= $ENV{INPATH}; 2747cdf0e10cSrcweir die("Cannot open $temp_html_file") if (!open(HTML, ">$temp_html_file")); 2748cdf0e10cSrcweir print HTML '<html><head>'; 2749cdf0e10cSrcweir print HTML '<TITLE id=MainTitle>' . $title . '</TITLE>'; 2750cdf0e10cSrcweir print HTML '<script type="text/javascript">' . "\n"; 2751cdf0e10cSrcweir print HTML 'initFrames();' . "\n"; 2752cdf0e10cSrcweir print HTML 'var IntervalID;' . "\n"; 2753cdf0e10cSrcweir print HTML 'function loadFrame_0() {' . "\n"; 2754cdf0e10cSrcweir print HTML ' document.write("<html>");' . "\n"; 2755cdf0e10cSrcweir print HTML ' document.write("<head>");' . "\n"; 2756cdf0e10cSrcweir print HTML ' document.write("</head>");' . "\n"; 2757cdf0e10cSrcweir print HTML ' document.write("<body>");' . "\n"; 2758cdf0e10cSrcweir if ($build_finished) { 2759cdf0e10cSrcweir print HTML 'document.write("<h3 align=center style=\"color:red\">Build process is finished</h3>");' . "\n"; 2760cdf0e10cSrcweir print HTML ' top.frames[0].clearInterval(top.frames[0].IntervalID);' . "\n"; 2761cdf0e10cSrcweir } elsif ($interactive) { 2762cdf0e10cSrcweir print HTML 'document.write(" <div id=divContext style=\"border: 1px solid; display: none; position: absolute\">");' . "\n"; 2763cdf0e10cSrcweir print HTML 'document.write(" <ul style=\"margin: 0; padding: 0.3em; list-style-type: none; background-color: lightgrey;\" :li:hover {} :hr {border: 0; border-bottom: 1px solid grey; margin: 3px 0px 3px 0px; width: 10em;} :a {border: 0 !important;} >");' . "\n"; 2764cdf0e10cSrcweir print HTML 'document.write(" <li><a onmouseover=\"this.style.color=\'red\'\" onmouseout=\"this.style.color=\'black\'\" id=aRebuild href=\"#\">Rebuild module</a></li>");' . "\n"; 2765cdf0e10cSrcweir print HTML 'document.write(" <li><a onmouseover=\"this.style.color=\'red\'\" onmouseout=\"this.style.color=\'black\'\" id=aDelete href=\"#\" >Remove module</a></li>");' . "\n"; 2766cdf0e10cSrcweir print HTML 'document.write(" </ul>");' . "\n"; 2767cdf0e10cSrcweir print HTML 'document.write(" </div>");' . "\n"; 2768cdf0e10cSrcweir }; 2769cdf0e10cSrcweir if ($build_all_parents) { 2770cdf0e10cSrcweir print HTML 'document.write("<table valign=top cellpadding=0 hspace=0 vspace=0 cellspacing=0 border=0>");' . "\n"; 2771cdf0e10cSrcweir print HTML 'document.write(" <tr>");' . "\n"; 2772cdf0e10cSrcweir print HTML 'document.write(" <td><a id=ErroneousModules href=\"javascript:top.Error(\'\', \''; 2773cdf0e10cSrcweir print HTML join('<br>', sort keys %modules_with_errors); 2774cdf0e10cSrcweir print HTML '\', \'\')\"); title=\"'; 2775cdf0e10cSrcweir print HTML scalar keys %modules_with_errors; 2776cdf0e10cSrcweir print HTML ' module(s) with errors\">Total Progress:</a></td>");' . "\n"; 2777cdf0e10cSrcweir print HTML 'document.write(" <td>");' . "\n"; 2778cdf0e10cSrcweir print HTML 'document.write(" <table width=100px valign=top cellpadding=0 hspace=0 vspace=0 cellspacing=0 border=0>");' . "\n"; 2779cdf0e10cSrcweir print HTML 'document.write(" <tr>");' . "\n"; 2780cdf0e10cSrcweir print HTML 'document.write(" <td height=20px width='; 2781cdf0e10cSrcweir print HTML $successes_percent + $errors_percent; 2782cdf0e10cSrcweir if (scalar keys %modules_with_errors) { 2783cdf0e10cSrcweir print HTML '% bgcolor=red valign=top></td>");' . "\n"; 2784cdf0e10cSrcweir } else { 2785cdf0e10cSrcweir print HTML '% bgcolor=#25A528 valign=top></td>");' . "\n"; 2786cdf0e10cSrcweir }; 2787cdf0e10cSrcweir print HTML 'document.write(" <td width='; 2788cdf0e10cSrcweir print HTML 100 - ($successes_percent + $errors_percent); 2789cdf0e10cSrcweir print HTML '% bgcolor=lightgrey valign=top></td>");' . "\n"; 2790cdf0e10cSrcweir print HTML 'document.write(" </tr>");' . "\n"; 2791cdf0e10cSrcweir print HTML 'document.write(" </table>");' . "\n"; 2792cdf0e10cSrcweir print HTML 'document.write(" </td>");' . "\n"; 2793cdf0e10cSrcweir print HTML 'document.write(" <td align=right>  Build time: ' . $build_duration .'</td>");' . "\n"; 2794cdf0e10cSrcweir print HTML 'document.write(" </tr>");' . "\n"; 2795cdf0e10cSrcweir print HTML 'document.write("</table>");' . "\n"; 2796cdf0e10cSrcweir }; 2797cdf0e10cSrcweir 2798cdf0e10cSrcweir print HTML 'document.write("<table width=100% bgcolor=white>");' . "\n"; 2799cdf0e10cSrcweir print HTML 'document.write(" <tr>");' . "\n"; 2800cdf0e10cSrcweir print HTML 'document.write(" <td width=30% align=\"center\"><strong style=\"color:blue\">Module</strong></td>");' . "\n"; 2801cdf0e10cSrcweir print HTML 'document.write(" <td width=* align=\"center\"><strong style=\"color:blue\">Status</strong></td>");' . "\n"; 2802cdf0e10cSrcweir print HTML 'document.write(" <td width=15% align=\"center\"><strong style=\"color:blue\">CPU Time</strong></td>");' . "\n"; 2803cdf0e10cSrcweir print HTML 'document.write(" </tr>");' . "\n"; 2804cdf0e10cSrcweir 2805cdf0e10cSrcweir foreach (@modules_order) { 2806cdf0e10cSrcweir next if ($modules_types{$_} eq 'lnk'); 2807cdf0e10cSrcweir next if (!defined $active_modules{$_}); 2808cdf0e10cSrcweir my ($errors_info_line, $dirs_info_line, $errors_number, $successes_percent, $errors_percent, $time) = get_html_info($_); 2809cdf0e10cSrcweir#<one module> 2810cdf0e10cSrcweir print HTML 'document.write(" <tr>");' . "\n"; 2811cdf0e10cSrcweir print HTML 'document.write(" <td width=*>");' . "\n"; 2812cdf0e10cSrcweir 2813cdf0e10cSrcweir if (defined $dirs_info_line) { 2814cdf0e10cSrcweir print HTML 'document.write(" <a id='; 2815cdf0e10cSrcweir print HTML $_; 2816cdf0e10cSrcweir print HTML ' href=\"javascript:top.Error(\''; 2817cdf0e10cSrcweir print HTML $_ , '\', ' ; 2818cdf0e10cSrcweir print HTML $errors_info_line; 2819cdf0e10cSrcweir print HTML ','; 2820cdf0e10cSrcweir print HTML $dirs_info_line; 2821cdf0e10cSrcweir print HTML ')\"); title=\"'; 2822cdf0e10cSrcweir print HTML $errors_number; 2823cdf0e10cSrcweir print HTML ' error(s)\">', $_, '</a>");' . "\n"; 2824cdf0e10cSrcweir } else { 2825cdf0e10cSrcweir# print HTML 'document.write("<em style=color:gray>' . $_ . '</em>");'; 2826cdf0e10cSrcweir#### print HTML 'document.write("<em style=color:gray>' . $_ ."href=\'http://$local_host_ip:$html_port/delete=\'$_". '</em>");'; 2827cdf0e10cSrcweir 2828cdf0e10cSrcweir print HTML 'document.write(" <a target=\'infoframe\' id='; 2829cdf0e10cSrcweir print HTML $_; 2830cdf0e10cSrcweir print HTML ' href=\"javascript:void(0)\"; title=\"Remove module\">' . $_ . '</a>");' . "\n"; 2831cdf0e10cSrcweir }; 2832cdf0e10cSrcweir 2833cdf0e10cSrcweir 2834cdf0e10cSrcweir print HTML 'document.write(" </td>");' . "\n"; 2835cdf0e10cSrcweir print HTML 'document.write(" <td>");' . "\n"; 2836cdf0e10cSrcweir print HTML 'document.write(" <table width=100% valign=top cellpadding=0 hspace=0 vspace=0 cellspacing=0 border=0>");' . "\n"; 2837cdf0e10cSrcweir print HTML 'document.write(" <tr>");' . "\n"; 28386086b28aSAndrew Rist print HTML 'document.write(" <td height=15 width='; 2839cdf0e10cSrcweir 2840cdf0e10cSrcweir print HTML $successes_percent + $errors_percent; 2841cdf0e10cSrcweir if ($errors_number) { 2842cdf0e10cSrcweir print HTML '% bgcolor=red valign=top></td>");' . "\n"; 2843cdf0e10cSrcweir } else { 2844cdf0e10cSrcweir print HTML '% bgcolor=#25A528 valign=top></td>");' . "\n"; 2845cdf0e10cSrcweir }; 2846cdf0e10cSrcweir print HTML 'document.write(" <td width='; 2847cdf0e10cSrcweir 2848cdf0e10cSrcweir print HTML 100 - ($successes_percent + $errors_percent); 2849cdf0e10cSrcweir print HTML '% bgcolor=lightgrey valign=top></td>");' . "\n"; 2850cdf0e10cSrcweir print HTML 'document.write(" </tr>");' . "\n"; 2851cdf0e10cSrcweir print HTML 'document.write(" </table>");' . "\n"; 2852cdf0e10cSrcweir print HTML 'document.write(" </td>");' . "\n"; 2853cdf0e10cSrcweir print HTML 'document.write(" <td align=\"center\">', $time, '</td>");' . "\n"; 2854cdf0e10cSrcweir print HTML 'document.write(" </tr>");' . "\n"; 2855cdf0e10cSrcweir# </one module> 2856cdf0e10cSrcweir } 2857cdf0e10cSrcweir print HTML 'document.write(" </table>");' . "\n"; 2858cdf0e10cSrcweir print HTML 'document.write(" </body>");' . "\n"; 2859cdf0e10cSrcweir print HTML 'document.write("</html>");' . "\n"; 2860cdf0e10cSrcweir print HTML 'document.close();' . "\n"; 2861cdf0e10cSrcweir print HTML 'refreshInfoFrames();' . "\n"; 2862cdf0e10cSrcweir print HTML '}' . "\n"; 2863cdf0e10cSrcweir 2864cdf0e10cSrcweir 2865cdf0e10cSrcweir if (!$build_finished && $interactive ) { 2866cdf0e10cSrcweir print HTML 'var _replaceContext = false;' . "\n"; 2867cdf0e10cSrcweir print HTML 'var _mouseOverContext = false;' . "\n"; 2868cdf0e10cSrcweir print HTML 'var _noContext = false;' . "\n"; 2869cdf0e10cSrcweir print HTML 'var _divContext = $(\'divContext\');' . "\n"; 2870cdf0e10cSrcweir print HTML 'var activeElement = 0;' . "\n"; 2871cdf0e10cSrcweir print HTML 'function $(id) {return document.getElementById(id);}' . "\n"; 2872cdf0e10cSrcweir print HTML 'InitContext();' . "\n"; 2873cdf0e10cSrcweir print HTML 'function InitContext()' . "\n"; 2874cdf0e10cSrcweir print HTML '{' . "\n"; 2875cdf0e10cSrcweir print HTML ' $(\'aRebuild\').target = \'infoframe\';' . "\n"; 2876cdf0e10cSrcweir print HTML ' $(\'aDelete\').target = \'infoframe\';' . "\n"; 2877cdf0e10cSrcweir print HTML ' $(\'aRebuild\').style.color = \'black\';' . "\n"; 2878cdf0e10cSrcweir print HTML ' $(\'aDelete\').style.color = \'black\';' . "\n"; 2879cdf0e10cSrcweir print HTML ' _divContext.onmouseover = function() { _mouseOverContext = true; };' . "\n"; 2880cdf0e10cSrcweir print HTML ' _divContext.onmouseout = function() { _mouseOverContext = false; };' . "\n"; 2881cdf0e10cSrcweir print HTML ' _divContext.onclick = function() { _divContext.style.display = \'none\'; };' . "\n"; 2882cdf0e10cSrcweir print HTML ' document.body.onmousedown = ContextMouseDown;' . "\n"; 2883cdf0e10cSrcweir print HTML ' document.body.oncontextmenu = ContextShow;' . "\n"; 2884cdf0e10cSrcweir print HTML '}' . "\n"; 2885cdf0e10cSrcweir print HTML 'function ContextMouseDown(event) {' . "\n"; 2886cdf0e10cSrcweir print HTML ' if (_noContext || _mouseOverContext) return;' . "\n"; 2887cdf0e10cSrcweir print HTML ' if (event == null) event = window.event;' . "\n"; 2888cdf0e10cSrcweir print HTML ' var target = event.target != null ? event.target : event.srcElement;' . "\n"; 2889cdf0e10cSrcweir print HTML ' if (event.button == 2 && target.tagName.toLowerCase() == \'a\')' . "\n"; 2890cdf0e10cSrcweir print HTML ' _replaceContext = true;' . "\n"; 2891cdf0e10cSrcweir print HTML ' else if (!_mouseOverContext)' . "\n"; 2892cdf0e10cSrcweir print HTML ' _divContext.style.display = \'none\';' . "\n"; 2893cdf0e10cSrcweir print HTML '}' . "\n"; 2894cdf0e10cSrcweir print HTML 'function ContextShow(event) {' . "\n"; 2895cdf0e10cSrcweir print HTML ' if (_noContext || _mouseOverContext) return;' . "\n"; 2896cdf0e10cSrcweir print HTML ' if (event == null) event = window.event;' . "\n"; 2897cdf0e10cSrcweir print HTML ' var target = event.target != null ? event.target : event.srcElement;' . "\n"; 2898cdf0e10cSrcweir print HTML ' if (_replaceContext) {' . "\n"; 2899cdf0e10cSrcweir print HTML ' $(\'aRebuild\').href = \'http://'. $local_host_ip .':' . $html_port . '/rebuild=\' + target.id;' . "\n"; 2900cdf0e10cSrcweir print HTML ' $(\'aDelete\').href = \'http://'. $local_host_ip .':' . $html_port . '/delete=\' + target.id' . "\n"; 2901cdf0e10cSrcweir print HTML ' var scrollTop = document.body.scrollTop ? document.body.scrollTop : '; 2902cdf0e10cSrcweir print HTML 'document.documentElement.scrollTop;' . "\n"; 2903cdf0e10cSrcweir print HTML ' var scrollLeft = document.body.scrollLeft ? document.body.scrollLeft : '; 2904cdf0e10cSrcweir print HTML 'document.documentElement.scrollLeft;' . "\n"; 2905cdf0e10cSrcweir print HTML ' _divContext.style.display = \'none\';' . "\n"; 2906cdf0e10cSrcweir print HTML ' _divContext.style.left = event.clientX + scrollLeft + \'px\';' . "\n"; 2907cdf0e10cSrcweir print HTML ' _divContext.style.top = event.clientY + scrollTop + \'px\';' . "\n"; 2908cdf0e10cSrcweir print HTML ' _divContext.style.display = \'block\';' . "\n"; 2909cdf0e10cSrcweir print HTML ' _replaceContext = false;' . "\n"; 2910cdf0e10cSrcweir print HTML ' return false;' . "\n"; 2911cdf0e10cSrcweir print HTML ' }' . "\n"; 2912cdf0e10cSrcweir print HTML '}' . "\n"; 2913cdf0e10cSrcweir }; 2914cdf0e10cSrcweir 2915cdf0e10cSrcweir print HTML 'function refreshInfoFrames() { ' . "\n"; 29167a7e0d26SAndrew Rist print HTML ' var ModuleNameObj = top.innerFrame.frames[2].document.getElementById("ModuleErrors");' . "\n"; 29177a7e0d26SAndrew Rist print HTML ' if (ModuleNameObj != null) {' . "\n"; 29187a7e0d26SAndrew Rist print HTML ' var ModuleName = ModuleNameObj.getAttribute(\'name\');' . "\n"; 29197a7e0d26SAndrew Rist print HTML ' var ModuleHref = top.innerFrame.frames[0].document.getElementById(ModuleName).getAttribute(\'href\');' . "\n"; 29207a7e0d26SAndrew Rist print HTML ' eval(ModuleHref);' . "\n"; 29217a7e0d26SAndrew Rist print HTML ' } else if (top.innerFrame.frames[2].document.getElementById("ErroneousModules") != null) {' . "\n"; 29227a7e0d26SAndrew Rist print HTML ' var ModuleHref = top.innerFrame.frames[0].document.getElementById("ErroneousModules").getAttribute(\'href\');' . "\n"; 29237a7e0d26SAndrew Rist print HTML ' eval(ModuleHref);' . "\n"; 29247a7e0d26SAndrew Rist print HTML ' if (top.innerFrame.frames[1].document.getElementById("ModuleJobs") != null) {' . "\n"; 29257a7e0d26SAndrew Rist print HTML ' var ModuleName = top.innerFrame.frames[1].document.getElementById("ModuleJobs").getAttribute(\'name\');' . "\n"; 29267a7e0d26SAndrew Rist print HTML ' ModuleHref = top.innerFrame.frames[0].document.getElementById(ModuleName).getAttribute(\'href\');' . "\n"; 29277a7e0d26SAndrew Rist print HTML ' var HrefString = ModuleHref.toString();' . "\n"; 29287a7e0d26SAndrew Rist print HTML ' var RefEntries = HrefString.split(",");' . "\n"; 29297a7e0d26SAndrew Rist print HTML ' var RefreshParams = new Array();' . "\n"; 29307a7e0d26SAndrew Rist print HTML ' for (i = 0; i < RefEntries.length; i++) {' . "\n"; 29317a7e0d26SAndrew Rist print HTML ' RefreshParams[i] = RefEntries[i].substring(RefEntries[i].indexOf("\'") + 1, RefEntries[i].lastIndexOf("\'"));' . "\n"; 29327a7e0d26SAndrew Rist print HTML ' };' . "\n"; 29337a7e0d26SAndrew Rist print HTML ' FillFrame_1(RefreshParams[0], RefreshParams[1], RefreshParams[2]);' . "\n"; 29347a7e0d26SAndrew Rist print HTML ' }' . "\n"; 29357a7e0d26SAndrew Rist print HTML ' };' . "\n"; 2936cdf0e10cSrcweir print HTML '}' . "\n"; 2937cdf0e10cSrcweir print HTML 'function loadFrame_1() {' . "\n"; 2938cdf0e10cSrcweir print HTML ' document.write("<h3 align=center>Jobs</h3>");' . "\n"; 2939cdf0e10cSrcweir print HTML ' document.write("Click on the project of interest");' . "\n"; 2940cdf0e10cSrcweir print HTML ' document.close();' . "\n"; 2941cdf0e10cSrcweir print HTML '}' . "\n"; 2942cdf0e10cSrcweir print HTML 'function loadFrame_2() {' . "\n"; 2943cdf0e10cSrcweir print HTML ' document.write("<tr bgcolor=lightgrey<td><h3>Errors</h3></pre></td></tr>");' . "\n"; 2944cdf0e10cSrcweir print HTML ' document.write("Click on the project of interest");' . "\n"; 2945cdf0e10cSrcweir print HTML ' document.close();' . "\n"; 2946cdf0e10cSrcweir print HTML '} function getStatusInnerHTML(Status) { var StatusInnerHtml;' . "\n"; 2947cdf0e10cSrcweir print HTML ' if (Status == "success") {' . "\n"; 2948cdf0e10cSrcweir print HTML ' StatusInnerHtml = "<em style=color:green>";' . "\n"; 2949cdf0e10cSrcweir print HTML ' } else if (Status == "building") {' . "\n"; 2950cdf0e10cSrcweir print HTML ' StatusInnerHtml = "<em style=color:blue>";' . "\n"; 2951cdf0e10cSrcweir print HTML ' } else if (Status == "error") {' . "\n"; 2952cdf0e10cSrcweir print HTML ' StatusInnerHtml = "<em style=color:red>";' . "\n"; 2953cdf0e10cSrcweir print HTML ' } else {' . "\n"; 2954cdf0e10cSrcweir print HTML ' StatusInnerHtml = "<em style=color:gray>";' . "\n"; 2955cdf0e10cSrcweir print HTML ' };' . "\n"; 2956cdf0e10cSrcweir print HTML ' StatusInnerHtml += Status + "</em>";' . "\n"; 2957cdf0e10cSrcweir print HTML ' return StatusInnerHtml;' . "\n"; 2958cdf0e10cSrcweir print HTML '} ' . "\n"; 2959cdf0e10cSrcweir print HTML 'function ShowLog(LogFilePath, ModuleJob) {' . "\n"; 29607a7e0d26SAndrew Rist print HTML ' top.innerFrame.frames[2].document.write("<h3 id=ModuleErrors name=\"" + null + "\">Log for " + ModuleJob + "</h3>");' . "\n"; 29617a7e0d26SAndrew Rist print HTML ' top.innerFrame.frames[2].document.write("<iframe id=LogFile name=Log src="'; 29627a7e0d26SAndrew Rist if (defined $html_path) { 29637a7e0d26SAndrew Rist print HTML 'file://'; 29647a7e0d26SAndrew Rist } 29657a7e0d26SAndrew Rist print HTML '+ LogFilePath + " width=100%></iframe>");' . "\n"; 29667a7e0d26SAndrew Rist print HTML ' top.innerFrame.frames[2].document.close();' . "\n"; 2967cdf0e10cSrcweir print HTML '};' . "\n"; 2968cdf0e10cSrcweir print HTML 'function FillFrame_1(Module, Message1, Message2) {' . "\n"; 2969cdf0e10cSrcweir print HTML ' var FullUpdate = 1;' . "\n"; 2970cdf0e10cSrcweir print HTML ' if (top.innerFrame.frames[1].document.getElementById("ModuleJobs") != null) {' . "\n"; 2971cdf0e10cSrcweir print HTML ' var ModuleName = top.innerFrame.frames[1].document.getElementById("ModuleJobs").getAttribute(\'name\');' . "\n"; 2972cdf0e10cSrcweir print HTML ' if (Module == ModuleName) FullUpdate = 0;' . "\n"; 2973cdf0e10cSrcweir print HTML ' }' . "\n"; 2974cdf0e10cSrcweir print HTML ' if (FullUpdate) {' . "\n"; 2975cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write("<h3 align=center>Jobs in module " + Module + ":</h3>");' . "\n"; 2976cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write("<table id=ModuleJobs name=" + Module + " width=100% bgcolor=white>");' . "\n"; 2977cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <tr>");' . "\n"; 2978cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td width=* align=center><strong style=color:blue>Status</strong></td>");' . "\n"; 2979cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td width=* align=center><strong style=color:blue>Job</strong></td>");' . "\n"; 2980cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td width=* align=center><strong style=color:blue>Start Time</strong></td>");' . "\n"; 2981cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td width=* align=center><strong style=color:blue>Finish Time</strong></td>");' . "\n"; 2982cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td width=* align=center><strong style=color:blue>Client</strong></td>");' . "\n" if ($server_mode); 2983cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" </tr>");' . "\n"; 2984cdf0e10cSrcweir print HTML ' var dir_info_strings = Message2.split("<br><br>");' . "\n"; 2985cdf0e10cSrcweir print HTML ' for (i = 0; i < dir_info_strings.length; i++) {' . "\n"; 2986cdf0e10cSrcweir print HTML ' var dir_info_array = dir_info_strings[i].split("<br>");' . "\n"; 2987cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <tr status=" + dir_info_array[0] + ">");' . "\n"; 2988cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td align=center>");' . "\n"; 2989cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write( getStatusInnerHTML(dir_info_array[0]) + " ");' . "\n"; 2990cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" </td>");' . "\n"; 2991cdf0e10cSrcweir print HTML ' if (dir_info_array[4] == "@") {' . "\n"; 2992cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td style=white-space:nowrap>" + dir_info_array[1] + "</td>");' . "\n"; 2993cdf0e10cSrcweir print HTML ' } else {' . "\n"; 2994cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td><a href=\"javascript:top.ShowLog(\'" + dir_info_array[4] + "\', \'" + dir_info_array[1] + "\')\"); title=\"Show Log\">" + dir_info_array[1] + "</a></td>");' . "\n"; 2995cdf0e10cSrcweir print HTML ' };' . "\n"; 2996cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td align=center>" + dir_info_array[2] + "</td>");' . "\n"; 2997cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td align=center>" + dir_info_array[3] + "</td>");' . "\n"; 2998cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" <td align=center>" + dir_info_array[5] + "</td>");' . "\n" if ($server_mode); 2999cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write(" </tr>");' . "\n"; 3000cdf0e10cSrcweir print HTML ' };' . "\n"; 3001cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.write("</table>");' . "\n"; 3002cdf0e10cSrcweir print HTML ' } else {' . "\n"; 3003cdf0e10cSrcweir print HTML ' var dir_info_strings = Message2.split("<br><br>");' . "\n"; 3004cdf0e10cSrcweir print HTML ' var ModuleRows = top.innerFrame.frames[1].document.getElementById("ModuleJobs").rows;' . "\n"; 3005cdf0e10cSrcweir print HTML ' for (i = 0; i < dir_info_strings.length; i++) {' . "\n"; 3006cdf0e10cSrcweir print HTML ' var dir_info_array = dir_info_strings[i].split("<br>");' . "\n"; 3007cdf0e10cSrcweir print HTML ' var OldStatus = ModuleRows[i + 1].getAttribute(\'status\');' . "\n"; 3008cdf0e10cSrcweir print HTML ' if(dir_info_array[0] != OldStatus) {' . "\n"; 3009cdf0e10cSrcweir print HTML ' var DirectoryInfos = ModuleRows[i + 1].cells;' . "\n"; 3010cdf0e10cSrcweir print HTML ' DirectoryInfos[0].innerHTML = getStatusInnerHTML(dir_info_array[0]) + " ";' . "\n"; 3011cdf0e10cSrcweir print HTML ' if (dir_info_array[4] != "@") {' . "\n"; 3012cdf0e10cSrcweir print HTML ' DirectoryInfos[1].innerHTML = "<a href=\"javascript:top.ShowLog(\'" + dir_info_array[4] + "\', \'" + dir_info_array[1] + "\')\"); title=\"Show Log\">" + dir_info_array[1] + "</a>";' . "\n"; 3013cdf0e10cSrcweir print HTML ' };' . "\n"; 3014cdf0e10cSrcweir print HTML ' DirectoryInfos[2].innerHTML = dir_info_array[2];' . "\n"; 3015cdf0e10cSrcweir print HTML ' DirectoryInfos[3].innerHTML = dir_info_array[3];' . "\n"; 3016cdf0e10cSrcweir print HTML ' DirectoryInfos[4].innerHTML = dir_info_array[5];' . "\n" if ($server_mode); 3017cdf0e10cSrcweir print HTML ' };' . "\n"; 3018cdf0e10cSrcweir print HTML ' };' . "\n"; 3019cdf0e10cSrcweir print HTML ' };' . "\n"; 3020cdf0e10cSrcweir print HTML ' top.innerFrame.frames[1].document.close();' . "\n"; 3021cdf0e10cSrcweir print HTML '};' . "\n"; 3022cdf0e10cSrcweir print HTML 'function Error(Module, Message1, Message2) {' . "\n"; 3023cdf0e10cSrcweir print HTML ' if (Module == \'\') {' . "\n"; 3024cdf0e10cSrcweir print HTML ' if (Message1 != \'\') {' . "\n"; 3025cdf0e10cSrcweir print HTML ' var erroneous_modules = Message1.split("<br>");' . "\n"; 3026cdf0e10cSrcweir print HTML ' var ErrorNumber = erroneous_modules.length;' . "\n"; 3027cdf0e10cSrcweir 3028cdf0e10cSrcweir print HTML ' top.innerFrame.frames[2].document.write("<h3 id=ErroneousModules errors=" + erroneous_modules.length + ">Modules with errors:</h3>");' . "\n"; 3029cdf0e10cSrcweir print HTML ' for (i = 0; i < ErrorNumber; i++) {' . "\n"; 3030cdf0e10cSrcweir print HTML ' var ModuleObj = top.innerFrame.frames[0].document.getElementById(erroneous_modules[i]);' . "\n"; 3031cdf0e10cSrcweir print HTML ' top.innerFrame.frames[2].document.write("<a href=\"");' . "\n"; 3032cdf0e10cSrcweir print HTML ' top.innerFrame.frames[2].document.write(ModuleObj.getAttribute(\'href\'));' . "\n"; 3033cdf0e10cSrcweir print HTML ' top.innerFrame.frames[2].document.write("\"); title=\"");' . "\n"; 3034cdf0e10cSrcweir print HTML ' top.innerFrame.frames[2].document.write("\">" + erroneous_modules[i] + "</a>  ");' . "\n"; 3035cdf0e10cSrcweir print HTML ' };' . "\n"; 3036cdf0e10cSrcweir print HTML ' top.innerFrame.frames[2].document.close();' . "\n"; 3037cdf0e10cSrcweir print HTML ' };' . "\n"; 30387a7e0d26SAndrew Rist print HTML ' } else {' . "\n"; 30397a7e0d26SAndrew Rist print HTML ' var ModuleNameObj = top.innerFrame.frames[2].document.getElementById("ModuleErrors");' . "\n"; 30407a7e0d26SAndrew Rist print HTML ' var OldErrors = null;' . "\n"; 30417a7e0d26SAndrew Rist print HTML ' var ErrorNumber = Message1.split("<br>").length;' . "\n"; 30427a7e0d26SAndrew Rist print HTML ' if ((ModuleNameObj != null) && (Module == ModuleNameObj.getAttribute(\'name\')) ) {' . "\n"; 30437a7e0d26SAndrew Rist print HTML ' OldErrors = ModuleNameObj.getAttribute(\'errors\');' . "\n"; 30447a7e0d26SAndrew Rist print HTML ' }' . "\n"; 30457a7e0d26SAndrew Rist print HTML ' if ((OldErrors == null) || (OldErrors != ErrorNumber)) {' . "\n"; 30467a7e0d26SAndrew Rist print HTML ' top.innerFrame.frames[2].document.write("<h3 id=ModuleErrors errors=" + ErrorNumber + " name=\"" + Module + "\">Errors in module " + Module + ":</h3>");' . "\n"; 30477a7e0d26SAndrew Rist print HTML ' top.innerFrame.frames[2].document.write(Message1);' . "\n"; 30487a7e0d26SAndrew Rist print HTML ' top.innerFrame.frames[2].document.close();' . "\n"; 30497a7e0d26SAndrew Rist print HTML ' }' . "\n"; 30507a7e0d26SAndrew Rist print HTML ' FillFrame_1(Module, Message1, Message2);' . "\n"; 3051cdf0e10cSrcweir print HTML ' }' . "\n"; 3052cdf0e10cSrcweir print HTML '}' . "\n"; 3053cdf0e10cSrcweir print HTML 'function updateInnerFrame() {' . "\n"; 3054cdf0e10cSrcweir print HTML ' top.innerFrame.frames[0].document.location.reload();' . "\n"; 3055cdf0e10cSrcweir print HTML ' refreshInfoFrames();' . "\n"; 3056cdf0e10cSrcweir print HTML '};' . "\n\n"; 3057cdf0e10cSrcweir 3058cdf0e10cSrcweir print HTML 'function setRefreshRate() {' . "\n"; 3059cdf0e10cSrcweir print HTML ' RefreshRate = document.Formular.rate.value;' . "\n"; 3060cdf0e10cSrcweir print HTML ' if (!isNaN(RefreshRate * 1)) {' . "\n"; 3061cdf0e10cSrcweir print HTML ' top.frames[0].clearInterval(IntervalID);' . "\n"; 3062cdf0e10cSrcweir print HTML ' IntervalID = top.frames[0].setInterval("updateInnerFrame()", RefreshRate * 1000);' . "\n"; 3063cdf0e10cSrcweir print HTML ' };' . "\n"; 3064cdf0e10cSrcweir print HTML '};' . "\n"; 3065cdf0e10cSrcweir 3066cdf0e10cSrcweir print HTML 'function initFrames() {' . "\n"; 3067cdf0e10cSrcweir print HTML ' var urlquery = location.href.split("?");' . "\n"; 3068cdf0e10cSrcweir print HTML ' if (urlquery.length == 1) {' . "\n"; 3069cdf0e10cSrcweir print HTML ' document.write("<html><head><TITLE id=MainTitle>' . $ENV{INPATH} .'</TITLE>");' . "\n"; 30706086b28aSAndrew Rist print HTML ' document.write(" <frameset rows=\"40,*\">");' . "\n"; 3071cdf0e10cSrcweir print HTML ' document.write(" <frame name=\"topFrame\" src=\"" + urlquery + "?initTop\"/>");' . "\n"; 3072cdf0e10cSrcweir print HTML ' document.write(" <frame name=\"innerFrame\" src=\"" + urlquery + "?initInnerPage\"/>");' . "\n"; 3073cdf0e10cSrcweir print HTML ' document.write(" </frameset>");' . "\n"; 3074cdf0e10cSrcweir print HTML ' document.write("</head></html>");' . "\n"; 3075cdf0e10cSrcweir print HTML ' } else if (urlquery[1].substring(0,7) == "initTop") {' . "\n"; 3076cdf0e10cSrcweir print HTML ' var urlquerycontent = urlquery[1].split("=");' . "\n"; 3077cdf0e10cSrcweir print HTML ' var UpdateRate = 10' . "\n"; 3078cdf0e10cSrcweir print HTML ' if (urlquerycontent.length > 2) {' . "\n"; 3079cdf0e10cSrcweir print HTML ' if (isNaN(urlquerycontent[2] * 1)) {' . "\n"; 3080cdf0e10cSrcweir print HTML ' alert(urlquerycontent[2] + " is not a number. Ignored.");' . "\n"; 3081cdf0e10cSrcweir print HTML ' } else {' . "\n"; 3082cdf0e10cSrcweir print HTML ' UpdateRate = urlquerycontent[2];' . "\n"; 3083cdf0e10cSrcweir print HTML ' };' . "\n"; 3084cdf0e10cSrcweir print HTML ' };' . "\n"; 3085cdf0e10cSrcweir print HTML ' document.write("<html><body>");' . "\n"; 30866086b28aSAndrew Rist print HTML ' document.write("<table border=\"0\" width=\"100%\"> <tr>");' . "\n"; 30876086b28aSAndrew Rist print HTML ' document.write("<td align=\"left\"><h3>Build process progress status</h3></td>");' . "\n"; 30886086b28aSAndrew Rist print HTML ' document.write("<td align=\"right\">");' . "\n"; 3089cdf0e10cSrcweir print HTML ' document.write("<FORM name=\"Formular\" onsubmit=\"setRefreshRate()\">");' . "\n"; 3090cdf0e10cSrcweir print HTML ' document.write("<input type=\"hidden\" name=\"initTop\" value=\"\"/>");' . "\n"; 3091cdf0e10cSrcweir print HTML ' document.write("<input type=\"text\" id=\"RateValue\" name=\"rate\" autocomplete=\"off\" value=\"" + UpdateRate + "\" size=\"1\"/>");' . "\n"; 30926086b28aSAndrew Rist print HTML ' document.write("<input type=\"submit\" value=\"Update refresh rate (sec)\">");' . "\n"; 3093cdf0e10cSrcweir print HTML ' document.write("</FORM>");' . "\n"; 30946086b28aSAndrew Rist print HTML ' document.write("</td></tr></table>");' . "\n"; 3095cdf0e10cSrcweir print HTML ' document.write(" </frameset>");' . "\n"; 3096cdf0e10cSrcweir print HTML ' document.write("</body></html>");' . "\n"; 3097cdf0e10cSrcweir print HTML ' top.frames[0].clearInterval(IntervalID);' . "\n"; 3098cdf0e10cSrcweir print HTML ' IntervalID = top.frames[0].setInterval("updateInnerFrame()", UpdateRate * 1000);' . "\n"; 3099cdf0e10cSrcweir print HTML ' } else if (urlquery[1] == "initInnerPage") {' . "\n"; 3100cdf0e10cSrcweir print HTML ' document.write("<html><head>");' . "\n"; 31016086b28aSAndrew Rist print HTML ' document.write(\' <frameset rows="50%,50%\">\');' . "\n"; 31026086b28aSAndrew Rist print HTML ' document.write(\' <frameset cols="50%,50%">\');' . "\n"; 3103cdf0e10cSrcweir print HTML ' document.write(\' <frame src="\');' . "\n"; 3104cdf0e10cSrcweir print HTML ' document.write(urlquery[0]);' . "\n"; 3105cdf0e10cSrcweir print HTML ' document.write(\'?initFrame0"/>\');' . "\n"; 3106cdf0e10cSrcweir print HTML ' document.write(\' <frame src="\');' . "\n"; 3107cdf0e10cSrcweir print HTML ' document.write(urlquery[0]);' . "\n"; 3108cdf0e10cSrcweir print HTML ' document.write(\'?initFrame1"/>\');' . "\n"; 3109cdf0e10cSrcweir print HTML ' document.write(\' </frameset>\');' . "\n"; 3110cdf0e10cSrcweir print HTML ' document.write(\' <frame src="\');' . "\n"; 3111cdf0e10cSrcweir print HTML ' document.write(urlquery[0]);' . "\n"; 3112cdf0e10cSrcweir print HTML ' document.write(\'?initFrame2" name="infoframe"/>\');' . "\n"; 3113cdf0e10cSrcweir print HTML ' document.write(\' </frameset>\');' . "\n"; 3114cdf0e10cSrcweir print HTML ' document.write("</head></html>");' . "\n"; 3115cdf0e10cSrcweir print HTML ' } else {' . "\n"; 3116cdf0e10cSrcweir print HTML ' if (urlquery[1] == "initFrame0" ) {' . "\n"; 3117cdf0e10cSrcweir print HTML ' loadFrame_0();' . "\n"; 3118cdf0e10cSrcweir print HTML ' } else if (urlquery[1] == "initFrame1" ) { ' . "\n"; 3119cdf0e10cSrcweir print HTML ' loadFrame_1();' . "\n"; 3120cdf0e10cSrcweir print HTML ' } else if (urlquery[1] == "initFrame2" ) {' . "\n"; 3121cdf0e10cSrcweir print HTML ' loadFrame_2();' . "\n"; 3122cdf0e10cSrcweir print HTML ' }' . "\n"; 3123cdf0e10cSrcweir print HTML ' };' . "\n"; 3124cdf0e10cSrcweir print HTML '};' . "\n"; 3125cdf0e10cSrcweir print HTML '</script><noscript>Your browser doesn\'t support JavaScript!</noscript></head></html>' . "\n"; 3126cdf0e10cSrcweir close HTML; 3127cdf0e10cSrcweir rename_file($temp_html_file, $html_file); 3128cdf0e10cSrcweir}; 3129cdf0e10cSrcweir 3130cdf0e10cSrcweirsub get_local_time_line { 3131cdf0e10cSrcweir my $epoch_time = shift; 3132cdf0e10cSrcweir my $local_time_line; 3133cdf0e10cSrcweir my @time_array; 3134cdf0e10cSrcweir if ($epoch_time) { 3135cdf0e10cSrcweir @time_array = localtime($epoch_time); 3136cdf0e10cSrcweir $local_time_line = sprintf("%02d:%02d:%02d", $time_array[2], $time_array[1], $time_array[0]); 3137cdf0e10cSrcweir } else { 3138cdf0e10cSrcweir $local_time_line = '-'; 3139cdf0e10cSrcweir }; 3140cdf0e10cSrcweir return $local_time_line; 3141cdf0e10cSrcweir}; 3142cdf0e10cSrcweir 3143cdf0e10cSrcweirsub get_dirs_info_line { 3144cdf0e10cSrcweir my $job = shift; 3145cdf0e10cSrcweir my $dirs_info_line = $jobs_hash{$job}->{STATUS} . '<br>'; 3146cdf0e10cSrcweir my @time_array; 3147cdf0e10cSrcweir my $log_path_string; 3148cdf0e10cSrcweir $dirs_info_line .= $jobs_hash{$job}->{SHORT_NAME} . '<br>'; 3149cdf0e10cSrcweir $dirs_info_line .= get_local_time_line($jobs_hash{$job}->{START_TIME}) . '<br>'; 3150cdf0e10cSrcweir $dirs_info_line .= get_local_time_line($jobs_hash{$job}->{FINISH_TIME}) . '<br>'; 3151cdf0e10cSrcweir if ($jobs_hash{$job}->{STATUS} eq 'waiting' || (!-f $jobs_hash{$job}->{LONG_LOG_PATH})) { 3152cdf0e10cSrcweir $dirs_info_line .= '@'; 3153cdf0e10cSrcweir } else { 3154cdf0e10cSrcweir if (defined $html_path) { 3155cdf0e10cSrcweir $log_path_string = $jobs_hash{$job}->{LONG_LOG_PATH}; 3156cdf0e10cSrcweir } else { 3157cdf0e10cSrcweir $log_path_string = $jobs_hash{$job}->{LOG_PATH}; 3158cdf0e10cSrcweir }; 3159cdf0e10cSrcweir $log_path_string =~ s/\\/\//g; 3160cdf0e10cSrcweir $dirs_info_line .= $log_path_string; 3161cdf0e10cSrcweir }; 3162cdf0e10cSrcweir $dirs_info_line .= '<br>'; 3163cdf0e10cSrcweir $dirs_info_line .= $jobs_hash{$job}->{CLIENT} . '<br>' if ($server_mode); 3164cdf0e10cSrcweir return $dirs_info_line; 3165cdf0e10cSrcweir}; 3166cdf0e10cSrcweir 3167cdf0e10cSrcweirsub get_html_info { 3168cdf0e10cSrcweir my $module = shift; 3169cdf0e10cSrcweir my $module_info_hash = $html_info{$module}; 3170cdf0e10cSrcweir my $dirs = $$module_info_hash{DIRS}; 3171cdf0e10cSrcweir my $dirs_number = scalar @$dirs; 3172cdf0e10cSrcweir my $dirs_info_line = '\''; 3173cdf0e10cSrcweir if ($dirs_number) { 3174cdf0e10cSrcweir my %dirs_sorted_by_order = (); 3175cdf0e10cSrcweir foreach (@$dirs) { 3176cdf0e10cSrcweir $dirs_sorted_by_order{$jobs_hash{$_}->{BUILD_NUMBER}} = $_; 3177cdf0e10cSrcweir } 3178cdf0e10cSrcweir foreach (sort {$a <=> $b} keys %dirs_sorted_by_order) { 3179cdf0e10cSrcweir $dirs_info_line .= get_dirs_info_line($dirs_sorted_by_order{$_}) . '<br>'; 3180cdf0e10cSrcweir } 3181cdf0e10cSrcweir } else { 3182cdf0e10cSrcweir return(undef, undef, 0, 0, 0, '-'); 3183cdf0e10cSrcweir# $dirs_info_line .= 'No information available yet'; 3184cdf0e10cSrcweir }; 3185cdf0e10cSrcweir $dirs_info_line =~ s/(<br>)*$//o; 3186cdf0e10cSrcweir $dirs_info_line .= '\''; 3187cdf0e10cSrcweir $dirs = $$module_info_hash{SUCCESSFUL}; 3188cdf0e10cSrcweir my $successful_number = scalar @$dirs; 3189cdf0e10cSrcweir $dirs = $$module_info_hash{ERRORFUL}; 3190cdf0e10cSrcweir my $errorful_number = scalar @$dirs; 3191cdf0e10cSrcweir my $errors_info_line = '\''; 3192cdf0e10cSrcweir if ($errorful_number) { 3193cdf0e10cSrcweir $errors_info_line .= $_ . '<br>' foreach (@$dirs); 3194cdf0e10cSrcweir } else { 3195cdf0e10cSrcweir $errors_info_line .= 'No errors'; 3196cdf0e10cSrcweir }; 3197cdf0e10cSrcweir $errors_info_line .= '\''; 3198cdf0e10cSrcweir# if (defined $full_info) { 3199cdf0e10cSrcweir my $time_line = get_time_line($$module_info_hash{BUILD_TIME}); 3200cdf0e10cSrcweir my ($successes_percent, $errors_percent) = get_progress_percentage($dirs_number - 1, $successful_number - 1, $errorful_number); 3201cdf0e10cSrcweir return($errors_info_line, $dirs_info_line, $errorful_number, $successes_percent, $errors_percent, $time_line); 3202cdf0e10cSrcweir# } else { 3203cdf0e10cSrcweir# return($errors_info_line, $dirs_info_line, $errorful_number); 3204cdf0e10cSrcweir# }; 3205cdf0e10cSrcweir}; 3206cdf0e10cSrcweir 3207cdf0e10cSrcweirsub get_time_line { 3208cdf0e10cSrcweir use integer; 3209cdf0e10cSrcweir my $seconds = shift; 3210cdf0e10cSrcweir my $hours = $seconds/3600; 3211cdf0e10cSrcweir my $minits = ($seconds/60)%60; 3212cdf0e10cSrcweir $seconds -= ($hours*3600 + $minits*60); 3213cdf0e10cSrcweir return(sprintf("%02d\:%02d\:%02d" , $hours, $minits, $seconds)); 3214cdf0e10cSrcweir}; 3215cdf0e10cSrcweir 3216cdf0e10cSrcweirsub get_progress_percentage { 3217cdf0e10cSrcweir use integer; 3218cdf0e10cSrcweir my ($dirs_number, $successful_number, $errorful_number) = @_; 3219cdf0e10cSrcweir return (0 ,0) if (!$dirs_number); 3220cdf0e10cSrcweir my $errors_percent = ($errorful_number * 100)/ $dirs_number; 3221cdf0e10cSrcweir my $successes_percent; 3222cdf0e10cSrcweir if ($dirs_number == ($successful_number + $errorful_number)) { 3223cdf0e10cSrcweir $successes_percent = 100 - $errors_percent; 3224cdf0e10cSrcweir } else { 3225cdf0e10cSrcweir $successes_percent = ($successful_number * 100)/ $dirs_number; 3226cdf0e10cSrcweir }; 3227cdf0e10cSrcweir return ($successes_percent, $errors_percent); 3228cdf0e10cSrcweir}; 3229cdf0e10cSrcweir 3230cdf0e10cSrcweir# 3231cdf0e10cSrcweir# This procedure stores the dmake result in %html_info 3232cdf0e10cSrcweir# 3233cdf0e10cSrcweirsub html_store_job_info { 3234cdf0e10cSrcweir return if (!$html); 3235cdf0e10cSrcweir my ($deps_hash, $build_dir, $error_code) = @_; 3236cdf0e10cSrcweir my $force_update = 0; 3237cdf0e10cSrcweir if ($build_dir =~ /(\s)/o && (defined $error_code)) { 3238cdf0e10cSrcweir $force_update++ if (!children_number()); 3239cdf0e10cSrcweir } 3240cdf0e10cSrcweir my $module = $module_by_hash{$deps_hash}; 3241cdf0e10cSrcweir my $module_info_hash = $html_info{$module}; 3242cdf0e10cSrcweir my $dmake_array; 3243cdf0e10cSrcweir if (defined $error_code) { 3244cdf0e10cSrcweir $jobs_hash{$build_dir}->{FINISH_TIME} = time(); 3245cdf0e10cSrcweir $$module_info_hash{BUILD_TIME} += $jobs_hash{$build_dir}->{FINISH_TIME} - $jobs_hash{$build_dir}->{START_TIME}; 3246cdf0e10cSrcweir if ($error_code) { 3247cdf0e10cSrcweir $jobs_hash{$build_dir}->{STATUS} = 'error'; 3248cdf0e10cSrcweir $dmake_array = $$module_info_hash{ERRORFUL}; 3249cdf0e10cSrcweir $build_dir =~ s/\\/\//g; 3250cdf0e10cSrcweir $modules_with_errors{$module}++; 3251cdf0e10cSrcweir } else { 3252cdf0e10cSrcweir if ($build_dir =~ /(\s)announce/o) { 3253cdf0e10cSrcweir $jobs_hash{$build_dir}->{STATUS} = '-'; 3254cdf0e10cSrcweir } else { 3255cdf0e10cSrcweir $jobs_hash{$build_dir}->{STATUS} = 'success'; 3256cdf0e10cSrcweir }; 3257cdf0e10cSrcweir $dmake_array = $$module_info_hash{SUCCESSFUL}; 3258cdf0e10cSrcweir }; 3259cdf0e10cSrcweir push (@$dmake_array, $build_dir); 3260cdf0e10cSrcweir }; 3261cdf0e10cSrcweir}; 3262cdf0e10cSrcweir 3263cdf0e10cSrcweirsub start_server_on_port { 3264cdf0e10cSrcweir my $port = shift; 3265cdf0e10cSrcweir my $socket_obj = shift; 3266cdf0e10cSrcweir $client_timeout = 1 if (!$parent_process); 3267cdf0e10cSrcweir if ($ENV{GUI} eq 'WNT') { 3268cdf0e10cSrcweir $$socket_obj = new IO::Socket::INET (#LocalAddr => hostname(), 3269cdf0e10cSrcweir LocalPort => $port, 3270cdf0e10cSrcweir Proto => 'tcp', 3271cdf0e10cSrcweir Listen => 100); # 100 clients can be on queue, I think it is enough 3272cdf0e10cSrcweir } else { 3273cdf0e10cSrcweir $$socket_obj = new IO::Socket::INET (#LocalAddr => hostname(), 3274cdf0e10cSrcweir LocalPort => $port, 3275cdf0e10cSrcweir Proto => 'tcp', 3276cdf0e10cSrcweir ReuseAddr => 1, 3277cdf0e10cSrcweir Listen => 100); # 100 clients can be on queue, I think it is enough 3278cdf0e10cSrcweir }; 3279cdf0e10cSrcweir return('Cannot create socket object') if (!defined $$socket_obj); 3280cdf0e10cSrcweir my $timeout = $$socket_obj->timeout($client_timeout); 3281cdf0e10cSrcweir $$socket_obj->autoflush(1); 3282cdf0e10cSrcweir if ($parent_process && $debug) { 3283cdf0e10cSrcweir print "SERVER started on port $port\n"; 3284cdf0e10cSrcweir } else { 3285cdf0e10cSrcweir print "html_port:$html_port html_socket_obj: $html_socket_obj\n"; 3286cdf0e10cSrcweir }; 3287cdf0e10cSrcweir return 0; 3288cdf0e10cSrcweir}; 3289cdf0e10cSrcweir 3290cdf0e10cSrcweirsub accept_html_connection { 3291cdf0e10cSrcweir my $new_socket_obj = undef; 3292cdf0e10cSrcweir $new_socket_obj = $html_socket_obj->accept(); 3293cdf0e10cSrcweir return $new_socket_obj; 3294cdf0e10cSrcweir}; 3295cdf0e10cSrcweir 3296cdf0e10cSrcweirsub accept_connection { 3297cdf0e10cSrcweir my $new_socket_obj = undef; 3298cdf0e10cSrcweir do { 3299cdf0e10cSrcweir $new_socket_obj = $server_socket_obj->accept(); 3300cdf0e10cSrcweir if (!$new_socket_obj) { 3301cdf0e10cSrcweir print "Timeout on incoming connection\n"; 3302cdf0e10cSrcweir check_client_jobs(); 3303cdf0e10cSrcweir }; 3304cdf0e10cSrcweir } while (!$new_socket_obj); 3305cdf0e10cSrcweir return $new_socket_obj; 3306cdf0e10cSrcweir}; 3307cdf0e10cSrcweir 3308cdf0e10cSrcweirsub check_client_jobs { 3309cdf0e10cSrcweir foreach (keys %clients_times) { 3310cdf0e10cSrcweir if (time - $clients_times{$_} > $client_timeout) { 3311cdf0e10cSrcweir print "Client's $_ Job: \"$clients_jobs{$_}\" apparently got lost...\n"; 3312cdf0e10cSrcweir print "Scheduling for rebuild...\n"; 3313cdf0e10cSrcweir print "You might need to check the $_\n"; 3314cdf0e10cSrcweir $lost_client_jobs{$clients_jobs{$_}}++; 3315cdf0e10cSrcweir delete $processes_hash{$_}; 3316cdf0e10cSrcweir delete $clients_jobs{$_}; 3317cdf0e10cSrcweir delete $clients_times{$_}; 3318cdf0e10cSrcweir# } else { 3319cdf0e10cSrcweir# print time - $clients_times{$_} . "\n"; 3320cdf0e10cSrcweir }; 3321cdf0e10cSrcweir }; 3322cdf0e10cSrcweir}; 3323cdf0e10cSrcweir 3324cdf0e10cSrcweirsub get_server_ports { 3325cdf0e10cSrcweir # use port 7890 as default 3326cdf0e10cSrcweir my $default_port = 7890; 3327cdf0e10cSrcweir if ($ports_string) { 3328cdf0e10cSrcweir @server_ports = split( /:/, $ports_string); 3329cdf0e10cSrcweir } else { 3330cdf0e10cSrcweir @server_ports = ($default_port .. $default_port + 4); 3331cdf0e10cSrcweir }; 3332cdf0e10cSrcweir}; 3333cdf0e10cSrcweir 3334cdf0e10cSrcweirsub run_server { 3335cdf0e10cSrcweir my @build_queue = (); # array, containing queue of projects 3336cdf0e10cSrcweir # to build 3337cdf0e10cSrcweir my $error = 0; 3338cdf0e10cSrcweir if (scalar @server_ports) { 3339cdf0e10cSrcweir foreach (@server_ports) { 3340cdf0e10cSrcweir $error = start_server_on_port($_, \$server_socket_obj); 3341cdf0e10cSrcweir if ($error) { 3342cdf0e10cSrcweir print STDERR "port $_: $error\n"; 3343cdf0e10cSrcweir } else { 3344cdf0e10cSrcweir# $SIG{KILL} = \&stop_server; 3345cdf0e10cSrcweir# $SIG{INT} = \&stop_server; 3346cdf0e10cSrcweir# $SIG{TERM} = \&stop_server; 3347cdf0e10cSrcweir# $SIG{QUIT} = \&stop_server; 3348cdf0e10cSrcweir last; 3349cdf0e10cSrcweir }; 3350cdf0e10cSrcweir }; 3351cdf0e10cSrcweir print_error('Unable to start server on port(s): ' . "@server_ports\n") if ($error); 3352cdf0e10cSrcweir } else { 3353cdf0e10cSrcweir print_error('No ports for server to start'); 3354cdf0e10cSrcweir }; 3355cdf0e10cSrcweir 3356cdf0e10cSrcweir my $client_addr; 3357cdf0e10cSrcweir my $job_string_base = get_job_string_base(); 3358cdf0e10cSrcweir my $new_socket_obj; 3359cdf0e10cSrcweir while ($new_socket_obj = accept_connection()) { 3360cdf0e10cSrcweir check_client_jobs(); 3361cdf0e10cSrcweir # find out who connected 3362cdf0e10cSrcweir my $client_ipnum = $new_socket_obj->peerhost(); 3363cdf0e10cSrcweir my $client_host = gethostbyaddr(inet_aton($client_ipnum), AF_INET); 3364cdf0e10cSrcweir # print who is connected 3365cdf0e10cSrcweir # send them a message, close connection 3366cdf0e10cSrcweir my $client_message = <$new_socket_obj>; 3367cdf0e10cSrcweir chomp $client_message; 3368cdf0e10cSrcweir my @client_data = split(/ /, $client_message); 3369cdf0e10cSrcweir my %client_hash = (); 3370cdf0e10cSrcweir foreach (@client_data) { 3371cdf0e10cSrcweir /(=)/; 3372cdf0e10cSrcweir $client_hash{$`} = $'; 3373cdf0e10cSrcweir } 3374cdf0e10cSrcweir my $pid = $client_hash{pid} . '@' . $client_host; 3375cdf0e10cSrcweir if (defined $client_hash{platform}) { 3376cdf0e10cSrcweir if ($client_hash{platform} ne $ENV{OUTPATH} || (defined $client_hash{osname} && ($^O ne $client_hash{osname}))) { 3377cdf0e10cSrcweir print $new_socket_obj "Wrong platform"; 3378cdf0e10cSrcweir close($new_socket_obj); 3379cdf0e10cSrcweir next; 3380cdf0e10cSrcweir }; 3381cdf0e10cSrcweir } else { 3382cdf0e10cSrcweir if ($client_hash{result} eq "0") { 3383cdf0e10cSrcweir# print "$clients_jobs{$pid} succedded on $pid\n"; 3384cdf0e10cSrcweir } else { 3385cdf0e10cSrcweir print "Error $client_hash{result}\n"; 3386cdf0e10cSrcweir if (store_error($pid, $client_hash{result})) { 3387cdf0e10cSrcweir print $new_socket_obj $job_string_base . $clients_jobs{$pid}; 3388cdf0e10cSrcweir close($new_socket_obj); 3389cdf0e10cSrcweir $clients_times{$pid} = time; 3390cdf0e10cSrcweir next; 3391cdf0e10cSrcweir }; 3392cdf0e10cSrcweir }; 3393cdf0e10cSrcweir delete $clients_times{$pid}; 3394cdf0e10cSrcweir clear_from_child($pid); 3395cdf0e10cSrcweir delete $clients_jobs{$pid}; 3396cdf0e10cSrcweir $verbose_mode && print 'Running processes: ', children_number(), "\n"; 3397cdf0e10cSrcweir # Actually, next 3 strings are only for even distribution 3398cdf0e10cSrcweir # of clients if there are more than one build server running 3399cdf0e10cSrcweir print $new_socket_obj 'No job'; 3400cdf0e10cSrcweir close($new_socket_obj); 3401cdf0e10cSrcweir next; 3402cdf0e10cSrcweir }; 3403cdf0e10cSrcweir my $job_string; 3404cdf0e10cSrcweir my @lost_jobs = keys %lost_client_jobs; 3405cdf0e10cSrcweir if (scalar @lost_jobs) { 3406cdf0e10cSrcweir $job_string = $lost_jobs[0]; 3407cdf0e10cSrcweir delete $lost_client_jobs{$lost_jobs[0]}; 3408cdf0e10cSrcweir } else { 3409cdf0e10cSrcweir# $job_string = get_job_string(\@build_queue, $pid); 3410cdf0e10cSrcweir $job_string = get_job_string(\@build_queue); 3411cdf0e10cSrcweir }; 3412cdf0e10cSrcweir if ($job_string) { 3413cdf0e10cSrcweir my $job_dir = $job_jobdir{$job_string}; 3414cdf0e10cSrcweir $processes_hash{$pid} = $job_dir; 3415cdf0e10cSrcweir $jobs_hash{$job_dir}->{CLIENT} = $pid; 3416cdf0e10cSrcweir print "$pid got $job_dir\n"; 3417cdf0e10cSrcweir print $new_socket_obj $job_string_base . $job_string; 3418cdf0e10cSrcweir $clients_jobs{$pid} = $job_string; 3419cdf0e10cSrcweir $clients_times{$pid} = time; 3420cdf0e10cSrcweir my $children_running = children_number(); 3421cdf0e10cSrcweir $verbose_mode && print 'Running processes: ', $children_running, "\n"; 3422cdf0e10cSrcweir $maximal_processes = $children_running if ($children_running > $maximal_processes); 3423cdf0e10cSrcweir } else { 3424cdf0e10cSrcweir print $new_socket_obj 'No job'; 3425cdf0e10cSrcweir }; 3426cdf0e10cSrcweir close($new_socket_obj); 3427cdf0e10cSrcweir }; 3428cdf0e10cSrcweir}; 3429cdf0e10cSrcweir 3430cdf0e10cSrcweir# 3431cdf0e10cSrcweir# Procedure returns the part of the job string that is similar for all clients 3432cdf0e10cSrcweir# 3433cdf0e10cSrcweirsub get_job_string_base { 3434cdf0e10cSrcweir if ($setenv_string) { 3435cdf0e10cSrcweir return "setenv_string=$setenv_string "; 3436cdf0e10cSrcweir }; 3437cdf0e10cSrcweir my $job_string_base = "server_pid=$$ setsolar_cmd=$ENV{SETSOLAR_CMD} "; 3438cdf0e10cSrcweir $job_string_base .= "source_root=$ENV{SOURCE_ROOT} " if (defined $ENV{SOURCE_ROOT}); 3439cdf0e10cSrcweir $job_string_base .= "updater=$ENV{UPDATER} " if (defined $ENV{UPDATER}); 3440cdf0e10cSrcweir return $job_string_base; 3441cdf0e10cSrcweir}; 3442cdf0e10cSrcweir 3443cdf0e10cSrcweirsub get_job_string { 3444cdf0e10cSrcweir my $build_queue = shift; 3445cdf0e10cSrcweir my $job = $dmake; 3446cdf0e10cSrcweir my ($job_dir, $dependencies_hash); 3447cdf0e10cSrcweir if ($build_all_parents) { 3448cdf0e10cSrcweir fill_modules_queue($build_queue); 3449cdf0e10cSrcweir do { 3450cdf0e10cSrcweir ($job_dir, $dependencies_hash) = pick_jobdir($build_queue); 3451cdf0e10cSrcweir return '' if (!$job_dir); 3452cdf0e10cSrcweir $jobs_hash{$job_dir}->{START_TIME} = time(); 3453cdf0e10cSrcweir $jobs_hash{$job_dir}->{STATUS} = 'building'; 3454cdf0e10cSrcweir if ($job_dir =~ /(\s)$pre_job/o) { 3455cdf0e10cSrcweir do_custom_job($job_dir, $dependencies_hash); 3456cdf0e10cSrcweir $job_dir = ''; 3457cdf0e10cSrcweir }; 3458cdf0e10cSrcweir } while (!$job_dir); 3459cdf0e10cSrcweir } else { 3460cdf0e10cSrcweir $dependencies_hash = \%local_deps_hash; 3461cdf0e10cSrcweir do { 3462cdf0e10cSrcweir $job_dir = pick_prj_to_build(\%local_deps_hash); 3463cdf0e10cSrcweir if (!$job_dir && !children_number()) { 3464cdf0e10cSrcweir cancel_build() if (scalar keys %broken_build); 3465cdf0e10cSrcweir mp_success_exit(); 3466cdf0e10cSrcweir }; 3467cdf0e10cSrcweir return '' if (!$job_dir); 3468cdf0e10cSrcweir $jobs_hash{$job_dir}->{START_TIME} = time(); 3469cdf0e10cSrcweir $jobs_hash{$job_dir}->{STATUS} = 'building'; 3470cdf0e10cSrcweir if ($job_dir =~ /(\s)$pre_job/o) { 3471cdf0e10cSrcweir# if ($' eq $pre_job) { 3472cdf0e10cSrcweir do_custom_job($job_dir, $dependencies_hash); 3473cdf0e10cSrcweir $job_dir = ''; 3474cdf0e10cSrcweir# } 3475cdf0e10cSrcweir }; 3476cdf0e10cSrcweir } while (!$job_dir); 3477cdf0e10cSrcweir }; 3478cdf0e10cSrcweir $running_children{$dependencies_hash}++; 3479cdf0e10cSrcweir $folders_hashes{$job_dir} = $dependencies_hash; 3480cdf0e10cSrcweir my $log_file = $jobs_hash{$job_dir}->{LONG_LOG_PATH}; 3481cdf0e10cSrcweir my $full_job_dir = $job_dir; 3482cdf0e10cSrcweir if ($job_dir =~ /(\s)/o) { 3483cdf0e10cSrcweir $job = $'; 3484cdf0e10cSrcweir $job = $deliver_command if ($job eq $post_job); 3485cdf0e10cSrcweir $full_job_dir = $module_paths{$`}; 3486cdf0e10cSrcweir } 3487cdf0e10cSrcweir my $log_dir = File::Basename::dirname($log_file); 3488cdf0e10cSrcweir if (!-d $log_dir) { 3489cdf0e10cSrcweir chdir $full_job_dir; 3490cdf0e10cSrcweir getcwd(); 3491cdf0e10cSrcweir system("$perl $mkout"); 3492cdf0e10cSrcweir }; 3493cdf0e10cSrcweir my $job_string = "job_dir=$full_job_dir job=$job log=$log_file"; 3494cdf0e10cSrcweir $job_jobdir{$job_string} = $job_dir; 3495cdf0e10cSrcweir return $job_string; 3496cdf0e10cSrcweir}; 3497cdf0e10cSrcweir 3498cdf0e10cSrcweirsub pick_jobdir { 3499cdf0e10cSrcweir my $build_queue = shift; 3500cdf0e10cSrcweir my $i = 0; 3501cdf0e10cSrcweir foreach (@$build_queue) { 3502cdf0e10cSrcweir my $prj = $$build_queue[$i]; 3503cdf0e10cSrcweir my $prj_deps_hash = $projects_deps_hash{$prj}; 3504cdf0e10cSrcweir if (defined $modules_with_errors{$prj_deps_hash} && !$ignore) { 3505cdf0e10cSrcweir push (@broken_module_names, $prj); 3506cdf0e10cSrcweir splice (@$build_queue, $i, 1); 3507cdf0e10cSrcweir next; 3508cdf0e10cSrcweir }; 3509cdf0e10cSrcweir $running_children{$prj_deps_hash} = 0 if (!defined $running_children{$prj_deps_hash}); 3510cdf0e10cSrcweir my $child_nick = pick_prj_to_build($prj_deps_hash); 3511cdf0e10cSrcweir if ($child_nick) { 3512cdf0e10cSrcweir return ($child_nick, $prj_deps_hash); 3513cdf0e10cSrcweir } 3514cdf0e10cSrcweir if ((!scalar keys %$prj_deps_hash) && !$running_children{$prj_deps_hash}) { 3515cdf0e10cSrcweir if (!defined $modules_with_errors{$prj_deps_hash} || $ignore) 3516cdf0e10cSrcweir { 3517cdf0e10cSrcweir remove_from_dependencies($prj, \%global_deps_hash); 3518cdf0e10cSrcweir $build_is_finished{$prj}++; 3519cdf0e10cSrcweir splice (@$build_queue, $i, 1); 3520cdf0e10cSrcweir next; 3521cdf0e10cSrcweir }; 3522cdf0e10cSrcweir }; 3523cdf0e10cSrcweir $i++; 3524cdf0e10cSrcweir }; 3525cdf0e10cSrcweir}; 3526cdf0e10cSrcweir 3527cdf0e10cSrcweirsub fill_modules_queue { 3528cdf0e10cSrcweir my $build_queue = shift; 3529cdf0e10cSrcweir my $prj; 3530cdf0e10cSrcweir while ($prj = pick_prj_to_build(\%global_deps_hash)) { 3531cdf0e10cSrcweir push @$build_queue, $prj; 3532cdf0e10cSrcweir $projects_deps_hash{$prj} = {}; 3533cdf0e10cSrcweir get_module_dep_hash($prj, $projects_deps_hash{$prj}); 3534cdf0e10cSrcweir my $info_hash = $html_info{$prj}; 3535cdf0e10cSrcweir $$info_hash{DIRS} = check_deps_hash($projects_deps_hash{$prj}, $prj); 3536cdf0e10cSrcweir $module_by_hash{$projects_deps_hash{$prj}} = $prj; 3537cdf0e10cSrcweir }; 3538cdf0e10cSrcweir if (!$prj && !children_number() && (!scalar @$build_queue)) { 3539cdf0e10cSrcweir cancel_build() if (scalar keys %broken_build); 3540cdf0e10cSrcweir mp_success_exit(); 3541cdf0e10cSrcweir }; 3542cdf0e10cSrcweir}; 3543cdf0e10cSrcweir 3544cdf0e10cSrcweirsub is_gnumake_module { 3545cdf0e10cSrcweir my $module = shift; 3546cdf0e10cSrcweir my $bridgemakefile = $source_config->get_module_path($module) . "/prj/makefile.mk"; 3547cdf0e10cSrcweir return (-e $bridgemakefile); 3548cdf0e10cSrcweir} 3549cdf0e10cSrcweir 3550cdf0e10cSrcweirsub check_partial_gnumake_build { 3551cdf0e10cSrcweir if(!$build_all_parents && is_gnumake_module(shift)) { 3552cdf0e10cSrcweir print "This module has been migrated to GNU make.\n"; 3553cdf0e10cSrcweir print "You can only use build --all/--since here with build.pl.\n"; 3554cdf0e10cSrcweir print "To do the equivalent of 'build && deliver' call:\n"; 3555cdf0e10cSrcweir print "\tmake -sr\n"; 3556cdf0e10cSrcweir print "in the module root (This will modify the solver).\n"; 3557cdf0e10cSrcweir exit 1; 3558cdf0e10cSrcweir } 3559cdf0e10cSrcweir} 3560