diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index 795a5b4..a3bc846 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -172,7 +172,7 @@ def main(): for fname, diff in zip(patch_files, diffs): if fname and diff: print(f"# {fname}") - print("".join(diff), end="") + print("\n".join(diff)) else: with open(spec_file, "w") as fobj: fobj.write(spec_contents) @@ -180,7 +180,7 @@ def main(): for fname, diff in zip(patch_files, diffs): if fname and diff: with open(fname, "w") as fobj: - fobj.writelines(diff) + fobj.write("\n".join(diff)) log.success(f"Generated: {fobj.name}") diff --git a/rust2rpm/crate.py b/rust2rpm/crate.py index 139f0a4..98ca6d9 100644 --- a/rust2rpm/crate.py +++ b/rust2rpm/crate.py @@ -149,6 +149,16 @@ def guess_local_project_name_from_path(project: str) -> str: return name +@contextlib.contextmanager +def toml_temp_copy(toml_path: str): + with tempfile.TemporaryDirectory() as temp_dir: + temp_path = f"{temp_dir}/Cargo.toml" + with open(temp_path, "w") as file: + with open(toml_path) as orig: + file.write(orig.read()) + yield temp_path + + def process_project_local( project: str, patch: bool, patch_foreign: bool ) -> tuple[str, tuple[Optional[list[str]], Optional[list[str]]], Metadata, list[str], list[str]]: @@ -174,7 +184,9 @@ def process_project_local( package = metadata.packages[0] name = package.name features = package.get_feature_names() - diffs = make_patches(name, package.version, patch, patch_foreign, toml_path, features) + + with toml_temp_copy(toml_path) as temp_toml: + diffs = make_patches(name, package.version, patch, patch_foreign, temp_toml, features) # ensure metadata is up-to-date with changes from patches metadata = Metadata.from_cargo(toml_path) diff --git a/rust2rpm/patching.py b/rust2rpm/patching.py index ea25dfa..ce985f4 100644 --- a/rust2rpm/patching.py +++ b/rust2rpm/patching.py @@ -61,6 +61,7 @@ def make_diff_from_lines( tofile=diff_path, fromfiledate=mtime_before, tofiledate=mtime_after, + lineterm="", ) )