Can now build object files in generators, too.

pull/15/head
Jussi Pakkanen 11 years ago
parent 5f65255a66
commit 3a3be0f61b
  1. 4
      backends.py
  2. 10
      environment.py
  3. 18
      test cases/common/59 object generator/meson.build
  4. 18
      test cases/common/59 object generator/obj_generator.py
  5. 5
      test cases/common/59 object generator/prog.c
  6. 3
      test cases/common/59 object generator/source.c

@ -224,7 +224,9 @@ class Backend():
unity_deps = [] # Generated sources that must be built before compiling a Unity target.
for genlist in target.get_generated_sources():
for src in genlist.get_outfilelist():
if not self.environment.is_header(src):
if self.environment.is_object(src):
obj_list.append(os.path.join(self.get_target_dir(target), target.get_basename() + '.dir', src))
elif not self.environment.is_header(src):
if is_unity:
if '/' in src:
rel_src = src

@ -1068,6 +1068,7 @@ header_suffixes = ['h', 'hh', 'hpp', 'hxx', 'H']
cpp_suffixes = ['cc', 'cpp', 'cxx', 'h', 'hh', 'hpp', 'hxx', 'c++']
c_suffixes = ['c']
clike_suffixes = c_suffixes + cpp_suffixes
obj_suffixes = ['o', 'obj']
def is_header(fname):
suffix = fname.split('.')[-1]
@ -1077,6 +1078,10 @@ def is_source(fname):
suffix = fname.split('.')[-1]
return suffix in clike_suffixes
def is_object(fname):
suffix = fname.split('.')[-1]
return suffix in obj_suffixes
class Environment():
private_dir = 'meson-private'
log_dir = 'meson-logs'
@ -1158,10 +1163,13 @@ class Environment():
def is_header(self, fname):
return is_header(fname)
def is_source(self, fname):
return is_source(fname)
def is_object(self, fname):
return is_object(fname)
def merge_options(self, options):
for (name, value) in options.items():
if name not in self.coredata.user_options:

@ -0,0 +1,18 @@
project('object generator', 'c')
python = find_program('python3')
# Note that this will not add a dependency to the compiler executable.
# Code will not be rebuilt if it changes.
comp = '@0@/@1@'.format(meson.current_source_dir(), 'obj_generator.py')
# Generate a header file that needs to be included.
gen = generator(python,
output : '@BASENAME@.o',
arguments : [comp, '@INPUT@', '@OUTPUT@'])
generated = gen.process('source.c')
e = executable('prog', 'prog.c', generated)
test('objgen', e)

@ -0,0 +1,18 @@
#!/usr/bin/python3
# Mimic a binary that generates an object file (e.g. windres).
import sys, shutil, subprocess
if __name__ == '__main__':
if len(sys.argv) != 3:
print(sys.argv[0], 'input_file output_file')
sys.exit(1)
ifile = sys.argv[1]
ofile = sys.argv[2]
if shutil.which('cl'):
cmd = ['cl', '/nologo', '/Fo'+ofile, '/c', ifile]
else:
cmd = ['cc', '-c', ifile, '-o', ofile]
sys.exit(subprocess.call(cmd))

@ -0,0 +1,5 @@
int func_in_obj();
int main(int argc, char **argv) {
return func_in_obj();
}

@ -0,0 +1,3 @@
int func_in_obj() {
return 0;
}
Loading…
Cancel
Save