author | MattD <mattd@symbian.org> |
Sun, 13 Jun 2010 20:39:03 +0100 | |
branch | DBRToolsDev |
changeset 285 | 6a928cf9e181 |
parent 5 | 842a773e65f2 |
permissions | -rw-r--r-- |
5
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
1 |
# Copyright (c) 2009 Symbian Foundation Ltd |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
2 |
# This component and the accompanying materials are made available |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
3 |
# under the terms of the License "Eclipse Public License v1.0" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
4 |
# which accompanies this distribution, and is available |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
5 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
6 |
# |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
7 |
# Initial Contributors: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
8 |
# Symbian Foundation Ltd - initial contribution. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
9 |
# |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
10 |
# Contributors: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
11 |
# |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
12 |
# Description: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
13 |
# Create a barebones OBY file from a dependency report text file. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
14 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
15 |
"""Take a report generated by get_deps.py and attempt to create an OBY |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
16 |
file to build a ROM with the dependency list. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
17 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
18 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
19 |
from build_graph import without_comments |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
20 |
from optparse import OptionParser |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
21 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
22 |
import os |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
23 |
import re |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
24 |
import sys |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
25 |
import logging |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
26 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
27 |
__author__ = 'James Aley' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
28 |
__email__ = 'jamesa@symbian.org' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
29 |
__version__ = '1.0' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
30 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
31 |
# Logging config |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
32 |
_LOG_FORMAT = '%(levelname)s: %(message)s' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
33 |
logging.basicConfig(format=_LOG_FORMAT, level=logging.WARNING, stream=sys.stdout) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
34 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
35 |
# Regexes for bld.inf parsing |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
36 |
_RE_EXPORT_SECTION = '\\s*PRJ_EXPORTS\\s*' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
37 |
_RE_OTHER_SECTION = '\\s*PRJ_[a-z]+\\s*' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
38 |
_RE_IBY_OBY = '\\s*([^\\s]+\\.[oi]by)\\s+.*' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
39 |
_p_export_section = re.compile(_RE_EXPORT_SECTION, re.I) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
40 |
_p_other_section = re.compile(_RE_OTHER_SECTION, re.I) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
41 |
_p_iby_oby = re.compile(_RE_IBY_OBY, re.I) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
42 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
43 |
# OBY output templates |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
44 |
_OBY_HEADER = """// OBY file generated by genereate_oby.py. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
45 |
// The following includes are derived from the dependency report: %s |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
46 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
47 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
48 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
49 |
_OBY_INCLUDE = """ |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
50 |
// Required for: %s |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
51 |
%s |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
52 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
53 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
54 |
_OBY_UNRESOLVED = """ |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
55 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
56 |
// The following appear to be exported by this component, |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
57 |
// but were not found under the include directory: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
58 |
%s |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
59 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
60 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
61 |
_OBY_NO_EXPORTS = """ |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
62 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
63 |
// The following components are required in your dependency graph, but |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
64 |
// they appear not to export an IBY/OBY file. Your ROM will likely not |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
65 |
// build until you locate the correct include files for these. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
66 |
%s |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
67 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
68 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
69 |
_INCLUDE_TEMPLATE = '#include <%s>' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
70 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
71 |
def bld_inf_list(report_path): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
72 |
"""Returna list of bld.inf files from the report |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
73 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
74 |
bld_list = [] |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
75 |
report_file = None |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
76 |
try: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
77 |
report_file = open(report_path) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
78 |
except IOError, e: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
79 |
logging.critical('Could not open report: %s' % (repr(e), )) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
80 |
exit(1) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
81 |
return filter(lambda x: x and not x.isspace(), [line.strip() for line in without_comments(report_file)]) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
82 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
83 |
def get_paths(bld_inf_file): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
84 |
"""Returns a list of referenced OBY or IBY files from a bld.inf file. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
85 |
bld_inf_file is an open file handle, which will not be closed by this |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
86 |
function. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
87 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
88 |
oby_iby = [] |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
89 |
export_section = False |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
90 |
for line in without_comments(bld_inf_file): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
91 |
if export_section: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
92 |
match_iby_oby = _p_iby_oby.search(line) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
93 |
if match_iby_oby: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
94 |
file_name = match_iby_oby.groups()[0].strip() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
95 |
oby_iby.append(file_name) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
96 |
else: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
97 |
match_other_section = _p_other_section.search(line) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
98 |
if match_other_section: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
99 |
export_section = False |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
100 |
else: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
101 |
match_export_section = _p_export_section.search(line) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
102 |
if match_export_section: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
103 |
export_section = True |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
104 |
obys = filter(lambda x: x.lower().endswith('.oby'), oby_iby) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
105 |
if len(obys) > 0: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
106 |
return obys |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
107 |
return oby_iby |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
108 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
109 |
def rom_file_list(bld_inf_paths): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
110 |
"""Iterate through a list of bld.inf file paths and extra the references |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
111 |
to OBY or IBY files where appropriate (OBY takes precedence). Return a |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
112 |
dictionary of relevant files in the format: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
113 |
{ 'component_bld_inf' : [ iby_file_list] } |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
114 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
115 |
obys_ibys = {} |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
116 |
for path in bld_inf_paths: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
117 |
bld_inf_file = None |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
118 |
try: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
119 |
bld_inf_file = open(path) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
120 |
except IOError, e: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
121 |
logging.error('Unable to open bld.inf file: %s' % (repr(e), )) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
122 |
continue |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
123 |
rom_file_paths = get_paths(bld_inf_file) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
124 |
obys_ibys[path] = rom_file_paths |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
125 |
bld_inf_file.close() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
126 |
return obys_ibys |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
127 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
128 |
def iby_map(iby_dict, dir_name, file_names): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
129 |
"""Searches for the specified IBY/OBY file under the include_root path. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
130 |
Returns the absolute path to the IBY/OBY if it was found, otherwise a blank string. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
131 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
132 |
for component in iby_dict.keys(): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
133 |
# Map the file names for each component IBY file to a matching |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
134 |
# file name under the export directory, if it exists, otherwise |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
135 |
# keep the existing name for now - it might be matched later. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
136 |
file_names = map(lambda x: x.lower(), file_names) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
137 |
component_ibys = map(lambda x: os.path.basename(x).lower() in file_names \ |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
138 |
and os.path.join(dir_name, os.path.basename(x)) \ |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
139 |
or x, \ |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
140 |
iby_dict[component]) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
141 |
iby_dict[component] = component_ibys |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
142 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
143 |
def write_oby(out_path, iby_map, input_path, include_root): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
144 |
"""Write an OBY file to include the required IBY and OBY files for this |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
145 |
ROM specification, given by iby_map. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
146 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
147 |
out_file = None |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
148 |
try: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
149 |
out_file = open(out_path, 'w') |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
150 |
except IOError, e: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
151 |
logging.critical('Unable to write OBY file: %s' % repr(e)) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
152 |
exit(1) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
153 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
154 |
# Write the header with the input file name included |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
155 |
out_file.write(_OBY_HEADER % (input_path, )) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
156 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
157 |
exports = filter(lambda x: len(iby_map[x]) > 0, iby_map.keys()) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
158 |
no_exports = filter(lambda x: len(iby_map[x]) == 0, iby_map.keys()) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
159 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
160 |
# Write the includes and missing exports |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
161 |
for component in exports: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
162 |
iby_list = iby_map[component] |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
163 |
exported = filter(lambda x: x.startswith(include_root), iby_list) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
164 |
# Need relative paths for include, but os.path.relpath is added |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
165 |
# in Python 2.6, which isn't supported by other Symbian tools |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
166 |
# at present :-( |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
167 |
exported = map(lambda x: x[len(include_root) + 1:], exported) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
168 |
exported.sort() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
169 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
170 |
missing = filter(lambda x: not x.startswith(include_root), iby_list) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
171 |
missing = map(lambda x: os.path.basename(x), missing) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
172 |
missing.sort() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
173 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
174 |
# Write the IBY file includes for this component |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
175 |
out_file.write(_OBY_INCLUDE % (component, '\n'.join([_INCLUDE_TEMPLATE % (iby, ) for iby in exported]), )) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
176 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
177 |
# Write the missing IBY reports |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
178 |
if len(missing) > 0: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
179 |
out_file.write(_OBY_UNRESOLVED % ('\n'.join(['// %s' % (missed, ) for missed in missing]), )) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
180 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
181 |
# Write report for the IBY that appear not to export any ROM include files |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
182 |
out_file.write(_OBY_NO_EXPORTS % ('\n'.join(['// %s' % (path,) for path in no_exports]), )) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
183 |
out_file.close() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
184 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
185 |
# Main |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
186 |
if __name__ == '__main__': |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
187 |
# Options config |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
188 |
parser = OptionParser() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
189 |
parser.set_description(__doc__) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
190 |
parser.add_option('-r', '--report', dest='report_path', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
191 |
help='File name for the report generated by get_deps.py', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
192 |
metavar='INPUT_FILE', default='dependencies.txt') |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
193 |
parser.add_option('-o', '--output', dest='output_file', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
194 |
help='OBY ouput file to write to.', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
195 |
metavar='OUT_FILE', default='generated.oby') |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
196 |
parser.add_option('-i', '--include_root', dest='include_root', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
197 |
help='Environment ROM inlcude root.', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
198 |
metavar='INCLUDE_ROOT', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
199 |
default=os.path.sep.join(['epoc32', 'rom'])) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
200 |
(options, args) = parser.parse_args() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
201 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
202 |
# Read the report and get a list of bld.inf files, then convert to |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
203 |
# a dictionary of bld_inf -> [IBY file list] mappings. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
204 |
bld_infs = bld_inf_list(options.report_path) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
205 |
bld_iby_map = rom_file_list(bld_infs) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
206 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
207 |
# Walk the include tree to find the exported IBYs. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
208 |
os.path.walk(options.include_root, iby_map, bld_iby_map) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
209 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
210 |
# Write the OBY file |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
211 |
write_oby(options.output_file, bld_iby_map, options.report_path, options.include_root) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
212 |