Debian Codegraph @

docs/dev/python-integration

raw
1 Notes from Peter:
2
3 Python scripts inside .cocci files:
4 ### Issue 1
5 ### $ spatch file-path-error.cocci test1.c
6
7 Recently I needed to extract the path from the .cocci from the python script
8 for including a Python file using import. I needed to do something like:
9
10 source_dir = abspath(dirname(cocci.cocci_file))
11
12 This returns the directory correctly, but the Python way of doing it would
13 be something like:
14
15 source_dir = abspath(dirname(__file__))
16
17 Similar issue, maybe related issue, happens when there is an error on the
18 Python script. On the example below File contains "<string>", instead of
19 the path to the .cocci file
20
21 [peter@hp-peter linux]$ spatch /tmp/test777.cocci .
22 init_defs_builtins: /usr/local/lib/coccinelle/standard.h
23 HANDLING: ./net/mac802154/tx.c
24 Traceback (most recent call last):
25 File "<string>", line 3, in <module>
26 NameError: name '__file__' is not defined
27 while running simple python string:
28 from coccinelle import *
29
30 print __file__
31 :
32 Failure in rule starting on line 6
33 Fatal error: exception Yes_pycocci.Pycocciexception
34
35
36
37 ### Issue 2
38 ### $ spatch -j 2 file-path-error.cocci .
39
40 When using -j option python script errors are not displayed, instead,
41 spatch only reports:
42
43 [Parmap]: aborting due to exception on core 19: Yes_pycocci.Pycocciexception
44
45 This is a problem as using only one core can lead to a long time to reach
46 the corner case that is causing the error on the script