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