Skip to content

Commit

Permalink
backend/ninja: Fix cases where None is passed when unexpected
Browse files Browse the repository at this point in the history
When getting debug file arguments we can sometimes pass None, where a
None is unexpected. This becomes a particular problem in the Cuda
compiler, where the output will unconditionally be concatenated with a
static string, resulting in an uncaught exception. This is really easy
to spot once we annotate the functions in question, where a static type
checker like mypy easily spots the issue.

This commit adds those annotations, and then fixes the resulting error.

Fixes: mesonbuild#12997
  • Loading branch information
dcbaker committed Apr 18, 2024
1 parent 46b3c1c commit 9e3b3db
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2012-2017 The Meson development team
# Copyright © 2023 Intel Corporation
# Copyright © 2023-2024 Intel Corporation

from __future__ import annotations

Expand Down Expand Up @@ -2767,11 +2767,17 @@ def get_compile_debugfile_args(self, compiler, target, objfile):
else:
return compiler.get_compile_debugfile_args(objfile, pch=False)

def get_link_debugfile_name(self, linker, target) -> T.Optional[str]:
return linker.get_link_debugfile_name(self.get_target_debug_filename(target))
def get_link_debugfile_name(self, linker: T.Union[Compiler, StaticLinker], target: build.BuildTarget) -> T.Optional[str]:
filename = self.get_target_debug_filename(target)
if filename:
return linker.get_link_debugfile_name(filename)
return None

def get_link_debugfile_args(self, linker, target):
return linker.get_link_debugfile_args(self.get_target_debug_filename(target))
def get_link_debugfile_args(self, linker: T.Union[Compiler, StaticLinker], target: build.BuildTarget) -> T.List[str]:
filename = self.get_target_debug_filename(target)
if filename:
return linker.get_link_debugfile_args(filename)
return []

def generate_llvm_ir_compile(self, target, src: mesonlib.FileOrString):
base_proxy = target.get_options()
Expand Down

0 comments on commit 9e3b3db

Please sign in to comment.