1*9780544fSAndrew Rist#************************************************************** 2*9780544fSAndrew Rist# 3*9780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 4*9780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 5*9780544fSAndrew Rist# distributed with this work for additional information 6*9780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 7*9780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 8*9780544fSAndrew Rist# "License"); you may not use this file except in compliance 9*9780544fSAndrew Rist# with the License. You may obtain a copy of the License at 10*9780544fSAndrew Rist# 11*9780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*9780544fSAndrew Rist# 13*9780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 14*9780544fSAndrew Rist# software distributed under the License is distributed on an 15*9780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9780544fSAndrew Rist# KIND, either express or implied. See the License for the 17*9780544fSAndrew Rist# specific language governing permissions and limitations 18*9780544fSAndrew Rist# under the License. 19*9780544fSAndrew Rist# 20*9780544fSAndrew Rist#************************************************************** 21*9780544fSAndrew Rist 22*9780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweirpackage packager::work; 26cdf0e10cSrcweir 27cdf0e10cSrcweiruse packager::exiter; 28cdf0e10cSrcweiruse packager::existence; 29cdf0e10cSrcweiruse packager::files; 30cdf0e10cSrcweiruse packager::globals; 31cdf0e10cSrcweir 32cdf0e10cSrcweir########################################### 33cdf0e10cSrcweir# Setting global variables 34cdf0e10cSrcweir########################################### 35cdf0e10cSrcweir 36cdf0e10cSrcweirsub set_global_variable 37cdf0e10cSrcweir{ 38cdf0e10cSrcweir my $compiler = $ENV{'OUTPATH'}; 39cdf0e10cSrcweir 40cdf0e10cSrcweir if ( $ENV{'PROEXT'} ) { $compiler = $compiler . $ENV{'PROEXT'}; } 41cdf0e10cSrcweir 42cdf0e10cSrcweir $packager::globals::compiler = $compiler; 43cdf0e10cSrcweir} 44cdf0e10cSrcweir 45cdf0e10cSrcweir############################################################################# 46cdf0e10cSrcweir# Converting a string list with separator $listseparator 47cdf0e10cSrcweir# into an array 48cdf0e10cSrcweir############################################################################# 49cdf0e10cSrcweir 50cdf0e10cSrcweirsub convert_stringlist_into_array 51cdf0e10cSrcweir{ 52cdf0e10cSrcweir my ( $includestringref, $listseparator ) = @_; 53cdf0e10cSrcweir 54cdf0e10cSrcweir my @newarray = (); 55cdf0e10cSrcweir my $first; 56cdf0e10cSrcweir my $last = ${$includestringref}; 57cdf0e10cSrcweir 58cdf0e10cSrcweir while ( $last =~ /^\s*(.+?)\Q$listseparator\E(.+)\s*$/) # "$" for minimal matching 59cdf0e10cSrcweir { 60cdf0e10cSrcweir $first = $1; 61cdf0e10cSrcweir $last = $2; 62cdf0e10cSrcweir push(@newarray, "$first"); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir push(@newarray, "$last"); 66cdf0e10cSrcweir 67cdf0e10cSrcweir return \@newarray; 68cdf0e10cSrcweir} 69cdf0e10cSrcweir 70cdf0e10cSrcweir########################################### 71cdf0e10cSrcweir# Generating a list of package calls 72cdf0e10cSrcweir# corresponding to the package list 73cdf0e10cSrcweir########################################### 74cdf0e10cSrcweir 75cdf0e10cSrcweirsub create_package_todos 76cdf0e10cSrcweir{ 77cdf0e10cSrcweir my ( $packagelist ) = @_; 78cdf0e10cSrcweir 79cdf0e10cSrcweir my @targets = (); # only used, if the build server is not used 80cdf0e10cSrcweir 81cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$packagelist}; $i++ ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir my $line = ${$packagelist}[$i]; 84cdf0e10cSrcweir 85cdf0e10cSrcweir if ( $line =~ /^\s*\#/ ) { next; } # comment line 86cdf0e10cSrcweir 87cdf0e10cSrcweir if ( $line =~ /^\s*(\w+?)\s+(\S+?)\s+(\S+?)\s+(\w+?)\s*$/ ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir my $product = $1; 90cdf0e10cSrcweir my $compilerlist = $2; 91cdf0e10cSrcweir my $languagelist = $3; 92cdf0e10cSrcweir my $target = $4; 93cdf0e10cSrcweir 94cdf0e10cSrcweir $product =~ s/\s//g; 95cdf0e10cSrcweir $compilerlist =~ s/\s//g; 96cdf0e10cSrcweir $languagelist =~ s/\s//g; 97cdf0e10cSrcweir $target =~ s/\s//g; 98cdf0e10cSrcweir 99cdf0e10cSrcweir my $compilers = convert_stringlist_into_array(\$compilerlist, ","); 100cdf0e10cSrcweir 101cdf0e10cSrcweir # is the compiler of this "build" part of the compiler list in pack.lst ? 102cdf0e10cSrcweir 103cdf0e10cSrcweir if ( packager::existence::exists_in_array($packager::globals::compiler, $compilers) ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir # products are separated in pack.lst by "|" 106cdf0e10cSrcweir 107cdf0e10cSrcweir my $languagesets = convert_stringlist_into_array(\$languagelist, "\|"); 108cdf0e10cSrcweir 109cdf0e10cSrcweir # now all information is available to create the targets for the systemcalls 110cdf0e10cSrcweir 111cdf0e10cSrcweir for ( my $j = 0; $j <= $#{$languagesets}; $j++ ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir my $languagestring = ${$languagesets}[$j]; 114cdf0e10cSrcweir $languagestring =~ s/\,/\_/g; # comma in pack.lst becomes "_" in dmake command 115cdf0e10cSrcweir 116cdf0e10cSrcweir my $target = $target . "_" . $languagestring; 117cdf0e10cSrcweir push(@targets, $target); 118cdf0e10cSrcweir 119cdf0e10cSrcweir my $insertline = $target . "\n"; 120cdf0e10cSrcweir push( @packager::globals::logfileinfo, $insertline); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir return \@targets; 127cdf0e10cSrcweir} 128cdf0e10cSrcweir 129cdf0e10cSrcweir########################################### 130cdf0e10cSrcweir# Executing the generated system calls 131cdf0e10cSrcweir########################################### 132cdf0e10cSrcweir 133cdf0e10cSrcweirsub execute_system_calls 134cdf0e10cSrcweir{ 135cdf0e10cSrcweir my ( $targets ) = @_; 136cdf0e10cSrcweir 137cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$targets}; $i++ ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir my $systemcall = "dmake " . ${$targets}[$i]; 140cdf0e10cSrcweir 141cdf0e10cSrcweir my $infoline = "Packager: $systemcall\n"; 142cdf0e10cSrcweir print $infoline; 143cdf0e10cSrcweir push( @packager::globals::logfileinfo, $infoline); 144cdf0e10cSrcweir 145cdf0e10cSrcweir my $returnvalue = system($systemcall); 146cdf0e10cSrcweir 147cdf0e10cSrcweir $infoline = "Packager finished: $systemcall\n"; 148cdf0e10cSrcweir print $infoline; 149cdf0e10cSrcweir push( @packager::globals::logfileinfo, $infoline); 150cdf0e10cSrcweir 151cdf0e10cSrcweir if ( $returnvalue ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir $infoline = "\nERROR: Packager $systemcall\n"; 154cdf0e10cSrcweir print $infoline; 155cdf0e10cSrcweir push( @packager::globals::logfileinfo, $infoline); 156cdf0e10cSrcweir if (!($packager::globals::ignoreerrors)) { packager::exiter::exit_program("ERROR: Packing not successful : $systemcall", "execute_system_calls"); } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir} 160cdf0e10cSrcweir 161cdf0e10cSrcweir############################################################## 162cdf0e10cSrcweir# Starting the build server with the generated system calls 163cdf0e10cSrcweir############################################################## 164cdf0e10cSrcweir 165cdf0e10cSrcweirsub start_build_server 166cdf0e10cSrcweir{ 167cdf0e10cSrcweir my ( $targets ) = @_; 168cdf0e10cSrcweir 169cdf0e10cSrcweir # preparing the directory structure 170cdf0e10cSrcweir 171cdf0e10cSrcweir my $prj = $ENV{PRJ}; # for example ".."; 172cdf0e10cSrcweir my $platform = $ENV{INPATH}; # wntmsci10.pro, unxsols4.pro 173cdf0e10cSrcweir my $platformpath = $prj . $packager::globals::separator . $platform; 174cdf0e10cSrcweir if ( ! -d $platformpath ) { packager::files::create_directory($miscpath); } 175cdf0e10cSrcweir my $miscpath = $platformpath . $packager::globals::separator . "misc"; 176cdf0e10cSrcweir if ( ! -d $miscpath ) { packager::files::create_directory($miscpath); } 177cdf0e10cSrcweir $miscpath = $miscpath . $packager::globals::separator . "temp"; 178cdf0e10cSrcweir if ( -d $miscpath ) { packager::files::remove_complete_directory($miscpath); } # removing old files ! 179cdf0e10cSrcweir if ( ! -d $miscpath ) { packager::files::create_directory($miscpath); } 180cdf0e10cSrcweir 181cdf0e10cSrcweir my $prjroot = ".." . $packager::globals::separator . ".." . $packager::globals::separator . ".." . $packager::globals::separator . ".."; # platform/misc/temp/uniquetempdir 182cdf0e10cSrcweir 183cdf0e10cSrcweir my $makefilepath = $prj . $packager::globals::separator . "util" . $packager::globals::separator . "makefile.mk"; 184cdf0e10cSrcweir 185cdf0e10cSrcweir if ( ! $ENV{'PRJNAME'} ) { packager::exiter::exit_program("ERROR: Environment variable PRJNAME not set!", "do_broadcast"); } 186cdf0e10cSrcweir my $prjname = $ENV{PRJNAME}; 187cdf0e10cSrcweir 188cdf0e10cSrcweir my $pkgformat = $ENV{PKGFORMAT}; 189cdf0e10cSrcweir 190cdf0e10cSrcweir my $prjdep = $prjname . "\\" . "util"; # always windows like path 191cdf0e10cSrcweir my @targetdirs; 192cdf0e10cSrcweir my @targetlines = (); 193cdf0e10cSrcweir # iterating over all targets 194cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$targets}; $i++ ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir my $target = ${$targets}[$i]; 197cdf0e10cSrcweir my $tempdir = $miscpath . $packager::globals::separator . $target; 198cdf0e10cSrcweir $tempdir = packager::files::create_unique_directory ($tempdir); 199cdf0e10cSrcweir @targetlines=(); 200cdf0e10cSrcweir push( @targetlines, "\ngenerated_target : $target\n\n"); # to be included into the makefile.mk 201cdf0e10cSrcweir 202cdf0e10cSrcweir if ( defined $pkgformat ) { 203cdf0e10cSrcweir push( @targetlines, "\n$target : ".'$$@{$(PKGFORMAT:^".")}'."\n\n"); # to be included into the makefile.mk 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir generate_makefile($tempdir, $makefilepath, $prjroot, $target, \@targetlines); 207cdf0e10cSrcweir 208cdf0e10cSrcweir do_broadcast($tempdir, $prjname, $prj, $platform, $prjdep); 209cdf0e10cSrcweir push @targetdirs, $tempdir; 210cdf0e10cSrcweir } 211cdf0e10cSrcweir} 212cdf0e10cSrcweir 213cdf0e10cSrcweir############################################################## 214cdf0e10cSrcweir# Generating the makefile in the temporary directory 215cdf0e10cSrcweir############################################################## 216cdf0e10cSrcweir 217cdf0e10cSrcweirsub generate_makefile 218cdf0e10cSrcweir{ 219cdf0e10cSrcweir my ( $tempdir, $makefilepath, $prjroot, $target, $targetlines_ref ) = @_; 220cdf0e10cSrcweir 221cdf0e10cSrcweir my $makefile = packager::files::read_file($makefilepath); 222cdf0e10cSrcweir 223cdf0e10cSrcweir my @targetlines = (); 224cdf0e10cSrcweir push( @targetlines, @{$targetlines_ref}); # to be included into the makefile.mk 225cdf0e10cSrcweir 226cdf0e10cSrcweir $prjroot = $prjroot . "\n"; 227cdf0e10cSrcweir 228cdf0e10cSrcweir my $uniquename = $tempdir; 229cdf0e10cSrcweir get_filename_from_path(\$uniquename); 230cdf0e10cSrcweir $uniquename = $uniquename . "\n"; 231cdf0e10cSrcweir 232cdf0e10cSrcweir my $counter = 0; 233cdf0e10cSrcweir my $increase = 1; 234cdf0e10cSrcweir 235cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$makefile}; $i++ ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir if ( ${$makefile}[$i] =~ /^\s*TARGET\s*=.*/ ) { ${$makefile}[$i] = "TARGET=" . $uniquename; } # setting the new project root 238cdf0e10cSrcweir 239cdf0e10cSrcweir if ( ${$makefile}[$i] =~ /^\s*PRJ\s*=.*/ ) { ${$makefile}[$i] = "PRJ=" . $prjroot; } # setting the new project root 240cdf0e10cSrcweir 241cdf0e10cSrcweir if ( ${$makefile}[$i] =~ /^\s*\.INCLUDE[\t ]*:[\t ]*target.mk[\t ]*$/ ) { $increase = 0; } # no more increase of the counter 242cdf0e10cSrcweir 243cdf0e10cSrcweir if ( $increase ) { $counter++; } 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir splice(@{$makefile}, $counter, 0, @targetlines); # including the new target lines at position $counter 247cdf0e10cSrcweir 248cdf0e10cSrcweir my $newmakefilepath = $tempdir . $packager::globals::separator . "makefile.mk"; 249cdf0e10cSrcweir packager::files::save_file($newmakefilepath, $makefile); 250cdf0e10cSrcweir} 251cdf0e10cSrcweir 252cdf0e10cSrcweir############################################################## 253cdf0e10cSrcweir# Generating the broadcasts for the build server 254cdf0e10cSrcweir############################################################## 255cdf0e10cSrcweir 256cdf0e10cSrcweirsub do_broadcast 257cdf0e10cSrcweir{ 258cdf0e10cSrcweir use File::Temp; 259cdf0e10cSrcweir 260cdf0e10cSrcweir my ( $tempdir, $prjname, $prj, $platform, $prjdep ) = @_; 261cdf0e10cSrcweir 262cdf0e10cSrcweir # Syntax: cmd_bcst -s 18 "Version;Environment;Project;Verzeichnis;Restriction[;Abhaengigkeit1][;Abhaengigkeit n]..." 263cdf0e10cSrcweir # Example: cmd_bcst -s 18 "SRC680;wntmsci10.pro;instsetoo_native;;instsetoo_native\bla1;instsetoo_native\util" 264cdf0e10cSrcweir 265cdf0e10cSrcweir if ( ! $ENV{'WORK_STAMP'} ) { packager::exiter::exit_program("ERROR: Environment variable WORK_STAMP not set!", "do_broadcast"); } 266cdf0e10cSrcweir my $workstamp = $ENV{WORK_STAMP}; 267cdf0e10cSrcweir my $cwsworkstamp = $ENV{CWS_WORK_STAMP}; 268cdf0e10cSrcweir 269cdf0e10cSrcweir my $prjdir = $tempdir; 270cdf0e10cSrcweir $prjdir =~ s/$prj/$prjname/; 271cdf0e10cSrcweir $prjdir =~ s/\//\\/g; # convert to windows path syntax 272cdf0e10cSrcweir 273cdf0e10cSrcweir my $tempfiledir = $ENV{TMP}; 274cdf0e10cSrcweir $tempfiledir = $tempdir if ( ! defined $tempfiledir ); 275cdf0e10cSrcweir my ( $tmpfile_handle, $tmpfile_name ) = mkstemp( $tempfiledir . $packager::globals::separator . "packagerXXXXX"); 276cdf0e10cSrcweir if ( ! $tmpfile_handle ) { 277cdf0e10cSrcweir packager::exiter::exit_program("ERROR: Couldn't open temporary file \"$tmpfile_name\"!", "do_broadcast"); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir if (defined($cwsworkstamp)) { 280cdf0e10cSrcweir print $tmpfile_handle "\"$cwsworkstamp;$platform;$prjname;$prjdir;nobase;$prjdep\""; 281cdf0e10cSrcweir print "to tmpfile: \"$cwsworkstamp;$platform;$prjname;$prjdir;nobase;$prjdep\"\n"; 282cdf0e10cSrcweir } 283cdf0e10cSrcweir else { 284cdf0e10cSrcweir print $tmpfile_handle "\"$workstamp;$platform;$prjname;$prjdir;nobase;$prjdep\""; 285cdf0e10cSrcweir print "to tmpfile: \"$workstamp;$platform;$prjname;$prjdir;nobase;$prjdep\"\n"; 286cdf0e10cSrcweir } 287cdf0e10cSrcweir close $tmpfile_handle; 288cdf0e10cSrcweir my $returnvalue = system("cmd_bcst -s 18 \@$tmpfile_name"); 289cdf0e10cSrcweir print "cmd_bcst -s 18 \@$tmpfile_name\n"; 290cdf0e10cSrcweir unlink "$tmpfile_name"; 291cdf0e10cSrcweir 292cdf0e10cSrcweir if ( $returnvalue ) # an error occured 293cdf0e10cSrcweir { 294cdf0e10cSrcweir if (!($packager::globals::ignoreerrors)) { packager::exiter::exit_program("ERROR: Packing not successful!", "do_broadcast"); } 295cdf0e10cSrcweir } 296cdf0e10cSrcweir} 297cdf0e10cSrcweir 298cdf0e10cSrcweir############################################################## 299cdf0e10cSrcweir# Returning the name of file or directory from complete path 300cdf0e10cSrcweir############################################################## 301cdf0e10cSrcweir 302cdf0e10cSrcweirsub get_filename_from_path 303cdf0e10cSrcweir{ 304cdf0e10cSrcweir my ($longfilenameref) = @_; 305cdf0e10cSrcweir 306cdf0e10cSrcweir if ( $packager::globals::isunix ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir if ( $$longfilenameref =~ /^.*\/(\S.+\S?)/ ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir $$longfilenameref = $1; 311cdf0e10cSrcweir } 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir if ( $packager::globals::iswin ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir if ( $$longfilenameref =~ /^.*\\(\S.+\S?)/ ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir $$longfilenameref = $1; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir } 321cdf0e10cSrcweir} 322cdf0e10cSrcweir 323cdf0e10cSrcweir1; 324