Merge pull request #4860 from nioncode/fixPch

Fix missing PCH dependencies
pull/4907/head
Jussi Pakkanen 6 years ago committed by GitHub
commit 711f73e386
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      mesonbuild/backend/ninjabackend.py
  2. 5
      test cases/common/13 pch/generated/gen_custom.py
  3. 7
      test cases/common/13 pch/generated/gen_generator.py
  4. 1
      test cases/common/13 pch/generated/generated_generator.in
  5. 16
      test cases/common/13 pch/generated/meson.build
  6. 2
      test cases/common/13 pch/generated/pch/prog.h
  7. 5
      test cases/common/13 pch/generated/pch/prog_pch.c
  8. 6
      test cases/common/13 pch/generated/prog.c
  9. 2
      test cases/common/13 pch/meson.build
  10. 1
      test cases/common/13 pch/withIncludeDirectories/include/lib/lib.h
  11. 9
      test cases/common/13 pch/withIncludeDirectories/meson.build
  12. 1
      test cases/common/13 pch/withIncludeDirectories/pch/prog.h
  13. 5
      test cases/common/13 pch/withIncludeDirectories/pch/prog_pch.c
  14. 10
      test cases/common/13 pch/withIncludeDirectories/prog.c

@ -428,12 +428,7 @@ int dummy;
# Generate rules for building the remaining source files in this target
outname = self.get_target_filename(target)
obj_list = []
use_pch = self.environment.coredata.base_options.get('b_pch', False)
is_unity = self.is_unity(target)
if use_pch and target.has_pch():
pch_objects = self.generate_pch(target, outfile)
else:
pch_objects = []
header_deps = []
unity_src = []
unity_deps = [] # Generated sources that must be built before compiling a Unity target.
@ -486,6 +481,12 @@ int dummy;
header_deps=header_deps)
obj_list.append(o)
use_pch = self.environment.coredata.base_options.get('b_pch', False)
if use_pch and target.has_pch():
pch_objects = self.generate_pch(target, outfile, header_deps=header_deps)
else:
pch_objects = []
# Generate compilation targets for C sources generated from Vala
# sources. This can be extended to other $LANG->C compilers later if
# necessary. This needs to be separate for at least Vala
@ -2208,12 +2209,7 @@ rule FORTRAN_DEP_HACK%s
commands += compiler.get_module_outdir_args(self.get_target_private_dir(target))
element = NinjaBuildElement(self.all_outputs, rel_obj, compiler_name, rel_src)
for d in header_deps:
if isinstance(d, File):
d = d.rel_to_builddir(self.build_to_src)
elif not self.has_dir_part(d):
d = os.path.join(self.get_target_private_dir(target), d)
element.add_dep(d)
self.add_header_deps(target, element, header_deps)
for d in extra_deps:
element.add_dep(d)
for d in order_deps:
@ -2222,7 +2218,14 @@ rule FORTRAN_DEP_HACK%s
elif not self.has_dir_part(d):
d = os.path.join(self.get_target_private_dir(target), d)
element.add_orderdep(d)
element.add_orderdep(pch_dep)
if compiler.id == 'msvc':
# MSVC does not show includes coming from the PCH with '/showIncludes',
# thus we must add an implicit dependency to the generated PCH.
element.add_dep(pch_dep)
else:
# All other compilers properly handle includes through the PCH, so only an
# orderdep is needed to make the initial build without depfile work.
element.add_orderdep(pch_dep)
# Convert from GCC-style link argument naming to the naming used by the
# current compiler.
commands = commands.to_native()
@ -2233,6 +2236,14 @@ rule FORTRAN_DEP_HACK%s
element.write(outfile)
return rel_obj
def add_header_deps(self, target, ninja_element, header_deps):
for d in header_deps:
if isinstance(d, File):
d = d.rel_to_builddir(self.build_to_src)
elif not self.has_dir_part(d):
d = os.path.join(self.get_target_private_dir(target), d)
ninja_element.add_dep(d)
def has_dir_part(self, fname):
# FIXME FIXME: The usage of this is a terrible and unreliable hack
if isinstance(fname, File):
@ -2263,6 +2274,7 @@ rule FORTRAN_DEP_HACK%s
just_name = os.path.basename(header)
(objname, pch_args) = compiler.gen_pch_args(just_name, source, dst)
commands += pch_args
commands += self._generate_single_compile(target, compiler)
commands += self.get_compile_debugfile_args(compiler, target, objname)
dep = dst + '.' + compiler.get_depfile_suffix()
return commands, dep, dst, [objname]
@ -2278,7 +2290,7 @@ rule FORTRAN_DEP_HACK%s
dep = dst + '.' + compiler.get_depfile_suffix()
return commands, dep, dst, [] # Gcc does not create an object file during pch generation.
def generate_pch(self, target, outfile):
def generate_pch(self, target, outfile, header_deps=[]):
cstr = ''
pch_objects = []
if target.is_cross:
@ -2309,6 +2321,7 @@ rule FORTRAN_DEP_HACK%s
elem = NinjaBuildElement(self.all_outputs, dst, rulename, src)
if extradep is not None:
elem.add_dep(extradep)
self.add_header_deps(target, elem, header_deps)
elem.add_item('ARGS', commands)
elem.add_item('DEPFILE', dep)
elem.write(outfile)

