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
|
||||
raise RuntimeError('No specified compiler can handle file ' + src)
|
||||
|
||||
def get_target_filename(self, target):
|
||||
assert(isinstance(target, (build.BuildTarget, build.CustomTarget)))
|
||||
targetdir = self.get_target_dir(target)
|
||||
fname = target.get_filename()
|
||||
if isinstance(fname, list):
|
||||
# FIXME FIXME FIXME: build.CustomTarget has multiple output files
|
||||
# and get_filename() returns them all
|
||||
fname = fname[0]
|
||||
filename = os.path.join(targetdir, fname)
|
||||
return filename
|
||||
def get_target_filename(self, t):
|
||||
if isinstance(t, build.CustomTarget):
|
||||
if len(t.get_outputs()) != 1:
|
||||
mlog.log(mlog.red('WARNING'), 'custom_target {!r} has more ' \
|
||||
'than one output! Using the first one.'.format(t.name))
|
||||
filename = t.get_outputs()[0]
|
||||
else:
|
||||
assert(isinstance(t, build.BuildTarget))
|
||||
filename = t.get_filename()
|
||||
return os.path.join(self.get_target_dir(t), filename)
|
||||
|
||||
def get_target_filename_abs(self, target):
|
||||
return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target))
|
||||
|
@ -520,15 +520,17 @@ class Backend():
|
|||
outdir = '.'
|
||||
if absolute_paths:
|
||||
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'):
|
||||
i = i.held_object
|
||||
if isinstance(i, str):
|
||||
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)]
|
||||
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):
|
||||
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:
|
||||
fname = [i.rel_to_builddir(self.build_to_src)]
|
||||
if absolute_paths:
|
||||
|
@ -542,7 +544,7 @@ class Backend():
|
|||
elif 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.
|
||||
tmp = i.get_filename()[0]
|
||||
tmp = i.get_outputs()[0]
|
||||
i = os.path.join(self.get_target_dir(i), tmp)
|
||||
elif isinstance(i, mesonlib.File):
|
||||
i = i.rel_to_builddir(self.build_to_src)
|
||||
|
|
|
@ -219,7 +219,7 @@ int dummy;
|
|||
for gensource in target.get_generated_sources():
|
||||
if isinstance(gensource, build.CustomTarget):
|
||||
continue
|
||||
for src in gensource.get_outfilelist():
|
||||
for src in gensource.get_outputs():
|
||||
if self.environment.is_header(src):
|
||||
header_deps.append(os.path.join(self.get_target_private_dir(target), src))
|
||||
for dep in target.link_targets:
|
||||
|
@ -295,7 +295,7 @@ int dummy;
|
|||
# in their source files.
|
||||
header_deps.append(RawFilename(src))
|
||||
else:
|
||||
for src in gensource.get_outfilelist():
|
||||
for src in gensource.get_outputs():
|
||||
generated_output_sources.append(src)
|
||||
if self.environment.is_object(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.
|
||||
if isinstance(i, list):
|
||||
i = i[0]
|
||||
fname = i.get_filename()
|
||||
if isinstance(fname, list):
|
||||
fname = fname[0]
|
||||
deps.append(os.path.join(self.get_target_dir(i), fname))
|
||||
# Add a dependency on all the outputs of this target
|
||||
for output in i.get_outputs():
|
||||
deps.append(os.path.join(self.get_target_dir(i), output))
|
||||
return deps
|
||||
|
||||
def generate_custom_target(self, target, outfile):
|
||||
|
@ -401,11 +400,9 @@ int dummy;
|
|||
deps.append(os.path.join(self.build_to_src, i))
|
||||
elem.add_dep(deps)
|
||||
for d in target.extra_depends:
|
||||
tmp = d.get_filename()
|
||||
if not isinstance(tmp, list):
|
||||
tmp = [tmp]
|
||||
for fname in tmp:
|
||||
elem.add_dep(os.path.join(self.get_target_dir(d), fname))
|
||||
# Add a dependency on all the outputs of this target
|
||||
for output in d.get_outputs():
|
||||
elem.add_dep(os.path.join(self.get_target_dir(d), output))
|
||||
# If the target requires capturing stdout, then use the serialized
|
||||
# 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')
|
||||
for t in self.build.get_targets().values():
|
||||
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()
|
||||
if outdir is not None:
|
||||
pass
|
||||
|
@ -572,9 +570,14 @@ int dummy;
|
|||
# stripped, and doesn't have an install_rpath
|
||||
i = [self.get_target_debug_filename(t), outdir, [], False, '']
|
||||
d.targets.append(i)
|
||||
i = [self.get_target_filename(t), outdir, t.get_aliaslist(),\
|
||||
should_strip, t.install_rpath]
|
||||
d.targets.append(i)
|
||||
if isinstance(t, build.BuildTarget):
|
||||
i = [self.get_target_filename(t), outdir, t.get_aliaslist(),\
|
||||
should_strip, t.install_rpath]
|
||||
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):
|
||||
d.install_scripts = self.build.install_scripts
|
||||
|
@ -1013,7 +1016,7 @@ int dummy;
|
|||
rel = os.path.join(self.get_target_dir(genlist), ifile)
|
||||
all_srcs.append(rel)
|
||||
else:
|
||||
for ifile in genlist.get_outfilelist():
|
||||
for ifile in genlist.get_outputs():
|
||||
rel = os.path.join(self.get_target_private_dir(target), ifile)
|
||||
all_srcs.append(rel)
|
||||
srcs = []
|
||||
|
@ -1402,8 +1405,8 @@ rule FORTRAN_DEP_HACK
|
|||
generator = genlist.get_generator()
|
||||
exe = generator.get_exe()
|
||||
exe_arr = self.exe_object_to_cmd_array(exe)
|
||||
infilelist = genlist.get_infilelist()
|
||||
outfilelist = genlist.get_outfilelist()
|
||||
infilelist = genlist.get_inputs()
|
||||
outfilelist = genlist.get_outputs()
|
||||
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)):
|
||||
|
@ -1941,7 +1944,9 @@ rule FORTRAN_DEP_HACK
|
|||
# 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):
|
||||
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.write(outfile)
|
||||
|
|
|
@ -102,7 +102,7 @@ class Vs2010Backend(backends.Backend):
|
|||
down = self.target_to_build_root(target)
|
||||
for genlist in target.get_generated_sources():
|
||||
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
|
||||
ipath = os.path.join(down, self.get_target_dir(genlist), i)
|
||||
custom_target_output_files.append(ipath)
|
||||
|
@ -112,8 +112,8 @@ class Vs2010Backend(backends.Backend):
|
|||
else:
|
||||
generator = genlist.get_generator()
|
||||
exe = generator.get_exe()
|
||||
infilelist = genlist.get_infilelist()
|
||||
outfilelist = genlist.get_outfilelist()
|
||||
infilelist = genlist.get_inputs()
|
||||
outfilelist = genlist.get_outputs()
|
||||
exe_arr = self.exe_object_to_cmd_array(exe)
|
||||
base_args = generator.get_arglist()
|
||||
for i in range(len(infilelist)):
|
||||
|
|
|
@ -547,6 +547,9 @@ class BuildTarget():
|
|||
def get_filename(self):
|
||||
return self.filename
|
||||
|
||||
def get_outputs(self):
|
||||
return [self.filename]
|
||||
|
||||
def get_debug_filename(self):
|
||||
"""
|
||||
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))
|
||||
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):
|
||||
if len(pchlist) == 0:
|
||||
return
|
||||
|
@ -705,7 +702,7 @@ class Generator():
|
|||
def __init__(self, args, kwargs):
|
||||
if len(args) != 1:
|
||||
raise InvalidArguments('Generator requires one and only one positional argument')
|
||||
|
||||
|
||||
exe = args[0]
|
||||
if hasattr(exe, 'held_object'):
|
||||
exe = exe.held_object
|
||||
|
@ -791,10 +788,10 @@ class GeneratedList():
|
|||
self.outfilelist += outfiles
|
||||
self.outmap[newfile] = outfiles
|
||||
|
||||
def get_infilelist(self):
|
||||
def get_inputs(self):
|
||||
return self.infilelist
|
||||
|
||||
def get_outfilelist(self):
|
||||
def get_outputs(self):
|
||||
return self.outfilelist
|
||||
|
||||
def get_outputs_for(self, filename):
|
||||
|
@ -1085,7 +1082,6 @@ class CustomTarget:
|
|||
self.depfile = None
|
||||
self.process_kwargs(kwargs)
|
||||
self.extra_files = []
|
||||
self.install_rpath = ''
|
||||
unknowns = []
|
||||
for k in kwargs:
|
||||
if k not in CustomTarget.known_kwargs:
|
||||
|
@ -1217,12 +1213,9 @@ class CustomTarget:
|
|||
def get_subdir(self):
|
||||
return self.subdir
|
||||
|
||||
def get_filename(self):
|
||||
def get_outputs(self):
|
||||
return self.output
|
||||
|
||||
def get_aliaslist(self):
|
||||
return []
|
||||
|
||||
def get_sources(self):
|
||||
return self.sources
|
||||
|
||||
|
|
Loading…
Reference in New Issue