# Path: ros_buildfarm/common.py
# class Scope(object):
# 
#     def __init__(self, scope_name, description):  # noqa: D107
#         global next_scope_id
#         self.scope_name = scope_name
#         self.description = description
#         self.scope_id = next_scope_id
#         next_scope_id += 1
# 
#     def __enter__(self):
#         if os.environ.get('TRAVIS') == 'true':
#             print('travis_fold:start:scope%d' % self.scope_id)
#         print('# BEGIN %s: %s' % (self.scope_name, self.description))
# 
#     def __exit__(self, type, value, traceback):
#         print('# END %s' % self.scope_name)
#         if os.environ.get('TRAVIS') == 'true':
#             print('travis_fold:end:scope%d' % self.scope_id)
# 
# Path: ros_buildfarm/workspace.py
# def clean_workspace(workspace_root):
#     # clean up build, devel and install spaces
#     build_space = os.path.join(workspace_root, 'build_isolated')
#     if os.path.exists(build_space):
#         shutil.rmtree(build_space)
#     devel_space = os.path.join(workspace_root, 'devel_isolated')
#     if os.path.exists(devel_space):
#         shutil.rmtree(devel_space)
#     install_space = os.path.join(workspace_root, 'install_isolated')
#     if os.path.exists(install_space):
#         shutil.rmtree(install_space)
#     test_results_dir = os.path.join(workspace_root, 'test_results')
#     if os.path.exists(test_results_dir):
#         shutil.rmtree(test_results_dir)
#     log_dir = os.path.join(workspace_root, 'log')
#     if os.path.exists(log_dir):
#         shutil.rmtree(log_dir)
# 
# Path: ros_buildfarm/workspace.py
# def ensure_workspace_exists(workspace_root):
#     # ensure that workspace exists
#     assert os.path.exists(workspace_root), \
#         "Workspace root '%s' does not exist" % workspace_root
#     source_space = os.path.join(workspace_root, 'src')
#     assert os.path.exists(source_space), \
#         "Source space '%s' does not exist" % source_space


import argparse
import os
import subprocess
import sys
from catkin_pkg.packages import find_packages
from ros_buildfarm.common import Scope
from ros_buildfarm.workspace import clean_workspace
from ros_buildfarm.workspace import ensure_workspace_exists
    parser.add_argument(
        '--workspace-root',
        required=True,
        help='The root path of the workspace to document')
    parser.add_argument(
        '--rosdoc2-dir',
        required=True,
        help='The root path of the rosdoc2 repository')
    parser.add_argument(
        'pkg_tuples',
        nargs='*',
        help='A list of package tuples in topological order, each containing '
             'the name, and the relative path separated by a colon')
    args = parser.parse_args(argv)

    ensure_workspace_exists(args.workspace_root)
    clean_workspace(args.workspace_root)

    with Scope('SUBSECTION', 'Installing rosdoc2'):
        pip_rc = subprocess.call(['python3',
                                  '-m',
                                  'pip',
                                  'install',
                                  '--no-warn-script-location',
                                  '--use-deprecated=out-of-tree-build',
                                  '.'],
                                 cwd=args.rosdoc2_dir)
        if pip_rc:
            return pip_rc


# Path: ros_buildfarm/common.py
# class Scope(object):
# 
#     def __init__(self, scope_name, description):  # noqa: D107
#         global next_scope_id
#         self.scope_name = scope_name
#         self.description = description
#         self.scope_id = next_scope_id
#         next_scope_id += 1
# 
#     def __enter__(self):
#         if os.environ.get('TRAVIS') == 'true':
#             print('travis_fold:start:scope%d' % self.scope_id)
#         print('# BEGIN %s: %s' % (self.scope_name, self.description))
# 
#     def __exit__(self, type, value, traceback):
#         print('# END %s' % self.scope_name)
#         if os.environ.get('TRAVIS') == 'true':
#             print('travis_fold:end:scope%d' % self.scope_id)
# 
# Path: ros_buildfarm/workspace.py
# def clean_workspace(workspace_root):
#     # clean up build, devel and install spaces
#     build_space = os.path.join(workspace_root, 'build_isolated')
#     if os.path.exists(build_space):
#         shutil.rmtree(build_space)
#     devel_space = os.path.join(workspace_root, 'devel_isolated')
#     if os.path.exists(devel_space):
#         shutil.rmtree(devel_space)
#     install_space = os.path.join(workspace_root, 'install_isolated')
#     if os.path.exists(install_space):
#         shutil.rmtree(install_space)
#     test_results_dir = os.path.join(workspace_root, 'test_results')
#     if os.path.exists(test_results_dir):
#         shutil.rmtree(test_results_dir)
#     log_dir = os.path.join(workspace_root, 'log')
#     if os.path.exists(log_dir):
#         shutil.rmtree(log_dir)
# 
# Path: ros_buildfarm/workspace.py
# def ensure_workspace_exists(workspace_root):
#     # ensure that workspace exists
#     assert os.path.exists(workspace_root), \
#         "Workspace root '%s' does not exist" % workspace_root
#     source_space = os.path.join(workspace_root, 'src')
#     assert os.path.exists(source_space), \
#         "Source space '%s' does not exist" % source_space


# Path: scripts/doc/build_rosdoc2.py
import argparse
import os
import subprocess
import sys
from catkin_pkg.packages import find_packages
from ros_buildfarm.common import Scope
from ros_buildfarm.workspace import clean_workspace
from ros_buildfarm.workspace import ensure_workspace_exists

    parser.add_argument(
        '--workspace-root',
        required=True,
        help='The root path of the workspace to document')
    parser.add_argument(
        '--rosdoc2-dir',
        required=True,
        help='The root path of the rosdoc2 repository')
    parser.add_argument(
        'pkg_tuples',
        nargs='*',
        help='A list of package tuples in topological order, each containing '
             'the name, and the relative path separated by a colon')
    args = parser.parse_args(argv)

    ensure_workspace_exists(args.workspace_root)
    clean_workspace(args.workspace_root)

    with Scope('SUBSECTION', 'Installing rosdoc2'):
        pip_rc = subprocess.call(['python3',
                                  '-m',
                                  'pip',
                                  'install',
                                  '--no-warn-script-location',
                                  '--use-deprecated=out-of-tree-build',
                                  '.'],
                                 cwd=args.rosdoc2_dir)
        if pip_rc:
            return pip_rc


    with Scope('SUBSECTION', 'rosdoc2'):