Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,7 @@ def _generate_single_compile_target_args(self, target: build.BuildTarget, compil
# Add compiler args and include paths from several sources; defaults,
# build options, external dependencies, etc.
commands = self.generate_basic_compiler_args(target, compiler)
commands += compiler.get_ninja_compile_args()
# Add custom target dirs as includes automatically, but before
# target-specific include directories.
if target.implicit_include_directories:
Expand Down
3 changes: 3 additions & 0 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1704,3 +1704,6 @@ def get_crt_static(self) -> bool:
def get_target_libdir(self) -> str:
"""Where is the libdir for the current machine located"""
raise EnvironmentException(f'{self.get_id()} does not support Rust target libdir')

def get_ninja_compile_args(self) -> T.List[str]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to name this something like get_show_dep_args(), with a docstring like:

Arguments for printing depfile information in MSVC compatible format.

Only the base class needs the docstring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I respectfully disagree. That's what this function does, but it's not why this function does what it does.

If we were adding something to support a b_include_list option and there was a gcc version that returned ['-MD'], I would agree with you. But in this case, we're returning a list of arguments that ninja needs for this backend to work properly. We're not returning a flag that shows the end user the include files. (Well, we are, but that's not why we're returning that flag).

All that said, it's your project, so I'll change the name to whatever you like.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterh,

I agree with your high level explanation but the function does not actually have anything to do with ninja!

It is a "not_vsbackend_compile_args" and should be used on any backend that isn't visual studio, surely. It just so happens that the only such backend today is Ninja, but if we ever added another one then surely we would want to have showincludes in use.

return []
9 changes: 6 additions & 3 deletions mesonbuild/compilers/mixins/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ class VisualStudioLikeCompiler(Compiler, metaclass=mesonlib.SimpleABC):
'mtd': ['/MTd'],
}

# /showIncludes is needed for build dependency tracking in Ninja
# See: https://ninja-build.org/manual.html#_deps
# Assume UTF-8 sources by default, but self.unix_args_to_native() removes it
# if `/source-charset` is set too.
# It is also dropped if Visual Studio 2013 or earlier is used, since it would
# not be supported in that case.
always_args = ['/nologo', '/showIncludes', '/utf-8']
always_args = ['/nologo', '/utf-8']
warn_args: T.Dict[str, T.List[str]] = {
'0': [],
'1': ['/W2'],
Expand Down Expand Up @@ -354,6 +352,11 @@ def symbols_have_underscore_prefix(self) -> bool:
def get_pie_args(self) -> T.List[str]:
return []

def get_ninja_compile_args(self) -> T.List[str]:
# /showIncludes is needed for build dependency tracking in Ninja
# See: https://ninja-build.org/manual.html#_deps
return ['/showIncludes']

class MSVCCompiler(VisualStudioLikeCompiler):

"""Specific to the Microsoft Compilers."""
Expand Down
13 changes: 9 additions & 4 deletions unittests/internaltests.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,24 @@ def test_compiler_args_class_visualstudio(self):
cc = VisualStudioCPPCompiler([], [], '20.00', MachineChoice.HOST, env, 'x64', linker=linker)

a = cc.compiler_args(cc.get_always_args())
self.assertEqual(a.to_native(copy=True), ['/nologo', '/showIncludes', '/utf-8', '/Zc:__cplusplus'])
self.assertEqual(a.to_native(copy=True), ['/nologo', '/utf-8', '/Zc:__cplusplus'])

# Ensure /source-charset: removes /utf-8
a.append('/source-charset:utf-8')
self.assertEqual(a.to_native(copy=True), ['/nologo', '/showIncludes', '/Zc:__cplusplus', '/source-charset:utf-8'])
self.assertEqual(a.to_native(copy=True), ['/nologo', '/Zc:__cplusplus', '/source-charset:utf-8'])

# Ensure /execution-charset: removes /utf-8
a = cc.compiler_args(cc.get_always_args() + ['/execution-charset:utf-8'])
self.assertEqual(a.to_native(copy=True), ['/nologo', '/showIncludes', '/Zc:__cplusplus', '/execution-charset:utf-8'])
self.assertEqual(a.to_native(copy=True), ['/nologo', '/Zc:__cplusplus', '/execution-charset:utf-8'])

# Ensure /validate-charset- removes /utf-8
a = cc.compiler_args(cc.get_always_args() + ['/validate-charset-'])
self.assertEqual(a.to_native(copy=True), ['/nologo', '/showIncludes', '/Zc:__cplusplus', '/validate-charset-'])
self.assertEqual(a.to_native(copy=True), ['/nologo', '/Zc:__cplusplus', '/validate-charset-'])

# /showIncludes is needed for build dependency tracking in Ninja
# See: https://ninja-build.org/manual.html#_deps
a = cc.compiler_args(cc.get_ninja_compile_args())
self.assertEqual(a.to_native(copy=True), ['/showIncludes'])


def test_msvc_unix_args_to_native(self):
Expand Down
Loading