Skip to content

Commit 2ddec9e

Browse files
amysparkeli-schwartz
authored andcommitted
gnome.mkenums: Allow passthrough of ExternalPrograms to enable converting only the real arguments to response file
(cherry picked from commit e8c7157)
1 parent 8f66a59 commit 2ddec9e

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

mesonbuild/backend/backends.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ def get_custom_target_dir_include_args(
15851585

15861586
def eval_custom_target_command(
15871587
self, target: build.CustomTarget, absolute_outputs: bool = False) -> \
1588-
T.Tuple[T.List[str], T.List[str], T.List[str]]:
1588+
T.Tuple[T.List[str], T.List[str], T.List[str | programs.ExternalProgram]]:
15891589
# We want the outputs to be absolute only when using the VS backend
15901590
# XXX: Maybe allow the vs backend to use relative paths too?
15911591
source_root = self.build_to_src
@@ -1598,7 +1598,7 @@ def eval_custom_target_command(
15981598
outputs = [os.path.join(outdir, i) for i in target.get_outputs()]
15991599
inputs = self.get_custom_target_sources(target)
16001600
# Evaluate the command list
1601-
cmd: T.List[str] = []
1601+
cmd: T.List[str | programs.ExternalProgram] = []
16021602
for i in target.command:
16031603
if isinstance(i, build.BuildTarget):
16041604
cmd += self.build_target_to_cmd_array(i)
@@ -1634,6 +1634,9 @@ def eval_custom_target_command(
16341634
if not target.absolute_paths:
16351635
pdir = self.get_target_private_dir(target)
16361636
i = i.replace('@PRIVATE_DIR@', pdir)
1637+
elif isinstance(i, programs.ExternalProgram):
1638+
# Let it pass and be extended elsewhere
1639+
pass
16371640
else:
16381641
raise RuntimeError(f'Argument {i} is of unknown type {type(i)}')
16391642
cmd.append(i)
@@ -1658,7 +1661,7 @@ def eval_custom_target_command(
16581661
# fixed.
16591662
#
16601663
# https://github.com/mesonbuild/meson/pull/737
1661-
cmd = [i.replace('\\', '/') for i in cmd]
1664+
cmd = [i.replace('\\', '/') if isinstance(i, str) else i for i in cmd]
16621665
return inputs, outputs, cmd
16631666

16641667
def get_introspect_command(self) -> str:
@@ -2019,6 +2022,8 @@ def get_introspection_data(self, target_id: str, target: build.Target) -> T.List
20192022
compiler += [j]
20202023
elif isinstance(j, (build.BuildTarget, build.CustomTarget)):
20212024
compiler += j.get_outputs()
2025+
elif isinstance(j, programs.ExternalProgram):
2026+
compiler += j.get_command()
20222027
else:
20232028
raise RuntimeError(f'Type "{type(j).__name__}" is not supported in get_introspection_data. This is a bug')
20242029

mesonbuild/build.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ class CommandBase:
26002600
subproject: str
26012601

26022602
def flatten_command(self, cmd: T.Sequence[T.Union[str, File, programs.ExternalProgram, BuildTargetTypes]]) -> \
2603-
T.List[T.Union[str, File, BuildTarget, 'CustomTarget']]:
2603+
T.List[T.Union[str, File, BuildTarget, CustomTarget, programs.ExternalProgram]]:
26042604
cmd = listify(cmd)
26052605
final_cmd: T.List[T.Union[str, File, BuildTarget, 'CustomTarget']] = []
26062606
for c in cmd:
@@ -2617,7 +2617,8 @@ def flatten_command(self, cmd: T.Sequence[T.Union[str, File, programs.ExternalPr
26172617
# Can only add a dependency on an external program which we
26182618
# know the absolute path of
26192619
self.depend_files.append(File.from_absolute_file(path))
2620-
final_cmd += c.get_command()
2620+
# Do NOT flatten -- it is needed for later parsing
2621+
final_cmd.append(c)
26212622
elif isinstance(c, (BuildTarget, CustomTarget)):
26222623
self.dependencies.append(c)
26232624
final_cmd.append(c)

mesonbuild/utils/universal.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from ..environment import Environment
3939
from ..compilers.compilers import Compiler
4040
from ..interpreterbase.baseobjects import SubProject
41+
from .. import programs
4142

4243
class _EnvPickleLoadable(Protocol):
4344

@@ -1738,7 +1739,7 @@ def Popen_safe_logged(args: T.List[str], msg: str = 'Called', **kwargs: T.Any) -
17381739
return p, o, e
17391740

17401741

1741-
def iter_regexin_iter(regexiter: T.Iterable[str], initer: T.Iterable[str]) -> T.Optional[str]:
1742+
def iter_regexin_iter(regexiter: T.Iterable[str], initer: T.Iterable[str | programs.ExternalProgram]) -> T.Optional[str]:
17421743
'''
17431744
Takes each regular expression in @regexiter and tries to search for it in
17441745
every item in @initer. If there is a match, returns that match.
@@ -1754,7 +1755,7 @@ def iter_regexin_iter(regexiter: T.Iterable[str], initer: T.Iterable[str]) -> T.
17541755
return None
17551756

17561757

1757-
def _substitute_values_check_errors(command: T.List[str], values: T.Dict[str, T.Union[str, T.List[str]]]) -> None:
1758+
def _substitute_values_check_errors(command: T.List[str | programs.ExternalProgram], values: T.Dict[str, T.Union[str, T.List[str]]]) -> None:
17581759
# Error checking
17591760
inregex: T.List[str] = ['@INPUT([0-9]+)?@', '@PLAINNAME@', '@BASENAME@']
17601761
outregex: T.List[str] = ['@OUTPUT([0-9]+)?@', '@OUTDIR@']
@@ -1794,7 +1795,7 @@ def _substitute_values_check_errors(command: T.List[str], values: T.Dict[str, T.
17941795
raise MesonException(m.format(match2.group(), len(values['@OUTPUT@'])))
17951796

17961797

1797-
def substitute_values(command: T.List[str], values: T.Dict[str, T.Union[str, T.List[str]]]) -> T.List[str]:
1798+
def substitute_values(command: T.List[str | programs.ExternalProgram], values: T.Dict[str, T.Union[str, T.List[str]]]) -> T.List[str | programs.ExternalProgram]:
17981799
'''
17991800
Substitute the template strings in the @values dict into the list of
18001801
strings @command and return a new list. For a full list of the templates,
@@ -1821,7 +1822,7 @@ def replace(m: T.Match[str]) -> str:
18211822
_substitute_values_check_errors(command, values)
18221823

18231824
# Substitution
1824-
outcmd: T.List[str] = []
1825+
outcmd: T.List[str | programs.ExternalProgram] = []
18251826
rx_keys = [re.escape(key) for key in values if key not in ('@INPUT@', '@OUTPUT@')]
18261827
value_rx = re.compile('|'.join(rx_keys)) if rx_keys else None
18271828
for vv in command:

0 commit comments

Comments
 (0)