Can generate configuration files with custom scripts.

pull/15/head
Jussi Pakkanen 11 years ago
parent 5b0322ad15
commit d9d70372b4
  1. 39
      interpreter.py
  2. 0
      test cases/common/16 configure file/dummy.dat
  3. 13
      test cases/common/16 configure file/generator.py
  4. 12
      test cases/common/16 configure file/meson.build
  5. 5
      test cases/common/16 configure file/prog2.c
  6. 2
      test cases/common/55 file grabber/meson.build

@ -549,6 +549,7 @@ class MesonMain(InterpreterObject):
'has_exe_wrapper' : self.has_exe_wrapper_method,
'is_unity' : self.is_unity_method,
'current_source_dir' : self.current_source_dir_method,
'current_build_dir' : self.current_build_dir_method,
})
def current_source_dir_method(self, args, kwargs):
@ -558,6 +559,13 @@ class MesonMain(InterpreterObject):
return src
return os.path.join(src, sub)
def current_build_dir_method(self, args, kwargs):
src = self.interpreter.environment.build_dir
sub = self.interpreter.subdir
if sub == '':
return src
return os.path.join(src, sub)
def has_exe_wrapper_method(self, args, kwargs):
if self.is_cross_build_method(None, None):
return 'exe_wrap' in self.build.environment.cross_info
@ -1092,19 +1100,24 @@ class Interpreter():
raise InterpreterException('Required keyword argument "input" not defined.')
if not 'output' in kwargs:
raise InterpreterException('Required keyword argument "output" not defined.')
if not 'configuration' in kwargs:
raise InterpreterException('Required keyword argument "configuration" not defined.')
inputfile = kwargs['input']
output = kwargs['output']
conf = kwargs['configuration']
if not isinstance(conf, ConfigurationDataHolder):
raise InterpreterException('Argument "configuration" is not of type configuration_data')
conffile = os.path.join(self.subdir, inputfile)
self.build_def_files.append(conffile)
c = ConfigureFileHolder(self.subdir, inputfile, output, conf.held_object)
self.build.configure_files.append(c.held_object)
conf.mark_used()
if 'configuration' in kwargs:
inputfile = kwargs['input']
output = kwargs['output']
conf = kwargs['configuration']
if not isinstance(conf, ConfigurationDataHolder):
raise InterpreterException('Argument "configuration" is not of type configuration_data')
conffile = os.path.join(self.subdir, inputfile)
self.build_def_files.append(conffile)
c = ConfigureFileHolder(self.subdir, inputfile, output, conf.held_object)
self.build.configure_files.append(c.held_object)
conf.mark_used()
elif 'command' in kwargs:
res = self.func_run_command(node, kwargs['command'], {})
if res.returncode != 0:
raise InterpreterException('Running configure command failed.')
else:
raise InterpreterException('Configure_file must have either "configuration" or "command".')
def func_include_directories(self, node, args, kwargs):
absbase = os.path.join(self.environment.get_source_dir(), self.subdir)

@ -0,0 +1,13 @@
#!/usr/bin/env python3
import sys
if len(sys.argv) != 3:
print("Wrong amount of parameters.")
# Just test that it exists.
ifile = open(sys.argv[1], 'r')
ofile = open(sys.argv[2], 'w')
ofile.write("#define ZERO_RESULT 0\n")
ofile.close()

@ -13,3 +13,15 @@ configuration : conf)
e = executable('inctest', 'prog.c', include_dirs : include_directories('.'))
test('inctest', e)
# Now generate a header file with an external script.
genprog = find_program('generator.py')
ifile = '@0@/dummy.dat'.format(meson.current_source_dir())
ofile = '@0@/config2.h'.format(meson.current_build_dir())
configure_file(input : 'dummy.dat',
output : 'config2.h',
command : [genprog, ifile, ofile])
test('inctest2', executable('prog2', 'prog2.c',
include_dirs : include_directories('.')))

@ -0,0 +1,5 @@
#include"config2.h"
int main(int argc, char **argv) {
return ZERO_RESULT;
}

@ -11,7 +11,7 @@ project('grabber', 'c')
if build.name() == 'windows'
c = run_command('grabber.bat')
grabber = find_program('grabber')
grabber = find_program('grabber.bat')
else
c = run_command('grabber.sh')
grabber = find_program('grabber.sh')

Loading…
Cancel
Save