update dev300-m58
[ooovba.git] / solenv / bin / modules / CreatePDBRelocators.pm
blob46e5f8b55b622816cb1865d635640863131e9a16
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: CreatePDBRelocators.pm,v $
11 # $Revision: 1.8 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 #*************************************************************************
34 # createPDBRelocators - create for pdb relocator files
35 # PDB relocator files are used to find debug infos
36 # for analysis of creash reports
38 # usage: create_pdb_relocators($inpath, $milestone, $pre);
40 #*************************************************************************
42 package CreatePDBRelocators;
44 use strict;
45 use File::Basename;
47 sub create_pdb_relocators
49 my $inpath = shift;
50 my $milestone = shift;
51 my $pre = shift;
53 my $solarversion = $ENV{SOLARVERSION};
54 if ( !$solarversion ) {
55 print STDERR "can't determine SOLARVERSION.\n";
56 return undef;
59 my $o = $ENV{SRC_ROOT};
60 if ( !$o ) {
61 print STDERR "can't determine SOLAR_SRC.\n";
62 return undef;
65 my $root_dir = "$solarversion/$inpath";
67 # sanitize path
68 $root_dir =~ s/\\/\//g;
69 $o =~ s/\\/\//g;
70 my $pdb_dir = $root_dir . "/pdb.$pre$milestone";
71 my $pdb_so_dir = $root_dir . "/pdb.$pre$milestone/so";
73 # create pdb directories if necessary
74 if ( ! -d $pdb_dir ) {
75 if ( !mkdir($pdb_dir, 0775) ) {
76 print STDERR "can't create directory '$pdb_dir'\n";
77 return undef;
80 if ( ! -d $pdb_so_dir ) {
81 if ( !mkdir($pdb_so_dir, 0775) ) {
82 print STDERR "can't create directory '$pdb_so_dir'\n";
83 return undef;
87 # collect files
88 my @pdb_files;
89 collect_files( $o, $inpath, \@pdb_files);
91 foreach (@pdb_files) {
92 my $relocator = basename($_) . ".location";
93 /$o\/(.*)/i;
95 my $src_location = $1;
97 my $location = "";
98 my $target = "";
99 if ( $src_location =~ /\/so\// )
101 $location = "../../../src.$milestone/" . $src_location;
102 $target = "$pdb_dir/so/$relocator";
104 else
106 $location = "../../src.$milestone/" . $src_location;
107 $target = "$pdb_dir/$relocator";
110 if ( !open(RELOCATOR, ">$target") ) {
111 print STDERR "can't write file '$target'\n";
112 return undef;
114 print RELOCATOR "$location\n";
115 close(RELOCATOR);
117 return 1;
120 sub collect_files
122 my ($srcdir, $platform, $filesref) = @_;
123 my $template = "$srcdir/*/$platform";
124 if ( $^O eq 'MSWin32' ) {
125 # collect all pdb files on o:
126 # regular glob does not work with two wildcard on WNT
127 my @bin = glob("$template/bin/*.pdb");
128 my @bin_so = glob("$template/bin/so/*.pdb");
129 # we are only interested in pdb files which are accompanied by
130 # .exe or .dll which the same name
131 foreach (@bin, @bin_so) {
132 my $dir = dirname($_);
133 my $base = basename($_, ".pdb");
134 my $exe = "$dir/$base.exe";
135 my $dll = "$dir/$base.dll";
136 if ( -e $exe || -e $dll ) {
137 push(@$filesref, $_);
141 else {
142 # collect all shared libraries on o:
143 my @lib = glob("$template/lib/*.so*");
144 my @lib_so = glob("$template/lib/so/*.so*");
145 my @mac_lib = glob("$template/lib/*.dylib*");
146 my @mac_lib_so = glob("$template/lib/so/*.dylib*");
147 # collect all binary executables on o:
148 my @bin = find_binary_execs("$template/bin");
149 my @bin_so = find_binary_execs("$template/bin/so");
150 @$filesref = (@lib, @lib_so, @mac_lib, @mac_lib_so, @bin, @bin_so);
152 return 1;
155 sub find_binary_execs
157 my $path = shift;
158 my @files = glob("$path/*");
159 my @execs = grep(-x $_, @files);
160 my @elf_files = grep(`file $_` =~ /ELF/, @execs);
161 my @MachO_files = grep(`file $_` =~ /Mach\-O/, @execs);
162 return ( @elf_files, @MachO_files );
165 1; # required