mirror of
https://github.com/mesonbuild/meson.git
synced 2026-08-04 23:00:57 +00:00
Pass environment down to base Target class
This commit is contained in:
committed by
Xavier Claessens
parent
d93fe56e89
commit
e33ec88ac7
@@ -566,6 +566,7 @@ class Target(HoldableObject):
|
||||
subproject: 'SubProject'
|
||||
build_by_default: bool
|
||||
for_machine: MachineChoice
|
||||
environment: environment.Environment
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if has_path_sep(self.name):
|
||||
@@ -726,10 +727,9 @@ class BuildTarget(Target):
|
||||
def __init__(self, name: str, subdir: str, subproject: SubProject, for_machine: MachineChoice,
|
||||
sources: T.List['SourceOutputs'], structured_sources: T.Optional[StructuredSources],
|
||||
objects, environment: environment.Environment, compilers: T.Dict[str, 'Compiler'], kwargs):
|
||||
super().__init__(name, subdir, subproject, True, for_machine)
|
||||
super().__init__(name, subdir, subproject, True, for_machine, environment)
|
||||
unity_opt = environment.coredata.get_option(OptionKey('unity'))
|
||||
self.is_unity = unity_opt == 'on' or (unity_opt == 'subprojects' and subproject != '')
|
||||
self.environment = environment
|
||||
self.all_compilers = compilers
|
||||
self.compilers = OrderedDict() # type: OrderedDict[str, Compiler]
|
||||
self.objects: T.List[T.Union[str, 'File', 'ExtractedObjects']] = []
|
||||
@@ -2393,6 +2393,7 @@ class CustomTarget(Target, CommandBase):
|
||||
name: T.Optional[str],
|
||||
subdir: str,
|
||||
subproject: str,
|
||||
environment: environment.Environment,
|
||||
command: T.Sequence[T.Union[
|
||||
str, BuildTarget, CustomTarget, CustomTargetIndex, GeneratedList, programs.ExternalProgram, File]],
|
||||
sources: T.Sequence[T.Union[
|
||||
@@ -2418,7 +2419,7 @@ class CustomTarget(Target, CommandBase):
|
||||
backend: T.Optional['Backend'] = None,
|
||||
):
|
||||
# TODO expose keyword arg to make MachineChoice.HOST configurable
|
||||
super().__init__(name, subdir, subproject, False, MachineChoice.HOST)
|
||||
super().__init__(name, subdir, subproject, False, MachineChoice.HOST, environment)
|
||||
self.sources = list(sources)
|
||||
self.outputs = substitute_values(
|
||||
outputs, get_filenames_templates_dict(
|
||||
@@ -2589,10 +2590,11 @@ class RunTarget(Target, CommandBase):
|
||||
dependencies: T.Sequence[Target],
|
||||
subdir: str,
|
||||
subproject: str,
|
||||
environment: environment.Environment,
|
||||
env: T.Optional['EnvironmentVariables'] = None):
|
||||
self.typename = 'run'
|
||||
# These don't produce output artifacts
|
||||
super().__init__(name, subdir, subproject, False, MachineChoice.BUILD)
|
||||
super().__init__(name, subdir, subproject, False, MachineChoice.BUILD, environment)
|
||||
self.dependencies = dependencies
|
||||
self.depend_files = []
|
||||
self.command = self.flatten_command(command)
|
||||
@@ -2631,8 +2633,8 @@ class RunTarget(Target, CommandBase):
|
||||
|
||||
class AliasTarget(RunTarget):
|
||||
def __init__(self, name: str, dependencies: T.Sequence['Target'],
|
||||
subdir: str, subproject: str):
|
||||
super().__init__(name, [], dependencies, subdir, subproject)
|
||||
subdir: str, subproject: str, environment: environment.Environment):
|
||||
super().__init__(name, [], dependencies, subdir, subproject, environment)
|
||||
|
||||
def __repr__(self):
|
||||
repr_str = "<{0} {1}>"
|
||||
|
||||
@@ -1763,6 +1763,7 @@ external dependencies (including libraries) must go to "dependencies".''')
|
||||
kwargs['output'][0],
|
||||
self.subdir,
|
||||
self.subproject,
|
||||
self.environment,
|
||||
self.environment.get_build_command() +
|
||||
['--internal',
|
||||
'vcstagger',
|
||||
@@ -1889,6 +1890,7 @@ external dependencies (including libraries) must go to "dependencies".''')
|
||||
name,
|
||||
self.subdir,
|
||||
self.subproject,
|
||||
self.environment,
|
||||
command,
|
||||
inputs,
|
||||
kwargs['output'],
|
||||
@@ -1927,7 +1929,8 @@ external dependencies (including libraries) must go to "dependencies".''')
|
||||
if isinstance(all_args[0], str):
|
||||
all_args[0] = self.find_program_impl([all_args[0]])
|
||||
name = args[0]
|
||||
tg = build.RunTarget(name, all_args, kwargs['depends'], self.subdir, self.subproject, kwargs['env'])
|
||||
tg = build.RunTarget(name, all_args, kwargs['depends'], self.subdir, self.subproject, self.environment,
|
||||
kwargs['env'])
|
||||
self.add_target(name, tg)
|
||||
full_name = (self.subproject, name)
|
||||
assert full_name not in self.build.run_target_names
|
||||
@@ -1940,7 +1943,7 @@ external dependencies (including libraries) must go to "dependencies".''')
|
||||
def func_alias_target(self, node: mparser.BaseNode, args: T.Tuple[str, T.List[build.Target]],
|
||||
kwargs: 'TYPE_kwargs') -> build.AliasTarget:
|
||||
name, deps = args
|
||||
tg = build.AliasTarget(name, deps, self.subdir, self.subproject)
|
||||
tg = build.AliasTarget(name, deps, self.subdir, self.subproject, self.environment)
|
||||
self.add_target(name, tg)
|
||||
return tg
|
||||
|
||||
|
||||
@@ -500,6 +500,7 @@ class GnomeModule(ExtensionModule):
|
||||
name,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
target_cmd,
|
||||
[input_file],
|
||||
[output],
|
||||
@@ -520,6 +521,7 @@ class GnomeModule(ExtensionModule):
|
||||
f'{target_name}_h',
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
cmd,
|
||||
[input_file],
|
||||
[f'{target_name}.h'],
|
||||
@@ -967,6 +969,7 @@ class GnomeModule(ExtensionModule):
|
||||
girfile,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
scan_command,
|
||||
generated_files,
|
||||
[girfile],
|
||||
@@ -996,6 +999,7 @@ class GnomeModule(ExtensionModule):
|
||||
typelib_output,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
typelib_cmd,
|
||||
generated_files,
|
||||
[typelib_output],
|
||||
@@ -1220,6 +1224,7 @@ class GnomeModule(ExtensionModule):
|
||||
targetname,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
cmd,
|
||||
[],
|
||||
['gschemas.compiled'],
|
||||
@@ -1292,7 +1297,8 @@ class GnomeModule(ExtensionModule):
|
||||
pot_args: T.List[T.Union['ExternalProgram', str]] = [itstool, '-o', pot_file]
|
||||
pot_args.extend(pot_sources)
|
||||
pottarget = build.RunTarget(f'help-{project_id}-pot', pot_args, [],
|
||||
os.path.join(state.subdir, 'C'), state.subproject)
|
||||
os.path.join(state.subdir, 'C'), state.subproject,
|
||||
state.environment)
|
||||
targets.append(pottarget)
|
||||
|
||||
for l in langs:
|
||||
@@ -1322,7 +1328,8 @@ class GnomeModule(ExtensionModule):
|
||||
os.path.join('@SOURCE_ROOT@', l_subdir, po_file),
|
||||
os.path.join('@SOURCE_ROOT@', l_subdir, po_file), pot_file]
|
||||
potarget = build.RunTarget(f'help-{project_id}-{l}-update-po',
|
||||
po_args, [pottarget], l_subdir, state.subproject)
|
||||
po_args, [pottarget], l_subdir, state.subproject,
|
||||
state.environment)
|
||||
targets.append(potarget)
|
||||
potargets.append(potarget)
|
||||
|
||||
@@ -1331,6 +1338,7 @@ class GnomeModule(ExtensionModule):
|
||||
f'help-{project_id}-{l}-gmo',
|
||||
l_subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
[msgfmt, '@INPUT@', '-o', '@OUTPUT@'],
|
||||
[po_file],
|
||||
[gmo_file],
|
||||
@@ -1341,6 +1349,7 @@ class GnomeModule(ExtensionModule):
|
||||
f'help-{project_id}-{l}',
|
||||
l_subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
[itstool, '-m', os.path.join(l_subdir, gmo_file), '-o', '@OUTDIR@', '@INPUT@'],
|
||||
sources_files,
|
||||
sources,
|
||||
@@ -1351,7 +1360,7 @@ class GnomeModule(ExtensionModule):
|
||||
targets.append(mergetarget)
|
||||
|
||||
allpotarget = build.AliasTarget(f'help-{project_id}-update-po', potargets,
|
||||
state.subdir, state.subproject)
|
||||
state.subdir, state.subproject, state.environment)
|
||||
targets.append(allpotarget)
|
||||
|
||||
return ModuleReturnValue(None, targets)
|
||||
@@ -1484,13 +1493,14 @@ class GnomeModule(ExtensionModule):
|
||||
targetname,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
command + t_args,
|
||||
[],
|
||||
[f'{modulename}-decl.txt'],
|
||||
build_always_stale=True,
|
||||
extra_depends=new_depends,
|
||||
)
|
||||
alias_target = build.AliasTarget(targetname, [custom_target], state.subdir, state.subproject)
|
||||
alias_target = build.AliasTarget(targetname, [custom_target], state.subdir, state.subproject, state.environment)
|
||||
if kwargs['check']:
|
||||
check_cmd = state.find_program('gtkdoc-check')
|
||||
check_env = ['DOC_MODULE=' + modulename,
|
||||
@@ -1627,6 +1637,7 @@ class GnomeModule(ExtensionModule):
|
||||
output,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
c_cmd,
|
||||
xml_files,
|
||||
[output],
|
||||
@@ -1646,6 +1657,7 @@ class GnomeModule(ExtensionModule):
|
||||
output,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
hfile_cmd,
|
||||
xml_files,
|
||||
[output],
|
||||
@@ -1675,6 +1687,7 @@ class GnomeModule(ExtensionModule):
|
||||
output,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
docbook_cmd,
|
||||
xml_files,
|
||||
outputs,
|
||||
@@ -1891,6 +1904,7 @@ class GnomeModule(ExtensionModule):
|
||||
output,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
real_cmd,
|
||||
sources,
|
||||
[output],
|
||||
@@ -1956,6 +1970,7 @@ class GnomeModule(ExtensionModule):
|
||||
output + '_h',
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
h_cmd,
|
||||
sources,
|
||||
[header_file],
|
||||
@@ -1975,6 +1990,7 @@ class GnomeModule(ExtensionModule):
|
||||
output + '_c',
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
c_cmd,
|
||||
sources,
|
||||
[f'{output}.c'],
|
||||
@@ -2099,6 +2115,7 @@ class GnomeModule(ExtensionModule):
|
||||
vapi_output,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
command=cmd,
|
||||
sources=inputs,
|
||||
outputs=[vapi_output],
|
||||
|
||||
@@ -338,6 +338,7 @@ class HotdocTargetBuilder:
|
||||
target = HotdocTarget(fullname,
|
||||
subdir=self.subdir,
|
||||
subproject=self.state.subproject,
|
||||
environment=self.state.environment,
|
||||
hotdoc_conf=mesonlib.File.from_built_file(
|
||||
self.subdir, hotdoc_config_name),
|
||||
extra_extension_paths=self._extra_extension_paths,
|
||||
@@ -379,8 +380,8 @@ class HotdocTargetHolder(CustomTargetHolder):
|
||||
|
||||
class HotdocTarget(build.CustomTarget):
|
||||
def __init__(self, name, subdir, subproject, hotdoc_conf, extra_extension_paths, extra_assets,
|
||||
subprojects, **kwargs):
|
||||
super().__init__(name, subdir, subproject, **kwargs, absolute_paths=True)
|
||||
subprojects, environment, **kwargs):
|
||||
super().__init__(name, subdir, subproject, environment, **kwargs, absolute_paths=True)
|
||||
self.hotdoc_conf = hotdoc_conf
|
||||
self.extra_extension_paths = extra_extension_paths
|
||||
self.extra_assets = extra_assets
|
||||
|
||||
@@ -195,6 +195,7 @@ class I18nModule(ExtensionModule):
|
||||
'',
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
command,
|
||||
kwargs['input'],
|
||||
kwargs['output'],
|
||||
@@ -255,7 +256,8 @@ class I18nModule(ExtensionModule):
|
||||
if extra_arg:
|
||||
potargs.append(extra_arg)
|
||||
potargs.append('--xgettext=' + self.tools['xgettext'].get_path())
|
||||
pottarget = build.RunTarget(packagename + '-pot', potargs, [], state.subdir, state.subproject)
|
||||
pottarget = build.RunTarget(packagename + '-pot', potargs, [], state.subdir, state.subproject,
|
||||
state.environment)
|
||||
targets.append(pottarget)
|
||||
|
||||
install = kwargs['install']
|
||||
@@ -270,6 +272,7 @@ class I18nModule(ExtensionModule):
|
||||
f'{packagename}-{l}.mo',
|
||||
path.join(state.subdir, l, 'LC_MESSAGES'),
|
||||
state.subproject,
|
||||
state.environment,
|
||||
[self.tools['msgfmt'], '@INPUT@', '-o', '@OUTPUT@'],
|
||||
[po_file],
|
||||
[f'{packagename}.mo'],
|
||||
@@ -284,7 +287,8 @@ class I18nModule(ExtensionModule):
|
||||
targets.append(gmotarget)
|
||||
gmotargets.append(gmotarget)
|
||||
|
||||
allgmotarget = build.AliasTarget(packagename + '-gmo', gmotargets, state.subdir, state.subproject)
|
||||
allgmotarget = build.AliasTarget(packagename + '-gmo', gmotargets, state.subdir, state.subproject,
|
||||
state.environment)
|
||||
targets.append(allgmotarget)
|
||||
|
||||
updatepoargs = state.environment.get_build_command() + ['--internal', 'gettext', 'update_po', pkg_arg]
|
||||
@@ -296,7 +300,8 @@ class I18nModule(ExtensionModule):
|
||||
updatepoargs.append(extra_arg)
|
||||
for tool in ['msginit', 'msgmerge']:
|
||||
updatepoargs.append(f'--{tool}=' + self.tools[tool].get_path())
|
||||
updatepotarget = build.RunTarget(packagename + '-update-po', updatepoargs, [], state.subdir, state.subproject)
|
||||
updatepotarget = build.RunTarget(packagename + '-update-po', updatepoargs, [], state.subdir, state.subproject,
|
||||
state.environment)
|
||||
targets.append(updatepotarget)
|
||||
|
||||
return ModuleReturnValue([gmotargets, pottarget, updatepotarget], targets)
|
||||
@@ -349,6 +354,7 @@ class I18nModule(ExtensionModule):
|
||||
'',
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
command,
|
||||
kwargs['input'],
|
||||
kwargs['output'],
|
||||
|
||||
@@ -60,6 +60,7 @@ class JavaModule(NewExtensionModule):
|
||||
os.path.basename(header),
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
mesonlib.listify([
|
||||
javac.exelist,
|
||||
'-d',
|
||||
@@ -112,7 +113,11 @@ class JavaModule(NewExtensionModule):
|
||||
|
||||
prefix = classes[0] if not package else package
|
||||
|
||||
target = CustomTarget(f'{prefix}-native-headers', state.subdir, state.subproject, command,
|
||||
target = CustomTarget(f'{prefix}-native-headers',
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
command,
|
||||
sources=args[0], outputs=headers, backend=state.backend)
|
||||
|
||||
# It is only known that 1.8.0 won't pre-create the directory. 11 and 16
|
||||
|
||||
@@ -332,6 +332,7 @@ class QtBaseModule(ExtensionModule):
|
||||
name,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
self.tools['rcc'].get_command() + ['-name', name, '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS,
|
||||
sources,
|
||||
[f'{name}.cpp'],
|
||||
@@ -351,6 +352,7 @@ class QtBaseModule(ExtensionModule):
|
||||
name,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
self.tools['rcc'].get_command() + ['-name', '@BASENAME@', '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS,
|
||||
[rcc_file],
|
||||
[f'{name}.cpp'],
|
||||
@@ -579,6 +581,7 @@ class QtBaseModule(ExtensionModule):
|
||||
f'qt{self.qt_version}-compile-{ts}',
|
||||
outdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
cmd,
|
||||
[ts],
|
||||
['@BASENAME@.qm'],
|
||||
|
||||
@@ -231,6 +231,7 @@ class ExternalProject(NewExtensionModule):
|
||||
self.name,
|
||||
self.subdir.as_posix(),
|
||||
self.subproject,
|
||||
self.env,
|
||||
cmd + ['@OUTPUT@', '@DEPFILE@'],
|
||||
[],
|
||||
[f'{self.name}.stamp'],
|
||||
|
||||
@@ -213,6 +213,7 @@ class RustModule(ExtensionModule):
|
||||
f'rustmod-bindgen-{name}'.replace('/', '_'),
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
self._bindgen_bin.get_command() + [
|
||||
'@INPUT@', '--output',
|
||||
os.path.join(state.environment.build_dir, '@OUTPUT@')] +
|
||||
|
||||
@@ -61,6 +61,7 @@ class WaylandModule(ExtensionModule):
|
||||
f'{name}-protocol',
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
[self.scanner_bin, f'{scope}-code', '@INPUT@', '@OUTPUT@'],
|
||||
[xml_file],
|
||||
[f'{name}-protocol.c'],
|
||||
@@ -73,6 +74,7 @@ class WaylandModule(ExtensionModule):
|
||||
f'{name}-{side}-protocol',
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
[self.scanner_bin, f'{side}-header', '@INPUT@', '@OUTPUT@'],
|
||||
[xml_file],
|
||||
[f'{name}-{side}-protocol.h'],
|
||||
|
||||
@@ -193,6 +193,7 @@ class WindowsModule(ExtensionModule):
|
||||
name_formatted,
|
||||
state.subdir,
|
||||
state.subproject,
|
||||
state.environment,
|
||||
command,
|
||||
[src],
|
||||
[output],
|
||||
|
||||
Reference in New Issue
Block a user