modules/windows: allow CustomTargets with more than one output for compile_resources

pull/9375/head
Dylan Baker 3 years ago
parent 0d52a6161a
commit 6849baa476
  1. 18
      docs/markdown/Windows-module.md
  2. 22
      docs/markdown/snippets/windows_custom_targets.md
  3. 37
      mesonbuild/modules/windows.py

@ -7,10 +7,22 @@ Windows.
### compile_resources
```
windows.compile_resources(...(string | File | CustomTarget | CustomTargetIndex),
args: []string,
depend_files: [](string | File),
depends: [](BuildTarget | CustomTarget)
include_directories: [](IncludeDirectories | string)): []CustomTarget
```
Compiles Windows `rc` files specified in the positional arguments.
Returns an opaque object that you put in the list of sources for the
target you want to have the resources in. This method has the
following keyword argument.
Returns a list of `CustomTarget` objects that you put in the list of sources for
the target you want to have the resources in.
*Since 0.61.0* CustomTargetIndexs and CustomTargets with more than out output
*may be used as positional arguments.
This method has the following keyword arguments:
- `args` lists extra arguments to pass to the resource compiler
- `depend_files` lists resource files that the resource script depends on

@ -0,0 +1,22 @@
## Windows.compile_resources CustomTarget
Previously the Windows module only accepted CustomTargets with one output, it
now accepts them with more than one output, and creates a windows resource
target for each output. Additionally it now accepts indexes of CustomTargets
```meson
ct = custom_target(
'multiple',
output : ['resource', 'another resource'],
...
)
ct2 = custom_target(
'slice',
output : ['resource', 'not a resource'],
...
)
resources = windows.compile_resources(ct, ct2[0])
```

@ -143,24 +143,27 @@ class WindowsModule(ExtensionModule):
res_targets: T.List[build.CustomTarget] = []
for src in args[0]:
if isinstance(src, str):
name_formatted = src
name = os.path.join(state.subdir, src)
elif isinstance(src, mesonlib.File):
name_formatted = src.fname
name = src.relative_name()
else:
if isinstance(src, build.CustomTargetIndex):
def get_names() -> T.Iterable[T.Tuple[str, str, T.Union[str, mesonlib.File, build.CustomTargetIndex]]]:
for src in args[0]:
if isinstance(src, str):
yield os.path.join(state.subdir, src), src, src
elif isinstance(src, mesonlib.File):
yield src.relative_name(), src.fname, src
elif isinstance(src, build.CustomTargetIndex):
FeatureNew.single_use('windows.compile_resource CustomTargetIndex in positional arguments', '0.61.0', state.subproject)
if len(src.get_outputs()) > 1:
raise MesonException('windows.compile_resources does not accept custom targets with more than 1 output.')
# Chances are that src.get_filename() is already the name of that
# target, add a prefix to avoid name clash.
name_formatted = 'windows_compile_resources_' + src.get_filename()
name = src.get_id()
# This dance avoids a case where two indexs of the same
# target are given as separate arguments.
yield (f'{src.get_id()}_{src.target.get_outputs().index(src.output)}',
f'windows_compile_resources_{src.get_filename()}', src)
else:
if len(src.get_outputs()) > 1:
FeatureNew.single_use('windows.compile_resource CustomTarget with multiple outputs in positional arguments', '0.61.0', state.subproject)
for i, out in enumerate(src.get_outputs()):
# Chances are that src.get_filename() is already the name of that
# target, add a prefix to avoid name clash.
yield f'{src.get_id()}_{i}', f'windows_compile_resources_{i}_{out}', src[i]
for name, name_formatted, src in get_names():
# Path separators are not allowed in target names
name = name.replace('/', '_').replace('\\', '_').replace(':', '_')
name_formatted = name_formatted.replace('/', '_').replace('\\', '_').replace(':', '_')

Loading…
Cancel
Save