blob: d8f482c017a0ce2c8593292750d3c30ed02ff5ea [file] [log] [blame]
Rafaël Carré5b4a9b52010-05-31 00:46:04 +00001#!/usr/bin/python
2# -*- coding: utf8 -*-
3# __________ __ ___.
4# Open \______ \ ____ ____ | | _\_ |__ _______ ___
5# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8# \/ \/ \/ \/ \/
9#
10# Copyright © 2010 Rafaël Carré <rafael.carre@gmail>
11#
12# This program is free software; you can redistribute it and/or
13# modify it under the terms of the GNU General Public License
14# as published by the Free Software Foundation; either version 2
15# of the License, or (at your option) any later version.
16#
17# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18# KIND, either express or implied.
19#
20
21# TODO: iram
22
23import sys
24import os
25import re
26import stat
27import fnmatch
28
29
30def percent_diff(old, new):
31 if old == 0:
32 return '?'
33 diff = 100.0*(new-old)/old
34 return format(diff, '+2.2f') + '%'
35
36
37def find_map(dir):
38 dirs = []
39 for file in os.listdir(dir):
40 path = os.path.join(dir, file)
41 if stat.S_ISDIR(os.stat(path).st_mode) != 0:
42 dirs += find_map(path)
43 elif fnmatch.fnmatch(file, '*.map'):
44 dirs += [path]
45 return dirs
46
47
48def rb_version(dir):
49 info = os.path.join(dir, 'rockbox-info.txt')
50 if not os.path.lexists(info):
51 return 'unknown'
52 info = open(info).read()
53 s = re.search('^Version: .*', info, re.MULTILINE)
54 if not s:
55 return 'unknown'
56 return re.sub('^Version: ', '', info[s.start():s.end()])
57
58
59def map_info(map):
60 file = os.path.basename(map)
61 name = file.rsplit('.map', 1)[0]
62
63 # ignore ape-pre map, used to fill IRAM
64 if name == 'ape-pre':
65 return None
66
67 # ignore overlays
68 ovlmap = os.path.join(os.path.dirname(map), name, file)
69 if os.path.lexists(ovlmap):
70 return None
71
72 f = open(map).read() # read map content
73
74 s = re.search('^PLUGIN_RAM *0x(\d|[abcdef])*', f, re.MULTILINE)
Rafaël Carré3bc8fd02010-08-01 15:09:51 +000075 if not s: return (name, 0)
Rafaël Carré5b4a9b52010-05-31 00:46:04 +000076 plugin_start = re.sub('^PLUGIN_RAM *0x0*', '', f[s.start():s.end()])
77
78 s = re.search('^\.pluginend *0x(\d|[abcdef])*', f, re.MULTILINE)
Rafaël Carré3bc8fd02010-08-01 15:09:51 +000079 if not s: return (name, 0)
Rafaël Carré5b4a9b52010-05-31 00:46:04 +000080 plugin_end = re.sub('^\.pluginend *0x0*', '', f[s.start():s.end()])
81
82 size = int(plugin_end, 16) - int(plugin_start, 16)
83 return (name, size)
84
85
86def get_new(oldinfo, newinfo, name):
87 i = 0
88 while i < len(oldinfo) and i < len(newinfo):
89 if newinfo[i][0] == name:
90 return newinfo[i]
91 i += 1
92 return None
93
94
95def compare(olddir, newdir, oldver, newer):
96 oldinfo = []
97 for map in find_map(olddir):
98 info = map_info(map)
99 if info:
100 oldinfo += [info]
101
102 newinfo = []
103 for map in find_map(newdir):
104 info = map_info(map)
105 if info:
106 newinfo += [info]
107
108 oldinfo.sort()
109 newinfo.sort()
110
111 diff = []
112 longest_name = 0
113 for (name, old_size) in oldinfo:
114 new = get_new(oldinfo, newinfo, name)
115 if not new:
116 continue
117 (name, new_size) = new
118 if len(name) > longest_name:
119 longest_name = len(name)
120 diff += [(name, new_size - old_size, old_size)]
121
122 spacelen = (longest_name + 3)
123
124 print(' ' * spacelen + oldver + '\t\t' + newver + '\n')
125
126 for (name, diff, old_size) in diff:
127 space = ' ' * (longest_name - len(name) + 3)
128 new_size = old_size + diff
129 pdiff = percent_diff(old_size, new_size)
130 diff = str(diff)
131 if diff[0] != '-':
132 diff = '+' + diff
133
134 print(name + space + str(old_size) + '\t' + diff + \
135 '\t=\t' + str(new_size) + '\t-->\t' + pdiff)
136
137
138
139
140### main
141
142
143if len(sys.argv) != 3:
144 print('Usage: ' + sys.argv[0] + ' build-old build-new')
145 sys.exit(1)
146
147oldver = rb_version(sys.argv[1])
148newver = rb_version(sys.argv[2])
149
150oldplugindir = sys.argv[1] + '/apps/plugins'
151newplugindir = sys.argv[2] + '/apps/plugins'
Sean Bartellf40bfc92011-06-25 21:32:25 -0400152oldcodecsdir = sys.argv[1] + '/lib/rbcodec/codecs'
153newcodecsdir = sys.argv[2] + '/lib/rbcodec/codecs'
Rafaël Carré5b4a9b52010-05-31 00:46:04 +0000154
155if os.path.lexists(oldplugindir) and os.path.lexists(newplugindir):
156 compare(oldplugindir, newplugindir, oldver, newver)
157
158print('\n\n\n')
159
160if os.path.lexists(oldcodecsdir) and os.path.lexists(newcodecsdir):
161 compare(oldcodecsdir, newcodecsdir, oldver, newver)