Allow substitutions in custom_target() depfile:

Allow substitutions in custom_target() depfile: as well as in command:
pull/2278/merge
Jon Turney 7 years ago committed by Nirbheek Chauhan
parent 50aabc0129
commit 7e08e958c0
  1. 3
      docs/markdown/Reference-manual.md
  2. 4
      docs/markdown/snippets/custom-target-depends.md
  3. 3
      mesonbuild/backend/ninjabackend.py
  4. 12
      mesonbuild/build.py
  5. 2
      mesonbuild/interpreter.py

@ -285,6 +285,9 @@ the following special string substitutions:
- `@PLAINNAME@`: the input filename, without a path
- `@BASENAME@`: the input filename, with extension removed
The `depfile` keyword argument also accepts the `@BASENAME@` and `@PLAINNAME@`
substitutions. *(since 0.47)*
The returned object also has methods that are documented in the
[object methods section](#custom-target-object) below.

@ -0,0 +1,4 @@
## Substitutions in `custom_target(depends:)`
The `depfile` keyword argument to `custom_target` now accepts the `@BASENAME@`
and `@PLAINNAME@` substitutions.

@ -546,7 +546,8 @@ int dummy;
else:
cmd_type = 'custom'
if target.depfile is not None:
rel_dfile = os.path.join(self.get_target_dir(target), target.depfile)
depfile = target.get_dep_outname(elem.infilenames)
rel_dfile = os.path.join(self.get_target_dir(target), depfile)
abs_pdir = os.path.join(self.environment.get_build_dir(), self.get_target_dir(target))
os.makedirs(abs_pdir, exist_ok=True)
elem.add_item('DEPFILE', rel_dfile)

@ -1835,6 +1835,18 @@ class CustomTarget(Target):
def get_generated_sources(self):
return self.get_generated_lists()
def get_dep_outname(self, infilenames):
if self.depfile is None:
raise InvalidArguments('Tried to get depfile name for custom_target that does not have depfile defined.')
if len(infilenames):
plainname = os.path.basename(infilenames[0])
basename = os.path.splitext(plainname)[0]
return self.depfile.replace('@BASENAME@', basename).replace('@PLAINNAME@', plainname)
else:
if '@BASENAME@' in self.depfile or '@PLAINNAME@' in self.depfile:
raise InvalidArguments('Substitution in depfile for custom_target that does not have an input file.')
return self.depfile
def type_suffix(self):
return "@cus"

@ -2939,6 +2939,8 @@ root and issuing %s.
def func_custom_target(self, node, args, kwargs):
if len(args) != 1:
raise InterpreterException('custom_target: Only one positional argument is allowed, and it must be a string name')
if 'depfile' in kwargs and ('@BASENAME@' in kwargs['depfile'] or '@PLAINNAME@' in kwargs['depfile']):
FeatureNew('substitutions in custom_target depfile', '0.47.0').use()
name = args[0]
kwargs['install_mode'] = self._get_kwarg_install_mode(kwargs)
tg = CustomTargetHolder(build.CustomTarget(name, self.subdir, self.subproject, kwargs), self)

Loading…
Cancel
Save