From 1b6a87d8b459077e10985c81f806f0358a19e2c5 Mon Sep 17 00:00:00 2001 From: Gustavo Jose de Sousa Date: Wed, 23 Mar 2016 08:37:02 -0300 Subject: [PATCH] waf: toolchain: clang: use waf to find toolchain path The find_realexec_path function was used for finding the toolchain path mostly because of two reasons: 1) We couldn't really use CXX or CC variables because the user could set those from the OS's environment and Waf wouldn't look for the executable file in that case. 2) Our CI configuration sets up symlinks for ccache and find_realexec_path works around that issue. The bad side about using find_realexec_path() is that, besides working aroung symlinks, it does the same thing that is done by Waf. This patch removes the dependency for such a function by addressing each of the reasons above stated: 1) We create a local copy of os.environ and, if there's a variable with the same name we are using, we remove it from the local copy. 2) As done before, we are looking for the cross ar program instead of gcc program, since that is not used for ccache symlinks. --- Tools/ardupilotwaf/toolchain.py | 42 ++++++++++++--------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/Tools/ardupilotwaf/toolchain.py b/Tools/ardupilotwaf/toolchain.py index 2b98c56818..9795158ef4 100644 --- a/Tools/ardupilotwaf/toolchain.py +++ b/Tools/ardupilotwaf/toolchain.py @@ -17,30 +17,6 @@ from waflib.Tools import clang, clangxx, gcc, gxx import os -def find_realexec_path(cfg, filename, path_list=[]): - if not filename: - return '' - - if not path_list: - path_list = cfg.environ.get('PATH','').split(os.pathsep) - - for dir in path_list: - path = os.path.abspath(os.path.expanduser(os.path.join(dir, filename))) - - if os.path.isfile(path): - if os.path.islink(path): - realpath = os.path.realpath(path) - - if filename not in os.path.basename(realpath): - continue - else: - return os.path.dirname(realpath) - - else: - return os.path.dirname(path) - - cfg.fatal('Could not find real exec path to %s in path_list %s:' % (filename, path_list)) - def _set_toolchain_prefix_wrapper(tool_module, var, compiler_names): original_configure = tool_module.configure def new_configure(cfg): @@ -73,10 +49,22 @@ def _clang_cross_support(cfg): prefix = cfg.env.TOOLCHAIN + '-' cfg.find_program(prefix + 'gcc', var='CROSS_GCC') - toolchain_path = os.path.join(find_realexec_path(cfg, prefix + 'ar'), - '..') - toolchain_path = os.path.abspath(toolchain_path) + environ = dict(os.environ) + if 'TOOLCHAIN_CROSS_AR' in environ: + # avoid OS's environment to mess up toolchain path finding + del environ['TOOLCHAIN_CROSS_AR'] + try: + cfg.find_program( + prefix + 'ar', + var='TOOLCHAIN_CROSS_AR', + environ=environ, + ) + except Errors.ConfigurationError as e: + cfg.fatal('toolchain: clang: couldn\'t find toolchain path', ex=e) + + toolchain_path = os.path.join(cfg.env.TOOLCHAIN_CROSS_AR[0], '..', '..') + toolchain_path = os.path.abspath(toolchain_path) cfg.msg('Using toolchain path for clang', toolchain_path) sysroot = cfg.cmd_and_log(