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 #!/usr/bin/perl |
|
17 |
|
18 # |
|
19 # ============================================================================== |
|
20 # Name : targets_from_mmp.pl |
|
21 # Description : This script provides search functionality for target components |
|
22 # from mmp-files found from the environment. |
|
23 # Version : 1 |
|
24 # ============================================================================== |
|
25 # |
|
26 |
|
27 use strict; |
|
28 use Cwd; |
|
29 use File::Find; |
|
30 |
|
31 use Getopt::Std; |
|
32 use vars qw($opt_o $opt_i $opt_p $opt_s ); |
|
33 |
|
34 # ----------------------------------------------------------- |
|
35 # Check the arguments and if not any or too many print guide. |
|
36 # ----------------------------------------------------------- |
|
37 if (( $#ARGV < 0) || ($#ARGV > 5)) |
|
38 { |
|
39 print <<USAGE; |
|
40 |
|
41 Usage: targets_from_mmp.pl [-p component] [-o output-file] [-s] [-i input-file] |
|
42 |
|
43 -p prints the mmp-file(s) related to component. |
|
44 -i specify the input file from where to search for |
|
45 mmp-target relation (value is "targets_from_mmps.txt" |
|
46 if else not specified). |
|
47 -s scans the environment and prints the output to |
|
48 "targets_from_mmps.txt" or to separately specified |
|
49 file (with option -o). |
|
50 -o output-file where to write scanning results. |
|
51 |
|
52 At least one option is required. |
|
53 |
|
54 Examples: targets_from_mmp.pl -s |
|
55 targets_from_mmp.pl -s -o targets_from_mmps.txt |
|
56 targets_from_mmp.pl -p clock.dll |
|
57 targets_from_mmp.pl -p clock.dll -i targets_from_mmps.txt |
|
58 USAGE |
|
59 exit -1; |
|
60 } |
|
61 |
|
62 # --------------- |
|
63 # Collect options |
|
64 # --------------- |
|
65 getopts("o:i:p:s"); |
|
66 |
|
67 my ($inputfile, $outputfile); |
|
68 |
|
69 # ----------------------------------------------------------- |
|
70 # If output-file is defined in arguments open specified file |
|
71 # for printing the targets found from mmp-files. |
|
72 # ----------------------------------------------------------- |
|
73 if ($opt_s) |
|
74 { |
|
75 if ($opt_o) |
|
76 { |
|
77 $outputfile = $opt_o; |
|
78 } |
|
79 else |
|
80 { |
|
81 $outputfile = "targets_from_mmps.txt"; |
|
82 } |
|
83 |
|
84 open (OUTPUT, ">$outputfile"); |
|
85 print "\nWriting targets of mmp-files into \"$outputfile\".\n"; |
|
86 |
|
87 find(\&doFind, cwd); |
|
88 } |
|
89 |
|
90 # ---------------------------------------------------- |
|
91 # If special input file is defined. |
|
92 # ---------------------------------------------------- |
|
93 if ($opt_i) |
|
94 { |
|
95 $inputfile = $opt_i; |
|
96 } |
|
97 else |
|
98 { |
|
99 $inputfile = "targets_from_mmps.txt"; |
|
100 } |
|
101 |
|
102 # ---------------------------------------------------- |
|
103 # If component to search is defined in arguments print |
|
104 # indication of that on screen. |
|
105 # ---------------------------------------------------- |
|
106 if ($opt_p) |
|
107 { |
|
108 open (INPUT, $inputfile) or die "\nInputfile \"$inputfile\" not found, please check the filename or scan the environment first!\n"; |
|
109 #print "\nSearching mmp-file for target \"$opt_p\" from \"$inputfile\"...\n\n"; |
|
110 |
|
111 my $found_indicator=0; |
|
112 |
|
113 foreach my $line (<INPUT>) |
|
114 { |
|
115 if ($line =~ m/(.*) : $opt_p/i) |
|
116 { |
|
117 print "\n $opt_p -->\n" if ($found_indicator == 0); |
|
118 $found_indicator++; |
|
119 print " $1"; |
|
120 } |
|
121 } |
|
122 |
|
123 print "\nCould not find target \"$opt_p\" from any mmp-file (from \"$inputfile\")!\n" if ($found_indicator == 0); |
|
124 |
|
125 print "\n"; |
|
126 close INPUT; |
|
127 } |
|
128 |
|
129 # -------------------------------------------- |
|
130 # Function to find the targets from mmp-files. |
|
131 # -------------------------------------------- |
|
132 sub doFind |
|
133 { |
|
134 my $file = $File::Find::name; |
|
135 |
|
136 $file =~ s,/,\\,g; |
|
137 return unless -f $file; |
|
138 |
|
139 return unless $file =~ /(?i)\.mmp$/; |
|
140 |
|
141 open F, $file or return; |
|
142 #print $file . "\n"; |
|
143 |
|
144 if ($file =~ m/^\S:(.*)/i) |
|
145 { |
|
146 $file = $1; |
|
147 } |
|
148 |
|
149 my ($line, $foundSomething); |
|
150 |
|
151 $foundSomething = "false"; |
|
152 |
|
153 while ($line=<F>) |
|
154 { |
|
155 if ($line=~ m/^[\s|\t]*(?i)TARGET[\s|\t]+(\S*).*$/) |
|
156 { |
|
157 # If output-file is defined print all findings to that. |
|
158 if ($outputfile) |
|
159 { |
|
160 |
|
161 |
|
162 print OUTPUT "$file : $1\n"; |
|
163 } |
|
164 |
|
165 # If component to search is defined and found |
|
166 # print corresponding mmp-file on screen. |
|
167 |
|
168 $foundSomething = "true"; |
|
169 } |
|
170 } |
|
171 |
|
172 if ($foundSomething eq "false") |
|
173 { |
|
174 #print "no TARGET found from $file\n"; |
|
175 } |
|
176 |
|
177 close F; |
|
178 } |
|
179 |
|
180 if ($outputfile) |
|
181 { |
|
182 close OUTPUT; |
|
183 } |
|