ninja: Always use RawFilename for unity sources and deps

The use of has_dir_part is a terrible back that we need to move away
from. This will eventually be fixed by always using File() objects
everywhere. For now, this is needed for unity builds to work.
pull/938/head
Nirbheek Chauhan 8 years ago
parent 6f4406928b
commit 8bee336e2a
  1. 33
      mesonbuild/backend/ninjabackend.py

@ -329,13 +329,14 @@ int dummy;
generated_source_files = [] generated_source_files = []
for rel_src, gensrc in generated_sources.items(): for rel_src, gensrc in generated_sources.items():
generated_output_sources.append(rel_src) generated_output_sources.append(rel_src)
raw_src = RawFilename(rel_src)
if self.environment.is_source(rel_src) and not self.environment.is_header(rel_src): if self.environment.is_source(rel_src) and not self.environment.is_header(rel_src):
if is_unity: if is_unity:
unity_deps.append(rel_src) unity_deps.append(raw_src)
abs_src = os.path.join(self.environment.get_build_dir(), rel_src) abs_src = os.path.join(self.environment.get_build_dir(), rel_src)
unity_src.append(abs_src) unity_src.append(abs_src)
else: else:
generated_source_files.append(RawFilename(rel_src)) generated_source_files.append(raw_src)
elif self.environment.is_object(rel_src): elif self.environment.is_object(rel_src):
obj_list.append(rel_src) obj_list.append(rel_src)
elif self.environment.is_library(rel_src): elif self.environment.is_library(rel_src):
@ -344,7 +345,7 @@ int dummy;
# Assume anything not specifically a source file is a header. This is because # Assume anything not specifically a source file is a header. This is because
# people generate files with weird suffixes (.inc, .fh) that they then include # people generate files with weird suffixes (.inc, .fh) that they then include
# in their source files. # in their source files.
header_deps.append(RawFilename(rel_src)) header_deps.append(raw_src)
# These are the generated source files that need to be built for use by # These are the generated source files that need to be built for use by
# this target. We create the Ninja build file elements for this here # this target. We create the Ninja build file elements for this here
# because we need `header_deps` to be fully generated in the above loop. # because we need `header_deps` to be fully generated in the above loop.
@ -356,10 +357,11 @@ int dummy;
# sources. This can be extended to other $LANG->C compilers later if # sources. This can be extended to other $LANG->C compilers later if
# necessary. This needs to be separate for at least Vala # necessary. This needs to be separate for at least Vala
for src in vala_generated_sources: for src in vala_generated_sources:
raw_src = RawFilename(src)
src_list.append(src) src_list.append(src)
if is_unity: if is_unity:
unity_src.append(os.path.join(self.environment.get_build_dir(), src)) unity_src.append(os.path.join(self.environment.get_build_dir(), src))
header_deps.append(src) header_deps.append(raw_src)
else: else:
# Generated targets are ordered deps because the must exist # Generated targets are ordered deps because the must exist
# before the sources compiling them are used. After the first # before the sources compiling them are used. After the first
@ -367,12 +369,12 @@ int dummy;
# This should work in all cases. If it does not, then just # This should work in all cases. If it does not, then just
# move them from orderdeps to proper deps. # move them from orderdeps to proper deps.
if self.environment.is_header(src): if self.environment.is_header(src):
header_deps.append(src) header_deps.append(raw_src)
else: else:
# Passing 'vala' here signifies that we want the compile # Passing 'vala' here signifies that we want the compile
# arguments to be specialized for C code generated by # arguments to be specialized for C code generated by
# valac. For instance, no warnings should be emitted. # valac. For instance, no warnings should be emitted.
obj_list.append(self.generate_single_compile(target, outfile, src, 'vala', [], header_deps)) obj_list.append(self.generate_single_compile(target, outfile, raw_src, 'vala', [], header_deps))
# Generate compile targets for all the pre-existing sources for this target # Generate compile targets for all the pre-existing sources for this target
for f, src in target_sources.items(): for f, src in target_sources.items():
if not self.environment.is_header(src): if not self.environment.is_header(src):
@ -386,7 +388,7 @@ int dummy;
obj_list += self.flatten_object_list(target) obj_list += self.flatten_object_list(target)
if is_unity: if is_unity:
for src in self.generate_unity_files(target, unity_src): for src in self.generate_unity_files(target, unity_src):
obj_list.append(self.generate_single_compile(target, outfile, src, True, unity_deps + header_deps)) obj_list.append(self.generate_single_compile(target, outfile, RawFilename(src), True, unity_deps + header_deps))
linker = self.determine_linker(target, src_list + generated_output_sources) linker = self.determine_linker(target, src_list + generated_output_sources)
elem = self.generate_link(target, outfile, outname, obj_list, linker, pch_objects) elem = self.generate_link(target, outfile, outname, obj_list, linker, pch_objects)
self.generate_shlib_aliases(target, self.get_target_dir(target)) self.generate_shlib_aliases(target, self.get_target_dir(target))
@ -1670,10 +1672,10 @@ rule FORTRAN_DEP_HACK
""" """
Compiles only C/C++ and ObjC/ObjC++ sources Compiles only C/C++ and ObjC/ObjC++ sources
""" """
if(isinstance(src, str) and src.endswith('.h')): if isinstance(src, str) and src.endswith('.h'):
raise RuntimeError('Fug') raise AssertionError('BUG: sources should not contain headers')
if isinstance(src, RawFilename) and src.fname.endswith('.h'): if isinstance(src, RawFilename) and src.fname.endswith('.h'):
raise RuntimeError('Fug') raise AssertionError('BUG: sources should not contain headers')
extra_orderdeps = [] extra_orderdeps = []
compiler = self.get_compiler_for_source(src, target.is_cross) compiler = self.get_compiler_for_source(src, target.is_cross)
commands = [] commands = []
@ -1716,12 +1718,12 @@ rule FORTRAN_DEP_HACK
break break
if isinstance(src, RawFilename): if isinstance(src, RawFilename):
rel_src = src.fname rel_src = src.fname
elif is_generated: if os.path.isabs(src.fname):
if self.has_dir_part(src): abs_src = src.fname
rel_src = src
else: else:
rel_src = os.path.join(self.get_target_private_dir(target), src) abs_src = os.path.join(self.environment.get_build_dir(), src.fname)
abs_src = os.path.join(self.environment.get_source_dir(), rel_src) elif is_generated:
raise AssertionError('BUG: broken generated source file handling for {!r}'.format(src))
else: else:
if isinstance(src, File): if isinstance(src, File):
rel_src = src.rel_to_builddir(self.build_to_src) rel_src = src.rel_to_builddir(self.build_to_src)
@ -1805,6 +1807,7 @@ rule FORTRAN_DEP_HACK
return rel_obj return rel_obj
def has_dir_part(self, fname): def has_dir_part(self, fname):
# FIXME FIXME: The usage of this is a terrible and unreliable hack
return '/' in fname or '\\' in fname return '/' in fname or '\\' in fname
# Fortran is a bit weird (again). When you link against a library, just compiling a source file # Fortran is a bit weird (again). When you link against a library, just compiling a source file

Loading…
Cancel
Save