Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / modules / installer / control.pm
blobfd84a3b565776659daf1928181988d8a1c08aaf2
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 'TRUE')
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 LIBO_VERSION_MAJOR
269 LIBO_VERSION_MINOR
270 CPUNAME
273 PLATFORMID
274 LOCAL_OUT
275 LOCAL_COMMON_OUT
276 WORKDIR
277 SRCDIR
280 for my $key ( @environmentvariables )
282 $variables{$key} = defined($ENV{$key}) ? $ENV{$key} : "";
284 if ( $variables{$key} eq "" )
286 installer::logger::print_error( "$key not set in environment\n" );
287 $error = 1;
291 if ( $error )
293 installer::exiter::exit_program("ERROR: Environment variable not set!", "check_system_environment");
296 return \%variables;
299 #############################################################
300 # Controlling the log file at the end of the
301 # packaging process
302 #############################################################
304 sub check_logfile
306 my ($logfile) = @_;
308 my @errors = ();
309 my @output = ();
310 my $contains_error = 0;
312 my $ignore_error = 0;
313 my $make_error_to_warning = 0;
315 for ( my $i = 0; $i <= $#{$logfile}; $i++ )
317 my $line = ${$logfile}[$i];
319 # Errors are all errors, but not the Windows installer table "Error.idt"
321 my $compareline = $line;
322 $compareline =~ s/Error\.idt//g; # removing all occurrences of "Error.idt"
323 $compareline =~ s/Error\.ulf//g; # removing all occurrences of "Error.ulf"
324 $compareline =~ s/Error\.idl//g; # removing all occurrences of "Error.idl"
325 $compareline =~ s/Error\.html//g; # removing all occurrences of "Error.html"
326 $compareline =~ s/error\.py//g; # removing all occurrences of "error.py"
327 $compareline =~ s/error\.cpython-33\.py[oc]//g; # removing all occurrences of "error-cpython"
328 $compareline =~ s/libgpg-error-0.dll//g;
329 $compareline =~ s/Error-xref\.html//g;
331 if ( $compareline =~ /\bError\b/i )
333 $contains_error = 1;
334 push(@errors, $line);
336 if ( $ignore_error )
338 $contains_error = 0;
339 $make_error_to_warning = 1;
344 if ($contains_error)
346 my $line = "\n*********************************************************************\n";
347 push(@output, $line);
348 $line = "ERROR: The following errors occurred in packaging process:\n\n";
349 push(@output, $line);
351 for ( my $i = 0; $i <= $#errors; $i++ )
353 $line = "$errors[$i]";
354 push(@output, $line);
357 $line = "*********************************************************************\n";
358 push(@output, $line);
360 else
362 my $line = "";
364 if ( $make_error_to_warning )
366 $line = "\n*********************************************************************\n";
367 push(@output, $line);
368 $line = "The following errors in the log file were ignored:\n\n";
369 push(@output, $line);
371 for ( my $i = 0; $i <= $#errors; $i++ )
373 $line = "$errors[$i]";
374 push(@output, $line);
377 $line = "*********************************************************************\n";
378 push(@output, $line);
381 $line = "\n***********************************************************\n";
382 push(@output, $line);
383 $line = "Successful packaging process!\n";
384 push(@output, $line);
385 $line = "***********************************************************\n";
386 push(@output, $line);
389 # printing the output file and adding it to the logfile
391 installer::logger::include_header_into_logfile("Summary:");
393 my $force = 1; # print this message even in 'quiet' mode
394 for ( my $i = 0; $i <= $#output; $i++ )
396 my $line = "$output[$i]";
397 installer::logger::print_message( "$line", $force );
398 push( @installer::globals::logfileinfo, $line);
399 push( @installer::globals::errorlogfileinfo, $line);
402 return $contains_error;
405 #############################################################
406 # Reading the Windows list file for Windows language codes
407 # Encoding field is no longer used. We use UTF-8 everywhere.
408 #############################################################
410 sub read_lcidlist
412 my ($patharrayref) = @_;
414 if ( ! -f $installer::globals::lcidlistname ) { installer::exiter::exit_program("ERROR: Did not find Windows LCID list $installer::globals::lcidlistname!", "read_lcidlist"); }
416 my $infoline = "Found LCID file: $installer::globals::lcidlistname\n";
417 push(@installer::globals::globallogfileinfo, $infoline);
419 my $lcidlist = installer::files::read_file($installer::globals::lcidlistname);
420 my %msilanguage = ();
422 for ( my $i = 0; $i <= $#{$lcidlist}; $i++ )
424 my $line = ${$lcidlist}[$i];
425 # de-mangle various potential DOS line-ending problems
426 $line =~ s/\r//g;
427 $line =~ s/\n//g;
428 $line =~ s/\s*\#.*$//; # removing comments after "#"
429 if ( $line =~ /^\s*$/ ) { next; } # this is an empty line
431 if ( $line =~ /^\s*([\w-]+)\s+(\d+)\s+(\d+)\s*$/ )
433 my $onelanguage = $1;
434 my $windowslanguage = $3;
435 $msilanguage{$onelanguage} = $windowslanguage;
437 else
439 installer::exiter::exit_program("ERROR: Wrong syntax in Windows LCID list $installer::globals::lcidlistname in line $i: '$line'", "read_lcidlist");
442 $installer::globals::msilanguage = \%msilanguage;
445 #############################################################
446 # Only for Windows and Linux (RPM)there is currently
447 # a reliable mechanism to register extensions during
448 # installation process. Therefore it is for all other
449 # platforms forbidden to install oxt files into that
450 # directory, in which they are searched for registration.
451 #############################################################
453 sub check_oxtfiles
455 my ( $filesarray ) = @_;
457 for ( my $i = 0; $i <= $#{$filesarray}; $i++ )
459 my $onefile = ${$filesarray}[$i];
461 if (( $onefile->{'Name'} ) && ( $onefile->{'Dir'} ))
463 if (( $onefile->{'Name'} =~ /\.oxt\s*$/ ) && ( $onefile->{'Dir'} eq $installer::globals::extensioninstalldir ))
465 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");
471 #######################################################################
472 # Setting global variable "$installer::globals::addsystemintegration"
473 #######################################################################
475 sub set_addsystemintegration
477 my ($allvariables) = @_;
479 if ( $allvariables->{'ADDSYSTEMINTEGRATION'} ) { $installer::globals::addsystemintegration = 1; }
481 if ( $installer::globals::languagepack ) { $installer::globals::addsystemintegration = 0; }
482 if ( $installer::globals::helppack ) { $installer::globals::addsystemintegration = 0; }
484 my $infoline = "Value of \$installer::globals::addsystemintegration: $installer::globals::addsystemintegration\n";
485 push( @installer::globals::globallogfileinfo, $infoline);