Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / solenv / bin / modules / installer / control.pm
blobcaa9f52b1b9e484a9a1198a1576dffb684a4cac3
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer::control;
21 use Cwd;
22 use installer::converter;
23 use installer::exiter;
24 use installer::files;
25 use installer::globals;
26 use installer::pathanalyzer;
27 use installer::scriptitems;
28 use installer::systemactions;
30 #########################################################
31 # Function that can be used for additional controls.
32 # Search happens in $installer::globals::patharray.
33 #########################################################
35 sub check_needed_files_in_path
37 my ( $filesref ) = @_;
39 foreach $onefile ( @{$filesref} )
41 installer::logger::print_message( "...... searching $onefile ..." );
43 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$onefile, $installer::globals::patharray , 0);
45 if ( $$fileref eq "" )
47 $error = 1;
48 installer::logger::print_error( "$onefile not found\n" );
50 else
52 installer::logger::print_message( "\tFound: $$fileref\n" );
56 if ( $error )
58 installer::exiter::exit_program("ERROR: Could not find all needed files in path!", "check_needed_files_in_path");
62 #########################################################
63 # Checking the local system
64 # Checking existence of needed files in include path
65 #########################################################
67 sub check_system_path
69 # The following files have to be found in the environment variable PATH
70 # All platforms: zip
71 # Windows only: "msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe" for msi database and packaging
73 if ($ENV{'CROSS_COMPILING'} eq 'YES')
75 # we build our own msi* etc. tools when cross-compiling
76 $ENV{'PATH'} .= $installer::globals::pathseparator . $ENV{'WORKDIR_FOR_BUILD'} . '/LinkTarget/Executable';
79 my $onefile;
80 my $error = 0;
81 my $pathvariable = $ENV{'PATH'};
82 my $local_pathseparator = $installer::globals::pathseparator;
84 if( $^O =~ /cygwin/i )
86 # When using cygwin's perl the PATH variable is POSIX style and
87 # has to be converted to DOS style for further use.
88 $pathvariable = join ';',
89 map { $dir = qx{cygpath -m "$_"}; chomp($dir); $dir }
90 split /\Q$local_pathseparator\E\s*/, $pathvariable;
91 $local_pathseparator = ';';
93 my $patharrayref = installer::converter::convert_stringlist_into_array(\$pathvariable, $local_pathseparator);
95 $installer::globals::patharray = $patharrayref;
97 my @needed_files_in_path = ();
99 if (($installer::globals::iswin) && ($installer::globals::iswindowsbuild))
101 @needed_files_in_path = ("zip.exe", "msiinfo.exe", "msidb.exe", "uuidgen", "makecab.exe", "msitran.exe", "expand.exe");
103 elsif ($installer::globals::isunix && $installer::globals::packageformat eq 'msi')
105 @needed_files_in_path = ("zip", "msiinfo.exe", "msidb.exe", "uuidgen", "makecab.exe", "msitran.exe", "cabextract");
107 elsif ($installer::globals::iswin)
109 @needed_files_in_path = ("zip.exe");
111 else
113 @needed_files_in_path = ("zip");
116 foreach $onefile ( @needed_files_in_path )
118 installer::logger::print_message( "...... searching $onefile ..." );
120 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$onefile, $patharrayref , 0);
122 if ( $$fileref eq "" )
124 $error = 1;
125 installer::logger::print_error( "$onefile not found\n" );
127 else
129 installer::logger::print_message( "\tFound: $$fileref\n" );
130 # Saving the absolut path for msitran.exe. This is required for the determination of the checksum.
131 if ( $onefile eq "msitran.exe" ) { $installer::globals::msitranpath = $$fileref; }
135 if ( $error )
137 installer::exiter::exit_program("ERROR: Could not find all needed files in path!", "check_system_path");
140 # checking for epm, which has to be in the path or in the solver
142 if (( $installer::globals::call_epm ) && (!($installer::globals::iswindowsbuild)))
144 my $onefile = "epm";
145 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onefile, $patharrayref , 0);
146 if (!( $$fileref eq "" ))
148 $installer::globals::epm_in_path = 1;
150 if ( $$fileref =~ /^\s*\.\/epm\s*$/ )
152 my $currentdir = cwd();
153 $$fileref =~ s/\./$currentdir/;
156 $installer::globals::epm_path = $$fileref;
161 ######################################################################
162 # Determining the version of file makecab.exe
163 ######################################################################
165 sub get_makecab_version
167 my $makecabversion = -1;
169 my $systemcall = "makecab.exe |";
170 if ( $installer::globals::isunix )
172 $systemcall = "$ENV{'WORKDIR_FOR_BUILD'}/LinkTarget/Executable/makecab.exe |";
174 my @makecaboutput = ();
176 open (CAB, $systemcall);
177 while (<CAB>) { push(@makecaboutput, $_); }
178 close (CAB);
180 my $returnvalue = $?; # $? contains the return value of the systemcall
182 if ($returnvalue)
184 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
185 push( @installer::globals::globallogfileinfo, $infoline);
187 else
189 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
190 push( @installer::globals::globallogfileinfo, $infoline);
192 my $versionline = "";
194 for ( my $i = 0; $i <= $#makecaboutput; $i++ )
196 if ( $makecaboutput[$i] =~ /\bVersion\b/i )
198 $versionline = $makecaboutput[$i];
199 last;
203 $infoline = $versionline;
204 push( @installer::globals::globallogfileinfo, $infoline);
206 if ( $versionline =~ /\bVersion\b\s+(\d+[\d\.]+\d+)\s+/ )
208 $makecabversion = $1;
211 # Only using the first number
213 if ( $makecabversion =~ /^\s*(\d+?)\D*/ )
215 $makecabversion = $1;
218 $infoline = "Using version: " . $makecabversion . "\n";
219 push( @installer::globals::globallogfileinfo, $infoline);
222 return $makecabversion;
225 ######################################################################
226 # Checking the version of file makecab.exe
227 ######################################################################
229 sub check_makecab_version
231 # checking version of makecab.exe
232 # Now it is guaranteed, that makecab.exe is in the path
234 my $do_check = 1;
236 my $makecabversion = get_makecab_version();
238 my $infoline = "Tested version: " . $installer::globals::controlledmakecabversion . "\n";
239 push( @installer::globals::globallogfileinfo, $infoline);
241 if ( $makecabversion < 0 ) { $do_check = 0; } # version could not be determined
243 if ( $do_check )
245 if ( $makecabversion < $installer::globals::controlledmakecabversion )
247 installer::exiter::exit_program("makecab.exe too old. Found version: \"$makecabversion\", required version: \"$installer::globals::controlledmakecabversion\"!", "check_makecab_version");
250 else
252 $infoline = "Warning: No version check of makecab.exe\n";
253 push( @installer::globals::globallogfileinfo, $infoline);
257 ######################################################################
258 # Reading the environment variables for the paths in ziplist.
259 # solarenvpath, os, pmiscpath
260 ######################################################################
262 sub check_system_environment
264 my %variables = ();
265 my $error = 0;
267 my @environmentvariables = qw(
268 WORK_STAMP
269 OUTPATH
270 LOCAL_OUT
271 LOCAL_COMMON_OUT
272 WORKDIR
273 SRCDIR
276 for my $key ( @environmentvariables )
278 $variables{$key} = $ENV{$key} || "";
280 if ( $variables{$key} eq "" )
282 installer::logger::print_error( "$key not set in environment\n" );
283 $error = 1;
287 if ( $error )
289 installer::exiter::exit_program("ERROR: Environment variable not set!", "check_system_environment");
292 return \%variables;
295 #############################################################
296 # Controlling the log file at the end of the
297 # packaging process
298 #############################################################
300 sub check_logfile
302 my ($logfile) = @_;
304 my @errors = ();
305 my @output = ();
306 my $contains_error = 0;
308 my $ignore_error = 0;
309 my $make_error_to_warning = 0;
311 for ( my $i = 0; $i <= $#{$logfile}; $i++ )
313 my $line = ${$logfile}[$i];
315 # Errors are all errors, but not the Windows installer table "Error.idt"
317 my $compareline = $line;
318 $compareline =~ s/Error\.idt//g; # removing all occurrences of "Error.idt"
319 $compareline =~ s/Error\.ulf//g; # removing all occurrences of "Error.ulf"
320 $compareline =~ s/Error\.idl//g; # removing all occurrences of "Error.idl"
321 $compareline =~ s/Error\.html//g; # removing all occurrences of "Error.html"
322 $compareline =~ s/error\.py//g; # removing all occurrences of "error.py"
323 $compareline =~ s/error\.cpython-33\.py[oc]//g; # removing all occurrences of "error-cpython"
324 $compareline =~ s/libgpg-error-0.dll//g;
325 $compareline =~ s/Error-xref\.html//g;
327 if ( $compareline =~ /\bError\b/i )
329 $contains_error = 1;
330 push(@errors, $line);
332 if ( $ignore_error )
334 $contains_error = 0;
335 $make_error_to_warning = 1;
340 if ($contains_error)
342 my $line = "\n*********************************************************************\n";
343 push(@output, $line);
344 $line = "ERROR: The following errors occurred in packaging process:\n\n";
345 push(@output, $line);
347 for ( my $i = 0; $i <= $#errors; $i++ )
349 $line = "$errors[$i]";
350 push(@output, $line);
353 $line = "*********************************************************************\n";
354 push(@output, $line);
356 else
358 my $line = "";
360 if ( $make_error_to_warning )
362 $line = "\n*********************************************************************\n";
363 push(@output, $line);
364 $line = "The following errors in the log file were ignored:\n\n";
365 push(@output, $line);
367 for ( my $i = 0; $i <= $#errors; $i++ )
369 $line = "$errors[$i]";
370 push(@output, $line);
373 $line = "*********************************************************************\n";
374 push(@output, $line);
377 $line = "\n***********************************************************\n";
378 push(@output, $line);
379 $line = "Successful packaging process!\n";
380 push(@output, $line);
381 $line = "***********************************************************\n";
382 push(@output, $line);
385 # printing the output file and adding it to the logfile
387 installer::logger::include_header_into_logfile("Summary:");
389 my $force = 1; # print this message even in 'quiet' mode
390 for ( my $i = 0; $i <= $#output; $i++ )
392 my $line = "$output[$i]";
393 installer::logger::print_message( "$line", $force );
394 push( @installer::globals::logfileinfo, $line);
395 push( @installer::globals::errorlogfileinfo, $line);
398 return $contains_error;
401 #############################################################
402 # Reading the Windows list file for Windows language codes
403 # Encoding field is no longer used. We use UTF-8 everywhere.
404 #############################################################
406 sub read_lcidlist
408 my ($patharrayref) = @_;
410 if ( ! -f $installer::globals::lcidlistname ) { installer::exiter::exit_program("ERROR: Did not find Windows LCID list $installer::globals::lcidlistname!", "read_lcidlist"); }
412 my $infoline = "Found LCID file: $installer::globals::lcidlistname\n";
413 push(@installer::globals::globallogfileinfo, $infoline);
415 my $lcidlist = installer::files::read_file($installer::globals::lcidlistname);
416 my %msilanguage = ();
418 for ( my $i = 0; $i <= $#{$lcidlist}; $i++ )
420 my $line = ${$lcidlist}[$i];
421 # de-mangle various potential DOS line-ending problems
422 $line =~ s/\r//g;
423 $line =~ s/\n//g;
424 $line =~ s/\s*\#.*$//; # removing comments after "#"
425 if ( $line =~ /^\s*$/ ) { next; } # this is an empty line
427 if ( $line =~ /^\s*([\w-]+)\s+(\d+)\s+(\d+)\s*$/ )
429 my $onelanguage = $1;
430 my $windowslanguage = $3;
431 $msilanguage{$onelanguage} = $windowslanguage;
433 else
435 installer::exiter::exit_program("ERROR: Wrong syntax in Windows LCID list $installer::globals::lcidlistname in line $i: '$line'", "read_lcidlist");
438 $installer::globals::msilanguage = \%msilanguage;
441 #############################################################
442 # Only for Windows and Linux (RPM)there is currently
443 # a reliable mechanism to register extensions during
444 # installation process. Therefore it is for all other
445 # platforms forbidden to install oxt files into that
446 # directory, in which they are searched for registration.
447 #############################################################
449 sub check_oxtfiles
451 my ( $filesarray ) = @_;
453 for ( my $i = 0; $i <= $#{$filesarray}; $i++ )
455 my $onefile = ${$filesarray}[$i];
457 if (( $onefile->{'Name'} ) && ( $onefile->{'Dir'} ))
459 if (( $onefile->{'Name'} =~ /\.oxt\s*$/ ) && ( $onefile->{'Dir'} eq $installer::globals::extensioninstalldir ))
461 installer::exiter::exit_program("There is currently only for Linux (RPM) and Windows a reliable mechanism to register extensions during installation.\nPlease remove file \"$onefile->{'gid'}\" from your installation set!\nYou can use \"\#ifdef WNT\" and \"\#ifdef LINUX\" in scp.", "check_oxtfiles");
467 #######################################################################
468 # Setting global variable "$installer::globals::addsystemintegration"
469 #######################################################################
471 sub set_addsystemintegration
473 my ($allvariables) = @_;
475 if ( $allvariables->{'ADDSYSTEMINTEGRATION'} ) { $installer::globals::addsystemintegration = 1; }
477 if ( $installer::globals::languagepack ) { $installer::globals::addsystemintegration = 0; }
478 if ( $installer::globals::helppack ) { $installer::globals::addsystemintegration = 0; }
479 if (( $installer::globals::packageformat eq "native" ) || ( $installer::globals::packageformat eq "portable" )) { $installer::globals::addsystemintegration = 0; }
481 my $infoline = "Value of \$installer::globals::addsystemintegration: $installer::globals::addsystemintegration\n";
482 push( @installer::globals::globallogfileinfo, $infoline);