Skip to content

Commit

Permalink
perf python: Fix setup.py mypy errors
Browse files Browse the repository at this point in the history
getenv may return None, so assert it isn't None for CC and srctree
environmental variables required for the script.
Disable an optional warning related to Popen.

Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250311213628.569562-7-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
  • Loading branch information
Ian Rogers authored and Namhyung Kim committed Mar 24, 2025
1 parent 2194446 commit ba3b086
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/perf/util/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from re import sub

cc = getenv("CC")
assert cc, "Environment variable CC not set"

# Check if CC has options, as is the case in yocto, where it uses CC="cc --sysroot..."
cc_tokens = cc.split()
Expand All @@ -12,8 +13,13 @@
else:
cc_options = ""

# ignore optional stderr could be None as it is set to PIPE to avoid that.
# mypy: disable-error-code="union-attr"
cc_is_clang = b"clang version" in Popen([cc, "-v"], stderr=PIPE).stderr.readline()
src_feature_tests = getenv('srctree') + '/tools/build/feature'

srctree = getenv('srctree')
assert srctree, "Environment variable srctree, for the Linux sources, not set"
src_feature_tests = f'{srctree}/tools/build/feature'

def clang_has_option(option):
cc_output = Popen([cc, cc_options + option, path.join(src_feature_tests, "test-hello.c") ], stderr=PIPE).stderr.readlines()
Expand Down Expand Up @@ -71,7 +77,7 @@ def finalize_options(self):
# The python headers have mixed code with declarations (decls after asserts, for instance)
cflags += [ "-Wno-declaration-after-statement" ]

src_perf = getenv('srctree') + '/tools/perf'
src_perf = f'{srctree}/tools/perf'
build_lib = getenv('PYTHON_EXTBUILD_LIB')
build_tmp = getenv('PYTHON_EXTBUILD_TMP')

Expand Down

0 comments on commit ba3b086

Please sign in to comment.