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*cdf0e10cSrcweir# 30*cdf0e10cSrcweir# createPDBRelocators - create for pdb relocator files 31*cdf0e10cSrcweir# PDB relocator files are used to find debug infos 32*cdf0e10cSrcweir# for analysis of creash reports 33*cdf0e10cSrcweir# 34*cdf0e10cSrcweir# usage: create_pdb_relocators($inpath, $milestoneext, $pre); 35*cdf0e10cSrcweir# 36*cdf0e10cSrcweir#************************************************************************* 37*cdf0e10cSrcweir 38*cdf0e10cSrcweirpackage CreatePDBRelocators; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweiruse strict; 41*cdf0e10cSrcweiruse File::Basename; 42*cdf0e10cSrcweiruse SourceConfig; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweirsub new 45*cdf0e10cSrcweir{ 46*cdf0e10cSrcweir my $Object = shift; 47*cdf0e10cSrcweir my $solarversion = shift; 48*cdf0e10cSrcweir my $workdir; 49*cdf0e10cSrcweir my $relworkdir; 50*cdf0e10cSrcweir my $self = {}; 51*cdf0e10cSrcweir my @basedirs; 52*cdf0e10cSrcweir my @repos; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir if (!defined ($solarversion)) { 55*cdf0e10cSrcweir $solarversion = $ENV{SOLARVERSION}; 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir if ( !$solarversion ) { 58*cdf0e10cSrcweir print STDERR "can't determine SOLARVERSION.\n"; 59*cdf0e10cSrcweir exit (1); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir $self->{SOLARVERSION} = $solarversion; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir $workdir = $ENV{WORKDIR}; 65*cdf0e10cSrcweir if ( !$workdir ) { 66*cdf0e10cSrcweir print STDERR "can't determine WORKDIR.\n"; 67*cdf0e10cSrcweir exit (1); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir if ( $workdir =~ /^$solarversion/ ) { 71*cdf0e10cSrcweir $relworkdir = $workdir; 72*cdf0e10cSrcweir $relworkdir =~ s/^$solarversion\///; 73*cdf0e10cSrcweir } else { 74*cdf0e10cSrcweir print STDERR "ERROR: workdir outside $solarversion unsupported\n"; 75*cdf0e10cSrcweir exit (2); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir my $SourceConfigObj = SourceConfig->new(); 78*cdf0e10cSrcweir @repos = $SourceConfigObj->get_repositories(); 79*cdf0e10cSrcweir if ( defined $ENV{UPDMINOREXT} ) { 80*cdf0e10cSrcweir foreach my $onedir ( @repos ) { 81*cdf0e10cSrcweir push( @basedirs, $onedir.$ENV{UPDMINOREXT} ); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir # basdirs is repositories (dmake) + workdir (gnu make) 85*cdf0e10cSrcweir push(@basedirs, $relworkdir); 86*cdf0e10cSrcweir if (!scalar @basedirs) { 87*cdf0e10cSrcweir print STDERR "no basedir and no working directory found.\n"; 88*cdf0e10cSrcweir exit (2); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir $self->{BASEDIRS} = \@basedirs; 91*cdf0e10cSrcweir bless($self, $Object); 92*cdf0e10cSrcweir return $self; 93*cdf0e10cSrcweir} 94*cdf0e10cSrcweir 95*cdf0e10cSrcweirsub create_pdb_relocators 96*cdf0e10cSrcweir{ 97*cdf0e10cSrcweir my $self = shift; 98*cdf0e10cSrcweir my $inpath = shift; 99*cdf0e10cSrcweir my $milestoneext = shift; 100*cdf0e10cSrcweir my $pre = shift; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir my $solarversion = $self->{SOLARVERSION}; 103*cdf0e10cSrcweir my $root_dir = "$solarversion/$inpath"; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir # sanitize path 106*cdf0e10cSrcweir $root_dir =~ s/\\/\//g; 107*cdf0e10cSrcweir my $o =~ s/\\/\//g; 108*cdf0e10cSrcweir my $premilestoneext = $milestoneext; 109*cdf0e10cSrcweir if ( $pre ne "" ) { 110*cdf0e10cSrcweir $premilestoneext = ~ s/^\.//; 111*cdf0e10cSrcweir $premilestoneext = ".pre$premilestoneext"; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir my $pdb_dir = $root_dir . "/pdb$premilestoneext"; 114*cdf0e10cSrcweir my $pdb_so_dir = $root_dir . "/pdb$premilestoneext/so"; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir # create pdb directories if necessary 117*cdf0e10cSrcweir if ( ! -d $pdb_dir ) { 118*cdf0e10cSrcweir if ( !mkdir($pdb_dir, 0775) ) { 119*cdf0e10cSrcweir print STDERR "can't create directory '$pdb_dir'\n"; 120*cdf0e10cSrcweir return undef; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir if ( ! -d $pdb_so_dir ) { 124*cdf0e10cSrcweir if ( !mkdir($pdb_so_dir, 0775) ) { 125*cdf0e10cSrcweir print STDERR "can't create directory '$pdb_so_dir'\n"; 126*cdf0e10cSrcweir return undef; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir # collect files 131*cdf0e10cSrcweir foreach my $basedir (@{$self->{BASEDIRS}}) { 132*cdf0e10cSrcweir my @pdb_files; 133*cdf0e10cSrcweir my $o = $self->{SOLARVERSION} . "/$basedir"; 134*cdf0e10cSrcweir $basedir =~ s/(.*?)\.(.*)/$1/; 135*cdf0e10cSrcweir $self->collect_files( $o, $inpath, \@pdb_files); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir foreach (@pdb_files) { 138*cdf0e10cSrcweir my $relocator = basename($_) . ".location"; 139*cdf0e10cSrcweir /$o\/(.*)/i; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir my $src_location = $1; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir my $location = ""; 144*cdf0e10cSrcweir my $target = ""; 145*cdf0e10cSrcweir if ( $src_location =~ /\/so\// ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir $location = "../../../$basedir$milestoneext/" . $src_location; 148*cdf0e10cSrcweir $target = "$pdb_dir/so/$relocator"; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir else 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir $location = "../../$basedir$milestoneext/" . $src_location; 153*cdf0e10cSrcweir $target = "$pdb_dir/$relocator"; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir if ( !open(RELOCATOR, ">$target") ) { 157*cdf0e10cSrcweir print STDERR "can't write file '$target'\n"; 158*cdf0e10cSrcweir return undef; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir print RELOCATOR "$location\n"; 161*cdf0e10cSrcweir close(RELOCATOR); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir return 1; 165*cdf0e10cSrcweir} 166*cdf0e10cSrcweir 167*cdf0e10cSrcweirsub collect_files_from_all_basedirs 168*cdf0e10cSrcweir{ 169*cdf0e10cSrcweir my $self = shift; 170*cdf0e10cSrcweir my ($platform, $filesref) = @_; 171*cdf0e10cSrcweir my $basedir; 172*cdf0e10cSrcweir my $ret; 173*cdf0e10cSrcweir foreach $basedir (@{$self->{BASEDIRS}}) { 174*cdf0e10cSrcweir my $srcdir = $self->{SOLARVERSION} . "/$basedir"; 175*cdf0e10cSrcweir $ret |= $self->collect_files ($srcdir, $platform, $filesref); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir return $ret; 178*cdf0e10cSrcweir} 179*cdf0e10cSrcweir 180*cdf0e10cSrcweirsub collect_files 181*cdf0e10cSrcweir{ 182*cdf0e10cSrcweir my $self = shift; 183*cdf0e10cSrcweir my ($srcdir, $platform, $filesref) = @_; 184*cdf0e10cSrcweir my $template = "$srcdir/*/$platform"; 185*cdf0e10cSrcweir my $template2 = "$srcdir/LinkTarget"; 186*cdf0e10cSrcweir if ( $ENV{GUI} eq "WNT" ) { 187*cdf0e10cSrcweir # collect all pdb files on o: 188*cdf0e10cSrcweir # regular glob does not work with two wildcard on WNT 189*cdf0e10cSrcweir my @bin = glob("$template/bin/*.pdb"); 190*cdf0e10cSrcweir my @bin_so = glob("$template/bin/so/*.pdb"); 191*cdf0e10cSrcweir my @workdir = glob("$template2/*/*.pdb"); 192*cdf0e10cSrcweir # we are only interested in pdb files which are accompanied by 193*cdf0e10cSrcweir # .exe or .dll which the same name 194*cdf0e10cSrcweir foreach (@bin, @bin_so, @workdir) { 195*cdf0e10cSrcweir my $dir = dirname($_); 196*cdf0e10cSrcweir my $base = basename($_, ".pdb"); 197*cdf0e10cSrcweir my $exe = "$dir/$base.exe"; 198*cdf0e10cSrcweir my $dll = "$dir/$base.dll"; 199*cdf0e10cSrcweir if ( -e $exe || -e $dll ) { 200*cdf0e10cSrcweir push(@$filesref, $_); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir else { 205*cdf0e10cSrcweir # collect all shared libraries on o: 206*cdf0e10cSrcweir my @lib = glob("$template/lib/*.so*"); 207*cdf0e10cSrcweir my @workdir_lib = glob("$template2/Library/*.so*"); 208*cdf0e10cSrcweir my @lib_so = glob("$template/lib/so/*.so*"); 209*cdf0e10cSrcweir my @mac_lib = glob("$template/lib/*.dylib*"); 210*cdf0e10cSrcweir my @mac_workdir_lib = glob("$template2/Library/*.dylib*"); 211*cdf0e10cSrcweir my @mac_lib_so = glob("$template/lib/so/*.dylib*"); 212*cdf0e10cSrcweir # collect all binary executables on o: 213*cdf0e10cSrcweir my @bin = $self->find_binary_execs("$template/bin"); 214*cdf0e10cSrcweir my @workdir_bin = $self->find_binary_execs("$template2/Executable"); 215*cdf0e10cSrcweir my @bin_so = $self->find_binary_execs("$template/bin/so"); 216*cdf0e10cSrcweir push(@$filesref, (@lib, @lib_so, @workdir_lib, @mac_lib, @mac_workdir_lib, @mac_lib_so, @bin, @workdir_bin, @bin_so)); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir return 1; 219*cdf0e10cSrcweir} 220*cdf0e10cSrcweir 221*cdf0e10cSrcweirsub find_binary_execs 222*cdf0e10cSrcweir{ 223*cdf0e10cSrcweir my $self = shift; 224*cdf0e10cSrcweir my $path = shift; 225*cdf0e10cSrcweir my @files = glob("$path/*"); 226*cdf0e10cSrcweir my @execs = grep(-x $_, @files); 227*cdf0e10cSrcweir my @elf_files = grep(`file $_` =~ /ELF/, @execs); 228*cdf0e10cSrcweir my @MachO_files = grep(`file $_` =~ /Mach\-O/, @execs); 229*cdf0e10cSrcweir return ( @elf_files, @MachO_files ); 230*cdf0e10cSrcweir} 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir1; # required 233*cdf0e10cSrcweir 234