-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Detects header changes with windows.compile_resources #14977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bruchar1
wants to merge
3
commits into
mesonbuild:master
Choose a base branch
from
bruchar1:windows_rc_deps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
docs/markdown/snippets/compiler_methods_includes_directories.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## Methods from compiler object now accept strings for include_directories | ||
|
||
The various [[@compiler]] methods with a `include_directories` keyword argument | ||
now accept stings or array of strings, in addition to [[@inc]] objects | ||
generated from [[include_directories]] function, as it was already the case for | ||
[[build_target]] family of functions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## windows.compile_resources now detects header changes with rc.exe | ||
|
||
The `rc.exe` resource compiler neither provides *depfile* support nor | ||
allows showing includes, as is possible with C or C++ compilers. | ||
Therefore, changes to files included by the `.rc` file did not trigger | ||
recompilation of the resource file. | ||
|
||
A workaround was added to *meson* by calling the preprocessor on the | ||
`.rc` file to detect the included headers and adding the result as a | ||
dependency to the resource compilation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
from ..interpreterbase.decorators import ContainerTypeInfo, typed_kwargs, KwargInfo, typed_pos_args | ||
from ..options import OptionKey | ||
from .interpreterobjects import (extract_required_kwarg, extract_search_dirs) | ||
from .type_checking import REQUIRED_KW, in_set_validator, NoneType | ||
from .type_checking import INCLUDE_DIRECTORIES, REQUIRED_KW, in_set_validator, NoneType | ||
|
||
if T.TYPE_CHECKING: | ||
from ..interpreter import Interpreter | ||
|
@@ -86,15 +86,15 @@ class FindLibraryKW(ExtractRequired, ExtractSearchDirs): | |
# prepended to the key | ||
header_args: T.List[str] | ||
header_dependencies: T.List[dependencies.Dependency] | ||
header_include_directories: T.List[build.IncludeDirs] | ||
header_include_directories: T.List[T.Union[build.IncludeDirs, str]] | ||
header_no_builtin_args: bool | ||
header_prefix: str | ||
header_required: T.Union[bool, options.UserFeatureOption] | ||
|
||
class PreprocessKW(TypedDict): | ||
output: str | ||
compile_args: T.List[str] | ||
include_directories: T.List[build.IncludeDirs] | ||
include_directories: T.List[T.Union[build.IncludeDirs, str]] | ||
dependencies: T.List[dependencies.Dependency] | ||
depends: T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]] | ||
|
||
|
@@ -154,12 +154,6 @@ def stderr_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str: | |
listify=True, | ||
default=[], | ||
) | ||
_INCLUDE_DIRS_KW: KwargInfo[T.List[build.IncludeDirs]] = KwargInfo( | ||
'include_directories', | ||
ContainerTypeInfo(list, build.IncludeDirs), | ||
default=[], | ||
listify=True, | ||
) | ||
_PREFIX_KW: KwargInfo[str] = KwargInfo( | ||
'prefix', | ||
(str, ContainerTypeInfo(list, str)), | ||
|
@@ -173,10 +167,10 @@ def stderr_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str: | |
|
||
# Many of the compiler methods take this kwarg signature exactly, this allows | ||
# simplifying the `typed_kwargs` calls | ||
_COMMON_KWS: T.List[KwargInfo] = [_ARGS_KW, _DEPENDENCIES_KW, _INCLUDE_DIRS_KW, _PREFIX_KW, _NO_BUILTIN_ARGS_KW] | ||
_COMMON_KWS: T.List[KwargInfo] = [_ARGS_KW, _DEPENDENCIES_KW, INCLUDE_DIRECTORIES, _PREFIX_KW, _NO_BUILTIN_ARGS_KW] | ||
|
||
# Common methods of compiles, links, runs, and similar | ||
_COMPILES_KWS: T.List[KwargInfo] = [_NAME_KW, _ARGS_KW, _DEPENDENCIES_KW, _INCLUDE_DIRS_KW, _NO_BUILTIN_ARGS_KW, | ||
_COMPILES_KWS: T.List[KwargInfo] = [_NAME_KW, _ARGS_KW, _DEPENDENCIES_KW, INCLUDE_DIRECTORIES, _NO_BUILTIN_ARGS_KW, | ||
_WERROR_KW, | ||
REQUIRED_KW.evolve(since='1.5.0', default=False)] | ||
|
||
|
@@ -232,7 +226,7 @@ def cmd_array_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> T | |
def _determine_args(self, kwargs: BaseCompileKW, | ||
mode: CompileCheckMode = CompileCheckMode.LINK) -> T.List[str]: | ||
args: T.List[str] = [] | ||
for i in kwargs['include_directories']: | ||
for i in self.interpreter.extract_incdirs(kwargs, strings_since='1.10.0'): | ||
for idir in i.to_string_list(self.environment.get_source_dir(), self.environment.get_build_dir()): | ||
args.extend(self.compiler.get_include_args(idir, False)) | ||
if not kwargs['no_builtin_args']: | ||
|
@@ -687,13 +681,15 @@ def find_library_method(self, args: T.Tuple[str], kwargs: 'FindLibraryKW') -> 'd | |
mlog.log('Library', mlog.bold(libname), 'skipped: feature', mlog.bold(feature), 'disabled') | ||
return self.notfound_library(libname) | ||
|
||
include_directories = self.interpreter.extract_incdirs(kwargs, key='header_include_directories', strings_since='1.10.0') | ||
|
||
# This could be done with a comprehension, but that confuses the type | ||
# checker, and having it check this seems valuable | ||
has_header_kwargs: 'HeaderKW' = { | ||
'required': required, | ||
'args': kwargs['header_args'], | ||
'dependencies': kwargs['header_dependencies'], | ||
'include_directories': kwargs['header_include_directories'], | ||
'include_directories': include_directories, | ||
'prefix': kwargs['header_prefix'], | ||
'no_builtin_args': kwargs['header_no_builtin_args'], | ||
} | ||
|
@@ -890,7 +886,7 @@ def get_argument_syntax_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwa | |
'compiler.preprocess', | ||
KwargInfo('output', str, default='@[email protected]'), | ||
KwargInfo('compile_args', ContainerTypeInfo(list, str), listify=True, default=[]), | ||
_INCLUDE_DIRS_KW, | ||
INCLUDE_DIRECTORIES, | ||
_DEPENDENCIES_KW.evolve(since='1.1.0'), | ||
_DEPENDS_KW.evolve(since='1.4.0'), | ||
) | ||
|
@@ -918,7 +914,7 @@ def preprocess_method(self, args: T.Tuple[T.List['mesonlib.FileOrString']], kwar | |
compiler, | ||
self.interpreter.backend, | ||
kwargs['compile_args'], | ||
kwargs['include_directories'], | ||
self.interpreter.extract_incdirs(kwargs, strings_since='1.10.0'), | ||
kwargs['dependencies'], | ||
kwargs['depends']) | ||
self.interpreter.add_target(tg.name, tg) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,13 @@ | |
from . import ModuleState | ||
from ..compilers import Compiler | ||
from ..interpreter import Interpreter | ||
from ..interpreter.interpreter import SourceOutputs | ||
|
||
from typing_extensions import TypedDict | ||
|
||
class CompileResources(TypedDict): | ||
|
||
depend_files: T.List[mesonlib.FileOrString] | ||
depends: T.List[T.Union[build.BuildTarget, build.CustomTarget]] | ||
depends: T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]] | ||
include_directories: T.List[T.Union[str, build.IncludeDirs]] | ||
args: T.List[str] | ||
|
||
|
@@ -102,6 +102,33 @@ def _find_resource_compiler(self, state: 'ModuleState') -> T.Tuple[ExternalProgr | |
|
||
return self._rescomp | ||
|
||
def get_preprocessor_target(self, | ||
name_formatted: str, | ||
src: T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex], | ||
include_directories: T.List[build.IncludeDirs], | ||
state: ModuleState) -> build.CustomTargetIndex: | ||
compiler = self.detect_compiler(state.environment.coredata.compilers[MachineChoice.HOST]) | ||
_sources: T.List[T.Union[mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]] = self.interpreter.source_strings_to_files([src]) | ||
sources = T.cast('T.List[SourceOutputs]', _sources) | ||
|
||
tg = build.CompileTarget( | ||
name_formatted, | ||
state.subdir, | ||
state.subproject, | ||
state.environment, | ||
sources, | ||
'@[email protected]', | ||
compiler.get_preprocessor(), | ||
state.backend, | ||
['-DRC_INVOKED'], | ||
include_directories, | ||
[], | ||
[]) | ||
self.interpreter.add_target(tg.name, tg) | ||
|
||
private_dir = os.path.relpath(state.backend.get_target_private_dir(tg), state.subdir) | ||
return build.CustomTargetIndex(tg, os.path.join(private_dir, tg.outputs[0])) | ||
|
||
@typed_pos_args('windows.compile_resources', varargs=(str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex), min_varargs=1) | ||
@typed_kwargs( | ||
'windows.compile_resources', | ||
|
@@ -121,7 +148,8 @@ def compile_resources(self, state: 'ModuleState', | |
extra_args += state.get_include_args([ | ||
build.IncludeDirs('', [], False, [os.path.join('@BUILD_ROOT@', self.interpreter.backend.get_target_dir(d))]) | ||
]) | ||
extra_args += state.get_include_args(kwargs['include_directories']) | ||
include_directories = self.interpreter.extract_incdirs(kwargs) | ||
extra_args += state.get_include_args(include_directories) | ||
|
||
rescomp, rescomp_type = self._find_resource_compiler(state) | ||
if rescomp_type == ResourceCompilerType.rc: | ||
|
@@ -178,12 +206,20 @@ def get_names() -> T.Iterable[T.Tuple[str, str, T.Union[str, mesonlib.File, buil | |
command.append(rescomp) | ||
command.extend(res_args) | ||
depfile: T.Optional[str] = None | ||
# instruct binutils windres to generate a preprocessor depfile | ||
extra_depends = wrc_depends.copy() | ||
if rescomp_type == ResourceCompilerType.windres: | ||
# instruct binutils windres to generate a preprocessor depfile | ||
depfile = f'{output}.d' | ||
command.extend(['--preprocessor-arg=-MD', | ||
'--preprocessor-arg=-MQ@OUTPUT@', | ||
'--preprocessor-arg=-MF@DEPFILE@']) | ||
elif rescomp_type == ResourceCompilerType.rc: | ||
# use preprocessor to detect header dependencies | ||
extra_depends.append(self.get_preprocessor_target( | ||
name_formatted + '_i', | ||
src, | ||
include_directories, | ||
state)) | ||
|
||
res_targets.append(build.CustomTarget( | ||
name_formatted, | ||
|
@@ -195,7 +231,7 @@ def get_names() -> T.Iterable[T.Tuple[str, str, T.Union[str, mesonlib.File, buil | |
[output], | ||
depfile=depfile, | ||
depend_files=wrc_depend_files, | ||
extra_depends=wrc_depends, | ||
extra_depends=extra_depends, | ||
description='Compiling Windows resource {}', | ||
)) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.