From 460de248edac8b96180580749e77fbcb9543f77a Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Wed, 16 Jan 2013 16:23:16 -0800 Subject: [PATCH] add check to catkin_make to force cmake when cmake-specific arguments change --- bin/catkin_make | 21 ++++----------------- python/catkin/builder.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/bin/catkin_make b/bin/catkin_make index 4d57b969c..020eeb826 100755 --- a/bin/catkin_make +++ b/bin/catkin_make @@ -7,16 +7,12 @@ import subprocess import sys import os -from catkin_pkg.packages import find_packages - # find the import relatively if available to work before installing catkin or overlaying installed version if os.path.exists(os.path.join(os.path.dirname(__file__), 'CMakeLists.txt')): sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'python')) from catkin.init_workspace import init_workspace from catkin.terminal_color import disable_ANSI_colors -from catkin.builder import print_command_banner -from catkin.builder import run_command -from catkin.builder import run_command_colorized +from catkin.builder import cmake_input_changed, print_command_banner, run_command, run_command_colorized def main(): @@ -82,21 +78,12 @@ def main(): except Exception as e: return 'Creating the toplevel cmake file failed: %s' % str(e) - # compare list of package paths from last run and if it changed force cmake - packages = find_packages(source_path) - package_paths = os.pathsep.join(sorted(packages.keys())) - packages_changed = True - previous_package_paths_file = os.path.join(build_path, 'catkin_make.packages') - if os.path.exists(previous_package_paths_file): - with open(previous_package_paths_file, 'r') as f: - previous_package_paths = f.read() - packages_changed = (package_paths != previous_package_paths) - with open(previous_package_paths_file, 'w') as f: - f.write(package_paths) + # check if cmake must be run (either for a changed list of package paths or changed cmake arguments) + force_cmake = cmake_input_changed(source_path, build_path, cmake_args) # consider calling cmake makefile = os.path.join(build_path, 'Makefile') - if not os.path.exists(makefile) or args.force_cmake or packages_changed: + if not os.path.exists(makefile) or args.force_cmake or force_cmake: cmd = ['cmake', source_path, '-DCATKIN_DEVEL_PREFIX=%s' % devel_path, '-DCMAKE_INSTALL_PREFIX=%s' % install_path] cmd += cmake_args try: diff --git a/python/catkin/builder.py b/python/catkin/builder.py index 328cf08ee..74fa74105 100644 --- a/python/catkin/builder.py +++ b/python/catkin/builder.py @@ -41,6 +41,7 @@ import sys try: + from catkin_pkg.packages import find_packages from catkin_pkg.topological_order import topological_order except ImportError as e: sys.exit( @@ -574,3 +575,31 @@ def build_workspace_isolated( else 'KeyboardInterrupt') ) sys.exit('Command failed, exiting.') + + +def cmake_input_changed(source_path, build_path, cmake_args=None, filename='catkin_make'): + # get current input + packages = find_packages(source_path) + package_paths = os.pathsep.join(sorted(packages.keys())) + cmake_args = ' '.join(cmake_args) if cmake_args else '' + + # file to store current input + changed = False + input_filename = os.path.join(build_path, '%s.cache' % filename) + if not os.path.exists(input_filename): + changed = True + else: + # compare with previously stored input + with open(input_filename, 'r') as f: + previous_package_paths = f.readline().rstrip() + previous_cmake_args = f.readline().rstrip() + if package_paths != previous_package_paths: + changed = True + if cmake_args != previous_cmake_args: + changed = True + + # store current input for next invocation + with open(input_filename, 'w') as f: + f.write('%s\n%s' % (package_paths, cmake_args)) + + return changed