diff options
Diffstat (limited to 'meta/recipes-devtools/python/python3/get_module_deps3.py')
| -rw-r--r-- | meta/recipes-devtools/python/python3/get_module_deps3.py | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/meta/recipes-devtools/python/python3/get_module_deps3.py b/meta/recipes-devtools/python/python3/get_module_deps3.py index 6806f23172..1f4c982aed 100644 --- a/meta/recipes-devtools/python/python3/get_module_deps3.py +++ b/meta/recipes-devtools/python/python3/get_module_deps3.py | |||
| @@ -3,14 +3,18 @@ | |||
| 3 | # them out, the output of this execution will have all dependencies | 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 | 4 | # for a specific module, which will be parsed an dealt on create_manifest.py |
| 5 | # | 5 | # |
| 6 | # Author: Alejandro Enedino Hernandez Samaniego "aehs29" <aehs29@gmail.com> | 6 | # Author: Alejandro Enedino Hernandez Samaniego <alejandro at enedino dot org> |
| 7 | 7 | ||
| 8 | # We can get a log per module, for all the dependencies that were found, but its messy. | ||
| 9 | debug=False | ||
| 10 | 8 | ||
| 11 | import sys | 9 | import sys |
| 12 | import os | 10 | import os |
| 13 | 11 | ||
| 12 | # We can get a log per module, for all the dependencies that were found, but its messy. | ||
| 13 | if '-d' in sys.argv: | ||
| 14 | debug = True | ||
| 15 | else: | ||
| 16 | debug = False | ||
| 17 | |||
| 14 | # We can get a list of the modules which are currently required to run python | 18 | # 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 | 19 | # 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 | 20 | # and check what modules are currently running, if we substract them from the |
| @@ -19,13 +23,13 @@ import os | |||
| 19 | # We use importlib to achieve this, so we also need to know what modules importlib needs | 23 | # We use importlib to achieve this, so we also need to know what modules importlib needs |
| 20 | import importlib | 24 | import importlib |
| 21 | 25 | ||
| 22 | core_deps=set(sys.modules) | 26 | core_deps = set(sys.modules) |
| 23 | 27 | ||
| 24 | def fix_path(dep_path): | 28 | def fix_path(dep_path): |
| 25 | import os | 29 | import os |
| 26 | # We DONT want the path on our HOST system | 30 | # We DONT want the path on our HOST system |
| 27 | pivot='recipe-sysroot-native' | 31 | pivot = 'recipe-sysroot-native' |
| 28 | dep_path=dep_path[dep_path.find(pivot)+len(pivot):] | 32 | dep_path = dep_path[dep_path.find(pivot)+len(pivot):] |
| 29 | 33 | ||
| 30 | if '/usr/bin' in dep_path: | 34 | if '/usr/bin' in dep_path: |
| 31 | dep_path = dep_path.replace('/usr/bin''${bindir}') | 35 | dep_path = dep_path.replace('/usr/bin''${bindir}') |
| @@ -46,8 +50,8 @@ def fix_path(dep_path): | |||
| 46 | 50 | ||
| 47 | # Module to import was passed as an argument | 51 | # Module to import was passed as an argument |
| 48 | current_module = str(sys.argv[1]).rstrip() | 52 | current_module = str(sys.argv[1]).rstrip() |
| 49 | if(debug==True): | 53 | if debug == True: |
| 50 | log = open('log_%s' % current_module,'w') | 54 | log = open('temp/log_%s' % current_module.strip('.*'),'w') |
| 51 | log.write('Module %s generated the following dependencies:\n' % current_module) | 55 | log.write('Module %s generated the following dependencies:\n' % current_module) |
| 52 | try: | 56 | try: |
| 53 | m = importlib.import_module(current_module) | 57 | m = importlib.import_module(current_module) |
| @@ -63,13 +67,13 @@ try: | |||
| 63 | except: | 67 | except: |
| 64 | pass # ignore all import or other exceptions raised during import | 68 | pass # ignore all import or other exceptions raised during import |
| 65 | except ImportError as e: | 69 | except ImportError as e: |
| 66 | if (debug==True): | 70 | if debug == True: |
| 67 | log.write('Module was not found') | 71 | log.write('Module was not found\n') |
| 68 | pass | 72 | pass |
| 69 | 73 | ||
| 70 | 74 | ||
| 71 | # Get current module dependencies, dif will contain a list of specific deps for this module | 75 | # Get current module dependencies, dif will contain a list of specific deps for this module |
| 72 | module_deps=set(sys.modules) | 76 | module_deps = set(sys.modules) |
| 73 | 77 | ||
| 74 | # We handle the core package (1st pass on create_manifest.py) as a special case | 78 | # We handle the core package (1st pass on create_manifest.py) as a special case |
| 75 | if current_module == 'python-core-package': | 79 | if current_module == 'python-core-package': |
| @@ -81,14 +85,18 @@ else: | |||
| 81 | 85 | ||
| 82 | # Check where each dependency came from | 86 | # Check where each dependency came from |
| 83 | for item in dif: | 87 | for item in dif: |
| 84 | dep_path='' | 88 | # Main module returns script filename, __main matches mp_main__ as well |
| 89 | if 'main__' in item: | ||
| 90 | continue | ||
| 91 | |||
| 92 | dep_path = '' | ||
| 85 | try: | 93 | try: |
| 86 | if (debug==True): | 94 | if debug == True: |
| 87 | log.write('Calling: sys.modules[' + '%s' % item + '].__file__\n') | 95 | log.write('\nCalling: sys.modules[' + '%s' % item + '].__file__\n') |
| 88 | dep_path = sys.modules['%s' % item].__file__ | 96 | dep_path = sys.modules['%s' % item].__file__ |
| 89 | except AttributeError as e: | 97 | except AttributeError as e: |
| 90 | # Deals with thread (builtin module) not having __file__ attribute | 98 | # Deals with thread (builtin module) not having __file__ attribute |
| 91 | if debug==True: | 99 | if debug == True: |
| 92 | log.write(item + ' ') | 100 | log.write(item + ' ') |
| 93 | log.write(str(e)) | 101 | log.write(str(e)) |
| 94 | log.write('\n') | 102 | log.write('\n') |
| @@ -96,11 +104,16 @@ for item in dif: | |||
| 96 | except NameError as e: | 104 | except NameError as e: |
| 97 | # Deals with NameError: name 'dep_path' is not defined | 105 | # Deals with NameError: name 'dep_path' is not defined |
| 98 | # because module is not found (wasn't compiled?), e.g. bddsm | 106 | # because module is not found (wasn't compiled?), e.g. bddsm |
| 99 | if (debug==True): | 107 | if debug == True: |
| 100 | log.write(item+' ') | 108 | log.write(item+' ') |
| 101 | log.write(str(e)) | 109 | log.write(str(e)) |
| 102 | pass | 110 | pass |
| 103 | 111 | ||
| 112 | if dep_path == '': | ||
| 113 | continue | ||
| 114 | if debug == True: | ||
| 115 | log.write('Dependency path found:\n%s\n' % dep_path) | ||
| 116 | |||
| 104 | # Site-customize is a special case since we (OpenEmbedded) put it there manually | 117 | # Site-customize is a special case since we (OpenEmbedded) put it there manually |
| 105 | if 'sitecustomize' in dep_path: | 118 | if 'sitecustomize' in dep_path: |
| 106 | dep_path = '${libdir}/python${PYTHON_MAJMIN}/sitecustomize.py' | 119 | dep_path = '${libdir}/python${PYTHON_MAJMIN}/sitecustomize.py' |
| @@ -111,52 +124,51 @@ for item in dif: | |||
| 111 | dep_path = fix_path(dep_path) | 124 | dep_path = fix_path(dep_path) |
| 112 | 125 | ||
| 113 | import sysconfig | 126 | import sysconfig |
| 114 | soabi=sysconfig.get_config_var('SOABI') | 127 | soabi = sysconfig.get_config_var('SOABI') |
| 115 | # Check if its a shared library and deconstruct it | 128 | # Check if its a shared library and deconstruct it |
| 116 | if soabi in dep_path: | 129 | if soabi in dep_path: |
| 117 | if (debug==True): | 130 | if debug == True: |
| 118 | log.write('Shared library found in %s' % dep_path) | 131 | log.write('Shared library found in %s\n' % dep_path) |
| 119 | dep_path = dep_path.replace(soabi,'*') | 132 | dep_path = dep_path.replace(soabi,'*') |
| 120 | print (dep_path) | 133 | print (dep_path) |
| 121 | continue | 134 | continue |
| 122 | if "_sysconfigdata" in dep_path: | 135 | if "_sysconfigdata" in dep_path: |
| 123 | dep_path = dep_path.replace(sysconfig._get_sysconfigdata_name(), "_sysconfigdata*") | 136 | dep_path = dep_path.replace(sysconfig._get_sysconfigdata_name(), "_sysconfigdata*") |
| 124 | 137 | ||
| 125 | if (debug==True): | 138 | if debug == True: |
| 126 | log.write(dep_path+'\n') | 139 | log.write(dep_path+'\n') |
| 127 | # Prints out result, which is what will be used by create_manifest | 140 | # Prints out result, which is what will be used by create_manifest |
| 128 | print (dep_path) | 141 | print (dep_path) |
| 129 | 142 | ||
| 130 | 143 | ||
| 131 | import imp | 144 | cpython_tag = sys.implementation.cache_tag |
| 132 | cpython_tag = imp.get_tag() | 145 | cached = '' |
| 133 | cached='' | ||
| 134 | # Theres no naive way to find *.pyc files on python3 | 146 | # Theres no naive way to find *.pyc files on python3 |
| 135 | try: | 147 | try: |
| 136 | if (debug==True): | 148 | if debug == True: |
| 137 | log.write('Calling: sys.modules[' + '%s' % item + '].__cached__\n') | 149 | log.write('\nCalling: sys.modules[' + '%s' % item + '].__cached__\n') |
| 138 | cached = sys.modules['%s' % item].__cached__ | 150 | cached = sys.modules['%s' % item].__cached__ |
| 139 | except AttributeError as e: | 151 | except AttributeError as e: |
| 140 | # Deals with thread (builtin module) not having __cached__ attribute | 152 | # Deals with thread (builtin module) not having __cached__ attribute |
| 141 | if debug==True: | 153 | if debug == True: |
| 142 | log.write(item + ' ') | 154 | log.write(item + ' ') |
| 143 | log.write(str(e)) | 155 | log.write(str(e)) |
| 144 | log.write('\n') | 156 | log.write('\n') |
| 145 | pass | 157 | pass |
| 146 | except NameError as e: | 158 | except NameError as e: |
| 147 | # Deals with NameError: name 'cached' is not defined | 159 | # Deals with NameError: name 'cached' is not defined |
| 148 | if (debug==True): | 160 | if debug == True: |
| 149 | log.write(item+' ') | 161 | log.write(item+' ') |
| 150 | log.write(str(e)) | 162 | log.write(str(e)) |
| 151 | pass | 163 | pass |
| 152 | if cached is not None: | 164 | if cached is not None: |
| 153 | if (debug==True): | 165 | if debug == True: |
| 154 | log.write(cached) | 166 | log.write(cached + '\n') |
| 155 | cached = fix_path(cached) | 167 | cached = fix_path(cached) |
| 156 | cached = cached.replace(cpython_tag,'*') | 168 | cached = cached.replace(cpython_tag,'*') |
| 157 | if "_sysconfigdata" in cached: | 169 | if "_sysconfigdata" in cached: |
| 158 | cached = cached.replace(sysconfig._get_sysconfigdata_name(), "_sysconfigdata*") | 170 | cached = cached.replace(sysconfig._get_sysconfigdata_name(), "_sysconfigdata*") |
| 159 | print (cached) | 171 | print (cached) |
| 160 | 172 | ||
| 161 | if debug==True: | 173 | if debug == True: |
| 162 | log.close() | 174 | log.close() |
