cid#1607171 Data race condition
[LibreOffice.git] / solenv / bin / modules / installer / windows / strip.pm
blob0a59be7891e31d4e2cb5604416812e31ffb172e0
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::windows::strip;
21 use strict;
22 use warnings;
24 use File::Temp qw(tmpnam);
25 use installer::converter;
26 use installer::globals;
27 use installer::logger;
28 use installer::pathanalyzer;
29 use installer::systemactions;
31 #####################################################################
32 # Checking whether a file has to be stripped
33 #####################################################################
35 sub need_to_strip
37 my ( $filename ) = @_;
39 my $strip = 0;
41 # Check using the "nm" command
43 $filename =~ s/\\/\\\\/g;
45 open (FILE, "nm $filename 2>&1 |");
46 my $nmoutput = <FILE>;
47 close (FILE);
49 if ( $nmoutput && !( $nmoutput =~ /no symbols/i || $nmoutput =~ /not recognized/i )) { $strip = 1; }
51 return $strip
54 #####################################################################
55 # Checking whether a file has to be stripped
56 #####################################################################
58 sub do_strip
60 my ( $filename ) = @_;
62 my $systemcall = "strip" . " " . $filename;
64 my $returnvalue = system($systemcall);
66 my $infoline = "Systemcall: $systemcall\n";
67 push( @installer::globals::logfileinfo, $infoline);
69 if ($returnvalue)
71 $infoline = "ERROR: Could not strip $filename!\n";
72 push( @installer::globals::logfileinfo, $infoline);
74 else
76 $infoline = "SUCCESS: Stripped library $filename!\n";
77 push( @installer::globals::logfileinfo, $infoline);
81 #####################################################################
82 # Resolving all variables in the packagename.
83 #####################################################################
85 sub strip_binaries
87 my ( $filelist, $languagestringref ) = @_;
89 installer::logger::include_header_into_logfile("Stripping files:");
91 my $strippeddirbase = installer::systemactions::create_directories("stripped", $languagestringref);
93 if (! grep {$_ eq $strippeddirbase} @installer::globals::removedirs)
95 push(@installer::globals::removedirs, $strippeddirbase);
98 my ($tmpfilehandle, $tmpfilename) = tmpnam();
99 open SOURCEPATHLIST, ">$tmpfilename" or die "oops...\n";
100 for ( my $i = 0; $i <= $#{$filelist}; $i++ )
102 print SOURCEPATHLIST "${$filelist}[$i]->{'sourcepath'}\n";
104 close SOURCEPATHLIST;
105 my @filetypelist = qx{file -f "$tmpfilename"};
106 chomp @filetypelist;
107 unlink "$tmpfilename" or die "oops\n";
108 for ( my $i = 0; $i <= $#{$filelist}; $i++ )
110 ${$filelist}[$i]->{'is_executable'} = ( $filetypelist[$i] =~ /:.*PE executable/ );
113 if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_paths($filelist); }
115 for ( my $i = 0; $i <= $#{$filelist}; $i++ )
117 my $sourcefilename = ${$filelist}[$i]->{'cyg_sourcepath'};
119 if ( ${$filelist}[$i]->{'is_executable'} && need_to_strip($sourcefilename) )
121 my $shortfilename = $sourcefilename;
122 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename);
124 my $infoline = "Strip: $shortfilename\n";
125 push( @installer::globals::logfileinfo, $infoline);
127 # copy file into directory for stripped libraries
129 my $onelanguage = ${$filelist}[$i]->{'specificlanguage'};
131 # files without language into directory "00"
133 if ($onelanguage eq "") { $onelanguage = "00"; }
135 my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage;
136 installer::systemactions::create_directory($strippeddir); # creating language specific subdirectories
138 my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename;
139 installer::systemactions::copy_one_file($sourcefilename, $destfilename);
141 # change sourcepath in files collector
143 ${$filelist}[$i]->{'sourcepath'} = $destfilename;
145 # strip file
147 do_strip($destfilename);