Skip to content

Commit

Permalink
Always treat host FS as case-insensitive to produce deterministic sys…
Browse files Browse the repository at this point in the history
…tem libraries regardless of OS (#23426)

Fixes #23379
  • Loading branch information
eagleoflqj authored Jan 16, 2025
1 parent a2ab73a commit 186cae3
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust
suffix = shared.suffix(libname)
build_dir = os.path.dirname(filename)

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


def is_case_insensitive(path):
"""Returns True if the filesystem at `path` is case insensitive."""
utils.write_file(os.path.join(path, 'test_file'), '')
case_insensitive = os.path.exists(os.path.join(path, 'TEST_FILE'))
os.remove(os.path.join(path, 'test_file'))
return case_insensitive


class Library:
"""
`Library` is the base class of all system libraries.
Expand Down Expand Up @@ -490,7 +480,6 @@ def build_objects(self, build_dir):
commands = []
objects = set()
cflags = self.get_cflags()
case_insensitive = is_case_insensitive(build_dir)
for src in self.get_files():
ext = shared.suffix(src)
if ext in {'.s', '.S', '.c'}:
Expand All @@ -507,15 +496,12 @@ def build_objects(self, build_dir):
cmd += cflags
cmd = self.customize_build_cmd(cmd, src)

object_basename = shared.unsuffixed_basename(src)
if case_insensitive:
object_basename = object_basename.lower()
object_basename = shared.unsuffixed_basename(src).lower()
o = os.path.join(build_dir, object_basename + '.o')
if o in objects:
# If we have seen a file with the same name before, we are on a case-insensitive
# filesystem and need a separate command to compile this file with a
# custom unique output object filename, as batch compile doesn't allow
# such customization.
# If we have seen a file with the same name before, we need a separate
# command to compile this file with a custom unique output object
# filename, as batch compile doesn't allow such customization.
#
# This is needed to handle, for example, _exit.o and _Exit.o.
object_uuid = 0
Expand All @@ -530,6 +516,8 @@ def build_objects(self, build_dir):
src = os.path.relpath(src, build_dir)
src = utils.normalize_path(src)
batches.setdefault(tuple(cmd), []).append(src)
# No -o in command, use original file name.
o = os.path.join(build_dir, shared.unsuffixed_basename(src) + '.o')
else:
commands.append(cmd + [src, '-o', o])
objects.add(o)
Expand Down

0 comments on commit 186cae3

Please sign in to comment.