<s> from __future__ import print_function <EOL> import argparse <EOL> import logging <EOL> import os <EOL> import sys <EOL> try : <EOL> from catkin_pkg . packages import find_packages <EOL> from catkin_pkg . topological_order import topological_order_packages <EOL> except ImportError as e : <EOL> sys . exit ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % e <EOL> ) <EOL> from catkin_pkg . package import InvalidPackage <EOL> from catkin_pkg . tool_detection import get_previous_tool_used_on_the_space <EOL> from catkin_pkg . tool_detection import mark_space_as_built_by <EOL> from catkin_tools . argument_parsing import add_context_args <EOL> from catkin_tools . argument_parsing import add_cmake_and_make_and_catkin_make_args <EOL> from catkin_tools . argument_parsing import configure_make_args <EOL> from catkin_tools . common import get_build_type <EOL> from catkin_tools . common import getcwd <EOL> from catkin_tools . common import is_tty <EOL> from catkin_tools . common import log <EOL> from catkin_tools . common import find_enclosing_package <EOL> from catkin_tools . common import format_env_dict <EOL> from catkin_tools . context import Context <EOL> import catkin_tools . execution . job_server as job_server <EOL> from catkin_tools . jobs . utils import get_env_loader <EOL> from catkin_tools . metadata import find_enclosing_workspace <EOL> from catkin_tools . metadata import get_metadata <EOL> from catkin_tools . metadata import update_metadata <EOL> from catkin_tools . resultspace import load_resultspace_environment <EOL> from catkin_tools . terminal_color import set_color <EOL> from . color import clr <EOL> from . build import build_isolated_workspace <EOL> from . build import determine_packages_to_be_built <EOL> from . build import verify_start_with_option <EOL> backup__ArgumentGroup___init__ = argparse . _ArgumentGroup . __init__ <EOL> def fixed__ArgumentGroup___init__ ( self , container , title = None , description = None , ** kwargs ) : <EOL> backup__ArgumentGroup___init__ ( self , container , title , description , ** kwargs ) <EOL> self . _mutually_exclusive_groups = container . _mutually_exclusive_groups <EOL> argparse . _ArgumentGroup . __init__ = fixed__ArgumentGroup___init__ <EOL> def prepare_arguments ( parser ) : <EOL> parser . description = """<STR_LIT>""" <EOL> add_context_args ( parser ) <EOL> add = parser . add_argument <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , dest = '<STR_LIT>' , metavar = '<STR_LIT>' , nargs = <NUM_LIT:1> , <EOL> help = '<STR_LIT>' ) <EOL> pkg_group = parser . add_argument_group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> add = pkg_group . add_argument <EOL> add ( '<STR_LIT>' , metavar = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> start_with_group = pkg_group . add_mutually_exclusive_group ( ) <EOL> add = start_with_group . add_argument <EOL> add ( '<STR_LIT>' , metavar = '<STR_LIT>' , type = str , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add = pkg_group . add_argument <EOL> add ( '<STR_LIT>' , '<STR_LIT:-c>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> build_group = parser . add_argument_group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> add = build_group . add_argument <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = None , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = None , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = None , <EOL> help = '<STR_LIT>' ) <EOL> config_group = parser . add_argument_group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> add = config_group . add_argument <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add_cmake_and_make_and_catkin_make_args ( config_group ) <EOL> behavior_group = parser . add_argument_group ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> add = behavior_group . add_argument <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = None , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = argparse . SUPPRESS ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = argparse . SUPPRESS ) <EOL> add ( '<STR_LIT>' , default = None , help = argparse . SUPPRESS ) <EOL> add ( '<STR_LIT>' , metavar = '<STR_LIT>' , default = None , help = argparse . SUPPRESS ) <EOL> def status_rate_type ( rate ) : <EOL> rate = float ( rate ) <EOL> if rate < <NUM_LIT:0> : <EOL> raise argparse . ArgumentTypeError ( "<STR_LIT>" ) <EOL> return rate <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , type = status_rate_type , default = <NUM_LIT> , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> return parser <EOL> def dry_run ( context , packages , no_deps , start_with ) : <EOL> log ( context . summary ( ) ) <EOL> workspace_packages = find_packages ( context . source_space_abs , exclude_subspaces = True , warnings = [ ] ) <EOL> packages_to_be_built , packages_to_be_built_deps , all_packages = determine_packages_to_be_built ( <EOL> packages , context , workspace_packages ) <EOL> verify_start_with_option ( start_with , packages , all_packages , packages_to_be_built + packages_to_be_built_deps ) <EOL> if not no_deps : <EOL> packages_to_be_built . extend ( packages_to_be_built_deps ) <EOL> packages_to_be_built = topological_order_packages ( dict ( packages_to_be_built ) ) <EOL> log ( "<STR_LIT>" ) <EOL> max_name_len = str ( max ( [ len ( pkg . name ) for pth , pkg in packages_to_be_built ] ) ) <EOL> prefix = clr ( '<STR_LIT>' + ( '<STR_LIT>' if start_with else '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> for pkg_path , pkg in packages_to_be_built : <EOL> build_type = get_build_type ( pkg ) <EOL> if build_type == '<STR_LIT>' and '<STR_LIT>' in [ e . tagname for e in pkg . exports ] : <EOL> build_type = '<STR_LIT>' <EOL> if start_with and pkg . name == start_with : <EOL> start_with = None <EOL> log ( clr ( "<STR_LIT>" + max_name_len + "<STR_LIT>" ) <EOL> . format ( prefix = clr ( '<STR_LIT>' ) if start_with else prefix , name = pkg . name , build_type = build_type ) ) <EOL> log ( "<STR_LIT>" + str ( len ( packages_to_be_built ) ) ) <EOL> def print_build_env ( context , package_name ) : <EOL> workspace_packages = find_packages ( context . source_space_abs , exclude_subspaces = True , warnings = [ ] ) <EOL> for pth , pkg in workspace_packages . items ( ) : <EOL> if pkg . name == package_name : <EOL> environ = get_env_loader ( pkg , context ) ( os . environ ) <EOL> print ( format_env_dict ( environ ) ) <EOL> return <NUM_LIT:0> <EOL> print ( '<STR_LIT>' . format ( package_name ) , <EOL> file = sys . stderr ) <EOL> return <NUM_LIT:1> <EOL> def main ( opts ) : <EOL> if opts . develdebug is not None : <EOL> os . environ [ '<STR_LIT>' ] = opts . develdebug . lower ( ) <EOL> logging . basicConfig ( level = opts . develdebug . upper ( ) ) <EOL> opts . force_color = os . environ . get ( '<STR_LIT>' , opts . force_color ) <EOL> if ( opts . force_color or is_tty ( sys . stdout ) ) and not opts . no_color : <EOL> set_color ( True ) <EOL> else : <EOL> set_color ( False ) <EOL> if opts . build_this or opts . start_with_this : <EOL> try : <EOL> ws_path = find_enclosing_workspace ( getcwd ( ) ) <EOL> this_package = find_enclosing_package ( <EOL> search_start_path = getcwd ( ) , <EOL> ws_path = ws_path , <EOL> warnings = [ ] ) <EOL> except ( InvalidPackage , RuntimeError ) : <EOL> this_package = None <EOL> if opts . build_this : <EOL> if this_package : <EOL> opts . packages += [ this_package ] <EOL> else : <EOL> sys . exit ( <EOL> "<STR_LIT>" ) <EOL> if opts . start_with_this : <EOL> if this_package : <EOL> opts . start_with = this_package <EOL> else : <EOL> sys . exit ( <EOL> "<STR_LIT>" ) <EOL> if opts . no_deps and not opts . packages and not opts . unbuilt : <EOL> sys . exit ( clr ( "<STR_LIT>" ) ) <EOL> ctx = Context . load ( opts . workspace , opts . profile , opts , append = True ) <EOL> make_args , makeflags , cli_flags , jobserver = configure_make_args ( <EOL> ctx . make_args , ctx . jobs_args , ctx . use_internal_make_jobserver ) <EOL> if jobserver and opts . mem_limit : <EOL> log ( clr ( "<STR_LIT>" % str ( opts . mem_limit ) ) ) <EOL> try : <EOL> import psutil <EOL> except ImportError as exc : <EOL> log ( "<STR_LIT>" ) <EOL> log ( "<STR_LIT>" ) <EOL> sys . exit ( "<STR_LIT>" . format ( exc ) ) <EOL> job_server . set_max_mem ( opts . mem_limit ) <EOL> ctx . make_args = make_args <EOL> if ctx . extend_path is not None : <EOL> try : <EOL> load_resultspace_environment ( ctx . extend_path ) <EOL> except IOError as exc : <EOL> sys . exit ( clr ( "<STR_LIT>" % <EOL> ( ctx . extend_path , exc . message ) ) ) <EOL> if not ctx . source_space_exists ( ) : <EOL> sys . exit ( clr ( "<STR_LIT>" ) % ctx . source_space_abs ) <EOL> previous_tool = get_previous_tool_used_on_the_space ( ctx . build_space_abs ) <EOL> if previous_tool is not None and previous_tool != '<STR_LIT>' : <EOL> if opts . override_build_tool_check : <EOL> log ( clr ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( ctx . build_space_abs , previous_tool ) ) ) <EOL> else : <EOL> sys . exit ( clr ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( ctx . build_space_abs , previous_tool ) ) ) <EOL> previous_tool = get_previous_tool_used_on_the_space ( ctx . devel_space_abs ) <EOL> if previous_tool is not None and previous_tool != '<STR_LIT>' : <EOL> if opts . override_build_tool_check : <EOL> log ( clr ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( ctx . devel_space_abs , previous_tool ) ) ) <EOL> else : <EOL> sys . exit ( clr ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( ctx . devel_space_abs , previous_tool ) ) ) <EOL> if opts . dry_run : <EOL> dry_run ( ctx , opts . packages , opts . no_deps , opts . start_with ) <EOL> return <EOL> if opts . get_env : <EOL> return print_build_env ( ctx , opts . get_env [ <NUM_LIT:0> ] ) <EOL> mark_space_as_built_by ( ctx . build_space_abs , '<STR_LIT>' ) <EOL> mark_space_as_built_by ( ctx . devel_space_abs , '<STR_LIT>' ) <EOL> build_metadata = get_metadata ( ctx . workspace , ctx . profile , '<STR_LIT>' ) <EOL> if build_metadata . get ( '<STR_LIT>' ) != ctx . cmake_args : <EOL> opts . force_cmake = True <EOL> last_devel_layout = build_metadata . get ( '<STR_LIT>' , ctx . devel_layout ) <EOL> if last_devel_layout != ctx . devel_layout : <EOL> sys . exit ( clr ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> last_devel_layout , ctx . devel_layout ) ) <EOL> if build_metadata . get ( '<STR_LIT>' , False ) : <EOL> opts . force_cmake = True <EOL> update_metadata ( ctx . workspace , ctx . profile , '<STR_LIT>' , { '<STR_LIT>' : False } ) <EOL> update_metadata ( ctx . workspace , ctx . profile , '<STR_LIT>' , ctx . get_stored_dict ( ) ) <EOL> if opts . save_config : <EOL> Context . save ( ctx ) <EOL> try : <EOL> parallel_jobs = int ( opts . parallel_jobs ) <EOL> except TypeError : <EOL> parallel_jobs = None <EOL> if opts . verbose : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> return build_isolated_workspace ( <EOL> ctx , <EOL> packages = opts . packages , <EOL> start_with = opts . start_with , <EOL> no_deps = opts . no_deps , <EOL> unbuilt = opts . unbuilt , <EOL> n_jobs = parallel_jobs , <EOL> force_cmake = opts . force_cmake , <EOL> pre_clean = opts . pre_clean , <EOL> force_color = opts . force_color , <EOL> quiet = not opts . verbose , <EOL> interleave_output = opts . interleave_output , <EOL> no_status = opts . no_status , <EOL> limit_status_rate = opts . limit_status_rate , <EOL> lock_install = not opts . no_install_lock , <EOL> no_notify = opts . no_notify , <EOL> continue_on_failure = opts . continue_on_failure , <EOL> summarize_build = opts . summarize <EOL> ) </s>
