Skip to content

Commit

Permalink
Handle switching between symlink and normal
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay committed Sep 1, 2023
1 parent 4b90b14 commit e4799ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 10 additions & 1 deletion colcon_core/distutils/commands/symlink_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the Apache License, Version 2.0

from distutils.command.install_data import install_data
import os.path
import os


class symlink_data(install_data): # noqa: N801
Expand All @@ -12,6 +12,15 @@ def copy_file(self, src, dst, **kwargs): # noqa: D102
if kwargs.get('link'):
return super().copy_file(src, dst, **kwargs)

if self.force:
# os.symlink fails if the destination exists as a regular file
if os.path.isdir(dst):
target = os.path.join(dst, os.path.basename(src))
else:
target = dst
if os.path.exists(dst) and not os.path.islink(dst):
os.remove(target)

kwargs['link'] = 'sym'
src = os.path.abspath(src)
return super().copy_file(src, dst, **kwargs)
13 changes: 12 additions & 1 deletion colcon_core/task/python/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ async def build(self, *, additional_hooks=None): # noqa: D102
# prevent installation of dependencies specified in setup.py
cmd.append('--single-version-externally-managed')
self._append_install_layout(args, cmd)
if setup_py_data.get('data_files'):
cmd += ['install_data']
if rc is not None:
cmd += ['--force']
completed = await run(
self.context, cmd, cwd=args.path, env=env)
if completed.returncode:
return completed.returncode

else:
self._undo_install(pkg, args, setup_py_data, python_lib)
rc = self._undo_install(pkg, args, setup_py_data, python_lib)
if rc:
return rc
temp_symlinks = self._symlinks_in_build(args, setup_py_data)

# invoke `setup.py develop` step in build space
Expand All @@ -139,6 +145,8 @@ async def build(self, *, additional_hooks=None): # noqa: D102
]
if setup_py_data.get('data_files'):
cmd += ['symlink_data']
if rc is not None:
cmd += ['--force']
completed = await run(
self.context, cmd, cwd=args.build_base, env=env)
finally:
Expand Down Expand Up @@ -198,6 +206,8 @@ async def _undo_develop(self, pkg, args, env):
]
completed = await run(
self.context, cmd, cwd=args.build_base, env=env)
if not completed.returncode:
os.remove(setup_py_build_space)
return completed.returncode

def _undo_install(self, pkg, args, setup_py_data, python_lib):
Expand Down Expand Up @@ -240,6 +250,7 @@ def _undo_install(self, pkg, args, setup_py_data, python_lib):
with suppress(OSError):
os.rmdir(d)
os.remove(install_log)
return 0

def _symlinks_in_build(self, args, setup_py_data):
items = ['setup.py']
Expand Down

0 comments on commit e4799ea

Please sign in to comment.