Skip to content

Commit

Permalink
add check to catkin_make to force cmake when cmake-specific arguments…
Browse files Browse the repository at this point in the history
… change
  • Loading branch information
dirk-thomas committed Jan 17, 2013
1 parent 8b43614 commit 460de24
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
21 changes: 4 additions & 17 deletions bin/catkin_make
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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:
Expand Down
29 changes: 29 additions & 0 deletions python/catkin/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

0 comments on commit 460de24

Please sign in to comment.