CustomTarget: Use get_outputs() instead of get_filename()
get_filename() made no sense for CustomTarget since it can have multiple outputs. Also use get_outputs() for GeneratedList since it has the same meaning and remove unused set_generated(). As a side-effect, we now install all the outputs of a CustomTarget.
This commit is contained in:
parent
c4fabc8ecf
commit
419b84784f
|
@ -93,16 +93,16 @@ class Backend():
|
||||||
src = src.fname
|
src = src.fname
|
||||||
raise RuntimeError('No specified compiler can handle file ' + src)
|
raise RuntimeError('No specified compiler can handle file ' + src)
|
||||||
|
|
||||||
def get_target_filename(self, target):
|
def get_target_filename(self, t):
|
||||||
assert(isinstance(target, (build.BuildTarget, build.CustomTarget)))
|
if isinstance(t, build.CustomTarget):
|
||||||
targetdir = self.get_target_dir(target)
|
if len(t.get_outputs()) != 1:
|
||||||
fname = target.get_filename()
|
mlog.log(mlog.red('WARNING'), 'custom_target {!r} has more ' \
|
||||||
if isinstance(fname, list):
|
'than one output! Using the first one.'.format(t.name))
|
||||||
# FIXME FIXME FIXME: build.CustomTarget has multiple output files
|
filename = t.get_outputs()[0]
|
||||||
# and get_filename() returns them all
|
else:
|
||||||
fname = fname[0]
|
assert(isinstance(t, build.BuildTarget))
|
||||||
filename = os.path.join(targetdir, fname)
|
filename = t.get_filename()
|
||||||
return filename
|
return os.path.join(self.get_target_dir(t), filename)
|
||||||
|
|
||||||
def get_target_filename_abs(self, target):
|
def get_target_filename_abs(self, target):
|
||||||
return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target))
|
return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target))
|
||||||
|
@ -520,15 +520,17 @@ class Backend():
|
||||||
outdir = '.'
|
outdir = '.'
|
||||||
if absolute_paths:
|
if absolute_paths:
|
||||||
outdir = os.path.join(self.environment.get_build_dir(), outdir)
|
outdir = os.path.join(self.environment.get_build_dir(), outdir)
|
||||||
for i in target.sources:
|
for i in target.get_sources():
|
||||||
if hasattr(i, 'held_object'):
|
if hasattr(i, 'held_object'):
|
||||||
i = i.held_object
|
i = i.held_object
|
||||||
if isinstance(i, str):
|
if isinstance(i, str):
|
||||||
fname = [os.path.join(self.build_to_src, target.subdir, i)]
|
fname = [os.path.join(self.build_to_src, target.subdir, i)]
|
||||||
elif isinstance(i, (build.BuildTarget, build.CustomTarget)):
|
elif isinstance(i, build.BuildTarget):
|
||||||
fname = [self.get_target_filename(i)]
|
fname = [self.get_target_filename(i)]
|
||||||
|
elif isinstance(i, build.CustomTarget):
|
||||||
|
fname = [os.path.join(self.get_target_dir(i), p) for p in i.get_outputs()]
|
||||||
elif isinstance(i, build.GeneratedList):
|
elif isinstance(i, build.GeneratedList):
|
||||||
fname = [os.path.join(self.get_target_private_dir(target), p) for p in i.get_outfilelist()]
|
fname = [os.path.join(self.get_target_private_dir(target), p) for p in i.get_outputs()]
|
||||||
else:
|
else:
|
||||||
fname = [i.rel_to_builddir(self.build_to_src)]
|
fname = [i.rel_to_builddir(self.build_to_src)]
|
||||||
if absolute_paths:
|
if absolute_paths:
|
||||||
|
@ -542,7 +544,7 @@ class Backend():
|
||||||
elif isinstance(i, build.CustomTarget):
|
elif isinstance(i, build.CustomTarget):
|
||||||
# GIR scanner will attempt to execute this binary but
|
# GIR scanner will attempt to execute this binary but
|
||||||
# it assumes that it is in path, so always give it a full path.
|
# it assumes that it is in path, so always give it a full path.
|
||||||
tmp = i.get_filename()[0]
|
tmp = i.get_outputs()[0]
|
||||||
i = os.path.join(self.get_target_dir(i), tmp)
|
i = os.path.join(self.get_target_dir(i), tmp)
|
||||||
elif isinstance(i, mesonlib.File):
|
elif isinstance(i, mesonlib.File):
|
||||||
i = i.rel_to_builddir(self.build_to_src)
|
i = i.rel_to_builddir(self.build_to_src)
|
||||||
|
|
|
@ -219,7 +219,7 @@ int dummy;
|
||||||
for gensource in target.get_generated_sources():
|
for gensource in target.get_generated_sources():
|
||||||
if isinstance(gensource, build.CustomTarget):
|
if isinstance(gensource, build.CustomTarget):
|
||||||
continue
|
continue
|
||||||
for src in gensource.get_outfilelist():
|
for src in gensource.get_outputs():
|
||||||
if self.environment.is_header(src):
|
if self.environment.is_header(src):
|
||||||
header_deps.append(os.path.join(self.get_target_private_dir(target), src))
|
header_deps.append(os.path.join(self.get_target_private_dir(target), src))
|
||||||
for dep in target.link_targets:
|
for dep in target.link_targets:
|
||||||
|
@ -295,7 +295,7 @@ int dummy;
|
||||||
# in their source files.
|
# in their source files.
|
||||||
header_deps.append(RawFilename(src))
|
header_deps.append(RawFilename(src))
|
||||||
else:
|
else:
|
||||||
for src in gensource.get_outfilelist():
|
for src in gensource.get_outputs():
|
||||||
generated_output_sources.append(src)
|
generated_output_sources.append(src)
|
||||||
if self.environment.is_object(src):
|
if self.environment.is_object(src):
|
||||||
obj_list.append(os.path.join(self.get_target_private_dir(target), src))
|
obj_list.append(os.path.join(self.get_target_private_dir(target), src))
|
||||||
|
@ -376,10 +376,9 @@ int dummy;
|
||||||
# FIXME, should not grab element at zero but rather expand all.
|
# FIXME, should not grab element at zero but rather expand all.
|
||||||
if isinstance(i, list):
|
if isinstance(i, list):
|
||||||
i = i[0]
|
i = i[0]
|
||||||
fname = i.get_filename()
|
# Add a dependency on all the outputs of this target
|
||||||
if isinstance(fname, list):
|
for output in i.get_outputs():
|
||||||
fname = fname[0]
|
deps.append(os.path.join(self.get_target_dir(i), output))
|
||||||
deps.append(os.path.join(self.get_target_dir(i), fname))
|
|
||||||
return deps
|
return deps
|
||||||
|
|
||||||
def generate_custom_target(self, target, outfile):
|
def generate_custom_target(self, target, outfile):
|
||||||
|
@ -401,11 +400,9 @@ int dummy;
|
||||||
deps.append(os.path.join(self.build_to_src, i))
|
deps.append(os.path.join(self.build_to_src, i))
|
||||||
elem.add_dep(deps)
|
elem.add_dep(deps)
|
||||||
for d in target.extra_depends:
|
for d in target.extra_depends:
|
||||||
tmp = d.get_filename()
|
# Add a dependency on all the outputs of this target
|
||||||
if not isinstance(tmp, list):
|
for output in d.get_outputs():
|
||||||
tmp = [tmp]
|
elem.add_dep(os.path.join(self.get_target_dir(d), output))
|
||||||
for fname in tmp:
|
|
||||||
elem.add_dep(os.path.join(self.get_target_dir(d), fname))
|
|
||||||
# If the target requires capturing stdout, then use the serialized
|
# If the target requires capturing stdout, then use the serialized
|
||||||
# executable wrapper to capture that output and save it to a file.
|
# executable wrapper to capture that output and save it to a file.
|
||||||
#
|
#
|
||||||
|
@ -541,7 +538,8 @@ int dummy;
|
||||||
should_strip = self.environment.coredata.get_builtin_option('strip')
|
should_strip = self.environment.coredata.get_builtin_option('strip')
|
||||||
for t in self.build.get_targets().values():
|
for t in self.build.get_targets().values():
|
||||||
if t.should_install():
|
if t.should_install():
|
||||||
# Find the installation directory
|
# Find the installation directory. FIXME: Currently only one
|
||||||
|
# installation directory is supported for each target
|
||||||
outdir = t.get_custom_install_dir()
|
outdir = t.get_custom_install_dir()
|
||||||
if outdir is not None:
|
if outdir is not None:
|
||||||
pass
|
pass
|
||||||
|
@ -572,9 +570,14 @@ int dummy;
|
||||||
# stripped, and doesn't have an install_rpath
|
# stripped, and doesn't have an install_rpath
|
||||||
i = [self.get_target_debug_filename(t), outdir, [], False, '']
|
i = [self.get_target_debug_filename(t), outdir, [], False, '']
|
||||||
d.targets.append(i)
|
d.targets.append(i)
|
||||||
|
if isinstance(t, build.BuildTarget):
|
||||||
i = [self.get_target_filename(t), outdir, t.get_aliaslist(),\
|
i = [self.get_target_filename(t), outdir, t.get_aliaslist(),\
|
||||||
should_strip, t.install_rpath]
|
should_strip, t.install_rpath]
|
||||||
d.targets.append(i)
|
d.targets.append(i)
|
||||||
|
elif isinstance(t, build.CustomTarget):
|
||||||
|
for output in t.get_outputs():
|
||||||
|
f = os.path.join(self.get_target_dir(t), output)
|
||||||
|
d.targets.append([f, outdir, [], False, None])
|
||||||
|
|
||||||
def generate_custom_install_script(self, d):
|
def generate_custom_install_script(self, d):
|
||||||
d.install_scripts = self.build.install_scripts
|
d.install_scripts = self.build.install_scripts
|
||||||
|
@ -1013,7 +1016,7 @@ int dummy;
|
||||||
rel = os.path.join(self.get_target_dir(genlist), ifile)
|
rel = os.path.join(self.get_target_dir(genlist), ifile)
|
||||||
all_srcs.append(rel)
|
all_srcs.append(rel)
|
||||||
else:
|
else:
|
||||||
for ifile in genlist.get_outfilelist():
|
for ifile in genlist.get_outputs():
|
||||||
rel = os.path.join(self.get_target_private_dir(target), ifile)
|
rel = os.path.join(self.get_target_private_dir(target), ifile)
|
||||||
all_srcs.append(rel)
|
all_srcs.append(rel)
|
||||||
srcs = []
|
srcs = []
|
||||||
|
@ -1402,8 +1405,8 @@ rule FORTRAN_DEP_HACK
|
||||||
generator = genlist.get_generator()
|
generator = genlist.get_generator()
|
||||||
exe = generator.get_exe()
|
exe = generator.get_exe()
|
||||||
exe_arr = self.exe_object_to_cmd_array(exe)
|
exe_arr = self.exe_object_to_cmd_array(exe)
|
||||||
infilelist = genlist.get_infilelist()
|
infilelist = genlist.get_inputs()
|
||||||
outfilelist = genlist.get_outfilelist()
|
outfilelist = genlist.get_outputs()
|
||||||
base_args = generator.get_arglist()
|
base_args = generator.get_arglist()
|
||||||
extra_dependencies = [os.path.join(self.build_to_src, i) for i in genlist.extra_depends]
|
extra_dependencies = [os.path.join(self.build_to_src, i) for i in genlist.extra_depends]
|
||||||
for i in range(len(infilelist)):
|
for i in range(len(infilelist)):
|
||||||
|
@ -1941,7 +1944,9 @@ rule FORTRAN_DEP_HACK
|
||||||
# are used by something else or are meant to be always built
|
# are used by something else or are meant to be always built
|
||||||
if isinstance(t, build.CustomTarget) and not (t.install or t.build_always):
|
if isinstance(t, build.CustomTarget) and not (t.install or t.build_always):
|
||||||
continue
|
continue
|
||||||
targetlist.append(self.get_target_filename(t))
|
# Add the first output of each target to the 'all' target so that
|
||||||
|
# they are all built
|
||||||
|
targetlist.append(os.path.join(self.get_target_dir(t), t.get_outputs()[0]))
|
||||||
|
|
||||||
elem = NinjaBuildElement(self.all_outputs, 'all', 'phony', targetlist)
|
elem = NinjaBuildElement(self.all_outputs, 'all', 'phony', targetlist)
|
||||||
elem.write(outfile)
|
elem.write(outfile)
|
||||||
|
|
|
@ -102,7 +102,7 @@ class Vs2010Backend(backends.Backend):
|
||||||
down = self.target_to_build_root(target)
|
down = self.target_to_build_root(target)
|
||||||
for genlist in target.get_generated_sources():
|
for genlist in target.get_generated_sources():
|
||||||
if isinstance(genlist, build.CustomTarget):
|
if isinstance(genlist, build.CustomTarget):
|
||||||
for i in genlist.output:
|
for i in genlist.get_outputs():
|
||||||
# Path to the generated source from the current vcxproj dir via the build root
|
# Path to the generated source from the current vcxproj dir via the build root
|
||||||
ipath = os.path.join(down, self.get_target_dir(genlist), i)
|
ipath = os.path.join(down, self.get_target_dir(genlist), i)
|
||||||
custom_target_output_files.append(ipath)
|
custom_target_output_files.append(ipath)
|
||||||
|
@ -112,8 +112,8 @@ class Vs2010Backend(backends.Backend):
|
||||||
else:
|
else:
|
||||||
generator = genlist.get_generator()
|
generator = genlist.get_generator()
|
||||||
exe = generator.get_exe()
|
exe = generator.get_exe()
|
||||||
infilelist = genlist.get_infilelist()
|
infilelist = genlist.get_inputs()
|
||||||
outfilelist = genlist.get_outfilelist()
|
outfilelist = genlist.get_outputs()
|
||||||
exe_arr = self.exe_object_to_cmd_array(exe)
|
exe_arr = self.exe_object_to_cmd_array(exe)
|
||||||
base_args = generator.get_arglist()
|
base_args = generator.get_arglist()
|
||||||
for i in range(len(infilelist)):
|
for i in range(len(infilelist)):
|
||||||
|
|
|
@ -547,6 +547,9 @@ class BuildTarget():
|
||||||
def get_filename(self):
|
def get_filename(self):
|
||||||
return self.filename
|
return self.filename
|
||||||
|
|
||||||
|
def get_outputs(self):
|
||||||
|
return [self.filename]
|
||||||
|
|
||||||
def get_debug_filename(self):
|
def get_debug_filename(self):
|
||||||
"""
|
"""
|
||||||
The name of the file that contains debugging symbols for this target
|
The name of the file that contains debugging symbols for this target
|
||||||
|
@ -650,12 +653,6 @@ by calling get_variable() on the subproject object.''')
|
||||||
raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name))
|
raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name))
|
||||||
self.link_targets.append(t)
|
self.link_targets.append(t)
|
||||||
|
|
||||||
def set_generated(self, genlist):
|
|
||||||
for g in genlist:
|
|
||||||
if not(isinstance(g, GeneratedList)):
|
|
||||||
raise InvalidArguments('Generated source argument is not the output of a generator.')
|
|
||||||
self.generated.append(g)
|
|
||||||
|
|
||||||
def add_pch(self, language, pchlist):
|
def add_pch(self, language, pchlist):
|
||||||
if len(pchlist) == 0:
|
if len(pchlist) == 0:
|
||||||
return
|
return
|
||||||
|
@ -791,10 +788,10 @@ class GeneratedList():
|
||||||
self.outfilelist += outfiles
|
self.outfilelist += outfiles
|
||||||
self.outmap[newfile] = outfiles
|
self.outmap[newfile] = outfiles
|
||||||
|
|
||||||
def get_infilelist(self):
|
def get_inputs(self):
|
||||||
return self.infilelist
|
return self.infilelist
|
||||||
|
|
||||||
def get_outfilelist(self):
|
def get_outputs(self):
|
||||||
return self.outfilelist
|
return self.outfilelist
|
||||||
|
|
||||||
def get_outputs_for(self, filename):
|
def get_outputs_for(self, filename):
|
||||||
|
@ -1085,7 +1082,6 @@ class CustomTarget:
|
||||||
self.depfile = None
|
self.depfile = None
|
||||||
self.process_kwargs(kwargs)
|
self.process_kwargs(kwargs)
|
||||||
self.extra_files = []
|
self.extra_files = []
|
||||||
self.install_rpath = ''
|
|
||||||
unknowns = []
|
unknowns = []
|
||||||
for k in kwargs:
|
for k in kwargs:
|
||||||
if k not in CustomTarget.known_kwargs:
|
if k not in CustomTarget.known_kwargs:
|
||||||
|
@ -1217,12 +1213,9 @@ class CustomTarget:
|
||||||
def get_subdir(self):
|
def get_subdir(self):
|
||||||
return self.subdir
|
return self.subdir
|
||||||
|
|
||||||
def get_filename(self):
|
def get_outputs(self):
|
||||||
return self.output
|
return self.output
|
||||||
|
|
||||||
def get_aliaslist(self):
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_sources(self):
|
def get_sources(self):
|
||||||
return self.sources
|
return self.sources
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue