Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #60 from ament/fix_skip_if_exists
Browse files Browse the repository at this point in the history
change how skip_if_exists is used
  • Loading branch information
wjwwood committed Oct 28, 2015
2 parents bca00ef + 4bc3465 commit f8e6888
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
63 changes: 39 additions & 24 deletions ament_tools/build_types/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from ament_tools.context import ContextExtender

from ament_tools.helper import compute_deploy_destination
from ament_tools.helper import deploy_file
from ament_tools.helper import extract_argument_group

Expand Down Expand Up @@ -216,6 +217,39 @@ def _common_cmake_on_test(self, context, build_type):
context.ctest_args)

def on_install(self, context):
# First determine the files being deployed with skip_if_exists=True and remove them.
environment_hooks_path = \
os.path.join('share', context.package_manifest.name, 'environment')

environment_hooks_to_be_deployed = []

# Prepare to deploy PATH environment hook
ext = '.sh' if not IS_WINDOWS else '.bat'
path_template_path = get_environment_hook_template_path('path' + ext)
environment_hooks_to_be_deployed.append(path_template_path)
environment_hooks = [os.path.join(environment_hooks_path, 'path' + ext)]

# Prepare to deploy library path environment hook if not on Windows
if not IS_WINDOWS:
library_template_path = get_environment_hook_template_path('library_path.sh')
environment_hooks_to_be_deployed.append(library_template_path)
environment_hooks.append(os.path.join(environment_hooks_path, 'library_path.sh'))

# Expand package level setup files
destinations = \
expand_package_level_setup_files(context, environment_hooks, environment_hooks_path)

# Remove package level setup files so they can be replaced correctly either in the
# cmake install step or later with deploy_file(..., skip_if_exists=True)
for destination in destinations:
destination_path = compute_deploy_destination(
context,
os.path.basename(destination),
os.path.dirname(os.path.relpath(destination, context.build_space))
)
if os.path.exists(destination_path) or os.path.islink(destination_path):
os.remove(destination_path)

# Call cmake common on_install (defined in CmakeBuildType)
for step in self._common_cmake_on_install(context):
yield step
Expand All @@ -233,37 +267,18 @@ def on_install(self, context):
with open(marker_file, 'w'): # "touching" the file
pass

environment_hooks_path = \
os.path.join('share', context.package_manifest.name, 'environment')

# deploy PATH environment hook
ext = '.sh' if not IS_WINDOWS else '.bat'
path_template_path = get_environment_hook_template_path('path' + ext)
deploy_file(
context, os.path.dirname(path_template_path), os.path.basename(path_template_path),
dst_subfolder=environment_hooks_path)

environment_hooks = [os.path.join(environment_hooks_path, 'path' + ext)]

# deploy library path environment hook
if not IS_WINDOWS:
library_template_path = get_environment_hook_template_path('library_path.sh')
# Deploy environment hooks
for environment_hook in environment_hooks_to_be_deployed:
deploy_file(
context,
os.path.dirname(library_template_path), os.path.basename(library_template_path),
context, os.path.dirname(environment_hook), os.path.basename(environment_hook),
dst_subfolder=environment_hooks_path)
environment_hooks.append(os.path.join(environment_hooks_path, 'library_path.sh'))

# expand package-level setup files
destinations = expand_package_level_setup_files(
context, environment_hooks, environment_hooks_path)
# Expand package-level setup files
for destination in destinations:
rel_destination_dir = \
os.path.dirname(os.path.relpath(destination, context.build_space))
deploy_file(
context,
os.path.dirname(destination), os.path.basename(destination),
dst_subfolder=rel_destination_dir,
dst_subfolder=os.path.dirname(os.path.relpath(destination, context.build_space)),
skip_if_exists=True)

def _common_cmake_on_install(self, context):
Expand Down
7 changes: 5 additions & 2 deletions ament_tools/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def extract_argument_group(args, delimiting_option):
return trimmed_args, extracted_args


def compute_deploy_destination(context, filename, dst_subfolder=''):
return os.path.join(context.install_space, dst_subfolder, filename)


def deploy_file(
context,
source_base_path,
Expand All @@ -234,8 +238,7 @@ def deploy_file(
source_path = os.path.join(source_base_path, filename)

# create destination folder if necessary
destination_path = os.path.join(
context.install_space, dst_subfolder, filename)
destination_path = compute_deploy_destination(context, filename, dst_subfolder)
# If the file exists and we should skip if we didn't install it.
if (
(os.path.exists(destination_path) or os.path.islink(destination_path)) and
Expand Down

0 comments on commit f8e6888

Please sign in to comment.