diff options
Diffstat (limited to 'meta/recipes-devtools/python/python/get_module_deps2.py')
-rw-r--r-- | meta/recipes-devtools/python/python/get_module_deps2.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/meta/recipes-devtools/python/python/get_module_deps2.py b/meta/recipes-devtools/python/python/get_module_deps2.py new file mode 100644 index 0000000000..73e7c6f6dc --- /dev/null +++ b/meta/recipes-devtools/python/python/get_module_deps2.py | |||
@@ -0,0 +1,112 @@ | |||
1 | # This script is launched on separate task for each python module | ||
2 | # It checks for dependencies for that specific module and prints | ||
3 | # them out, the output of this execution will have all dependencies | ||
4 | # for a specific module, which will be parsed an dealt on create_manifest.py | ||
5 | # | ||
6 | # Author: Alejandro Enedino Hernandez Samaniego "aehs29" <aehs29@gmail.com> | ||
7 | |||
8 | |||
9 | # We can get a log per module, for all the dependencies that were found, but its messy. | ||
10 | debug=False | ||
11 | |||
12 | import sys | ||
13 | |||
14 | # We can get a list of the modules which are currently required to run python | ||
15 | # so we run python-core and get its modules, we then import what we need | ||
16 | # and check what modules are currently running, if we substract them from the | ||
17 | # modules we had initially, we get the dependencies for the module we imported. | ||
18 | |||
19 | # We use importlib to achieve this, so we also need to know what modules importlib needs | ||
20 | import importlib | ||
21 | |||
22 | core_deps=set(sys.modules) | ||
23 | |||
24 | def fix_path(dep_path): | ||
25 | import os | ||
26 | # We DONT want the path on our HOST system | ||
27 | pivot='recipe-sysroot-native' | ||
28 | dep_path=dep_path[dep_path.find(pivot)+len(pivot):] | ||
29 | |||
30 | if '/usr/bin' in dep_path: | ||
31 | dep_path = dep_path.replace('/usr/bin''${bindir}') | ||
32 | |||
33 | # Handle multilib, is there a better way? | ||
34 | if '/usr/lib32' in dep_path: | ||
35 | dep_path = dep_path.replace('/usr/lib32','${libdir}') | ||
36 | if '/usr/lib64' in dep_path: | ||
37 | dep_path = dep_path.replace('/usr/lib64','${libdir}') | ||
38 | if '/usr/lib' in dep_path: | ||
39 | dep_path = dep_path.replace('/usr/lib','${libdir}') | ||
40 | if '/usr/include' in dep_path: | ||
41 | dep_path = dep_path.replace('/usr/include','${includedir}') | ||
42 | if '__init__.' in dep_path: | ||
43 | dep_path = os.path.split(dep_path)[0] | ||
44 | |||
45 | # If a *.pyc file was imported, we replace it with *.py (since we deal with PYCs on create_manifest) | ||
46 | if '.pyc' in dep_path: | ||
47 | dep_path = dep_path.replace('.pyc','.py') | ||
48 | |||
49 | return dep_path | ||
50 | |||
51 | # Module to import was passed as an argument | ||
52 | current_module = str(sys.argv[1]).rstrip() | ||
53 | if(debug==True): | ||
54 | log = open('log_%s' % current_module,'w') | ||
55 | log.write('Module %s generated the following dependencies:\n' % current_module) | ||
56 | try: | ||
57 | importlib.import_module('%s' % current_module) | ||
58 | except ImportError as e: | ||
59 | if (debug==True): | ||
60 | log.write('Module was not found') | ||
61 | pass | ||
62 | |||
63 | |||
64 | # Get current module dependencies, dif will contain a list of specific deps for this module | ||
65 | module_deps=set(sys.modules) | ||
66 | |||
67 | # We handle the core package (1st pass on create_manifest.py) as a special case | ||
68 | if current_module == 'python-core-package': | ||
69 | dif = core_deps | ||
70 | else: | ||
71 | dif = module_deps-core_deps | ||
72 | |||
73 | |||
74 | # Check where each dependency came from | ||
75 | for item in dif: | ||
76 | dep_path='' | ||
77 | try: | ||
78 | if (debug==True): | ||
79 | log.write('Calling: sys.modules[' + '%s' % item + '].__file__\n') | ||
80 | dep_path = sys.modules['%s' % item].__file__ | ||
81 | except AttributeError as e: | ||
82 | # Deals with thread (builtin module) not having __file__ attribute | ||
83 | if debug==True: | ||
84 | log.write(item + ' ') | ||
85 | log.write(str(e)) | ||
86 | log.write('\n') | ||
87 | pass | ||
88 | except NameError as e: | ||
89 | # Deals with NameError: name 'dep_path' is not defined | ||
90 | # because module is not found (wasn't compiled?), e.g. bddsm | ||
91 | if (debug==True): | ||
92 | log.write(item+' ') | ||
93 | log.write(str(e)) | ||
94 | pass | ||
95 | |||
96 | # Site-customize is a special case since we (OpenEmbedded) put it there manually | ||
97 | if 'sitecustomize' in dep_path: | ||
98 | dep_path = '${libdir}/python2.7/sitecustomize.py' | ||
99 | # Prints out result, which is what will be used by create_manifest | ||
100 | print (dep_path) | ||
101 | continue | ||
102 | |||
103 | dep_path = fix_path(dep_path) | ||
104 | |||
105 | if (debug==True): | ||
106 | log.write(dep_path+'\n') | ||
107 | |||
108 | # Prints out result, which is what will be used by create_manifest | ||
109 | print (dep_path) | ||
110 | |||
111 | if debug==True: | ||
112 | log.close() | ||