Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check root dir #383

Closed
wants to merge 13 commits into from
30 changes: 30 additions & 0 deletions colcon_core/verb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from colcon_core.plugin_system import order_extensions_by_name

logger = colcon_logger.getChild(__name__)
DEFAULT_START_PATH = Path(os.path.abspath(os.getcwd()))
MARKER_NAME = '.colcon_root'


class VerbExtensionPoint:
Expand Down Expand Up @@ -124,6 +126,34 @@ def check_and_mark_install_layout(install_base, *, merge_install):
marker_path.write_text(this_install_layout + '\n')


def check_and_mark_colcon_root(start_path):
"""
Check the marker file for root workspace, otherwise create it.

The marker filename is `.colcon_root`.

:param str start_path: The path where verb is invoked
:raises RuntimeError: if marker file is found in parent directory
"""
current_path = start_path
home_path = Path(os.path.abspath(os.sep))
while current_path != home_path:
marker_path = current_path / MARKER_NAME
if marker_path.is_file():
if current_path != start_path:
raise RuntimeError(
"'{start_path}' is not marked as the root directory. "
"Please go to '{current_path}'. "
'If you want to mark current path as root directory, '
"please remove the '{MARKER_NAME}' file "
"in '{current_path}'.".format_map(locals()))
return
else:
current_path = current_path.parent
marker_path = start_path / MARKER_NAME
marker_path.write_text('\n')


def update_object(
object_, key, value, package_name, argument_type, value_source
):
Expand Down
5 changes: 4 additions & 1 deletion colcon_core/verb/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from colcon_core.task import TaskContext
from colcon_core.verb import check_and_mark_build_tool
from colcon_core.verb import check_and_mark_install_layout
from colcon_core.verb import check_and_mark_colcon_root
from colcon_core.verb import DEFAULT_START_PATH
from colcon_core.verb import logger
from colcon_core.verb import update_object
from colcon_core.verb import VerbExtensionPoint
Expand All @@ -49,7 +51,7 @@ def __init__(self, pkg, args, *, additional_destinations=None):
self.build_base = os.path.abspath(os.path.join(
os.getcwd(), args.build_base, pkg.name))
self.install_base = os.path.abspath(os.path.join(
os.getcwd(), args.install_base))
os.getcwd()))
self.merge_install = args.merge_install
if not args.merge_install:
self.install_base = os.path.join(
Expand Down Expand Up @@ -116,6 +118,7 @@ def add_arguments(self, *, parser): # noqa: D102
self.task_argument_destinations = decorated_parser.get_destinations()

def main(self, *, context): # noqa: D102
check_and_mark_colcon_root(DEFAULT_START_PATH)
check_and_mark_build_tool(context.args.build_base)
check_and_mark_install_layout(
context.args.install_base,
Expand Down
3 changes: 3 additions & 0 deletions colcon_core/verb/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from colcon_core.task import TaskContext
from colcon_core.verb import check_and_mark_build_tool
from colcon_core.verb import check_and_mark_install_layout
from colcon_core.verb import check_and_mark_colcon_root
from colcon_core.verb import DEFAULT_START_PATH
from colcon_core.verb import update_object
from colcon_core.verb import VerbExtensionPoint

Expand Down Expand Up @@ -130,6 +132,7 @@ def add_arguments(self, *, parser): # noqa: D102
'retest_until_fail'

def main(self, *, context): # noqa: D102
check_and_mark_colcon_root(DEFAULT_START_PATH)
check_and_mark_build_tool(context.args.build_base)
check_and_mark_install_layout(
context.args.install_base,
Expand Down