Skip to content
Merged
Changes from 2 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
31 changes: 10 additions & 21 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 @@ -232,9 +231,8 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust
# 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()
# Always apply it to produce same libraries on different filesystems.
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 @@ -524,15 +510,18 @@ def build_objects(self, build_dir):
object_uuid += 1
o = os.path.join(build_dir, f'{object_basename}__{object_uuid}.o')
commands.append(cmd + [src, '-o', o])
objects.add(o)
elif batch_inputs:
# Use relative paths to reduce the length of the command line.
# This allows to avoid switching to a response file as often.
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.
objects.add(os.path.join(build_dir, shared.unsuffixed_basename(src) + '.o'))
else:
commands.append(cmd + [src, '-o', o])
objects.add(o)
objects.add(o)

if batch_inputs:
# Choose a chunk size that is large enough to avoid too many subprocesses
Expand Down
Loading