@ -0,0 +1,5 @@
#!/usr/bin/env python3
import sys
with open(sys.argv[1], 'w') as f:
f.write("#define FOO 0")

@ -0,0 +1,7 @@
#!/usr/bin/env python3
import sys
with open(sys.argv[1]) as f:
content = f.read()
with open(sys.argv[2], 'w') as f:
f.write(content)

@ -0,0 +1,16 @@
cc = meson.get_compiler('c')
cc_id = cc.get_id()
if cc_id == 'lcc'
error('MESON_SKIP_TEST: Elbrus compiler does not support PCH.')
endif
generated_customTarget = custom_target('makeheader',
output: 'generated_customTarget.h',
command : [find_program('gen_custom.py'), '@OUTPUT0@'])
generated_generator = generator(find_program('gen_generator.py'),
output: '@BASENAME@.h',
arguments: ['@INPUT@', '@OUTPUT@'])
exe = executable('prog', 'prog.c', generated_customTarget, generated_generator.process('generated_generator.in'),
c_pch: ['pch/prog_pch.c', 'pch/prog.h'])

@ -0,0 +1,2 @@
#include "generated_customTarget.h"
#include "generated_generator.h"

@ -0,0 +1,5 @@
#if !defined(_MSC_VER)
#error "This file is only for use with MSVC."
#endif
#include "prog.h"

@ -0,0 +1,6 @@
// No includes here, they need to come from the PCH
int main(int argc, char **argv) {
return FOO + BAR;
}

@ -2,6 +2,8 @@ project('pch test', 'c', 'cpp')
subdir('c')
subdir('cpp')
subdir('generated')
subdir('withIncludeDirectories')
if meson.backend() == 'xcode'
warning('Xcode backend only supports one precompiled header per target. Skipping "mixed" which has various precompiled headers.')

@ -0,0 +1,9 @@
cc = meson.get_compiler('c')
cc_id = cc.get_id()
if cc_id == 'lcc'
error('MESON_SKIP_TEST: Elbrus compiler does not support PCH.')
endif
exe = executable('prog', 'prog.c',
include_directories: 'include',
c_pch : ['pch/prog_pch.c', 'pch/prog.h'])

@ -0,0 +1,5 @@
#if !defined(_MSC_VER)
#error "This file is only for use with MSVC."
#endif
#include "prog.h"

@ -0,0 +1,10 @@
// No includes here, they need to come from the PCH
void func() {
fprintf(stdout, "This is a function that fails if stdio is not #included.\n");
}
int main(int argc, char **argv) {
return 0;
}
Loading…
Cancel
Save