|
8 | 8 | import enum |
9 | 9 | import functools |
10 | 10 | import glob |
11 | | -import imp |
| 11 | +import importlib |
12 | 12 | import inspect |
13 | 13 | import itertools |
14 | 14 | import json |
@@ -105,7 +105,7 @@ def git_sha(repo_path): |
105 | 105 | consts['header_ext'] = '.h' |
106 | 106 | consts['kernel_module_ext'] = '.ko' |
107 | 107 | consts['obj_ext'] = '.o' |
108 | | -consts['userland_in_exts'] = [ |
| 108 | +consts['build_in_exts'] = [ |
109 | 109 | consts['asm_ext'], |
110 | 110 | consts['c_ext'], |
111 | 111 | consts['cxx_ext'], |
@@ -136,6 +136,32 @@ def git_sha(repo_path): |
136 | 136 | consts['emulator_choices'].add(consts['emulator_short_to_long_dict'][key]) |
137 | 137 | consts['host_arch'] = platform.processor() |
138 | 138 |
|
| 139 | +def import_path(path): |
| 140 | + ''' |
| 141 | + https://stackoverflow.com/questions/2601047/import-a-python-module-without-the-py-extension |
| 142 | + https://stackoverflow.com/questions/31773310/what-does-the-first-argument-of-the-imp-load-source-method-do |
| 143 | + ''' |
| 144 | + module_name = os.path.basename(path).replace('-', '_') |
| 145 | + spec = importlib.util.spec_from_loader( |
| 146 | + module_name, |
| 147 | + importlib.machinery.SourceFileLoader(module_name, path) |
| 148 | + ) |
| 149 | + module = importlib.util.module_from_spec(spec) |
| 150 | + spec.loader.exec_module(module) |
| 151 | + sys.modules[module_name] = module |
| 152 | + return module |
| 153 | + |
| 154 | +def import_path_relative_root(basename): |
| 155 | + return import_path(os.path.join(consts['root_dir'], basename)) |
| 156 | + |
| 157 | +def import_path_main(basename): |
| 158 | + ''' |
| 159 | + Import an object of the Main class of a given file. |
| 160 | +
|
| 161 | + By convention, we call the main object of all our CLI scripts as Main. |
| 162 | + ''' |
| 163 | + return import_path_relative_root(basename).Main() |
| 164 | + |
139 | 165 | class ExitLoop(Exception): |
140 | 166 | pass |
141 | 167 |
|
@@ -905,6 +931,8 @@ def join(*paths): |
905 | 931 | env['source_path'] = source_path |
906 | 932 | break |
907 | 933 | env['image'] = path |
| 934 | + elif env['userland'] is not None: |
| 935 | + env['image'] = self.resolve_userland_executable(env['userland']) |
908 | 936 | else: |
909 | 937 | if env['emulator'] == 'gem5': |
910 | 938 | env['image'] = env['vmlinux'] |
@@ -1084,24 +1112,6 @@ def github_make_request( |
1084 | 1112 | _json = {} |
1085 | 1113 | return _json |
1086 | 1114 |
|
1087 | | - def import_path(self, basename): |
1088 | | - ''' |
1089 | | - https://stackoverflow.com/questions/2601047/import-a-python-module-without-the-py-extension |
1090 | | - https://stackoverflow.com/questions/31773310/what-does-the-first-argument-of-the-imp-load-source-method-do |
1091 | | - ''' |
1092 | | - return imp.load_source( |
1093 | | - basename.replace('-', '_'), |
1094 | | - os.path.join(self.env['root_dir'], basename) |
1095 | | - ) |
1096 | | - |
1097 | | - def import_path_main(self, path): |
1098 | | - ''' |
1099 | | - Import an object of the Main class of a given file. |
1100 | | -
|
1101 | | - By convention, we call the main object of all our CLI scripts as Main. |
1102 | | - ''' |
1103 | | - return self.import_path(path).Main() |
1104 | | - |
1105 | 1115 | def is_arch_supported(self, arch): |
1106 | 1116 | return self.supported_archs is None or arch in self.supported_archs |
1107 | 1117 |
|
@@ -1270,6 +1280,8 @@ def resolve_executable( |
1270 | 1280 |
|
1271 | 1281 | If the input path is a file, add the executable extension automatically. |
1272 | 1282 | ''' |
| 1283 | + if not self.env['dry_run'] and not os.path.exists(in_path): |
| 1284 | + raise Exception('Input path does not exist: ' + in_path) |
1273 | 1285 | if self.is_subpath(in_path, magic_in_dir): |
1274 | 1286 | # Abspath needed to remove the trailing `/.` which makes e.g. rmrf fail. |
1275 | 1287 | out = os.path.abspath(os.path.join( |
|
0 commit comments