41
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
# Module for TraceCompiler
|
|
17 |
#
|
|
18 |
package tracecompiler;
|
|
19 |
|
|
20 |
# If this is 1, debug prints are shown
|
|
21 |
my $DEBUG = 0;
|
|
22 |
|
|
23 |
use FindBin;
|
|
24 |
|
|
25 |
# Get current directory as TraceCompiler path
|
|
26 |
my $trace_compiler_path = $FindBin::Bin; # e.g. X:/epoc32/tools
|
|
27 |
$trace_compiler_path =~ s/\\/\//g; # Replace all "\" with "/"
|
|
28 |
$trace_compiler_path =~ s/\/$//; # Remove possible trailing slash
|
|
29 |
|
|
30 |
#-------------------------------------------------------
|
|
31 |
# Concatenate path
|
|
32 |
#-------------------------------------------------------
|
|
33 |
sub concatenatePath
|
|
34 |
{
|
|
35 |
my $concatenatePathBase = $_[0];
|
|
36 |
my $concatenatePathFile = $_[1];
|
|
37 |
|
|
38 |
my $backCount = 0;
|
|
39 |
|
|
40 |
# Change all "\" characters to "/"
|
|
41 |
$concatenatePathBase =~ s/\\/\//g;
|
|
42 |
$concatenatePathFile =~ s/\\/\//g;
|
|
43 |
|
|
44 |
# Replace all "/./" with "/"
|
|
45 |
$concatenatePathBase =~ s/\/\.\//\//g;
|
|
46 |
$concatenatePathFile =~ s/\/\.\//\//g;
|
|
47 |
|
|
48 |
# Find how many back references there are and remove them
|
|
49 |
while ($concatenatePathFile =~ /\.\.\//g)
|
|
50 |
{
|
|
51 |
$backCount++
|
|
52 |
}
|
|
53 |
$concatenatePathFile =~ s/\.\.\///g;
|
|
54 |
|
|
55 |
# If there is / in the end of the base remove it
|
|
56 |
$concatenatePathBase =~ s/\/$//;
|
|
57 |
|
|
58 |
# Remove directories from the end of the path
|
|
59 |
$concatenatePathBase = reverse($concatenatePathBase);
|
|
60 |
for (my $i=0; $i<$backCount; $i++)
|
|
61 |
{
|
|
62 |
$concatenatePathBase =~ s/.*?\///;
|
|
63 |
}
|
|
64 |
$concatenatePathBase = reverse($concatenatePathBase);
|
|
65 |
|
|
66 |
my $concatenatePathFullFilePath = "$concatenatePathBase\/$concatenatePathFile";
|
|
67 |
|
|
68 |
# Replace again all "/./" with "/"
|
|
69 |
$concatenatePathFullFilePath =~ s/\/\.\//\//g;
|
|
70 |
|
|
71 |
debugMsg("Concatenate returns $concatenatePathFullFilePath");
|
|
72 |
return $concatenatePathFullFilePath;
|
|
73 |
}
|
|
74 |
|
|
75 |
#-------------------------------------------------------
|
|
76 |
# Get java command
|
|
77 |
#-------------------------------------------------------
|
|
78 |
sub getJavaCommand
|
|
79 |
{
|
|
80 |
my @java_commands = ("/tools/ncp_tools/helium/external/jdk1.5/jre/bin/java.exe", "java.exe", "c:/apps/seeinstaller/jre/bin/java.exe");
|
|
81 |
|
|
82 |
my $java_command;
|
|
83 |
|
|
84 |
foreach my $command (@java_commands)
|
|
85 |
{
|
|
86 |
if (checkJava($command))
|
|
87 |
{
|
|
88 |
$java_command = $command;
|
|
89 |
last;
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
return $java_command;
|
|
94 |
}
|
|
95 |
|
|
96 |
#-------------------------------------------------------
|
|
97 |
# Check java
|
|
98 |
#-------------------------------------------------------
|
|
99 |
sub checkJava
|
|
100 |
{
|
|
101 |
open (IN, "$_[0] -version 2>&1 |");
|
|
102 |
while(<IN>)
|
|
103 |
{
|
|
104 |
if (/(\d+\.\d+)/)
|
|
105 |
{
|
|
106 |
if ($1 >= 1.5)
|
|
107 |
{
|
|
108 |
return 1;
|
|
109 |
}
|
|
110 |
}
|
|
111 |
}
|
|
112 |
|
|
113 |
return 0;
|
|
114 |
}
|
|
115 |
|
|
116 |
#-------------------------------------------------------
|
|
117 |
# Gets TraceCompiler version number
|
|
118 |
#-------------------------------------------------------
|
|
119 |
sub getTraceCompilerVersion
|
|
120 |
{
|
|
121 |
# Get Java command or EXIT if not found
|
|
122 |
my $java_command = getJavaCommand();
|
|
123 |
|
|
124 |
if (not defined $java_command)
|
|
125 |
{
|
|
126 |
return "Java 1.5 or newer required!\n";
|
|
127 |
exit;
|
|
128 |
}
|
|
129 |
|
|
130 |
# run from class files class files
|
|
131 |
my $version_query_command = "$java_command -classpath $trace_compiler_path/tracecompiler com.nokia.tracecompiler.TraceCompilerMain -v";
|
|
132 |
|
|
133 |
# run from jar file command
|
|
134 |
#my $version_query_command = "$java_command -jar $trace_compiler_path/tracecompiler.jar -version";
|
|
135 |
|
|
136 |
my $version = qx($version_query_command);
|
|
137 |
|
|
138 |
return $version;
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
#-------------------------------------------------------
|
|
143 |
# Debug Message. Writes to log file and outputs to screen.
|
|
144 |
#-------------------------------------------------------
|
|
145 |
sub debugMsg
|
|
146 |
{
|
|
147 |
if ($DEBUG)
|
|
148 |
{
|
|
149 |
open FILE, ">>/tracecompiler_debug.txt" or die $!;
|
|
150 |
print FILE $_[0] . "\n";
|
|
151 |
close FILE;
|
|
152 |
|
|
153 |
return print "DEBUG: $_[0]\n";
|
|
154 |
}
|
|
155 |
}
|
|
156 |
|
|
157 |
#-------------------------------------------------------
|
|
158 |
# Writes TraceCompiler version to log and screen if Debug is on.
|
|
159 |
#-------------------------------------------------------
|
|
160 |
sub debugTraceCompilerVersion
|
|
161 |
{
|
|
162 |
if ($DEBUG)
|
|
163 |
{
|
|
164 |
open FILE, ">>/tracecompiler_debug.txt" or die $!;
|
|
165 |
my $version = getTraceCompilerVersion();
|
|
166 |
print FILE $version;
|
|
167 |
close FILE;
|
|
168 |
|
|
169 |
return print "DEBUG: $version\n";
|
|
170 |
}
|
|
171 |
}
|
|
172 |
|
|
173 |
1;
|
|
174 |
|