diff options
author | Koen Kooi <koen@dominion.thruhere.net> | 2011-10-14 11:51:42 +0200 |
---|---|---|
committer | Koen Kooi <koen@dominion.thruhere.net> | 2011-10-14 14:26:33 +0200 |
commit | b69e8206a71f3700b1b014973ef30f1f983f8aea (patch) | |
tree | 150112bb2b2b8b14bf2f947ccd47dc82cecdd2fe /contrib | |
parent | d790211484a789bcbe3c752733ea129c5653d5aa (diff) | |
download | meta-openembedded-b69e8206a71f3700b1b014973ef30f1f983f8aea.tar.gz |
contrib: import pw-am.sh and oe-stylize from OE classic
Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/oe-stylize.py | 405 | ||||
-rwxr-xr-x | contrib/pw-am.sh | 15 |
2 files changed, 420 insertions, 0 deletions
diff --git a/contrib/oe-stylize.py b/contrib/oe-stylize.py new file mode 100755 index 000000000..e254b6a25 --- /dev/null +++ b/contrib/oe-stylize.py | |||
@@ -0,0 +1,405 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | """\ | ||
4 | Sanitize a bitbake file following the OpenEmbedded style guidelines, | ||
5 | see http://openembedded.org/wiki/StyleGuide | ||
6 | |||
7 | (C) 2006 Cyril Romain <cyril.romain@gmail.com> | ||
8 | MIT license | ||
9 | |||
10 | TODO: | ||
11 | - add the others OpenEmbedded variables commonly used: | ||
12 | - parse command arguments and print usage on misuse | ||
13 | . prevent giving more than one .bb file in arguments | ||
14 | - write result to a file | ||
15 | - backup the original .bb file | ||
16 | - make a diff and ask confirmation for patching ? | ||
17 | - do not use startswith only: | ||
18 | /!\ startswith('SOMETHING') is not taken into account due to the previous startswith('S'). | ||
19 | - count rule breaks and displays them in the order frequence | ||
20 | """ | ||
21 | |||
22 | import fileinput | ||
23 | import string | ||
24 | import re | ||
25 | |||
26 | __author__ = "Cyril Romain <cyril.romain@gmail.com>" | ||
27 | __version__ = "$Revision: 0.5 $" | ||
28 | |||
29 | # The standard set of variables often found in .bb files in the preferred order | ||
30 | OE_vars = [ | ||
31 | 'DESCRIPTION', | ||
32 | 'AUTHOR', | ||
33 | 'HOMEPAGE', | ||
34 | 'SECTION', | ||
35 | 'LICENSE', | ||
36 | 'LIC_FILES_CHKSUM', | ||
37 | 'DEPENDS', | ||
38 | 'PROVIDES', | ||
39 | 'SRCREV', | ||
40 | 'SRCDATE', | ||
41 | 'PE', | ||
42 | 'PV', | ||
43 | 'PR', | ||
44 | 'INC_PR', | ||
45 | 'SRC_URI', | ||
46 | 'S', | ||
47 | 'GPE_TARBALL_SUFFIX', | ||
48 | 'inherit', | ||
49 | 'EXTRA_', | ||
50 | 'export', | ||
51 | 'do_fetch', | ||
52 | 'do_unpack', | ||
53 | 'do_patch', | ||
54 | 'WORKDIR', | ||
55 | 'acpaths', | ||
56 | 'do_configure', | ||
57 | 'do_compile', | ||
58 | 'do_install', | ||
59 | 'PACKAGES', | ||
60 | 'PACKAGE_ARCH', | ||
61 | 'RDEPENDS', | ||
62 | 'RRECOMMENDS', | ||
63 | 'RSUGGESTS', | ||
64 | 'RPROVIDES', | ||
65 | 'RCONFLICTS', | ||
66 | 'FILES', | ||
67 | 'do_package', | ||
68 | 'do_stage', | ||
69 | 'addhandler', | ||
70 | 'addtask', | ||
71 | 'bindir', | ||
72 | 'headers', | ||
73 | 'include', | ||
74 | 'includedir', | ||
75 | 'python', | ||
76 | 'qtopiadir', | ||
77 | 'pkg_preins', | ||
78 | 'pkg_prerm', | ||
79 | 'pkg_postins', | ||
80 | 'pkg_postrm', | ||
81 | 'require', | ||
82 | 'sbindir', | ||
83 | 'basesysconfdir', | ||
84 | 'sysconfdir', | ||
85 | 'ALLOW_EMPTY', | ||
86 | 'ALTERNATIVE_NAME', | ||
87 | 'ALTERNATIVE_PATH', | ||
88 | 'ALTERNATIVE_LINK', | ||
89 | 'ALTERNATIVE_PRIORITY', | ||
90 | 'ALTNAME', | ||
91 | 'AMD_DRIVER_LABEL', | ||
92 | 'AMD_DRIVER_VERSION', | ||
93 | 'ANGSTROM_EXTRA_INSTALL', | ||
94 | 'APPDESKTOP', | ||
95 | 'APPIMAGE', | ||
96 | 'APPNAME', | ||
97 | 'APPTYPE', | ||
98 | 'APPWEB_BUILD', | ||
99 | 'APPWEB_HOST', | ||
100 | 'AR', | ||
101 | 'ARCH', | ||
102 | 'ARM_INSTRUCTION_SET', | ||
103 | 'ARM_MUTEX', | ||
104 | 'ART_CONFIG', | ||
105 | 'B', | ||
106 | 'BJAM_OPTS', | ||
107 | 'BJAM_TOOLS', | ||
108 | 'BONOBO_HEADERS', | ||
109 | 'BOOTSCRIPTS', | ||
110 | 'BROKEN', | ||
111 | 'BUILD_CPPFLAGS', | ||
112 | 'CFLAGS', | ||
113 | 'CCFLAGS', | ||
114 | 'CMDLINE', | ||
115 | 'COLLIE_MEMORY_SIZE', | ||
116 | 'COMPATIBLE_HOST', | ||
117 | 'COMPATIBLE_MACHINE', | ||
118 | 'COMPILE_HERMES', | ||
119 | 'CONFFILES', | ||
120 | 'CONFLICTS', | ||
121 | 'CORE_EXTRA_D', | ||
122 | 'CORE_PACKAGES_D', | ||
123 | 'CORE_PACKAGES_RD', | ||
124 | 'CPPFLAGS', | ||
125 | 'CVSDATE', | ||
126 | 'CXXFLAGS', | ||
127 | 'DEBIAN_NOAUTONAME', | ||
128 | 'DEBUG_APPS', | ||
129 | 'DEFAULT_PREFERENCE', | ||
130 | 'DB4_CONFIG', | ||
131 | 'EXCLUDE_FROM_SHLIBS', | ||
132 | 'EXCLUDE_FROM_WORLD', | ||
133 | 'FIXEDSRCDATE', | ||
134 | 'GLIBC_ADDONS', | ||
135 | 'GLIBC_EXTRA_OECONF', | ||
136 | 'GNOME_VFS_HEADERS', | ||
137 | 'HEADERS', | ||
138 | 'INHIBIT_DEFAULT_DEPS', | ||
139 | 'INITSCRIPT_PACKAGES', | ||
140 | 'INITSCRIPT_NAME', | ||
141 | 'INITSCRIPT_PARAMS', | ||
142 | 'PACKAGE_INSTALL', | ||
143 | 'KERNEL_IMAGETYPE', | ||
144 | 'KERNEL_IMAGEDEST', | ||
145 | 'KERNEL_OUTPUT', | ||
146 | 'KERNEL_RELEASE', | ||
147 | 'KERNEL_PRIORITY', | ||
148 | 'KERNEL_SOURCE', | ||
149 | 'KERNEL_SUFFIX', | ||
150 | 'KERNEL_VERSION', | ||
151 | 'K_MAJOR', | ||
152 | 'K_MICRO', | ||
153 | 'K_MINOR', | ||
154 | 'HHV', | ||
155 | 'KV', | ||
156 | 'LDFLAGS', | ||
157 | 'LD', | ||
158 | 'LD_SO', | ||
159 | 'LDLIBS', | ||
160 | 'LEAD_SONAME', | ||
161 | 'LIBTOOL', | ||
162 | 'LIBBDB_EXTRA', | ||
163 | 'LIBV', | ||
164 | 'MACHINE_ESSENTIAL_EXTRA_RDEPENDS', | ||
165 | 'MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS', | ||
166 | 'MACHINE_EXTRA_RDEPENDS', | ||
167 | 'MACHINE_EXTRA_RRECOMMENDS', | ||
168 | 'MACHINE_FEATURES', | ||
169 | 'MACHINE_TASKS', | ||
170 | 'MACHINE', | ||
171 | 'MACHTYPE', | ||
172 | 'MAKE_TARGETS', | ||
173 | 'MESSAGEUSER', | ||
174 | 'MESSAGEHOME', | ||
175 | 'MIRRORS', | ||
176 | 'MUTEX', | ||
177 | 'OE_QMAKE_INCDIR_QT', | ||
178 | 'OE_QMAKE_CXXFLAGS', | ||
179 | 'ORBIT_IDL_SRC', | ||
180 | 'PARALLEL_MAKE', | ||
181 | 'PAKCAGE_ARCH', | ||
182 | 'PCMCIA_MANAGER', | ||
183 | 'PKG_BASENAME', | ||
184 | 'PKG', | ||
185 | 'QEMU', | ||
186 | 'QMAKE_PROFILES', | ||
187 | 'QPEDIR', | ||
188 | 'QPF_DESCRIPTION', | ||
189 | 'QPF_PKGPATTERN', | ||
190 | 'QT_CONFIG_FLAGS', | ||
191 | 'QT_LIBRARY', | ||
192 | 'ROOTFS_POSTPROCESS_COMMAND', | ||
193 | 'RREPLACES', | ||
194 | 'TARGET_CFLAGS', | ||
195 | 'TARGET_CPPFLAGS', | ||
196 | 'TARGET_LDFLAGS', | ||
197 | 'UBOOT_MACHINE', | ||
198 | 'UCLIBC_BASE', | ||
199 | 'UCLIBC_PATCHES', | ||
200 | 'VIRTUAL_NAME', | ||
201 | 'XORG_PN', | ||
202 | 'XSERVER', | ||
203 | 'others' | ||
204 | ] | ||
205 | |||
206 | varRegexp = r'^([a-zA-Z_0-9${}-]*)([ \t]*)([+.:]?=[+.]?)([ \t]*)([^\t]+)' | ||
207 | routineRegexp = r'^([a-zA-Z0-9_ ${}-]+?)\(' | ||
208 | |||
209 | # Variables seen in the processed .bb | ||
210 | seen_vars = {} | ||
211 | for v in OE_vars: | ||
212 | seen_vars[v] = [] | ||
213 | |||
214 | # _Format guideline #0_: | ||
215 | # No spaces are allowed at the beginning of lines that define a variable or | ||
216 | # a do_ routine | ||
217 | def respect_rule0(line): | ||
218 | return line.lstrip()==line | ||
219 | def conformTo_rule0(line): | ||
220 | return line.lstrip() | ||
221 | |||
222 | # _Format guideline #1_: | ||
223 | # No spaces are allowed behind the line continuation symbol '\' | ||
224 | def respect_rule1(line): | ||
225 | if line.rstrip().endswith('\\'): | ||
226 | return line.endswith('\\') | ||
227 | else: | ||
228 | return True | ||
229 | def conformTo_rule1(line): | ||
230 | return line.rstrip() | ||
231 | |||
232 | # _Format guideline #2_: | ||
233 | # Tabs should not be used (use spaces instead). | ||
234 | def respect_rule2(line): | ||
235 | return line.count('\t')==0 | ||
236 | def conformTo_rule2(line): | ||
237 | return line.expandtabs() | ||
238 | |||
239 | # _Format guideline #3_: | ||
240 | # Comments inside bb files are allowed using the '#' character at the | ||
241 | # beginning of a line. | ||
242 | def respect_rule3(line): | ||
243 | if line.lstrip().startswith('#'): | ||
244 | return line.startswith('#') | ||
245 | else: | ||
246 | return True | ||
247 | def conformTo_rule3(line): | ||
248 | return line.lstrip() | ||
249 | |||
250 | # _Format guideline #4_: | ||
251 | # Use quotes on the right hand side of assignments FOO = "BAR" | ||
252 | def respect_rule4(line): | ||
253 | r = re.search(varRegexp, line) | ||
254 | if r is not None: | ||
255 | r2 = re.search(r'("?)([^"\\]*)(["\\]?)', r.group(5)) | ||
256 | # do not test for None it because always match | ||
257 | return r2.group(1)=='"' and r2.group(3)!='' | ||
258 | return False | ||
259 | def conformTo_rule4(line): | ||
260 | r = re.search(varRegexp, line) | ||
261 | return ''.join([r.group(1), ' ', r.group(3), ' "', r.group(5), r.group(5).endswith('"') and '' or '"']) | ||
262 | |||
263 | # _Format guideline #5_: | ||
264 | # The correct spacing for a variable is FOO = "BAR". | ||
265 | def respect_rule5(line): | ||
266 | r = re.search(varRegexp, line) | ||
267 | return r is not None and r.group(2)==" " and r.group(4)==" " | ||
268 | def conformTo_rule5(line): | ||
269 | r = re.search(varRegexp, line) | ||
270 | return ''.join([r.group(1), ' ', r.group(3), ' ', r.group(5)]) | ||
271 | |||
272 | # _Format guideline #6_: | ||
273 | # Don't use spaces or tabs on empty lines | ||
274 | def respect_rule6(line): | ||
275 | return not line.isspace() or line=="\n" | ||
276 | def conformTo_rule6(line): | ||
277 | return "" | ||
278 | |||
279 | # _Format guideline #7_: | ||
280 | # Indentation of multiline variables such as SRC_URI is desireable. | ||
281 | def respect_rule7(line): | ||
282 | return True | ||
283 | def conformTo_rule7(line): | ||
284 | return line | ||
285 | |||
286 | rules = ( | ||
287 | (respect_rule0, conformTo_rule0, "No spaces are allowed at the beginning of lines that define a variable or a do_ routine"), | ||
288 | (respect_rule1, conformTo_rule1, "No spaces are allowed behind the line continuation symbol '\\'"), | ||
289 | (respect_rule2, conformTo_rule2, "Tabs should not be used (use spaces instead)"), | ||
290 | (respect_rule3, conformTo_rule3, "Comments inside bb files are allowed using the '#' character at the beginning of a line"), | ||
291 | (respect_rule4, conformTo_rule4, "Use quotes on the right hand side of assignments FOO = \"BAR\""), | ||
292 | (respect_rule5, conformTo_rule5, "The correct spacing for a variable is FOO = \"BAR\""), | ||
293 | (respect_rule6, conformTo_rule6, "Don't use spaces or tabs on empty lines"), | ||
294 | (respect_rule7, conformTo_rule7, "Indentation of multiline variables such as SRC_URI is desireable"), | ||
295 | ) | ||
296 | |||
297 | # Function to check that a line respects a rule. If not, it tries to conform | ||
298 | # the line to the rule. Reminder or Disgression message are dump accordingly. | ||
299 | def follow_rule(i, line): | ||
300 | oldline = line | ||
301 | # if the line does not respect the rule | ||
302 | if not rules[i][0](line): | ||
303 | # try to conform it to the rule | ||
304 | line = rules[i][1](line) | ||
305 | # if the line still does not respect the rule | ||
306 | if not rules[i][0](line): | ||
307 | # this is a rule disgression | ||
308 | print "## Disgression: ", rules[i][2], " in:", oldline | ||
309 | else: | ||
310 | # just remind user about his/her errors | ||
311 | print "## Reminder: ", rules[i][2], " in :", oldline | ||
312 | return line | ||
313 | |||
314 | |||
315 | if __name__ == "__main__": | ||
316 | |||
317 | # -- retrieves the lines of the .bb file -- | ||
318 | lines = [] | ||
319 | for line in fileinput.input(): | ||
320 | # use 'if True' to warn user about all the rule he/she breaks | ||
321 | # use 'if False' to conform to rules{2,1,6} without warnings | ||
322 | if True: | ||
323 | lines.append(line) | ||
324 | else: | ||
325 | # expandtabs on each line so that rule2 is always respected | ||
326 | # rstrip each line so that rule1 is always respected | ||
327 | line = line.expandtabs().rstrip() | ||
328 | # ignore empty lines (or line filled with spaces or tabs only) | ||
329 | # so that rule6 is always respected | ||
330 | if line is not '': | ||
331 | lines.append(line) | ||
332 | |||
333 | # -- parse the file -- | ||
334 | var = "" | ||
335 | in_routine = False | ||
336 | commentBloc = [] | ||
337 | olines = [] | ||
338 | for line in lines: | ||
339 | originalLine = line | ||
340 | # rstrip line to remove line breaks characters | ||
341 | line = line.rstrip() | ||
342 | line = follow_rule(2, line) | ||
343 | line = follow_rule(1, line) | ||
344 | line = follow_rule(6, line) | ||
345 | |||
346 | # ignore empty lines | ||
347 | if line.isspace() or line is '': | ||
348 | # flush comments into the olines | ||
349 | for c in commentBloc: olines.append(c) | ||
350 | commentBloc = [] | ||
351 | continue | ||
352 | |||
353 | if line.startswith('}'): | ||
354 | in_routine=False | ||
355 | keep = line.endswith('\\') or in_routine | ||
356 | |||
357 | # handles commented lines | ||
358 | if line.lstrip().startswith('#'): | ||
359 | # check and follow rule3 if not in a variables or routines | ||
360 | if not in_routine: | ||
361 | line = follow_rule(3, line) | ||
362 | commentBloc.append(line) | ||
363 | continue | ||
364 | |||
365 | if seen_vars.has_key(var): | ||
366 | for c in commentBloc: seen_vars[var].append(c) | ||
367 | commentBloc = [] | ||
368 | seen_vars[var].append(line) | ||
369 | else: | ||
370 | for k in OE_vars: | ||
371 | if line.startswith(k): | ||
372 | var = k | ||
373 | break | ||
374 | if re.match(routineRegexp, line) is not None: | ||
375 | in_routine=True | ||
376 | line = follow_rule(0, line) | ||
377 | elif re.match(varRegexp, line) is not None: | ||
378 | line = follow_rule(0, line) | ||
379 | line = follow_rule(4, line) | ||
380 | line = follow_rule(5, line) | ||
381 | if var == "": | ||
382 | if not in_routine: | ||
383 | print "## Warning: unknown variable/routine \"%s\"" % originalLine.rstrip('\n') | ||
384 | var = 'others' | ||
385 | for c in commentBloc: seen_vars[var].append(c) | ||
386 | commentBloc = [] | ||
387 | seen_vars[var].append(line) | ||
388 | if not keep and not in_routine: var = "" | ||
389 | |||
390 | # -- dump the sanitized .bb file -- | ||
391 | addEmptyLine = False | ||
392 | # write comments that are not related to variables nor routines | ||
393 | for l in commentBloc: olines.append(l) | ||
394 | # write variables and routines | ||
395 | previourVarPrefix = "unknown" | ||
396 | for k in OE_vars: | ||
397 | if k=='SRC_URI': addEmptyLine = True | ||
398 | if seen_vars[k] != []: | ||
399 | if addEmptyLine and not k.startswith(previourVarPrefix): | ||
400 | olines.append("") | ||
401 | for l in seen_vars[k]: | ||
402 | olines.append(l) | ||
403 | previourVarPrefix = k.split('_')[0]=='' and "unknown" or k.split('_')[0] | ||
404 | for line in olines: print line | ||
405 | |||
diff --git a/contrib/pw-am.sh b/contrib/pw-am.sh new file mode 100755 index 000000000..8987eee8e --- /dev/null +++ b/contrib/pw-am.sh | |||
@@ -0,0 +1,15 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # Idea and implementation: Koen Kooi | ||
4 | # Multiple patches support: Marcin Juszkiewicz | ||
5 | # | ||
6 | # This script will fetch an 'mbox' patch from patchwork and git am it | ||
7 | # usage: pw-am.sh <number> | ||
8 | # example: 'pw-am.sh 221' will get the patch from http://patchwork.openembedded.org/patch/221/ | ||
9 | |||
10 | for patchnumber in $@; | ||
11 | do | ||
12 | wget -nv http://patches.openembedded.org/patch/$patchnumber/mbox/ -O pw-am-$patchnumber.patch | ||
13 | git am -s pw-am-$patchnumber.patch | ||
14 | rm pw-am-$patchnumber.patch | ||
15 | done | ||