Can use built exes in custom targets.

pull/319/head
Jussi Pakkanen 9 years ago
parent 5f44748ddd
commit 16fa657304
  1. 17
      backends.py
  2. 2
      gtkdochelper.py
  3. 17
      ninjabackend.py
  4. 1
      test cases/common/97 selfbuilt custom/data.dat
  5. 5
      test cases/common/97 selfbuilt custom/mainprog.cpp
  6. 16
      test cases/common/97 selfbuilt custom/meson.build
  7. 34
      test cases/common/97 selfbuilt custom/tool.cpp

@ -352,6 +352,20 @@ class Backend():
deps.append(os.path.join(self.build_to_src, sp, 'meson_options.txt'))
return deps
def exe_object_to_cmd_array(self, exe):
if self.environment.is_cross_build() and \
isinstance(exe, build.BuildTarget) and exe.is_cross:
if 'exe_wrapper' not in self.environment.cross_info:
s = 'Can not use target %s as a generator because it is cross-built\n'
s += 'and no exe wrapper is defined. You might want to set it to native instead.'
s = s % exe.name
raise MesonException(s)
if isinstance(exe, build.BuildTarget):
exe_arr = [os.path.join(self.environment.get_build_dir(), self.get_target_filename(exe))]
else:
exe_arr = exe.get_command()
return exe_arr
def eval_custom_target_command(self, target, absolute_paths=False):
ofilenames = [os.path.join(self.get_target_dir(target), i) for i in target.output]
srcs = []
@ -368,6 +382,9 @@ class Backend():
srcs.append(fname)
cmd = []
for i in target.command:
if isinstance(i, build.Executable):
cmd += self.exe_object_to_cmd_array(i)
continue
if isinstance(i, build.CustomTarget):
# GIR scanner will attempt to execute this binary but
# it assumes that it is in path, so always give it a full path.

@ -37,6 +37,8 @@ def build_gtkdoc(source_root, build_root, doc_subdir, src_subdir,
scan_cmd = ['gtkdoc-scan',
'--module=' + module,
'--source-dir=' + abs_src] + scan_args
# print(scan_cmd)
# sys.exit(1)
subprocess.check_call(scan_cmd,
cwd=abs_out)
if main_file.endswith('sgml'):

@ -293,7 +293,10 @@ class NinjaBackend(backends.Backend):
# FIXME, should not grab element at zero but rather expand all.
if isinstance(i, list):
i = i[0]
deps.append(os.path.join(self.get_target_dir(i), i.get_filename()[0]))
fname = i.get_filename()
if isinstance(fname, list):
fname = fname[0]
deps.append(os.path.join(self.get_target_dir(i), fname))
if target.build_always:
deps.append('PHONY')
elem = NinjaBuildElement(ofilenames, 'CUSTOM_COMMAND', srcs)
@ -1115,19 +1118,9 @@ rule FORTRAN_DEP_HACK
continue # Customtarget has already written its output rules
generator = genlist.get_generator()
exe = generator.get_exe()
if self.environment.is_cross_build() and \
isinstance(exe, build.BuildTarget) and exe.is_cross:
if 'exe_wrapper' not in self.environment.cross_info:
s = 'Can not use target %s as a generator because it is cross-built\n'
s += 'and no exe wrapper is defined. You might want to set it to native instead.'
s = s % exe.name
raise MesonException(s)
exe_arr = self.exe_object_to_cmd_array(exe)
infilelist = genlist.get_infilelist()
outfilelist = genlist.get_outfilelist()
if isinstance(exe, build.BuildTarget):
exe_arr = [os.path.join(self.environment.get_build_dir(), self.get_target_filename(exe))]
else:
exe_arr = exe.get_command()
base_args = generator.get_arglist()
extra_dependencies = [os.path.join(self.build_to_src, i) for i in genlist.extra_depends]
for i in range(len(infilelist)):

@ -0,0 +1,5 @@
#include"data.h"
int main(int, char **) {
return generated_function() != 52;
}

@ -0,0 +1,16 @@
project('selfbuilt custom', 'cpp')
# Build an exe and use it in a custom target
# whose output is used to build a different exe.
tool = executable('tool', 'tool.cpp')
hfile = custom_target('datah',
output : 'data.h',
input : 'data.dat',
command : [tool, '@INPUT@', '@OUTPUT@'],
)
main = executable('mainprog', 'mainprog.cpp', hfile)
test('maintest', main)

@ -0,0 +1,34 @@
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
const char prefix[] = "int ";
const char suffix[] = " () {\n return 52;}\n";
int main(int argc, char **argv) {
if(argc != 3) {
cout << "You is fail.\n";
return 1;
}
ifstream is(argv[1], ifstream::binary);
if(!is) {
cout << "Opening input file failed.\n";
return 1;
}
string funcname;
is >> funcname;
ofstream os(argv[2], ofstream::binary);
if(!os) {
cout << "Opening output file failed.\n";
return 1;
}
os << prefix << funcname << suffix;
os.close();
if(!os.good()) {
cout << "Writing data out failed.\n";
return 1;
}
return 0;
}
Loading…
Cancel
Save