diff --git a/pyro/BuildFacade.py b/pyro/BuildFacade.py index 14c3ffc1..fa0ae2a6 100644 --- a/pyro/BuildFacade.py +++ b/pyro/BuildFacade.py @@ -132,20 +132,14 @@ def try_anonymize(self) -> None: if not scripts and not self.ppj.missing_script_names and not self.ppj.options.no_incremental_build: BuildFacade.log.error('Cannot anonymize compiled scripts because no source scripts were modified') else: + # these are absolute paths. there's no reason to manipulate them. for pex_path in self.ppj.pex_paths: - if self.ppj.options.game_type == 'fo4': - namespace, file_name = PathHelper.nsify(pex_path) - target_path = os.path.join(self.ppj.options.output_path, namespace, file_name) - else: - pex_path = os.path.basename(pex_path) - target_path = os.path.join(self.ppj.options.output_path, pex_path) - - if not os.path.exists(target_path): - BuildFacade.log.error('Cannot locate file to anonymize: "%s"' % target_path) + if not os.path.exists(pex_path): + BuildFacade.log.warn('Cannot locate file to anonymize: "%s"' % pex_path) continue - BuildFacade.log.info('Anonymizing "%s"...' % target_path) - Anonymizer.anonymize_script(target_path) + BuildFacade.log.info('Anonymizing "%s"...' % pex_path) + Anonymizer.anonymize_script(pex_path) def try_pack(self) -> None: """Generates ZIP archive for project""" diff --git a/pyro/PackageManager.py b/pyro/PackageManager.py index 08dd884d..a16980ce 100644 --- a/pyro/PackageManager.py +++ b/pyro/PackageManager.py @@ -24,9 +24,9 @@ def _copy_scripts_to_temp_path(self, psc_paths: list, temp_path: str) -> None: for pex_path in pex_paths: if self.ppj.options.game_type == 'fo4': - namespace, file_name = PathHelper.nsify(pex_path) - target_path = os.path.join(self.ppj.options.output_path, namespace, file_name) - temp_file_path = os.path.join(temp_path, namespace, file_name) + rel_object_name = PathHelper.calculate_relative_object_name(pex_path, self.ppj.import_paths) + target_path = os.path.join(self.ppj.options.output_path, rel_object_name) + temp_file_path = os.path.join(temp_path, rel_object_name) else: target_path = os.path.abspath(pex_path) temp_file_path = os.path.join(temp_path, os.path.basename(pex_path)) diff --git a/pyro/PapyrusProject.py b/pyro/PapyrusProject.py index a60ee42c..1b5a3422 100644 --- a/pyro/PapyrusProject.py +++ b/pyro/PapyrusProject.py @@ -217,11 +217,9 @@ def _get_pex_paths(self) -> list: # build paths to compiled scripts for psc_path in psc_paths: if self.options.game_type == 'fo4': - namespace, file_name = PathHelper.nsify(psc_path) - target_path = os.path.join(self.options.output_path, namespace, file_name.replace('.psc', '.pex')) - else: - target_path = os.path.join(self.options.output_path, psc_path.replace('.psc', '.pex')) + psc_path = PathHelper.calculate_relative_object_name(psc_path, self.import_paths) + target_path = os.path.join(self.options.output_path, psc_path.replace('.psc', '.pex')) pex_paths.append(target_path) return PathHelper.uniqify(pex_paths) @@ -384,8 +382,7 @@ def build_commands(self) -> list: # generate list of commands for psc_path in psc_paths: if self.options.game_type == 'fo4': - namespace, file_name = PathHelper.nsify(psc_path) - psc_path = os.path.join(namespace, file_name) + psc_path = PathHelper.calculate_relative_object_name(psc_path, self.import_paths) arguments.clear() arguments.append_quoted(compiler_path) diff --git a/pyro/PathHelper.py b/pyro/PathHelper.py index ba0e875a..beb89fc3 100644 --- a/pyro/PathHelper.py +++ b/pyro/PathHelper.py @@ -18,10 +18,14 @@ def try_append_abspath(a: str, b: list) -> bool: return False @staticmethod - def nsify(path: str) -> tuple: - """Returns tuple(parent folder, file name) from absolute path""" - parent_folder, file_name = map(lambda x: os.path.basename(x), [os.path.dirname(path), path]) - return parent_folder, file_name + def calculate_relative_object_name(path: str, import_paths: list) -> str: + """Returns import-relative path from absolute path (should be used only for Fallout 4 paths)""" + # reverse the list to find the best import path + for import_path in reversed(import_paths): + if len(path) > len(import_path) and import_path in path: + relative_path = os.path.relpath(path, import_path) + return relative_path + raise ValueError('Cannot build import-relative path from absolute path: "%s"' % path) @staticmethod def uniqify(items: list) -> list: