Skip to content

Always treat host FS as case-insensitive to produce deterministic system libraries regardless of OS #23426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading