1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: work.pm,v $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
33 package packager
::work
;
36 use packager
::existence
;
38 use packager
::globals
;
40 ###########################################
41 # Setting global variables
42 ###########################################
44 sub set_global_variable
46 my $compiler = $ENV{'OUTPATH'};
48 if ( $ENV{'PROEXT'} ) { $compiler = $compiler . $ENV{'PROEXT'}; }
50 $packager::globals
::compiler
= $compiler;
53 #############################################################################
54 # Converting a string list with separator $listseparator
56 #############################################################################
58 sub convert_stringlist_into_array
60 my ( $includestringref, $listseparator ) = @_;
64 my $last = ${$includestringref};
66 while ( $last =~ /^\s*(.+?)\Q$listseparator\E(.+)\s*$/) # "$" for minimal matching
70 push(@newarray, "$first");
73 push(@newarray, "$last");
78 ###########################################
79 # Generating a list of package calls
80 # corresponding to the package list
81 ###########################################
83 sub create_package_todos
85 my ( $packagelist ) = @_;
87 my @targets = (); # only used, if the build server is not used
89 for ( my $i = 0; $i <= $#{$packagelist}; $i++ )
91 my $line = ${$packagelist}[$i];
93 if ( $line =~ /^\s*\#/ ) { next; } # comment line
95 if ( $line =~ /^\s*(\w+?)\s+(\S+?)\s+(\S+?)\s+(\w+?)\s*$/ )
98 my $compilerlist = $2;
99 my $languagelist = $3;
103 $compilerlist =~ s/\s//g;
104 $languagelist =~ s/\s//g;
107 my $compilers = convert_stringlist_into_array
(\
$compilerlist, ",");
109 # is the compiler of this "build" part of the compiler list in pack.lst ?
111 if ( packager
::existence
::exists_in_array
($packager::globals
::compiler
, $compilers) )
113 # products are separated in pack.lst by "|"
115 my $languagesets = convert_stringlist_into_array
(\
$languagelist, "\|");
117 # now all information is available to create the targets for the systemcalls
119 for ( my $j = 0; $j <= $#{$languagesets}; $j++ )
121 my $languagestring = ${$languagesets}[$j];
122 $languagestring =~ s/\,/\_/g; # comma in pack.lst becomes "_" in dmake command
124 my $target = $target . "_" . $languagestring;
125 push(@targets, $target);
127 my $insertline = $target . "\n";
128 push( @packager::globals
::logfileinfo
, $insertline);
137 ###########################################
138 # Executing the generated system calls
139 ###########################################
141 sub execute_system_calls
143 my ( $targets ) = @_;
145 for ( my $i = 0; $i <= $#{$targets}; $i++ )
147 my $systemcall = "dmake " . ${$targets}[$i];
149 my $infoline = "Packager: $systemcall\n";
151 push( @packager::globals
::logfileinfo
, $infoline);
153 my $returnvalue = system($systemcall);
155 $infoline = "Packager finished: $systemcall\n";
157 push( @packager::globals
::logfileinfo
, $infoline);
161 $infoline = "\nERROR: Packager $systemcall\n";
163 push( @packager::globals
::logfileinfo
, $infoline);
164 if (!($packager::globals
::ignoreerrors
)) { packager
::exiter
::exit_program
("ERROR: Packing not successful : $systemcall", "execute_system_calls"); }
169 ##############################################################
170 # Starting the build server with the generated system calls
171 ##############################################################
173 sub start_build_server
175 my ( $targets ) = @_;
177 # preparing the directory structure
179 my $prj = $ENV{PRJ
}; # for example "..";
180 my $platform = $ENV{INPATH
}; # wntmsci10.pro, unxsols4.pro
181 my $platformpath = $prj . $packager::globals
::separator
. $platform;
182 if ( ! -d
$platformpath ) { packager
::files
::create_directory
($miscpath); }
183 my $miscpath = $platformpath . $packager::globals
::separator
. "misc";
184 if ( ! -d
$miscpath ) { packager
::files
::create_directory
($miscpath); }
185 $miscpath = $miscpath . $packager::globals
::separator
. "temp";
186 if ( -d
$miscpath ) { packager
::files
::remove_complete_directory
($miscpath); } # removing old files !
187 if ( ! -d
$miscpath ) { packager
::files
::create_directory
($miscpath); }
189 my $prjroot = ".." . $packager::globals
::separator
. ".." . $packager::globals
::separator
. ".." . $packager::globals
::separator
. ".."; # platform/misc/temp/uniquetempdir
191 my $makefilepath = $prj . $packager::globals
::separator
. "util" . $packager::globals
::separator
. "makefile.mk";
193 if ( ! $ENV{'PRJNAME'} ) { packager
::exiter
::exit_program
("ERROR: Environment variable PRJNAME not set!", "do_broadcast"); }
194 my $prjname = $ENV{PRJNAME
};
196 my $pkgformat = $ENV{PKGFORMAT
};
198 my $prjdep = $prjname . "\\" . "util"; # always windows like path
200 my @targetlines = ();
201 # iterating over all targets
202 for ( my $i = 0; $i <= $#{$targets}; $i++ )
204 my $target = ${$targets}[$i];
205 my $tempdir = $miscpath . $packager::globals
::separator
. $target;
206 $tempdir = packager
::files
::create_unique_directory
($tempdir);
208 push( @targetlines, "\ngenerated_target : $target\n\n"); # to be included into the makefile.mk
210 if ( defined $pkgformat ) {
211 push( @targetlines, "\n$target : ".'$$@{$(PKGFORMAT:^".")}'."\n\n"); # to be included into the makefile.mk
214 generate_makefile
($tempdir, $makefilepath, $prjroot, $target, \
@targetlines);
216 do_broadcast
($tempdir, $prjname, $prj, $platform, $prjdep);
217 push @targetdirs, $tempdir;
221 ##############################################################
222 # Generating the makefile in the temporary directory
223 ##############################################################
225 sub generate_makefile
227 my ( $tempdir, $makefilepath, $prjroot, $target, $targetlines_ref ) = @_;
229 my $makefile = packager
::files
::read_file
($makefilepath);
231 my @targetlines = ();
232 push( @targetlines, @
{$targetlines_ref}); # to be included into the makefile.mk
234 $prjroot = $prjroot . "\n";
236 my $uniquename = $tempdir;
237 get_filename_from_path
(\
$uniquename);
238 $uniquename = $uniquename . "\n";
243 for ( my $i = 0; $i <= $#{$makefile}; $i++ )
245 if ( ${$makefile}[$i] =~ /^\s*TARGET\s*=.*/ ) { ${$makefile}[$i] = "TARGET=" . $uniquename; } # setting the new project root
247 if ( ${$makefile}[$i] =~ /^\s*PRJ\s*=.*/ ) { ${$makefile}[$i] = "PRJ=" . $prjroot; } # setting the new project root
249 if ( ${$makefile}[$i] =~ /^\s*\.INCLUDE[\t ]*:[\t ]*target.mk[\t ]*$/ ) { $increase = 0; } # no more increase of the counter
251 if ( $increase ) { $counter++; }
254 splice(@
{$makefile}, $counter, 0, @targetlines); # including the new target lines at position $counter
256 my $newmakefilepath = $tempdir . $packager::globals
::separator
. "makefile.mk";
257 packager
::files
::save_file
($newmakefilepath, $makefile);
260 ##############################################################
261 # Generating the broadcasts for the build server
262 ##############################################################
268 my ( $tempdir, $prjname, $prj, $platform, $prjdep ) = @_;
270 # Syntax: cmd_bcst -s 18 "Version;Environment;Project;Verzeichnis;Restriction[;Abhaengigkeit1][;Abhaengigkeit n]..."
271 # Example: cmd_bcst -s 18 "SRC680;wntmsci10.pro;instsetoo_native;;instsetoo_native\bla1;instsetoo_native\util"
273 if ( ! $ENV{'WORK_STAMP'} ) { packager
::exiter
::exit_program
("ERROR: Environment variable WORK_STAMP not set!", "do_broadcast"); }
274 my $workstamp = $ENV{WORK_STAMP
};
275 my $cwsworkstamp = $ENV{CWS_WORK_STAMP
};
277 my $prjdir = $tempdir;
278 $prjdir =~ s/$prj/$prjname/;
279 $prjdir =~ s/\//\\/g
; # convert to windows path syntax
281 my $tempfiledir = $ENV{TMP
};
282 $tempfiledir = $tempdir if ( ! defined $tempfiledir );
283 my ( $tmpfile_handle, $tmpfile_name ) = mkstemp
( $tempfiledir . $packager::globals
::separator
. "packagerXXXXX");
284 if ( ! $tmpfile_handle ) {
285 packager
::exiter
::exit_program
("ERROR: Couldn't open temporary file \"$tmpfile_name\"!", "do_broadcast");
287 if (defined($cwsworkstamp)) {
288 print $tmpfile_handle "\"$cwsworkstamp;$platform;$prjname;$prjdir;nobase;$prjdep\"";
289 print "to tmpfile: \"$cwsworkstamp;$platform;$prjname;$prjdir;nobase;$prjdep\"\n";
292 print $tmpfile_handle "\"$workstamp;$platform;$prjname;$prjdir;nobase;$prjdep\"";
293 print "to tmpfile: \"$workstamp;$platform;$prjname;$prjdir;nobase;$prjdep\"\n";
295 close $tmpfile_handle;
296 my $returnvalue = system("cmd_bcst -s 18 \@$tmpfile_name");
297 print "cmd_bcst -s 18 \@$tmpfile_name\n";
298 unlink "$tmpfile_name";
300 if ( $returnvalue ) # an error occured
302 if (!($packager::globals
::ignoreerrors
)) { packager
::exiter
::exit_program
("ERROR: Packing not successful!", "do_broadcast"); }
306 ##############################################################
307 # Returning the name of file or directory from complete path
308 ##############################################################
310 sub get_filename_from_path
312 my ($longfilenameref) = @_;
314 if ( $packager::globals
::isunix
)
316 if ( $$longfilenameref =~ /^.*\/(\S
.+\S?
)/ )
318 $$longfilenameref = $1;
322 if ( $packager::globals
::iswin
)
324 if ( $$longfilenameref =~ /^.*\\(\S.+\S?)/ )
326 $$longfilenameref = $1;