Skip to content

Commit cde3208

Browse files
timfelabdelberni
authored andcommitted
Avoid updates to FrozenModules.java when just newlines change away from unix
(cherry picked from commit ba017ce)
1 parent e517dba commit cde3208

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

graalpython/com.oracle.graal.python.frozen/freeze_modules.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,19 +589,27 @@ def write_frozen_module_file(file, modules):
589589
if os.path.exists(file):
590590
with open(file, "r", encoding="utf-8", newline=os.linesep) as f:
591591
content = f.read()
592+
if os.linesep != "\n":
593+
if content.replace(os.linesep, "\n") == content:
594+
# Windows file has Unix line endings
595+
linesep = "\n"
596+
else:
597+
linesep = os.linesep
598+
else:
599+
linesep = "\n"
592600
stat_result = os.stat(file)
593601
atime, mtime = stat_result.st_atime, stat_result.st_mtime
594602
else:
595603
content = None
596604
os.makedirs(os.path.dirname(file), exist_ok=True)
597-
with open(file, "w", encoding="utf-8", newline=os.linesep) as out_file:
605+
with open(file, "w", encoding="utf-8", newline=linesep) as out_file:
598606
out_file.write(FROZEN_MODULES_HEADER)
599607
out_file.write("\n\n")
600608
write_frozen_modules_map(out_file, modules)
601609
out_file.write("\n")
602610
write_frozen_lookup(out_file, modules)
603611
out_file.write("}\n")
604-
with open(file, "r", encoding="utf-8", newline=os.linesep) as f:
612+
with open(file, "r", encoding="utf-8", newline=linesep) as f:
605613
new_content = f.read()
606614
if new_content == content:
607615
# set mtime to the old one, if we didn't change anything

0 commit comments

Comments
 (0)