From d1541c74a65db4d9016f8df130aea983cb64bc79 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Fri, 15 Nov 2019 12:51:18 +0100 Subject: [PATCH] Give info and warnings about the TERM environment variable --- make/project_config.mk | 8 +++++++- tools/check_term.py | 41 +++++++++++++++++++++++++++++++++++++++ tools/cmake/kconfig.cmake | 2 ++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tools/check_term.py diff --git a/make/project_config.mk b/make/project_config.mk index 73369ebae..05c5d06e7 100644 --- a/make/project_config.mk +++ b/make/project_config.mk @@ -107,6 +107,12 @@ else MENUCONFIG_CMD := $(PYTHON) $(IDF_PATH)/tools/kconfig_new/menuconfig.py endif +.PHONY: term_check +term_check: +ifneq ($(OS),Windows_NT) + ${PYTHON} ${IDF_PATH}/tools/check_term.py +endif + # macro for running menuconfig define RunMenuConf mkdir -p $(BUILD_DIR_BASE)/include/config @@ -130,7 +136,7 @@ ifndef MAKE_RESTARTS # depend on any prerequisite that may cause a make restart as part of # the prerequisite's own recipe. -menuconfig: $(KCONFIG_TOOL_DIR)/mconf-idf | check_python_dependencies prepare_kconfig_files +menuconfig: $(KCONFIG_TOOL_DIR)/mconf-idf | check_python_dependencies term_check prepare_kconfig_files $(summary) MENUCONFIG ifdef BATCH_BUILD @echo "Can't run interactive configuration inside non-interactive build process." diff --git a/tools/check_term.py b/tools/check_term.py new file mode 100644 index 000000000..7a3fdcfbe --- /dev/null +++ b/tools/check_term.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# +# Copyright 2019 Espressif Systems (Shanghai) PTE LTD +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function +import os +import sys + +if __name__ == '__main__': + # Checks for the content of environment variable TERM to use with the Python- and curses-based menuconfig. It is + # not implemented in shell so calling this script could not use some other shell environment where TERM is set + # differently. Implemented here so it could be checked at one place for make and cmake as well. + if sys.platform == 'win32' and 'MSYSTEM' not in os.environ: + # no TERM is used in Windows command line + exit(0) + + term = os.environ.get('TERM', None) + + if term is None: + print('WARNING: The TERM environment variable is not defined. The curses-based menuconfig ' + 'will probably fail to run. Please consult the documentation of your terminal to set it up.') + else: + if term.endswith('256color'): + print('TERM environment variable is set to "{}"'.format(term)) + else: + print('WARNING: Menuconfig may fail because of the TERM environment variable is set ' + 'to "{}". Please consult the documentation of your terminal to set it up. ' + 'Some good, proved to been working setups include xterm-256color, screen-256color, ' + 'rxvt-unicode-256color.'.format(term)) diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index 17488bc38..4fd2d4eab 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -256,6 +256,7 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults) set(MENUCONFIG_CMD ${mconf}) else() set(MENUCONFIG_CMD ${python} ${idf_path}/tools/kconfig_new/menuconfig.py) + set(TERM_CHECK_CMD ${python} ${idf_path}/tools/check_term.py) endif() # Generate the menuconfig target @@ -267,6 +268,7 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults) --env "IDF_TARGET=${idf_target}" --dont-write-deprecated --output config ${sdkconfig} + COMMAND ${TERM_CHECK_CMD} COMMAND ${CMAKE_COMMAND} -E env "COMPONENT_KCONFIGS_SOURCE_FILE=${kconfigs_path}" "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE=${kconfigs_projbuild_path}"