Skip to content

Commit 186cae3

Browse files
authored
Always treat host FS as case-insensitive to produce deterministic system libraries regardless of OS (#23426)
Fixes #23379
1 parent a2ab73a commit 186cae3

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

tools/system_libs.py

+11-23
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust
219219
suffix = shared.suffix(libname)
220220
build_dir = os.path.dirname(filename)
221221

222-
case_insensitive = is_case_insensitive(os.path.dirname(filename))
223222
if suffix == '.o':
224223
assert len(input_files) == 1
225224
input_file = escape_ninja_path(input_files[0])
@@ -229,12 +228,11 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust
229228
else:
230229
objects = []
231230
for src in input_files:
232-
# Resolve duplicates by appending unique.
233-
# This is needed on case insensitive filesystem to handle,
234-
# for example, _exit.o and _Exit.o.
235-
object_basename = shared.unsuffixed_basename(src)
236-
if case_insensitive:
237-
object_basename = object_basename.lower()
231+
# Resolve duplicates by appending unique. This is needed on case
232+
# insensitive filesystem to handle, for example, _exit.o and _Exit.o.
233+
# This is done even on case sensitive filesystem so that builds are
234+
# reproducible across platforms.
235+
object_basename = shared.unsuffixed_basename(src).lower()
238236
o = os.path.join(build_dir, object_basename + '.o')
239237
object_uuid = 0
240238
# Find a unique basename
@@ -270,14 +268,6 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust
270268
ensure_target_in_ninja_file(get_top_level_ninja_file(), f'subninja {escape_ninja_path(filename)}')
271269

272270

273-
def is_case_insensitive(path):
274-
"""Returns True if the filesystem at `path` is case insensitive."""
275-
utils.write_file(os.path.join(path, 'test_file'), '')
276-
case_insensitive = os.path.exists(os.path.join(path, 'TEST_FILE'))
277-
os.remove(os.path.join(path, 'test_file'))
278-
return case_insensitive
279-
280-
281271
class Library:
282272
"""
283273
`Library` is the base class of all system libraries.
@@ -490,7 +480,6 @@ def build_objects(self, build_dir):
490480
commands = []
491481
objects = set()
492482
cflags = self.get_cflags()
493-
case_insensitive = is_case_insensitive(build_dir)
494483
for src in self.get_files():
495484
ext = shared.suffix(src)
496485
if ext in {'.s', '.S', '.c'}:
@@ -507,15 +496,12 @@ def build_objects(self, build_dir):
507496
cmd += cflags
508497
cmd = self.customize_build_cmd(cmd, src)
509498

510-
object_basename = shared.unsuffixed_basename(src)
511-
if case_insensitive:
512-
object_basename = object_basename.lower()
499+
object_basename = shared.unsuffixed_basename(src).lower()
513500
o = os.path.join(build_dir, object_basename + '.o')
514501
if o in objects:
515-
# If we have seen a file with the same name before, we are on a case-insensitive
516-
# filesystem and need a separate command to compile this file with a
517-
# custom unique output object filename, as batch compile doesn't allow
518-
# such customization.
502+
# If we have seen a file with the same name before, we need a separate
503+
# command to compile this file with a custom unique output object
504+
# filename, as batch compile doesn't allow such customization.
519505
#
520506
# This is needed to handle, for example, _exit.o and _Exit.o.
521507
object_uuid = 0
@@ -530,6 +516,8 @@ def build_objects(self, build_dir):
530516
src = os.path.relpath(src, build_dir)
531517
src = utils.normalize_path(src)
532518
batches.setdefault(tuple(cmd), []).append(src)
519+
# No -o in command, use original file name.
520+
o = os.path.join(build_dir, shared.unsuffixed_basename(src) + '.o')
533521
else:
534522
commands.append(cmd + [src, '-o', o])
535523
objects.add(o)

0 commit comments

Comments
 (0)