|
16 | 16 | from misc.utility.color import print_error, print_info, print_warning |
17 | 17 |
|
18 | 18 | # Get the "Godot" folder name ahead of time |
19 | | -base_folder_path = str(os.path.abspath(Path(__file__).parent)) + "/" |
20 | | -base_folder_only = os.path.basename(os.path.normpath(base_folder_path)) |
| 19 | +base_folder = Path(__file__).resolve().parent |
21 | 20 |
|
22 | 21 | compiler_version_cache = None |
23 | 22 |
|
@@ -83,6 +82,29 @@ def add_source_files(self, sources, files, allow_gen=False): |
83 | 82 | return True |
84 | 83 |
|
85 | 84 |
|
| 85 | +def redirect_emitter(target, source, env): |
| 86 | + """ |
| 87 | + Emitter to automatically redirect object/library build files to the `bin/obj` directory, |
| 88 | + retaining subfolder structure. External build files will attempt to retain subfolder |
| 89 | + structure relative to their environment's parent directory, sorted under `bin/obj/external`. |
| 90 | + If `redirect_build_objects` is `False`, or an external build file isn't relative to the |
| 91 | + passed environment, this emitter does nothing. |
| 92 | + """ |
| 93 | + if not env["redirect_build_objects"]: |
| 94 | + return target, source |
| 95 | + |
| 96 | + redirected_targets = [] |
| 97 | + for item in target: |
| 98 | + if base_folder in (path := Path(item.get_abspath()).resolve()).parents: |
| 99 | + item = env.File(f"#bin/obj/{path.relative_to(base_folder)}") |
| 100 | + elif (alt_base := Path(env.Dir(".").get_abspath()).resolve().parent) in path.parents: |
| 101 | + item = env.File(f"#bin/obj/external/{path.relative_to(alt_base)}") |
| 102 | + else: |
| 103 | + print_warning(f'Failed to redirect "{path}"') |
| 104 | + redirected_targets.append(item) |
| 105 | + return redirected_targets, source |
| 106 | + |
| 107 | + |
86 | 108 | def disable_warnings(self): |
87 | 109 | # 'self' is the environment |
88 | 110 | if self.msvc and not using_clang(self): |
@@ -150,7 +172,7 @@ def get_version_info(module_version_string="", silent=False): |
150 | 172 |
|
151 | 173 |
|
152 | 174 | def get_git_info(): |
153 | | - os.chdir(base_folder_path) |
| 175 | + os.chdir(base_folder) |
154 | 176 |
|
155 | 177 | # Parse Git hash if we're in a Git repo. |
156 | 178 | git_hash = "" |
@@ -775,7 +797,7 @@ def show_progress(env): |
775 | 797 | if env["ninja"]: |
776 | 798 | return |
777 | 799 |
|
778 | | - NODE_COUNT_FILENAME = f"{base_folder_path}.scons_node_count" |
| 800 | + NODE_COUNT_FILENAME = base_folder / ".scons_node_count" |
779 | 801 |
|
780 | 802 | class ShowProgress: |
781 | 803 | def __init__(self): |
|
0 commit comments