コード例 #1
0
ファイル: cli.py プロジェクト: dornhege/catkin_tools
def main(opts):
    # Context-aware args
    if opts.build_this or opts.start_with_this:
        # Determine the enclosing package
        try:
            ws_path = find_enclosing_workspace(getcwd())
            # Suppress warnings since this won't necessaraly find all packages
            # in the workspace (it stops when it finds one package), and
            # relying on it for warnings could mislead people.
            this_package = find_enclosing_package(search_start_path=getcwd(),
                                                  ws_path=ws_path,
                                                  warnings=[])
        except (InvalidPackage, RuntimeError):
            this_package = None

        # Handle context-based package building
        if opts.build_this:
            if this_package:
                opts.packages += [this_package]
            else:
                sys.exit(
                    "catkin build: --this was specified, but this directory is not in a catkin package."
                )

        # If --start--with was used without any packages and --this was specified, start with this package
        if opts.start_with_this:
            if this_package:
                opts.start_with = this_package
            else:
                sys.exit(
                    "catkin build: --this was specified, but this directory is not in a catkin package."
                )

    if opts.no_deps and not opts.packages:
        sys.exit("With --no-deps, you must specify packages to build.")

    # Load the context
    ctx = Context.load(opts.workspace, opts.profile, opts, append=True)

    # Initialize the build configuration
    make_args, makeflags, cli_flags, jobserver = configure_make_args(
        ctx.make_args, ctx.use_internal_make_jobserver)

    # Set the jobserver memory limit
    if jobserver and opts.mem_limit:
        log(
            clr("@!@{pf}EXPERIMENTAL: limit memory to '%s'@|" %
                str(opts.mem_limit)))
        # At this point psuitl will be required, check for it and bail out if not set
        try:
            import psutil  # noqa
        except ImportError as exc:
            log("Could not import psutil, but psutil is required when using --mem-limit."
                )
            log("Please either install psutil or avoid using --mem-limit.")
            sys.exit("Exception: {0}".format(exc))
        set_jobserver_max_mem(opts.mem_limit)

    ctx.make_args = make_args

    # Load the environment of the workspace to extend
    if ctx.extend_path is not None:
        try:
            load_resultspace_environment(ctx.extend_path)
        except IOError as exc:
            log(
                clr("@!@{rf}Error:@| Unable to extend workspace from \"%s\": %s"
                    % (ctx.extend_path, exc.message)))
            return 1

    # Display list and leave the file system untouched
    if opts.dry_run:
        dry_run(ctx, opts.packages, opts.no_deps, opts.start_with)
        return

    # Check if the context is valid before writing any metadata
    if not ctx.source_space_exists():
        print("catkin build: error: Unable to find source space `%s`" %
              ctx.source_space_abs)
        return 1

    # Always save the last context under the build verb
    update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict())

    build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build')
    if build_metadata.get('needs_force', False):
        opts.force_cmake = True
        update_metadata(ctx.workspace, ctx.profile, 'build',
                        {'needs_force': False})

    # Save the context as the configuration
    if opts.save_config:
        Context.save(ctx)

    start = time.time()
    try:
        return build_isolated_workspace(
            ctx,
            packages=opts.packages,
            start_with=opts.start_with,
            no_deps=opts.no_deps,
            jobs=opts.parallel_jobs,
            force_cmake=opts.force_cmake,
            force_color=opts.force_color,
            quiet=not opts.verbose,
            interleave_output=opts.interleave_output,
            no_status=opts.no_status,
            limit_status_rate=opts.limit_status_rate,
            lock_install=not opts.no_install_lock,
            no_notify=opts.no_notify,
            continue_on_failure=opts.continue_on_failure,
            summarize_build=opts.summarize  # Can be True, False, or None
        )
    finally:
        log("[build] Runtime: {0}".format(
            format_time_delta(time.time() - start)))
コード例 #2
0
ファイル: cli.py プロジェクト: wjwwood/catkin_tools
def main(opts):
    # Context-aware args
    if opts.build_this or opts.start_with_this:
        # Determine the enclosing package
        try:
            this_package = find_enclosing_package()
        except InvalidPackage:
            pass

        # Handle context-based package building
        if opts.build_this:
            if this_package:
                opts.packages += [this_package]
            else:
                sys.exit(
                    "catkin build: --this was specified, but this directory is not in a catkin package."
                )

        # If --start--with was used without any packages and --this was specified, start with this package
        if opts.start_with_this:
            if this_package:
                opts.start_with = this_package
            else:
                sys.exit(
                    "catkin build: --this was specified, but this directory is not in a catkin package."
                )

    if opts.no_deps and not opts.packages:
        sys.exit("With --no-deps, you must specify packages to build.")

    if not opts.force_color and not is_tty(sys.stdout):
        set_color(False)

    # Load the context
    ctx = Context.Load(opts.workspace, opts.profile, opts)

    # Load the environment of the workspace to extend
    if ctx.extend_path is not None:
        try:
            load_resultspace_environment(ctx.extend_path)
        except IOError as exc:
            log(
                clr("@!@{rf}Error:@| Unable to extend workspace from \"%s\": %s"
                    % (ctx.extend_path, exc.message)))
            return 1

    # Display list and leave the filesystem untouched
    if opts.dry_run:
        dry_run(ctx, opts.packages, opts.no_deps, opts.start_with)
        return

    # Check if the context is valid before writing any metadata
    if not ctx.source_space_exists():
        print("catkin build: error: Unable to find source space `%s`" %
              ctx.source_space_abs)
        return 1

    # Always save the last context under the build verb
    update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict())

    build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build')
    if build_metadata.get('needs_force', False):
        opts.force_cmake = True
        update_metadata(ctx.workspace, ctx.profile, 'build',
                        {'needs_force': False})

    # Save the context as the configuration
    if opts.save_config:
        Context.Save(ctx)

    start = time.time()
    try:
        return build_isolated_workspace(
            ctx,
            packages=opts.packages,
            start_with=opts.start_with,
            no_deps=opts.no_deps,
            jobs=opts.parallel_jobs,
            force_cmake=opts.force_cmake,
            force_color=opts.force_color,
            quiet=not opts.verbose,
            interleave_output=opts.interleave_output,
            no_status=opts.no_status,
            limit_status_rate=opts.limit_status_rate,
            lock_install=not opts.no_install_lock,
            no_notify=opts.no_notify)
    finally:
        log("[build] Runtime: {0}".format(
            format_time_delta(time.time() - start)))
コード例 #3
0
ファイル: cli.py プロジェクト: simonlynen/catkin_tools
def main(opts):

    # Context-aware args
    if opts.build_this or opts.start_with_this:
        # Determine the enclosing package
        try:
            this_package = find_enclosing_package()
        except InvalidPackage:
            pass

        # Handle context-based package building
        if opts.build_this:
            if this_package:
                opts.packages += [this_package]
            else:
                sys.exit("catkin build: --this was specified, but this directory is not contained by a catkin package.")

        # If --start--with was used without any packages and --this was specified, start with this package
        if opts.start_with_this:
            if this_package:
                opts.start_with = this_package
            else:
                sys.exit("catkin build: --this was specified, but this directory is not contained by a catkin package.")

    if opts.no_deps and not opts.packages:
        sys.exit("With --no-deps, you must specify packages to build.")

    if not opts.force_color and not is_tty(sys.stdout):
        set_color(False)

    # Load the context
    ctx = Context.Load(opts.workspace, opts.profile, opts)

    # Load the environment of the workspace to extend
    if ctx.extend_path is not None:
        try:
            load_resultspace_environment(ctx.extend_path)
        except IOError as exc:
            log(clr("@!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" %
                    (ctx.extend_path, exc.message)))
            return 1

    # Display list and leave the filesystem untouched
    if opts.dry_run:
        dry_run(ctx, opts.packages, opts.no_deps, opts.start_with)
        return

    # Check if the context is valid before writing any metadata
    if not ctx.source_space_exists():
        print("catkin build: error: Unable to find source space `%s`" % ctx.source_space_abs)
        return 1

    # Always save the last context under the build verb
    update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict())

    build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build')
    if build_metadata.get('needs_force', False):
        opts.force_cmake = True
        update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False})

    # Save the context as the configuration
    if opts.save_config:
        Context.Save(ctx)

    start = time.time()
    try:
        return build_isolated_workspace(
            ctx,
            packages=opts.packages,
            start_with=opts.start_with,
            no_deps=opts.no_deps,
            jobs=opts.parallel_jobs,
            force_cmake=opts.force_cmake,
            force_color=opts.force_color,
            quiet=not opts.verbose,
            interleave_output=opts.interleave_output,
            no_status=opts.no_status,
            lock_install=not opts.no_install_lock,
            no_notify=opts.no_notify
        )
    finally:
        log("[build] Runtime: {0}".format(format_time_delta(time.time() - start)))
コード例 #4
0
ファイル: cli.py プロジェクト: esteve/catkin_tools
def main(opts):

    # Check for develdebug mode
    if opts.develdebug is not None:
        os.environ['TROLLIUSDEBUG'] = opts.develdebug.lower()
        logging.basicConfig(level=opts.develdebug.upper())

    # Set color options
    if (opts.force_color or is_tty(sys.stdout)) and not opts.no_color:
        set_color(True)
    else:
        set_color(False)

    # Context-aware args
    if opts.build_this or opts.start_with_this:
        # Determine the enclosing package
        try:
            ws_path = find_enclosing_workspace(getcwd())
            # Suppress warnings since this won't necessaraly find all packages
            # in the workspace (it stops when it finds one package), and
            # relying on it for warnings could mislead people.
            this_package = find_enclosing_package(
                search_start_path=getcwd(),
                ws_path=ws_path,
                warnings=[])
        except (InvalidPackage, RuntimeError):
            this_package = None

        # Handle context-based package building
        if opts.build_this:
            if this_package:
                opts.packages += [this_package]
            else:
                sys.exit(
                    "[build] Error: In order to use --this, the current directory must be part of a catkin package.")

        # If --start--with was used without any packages and --this was specified, start with this package
        if opts.start_with_this:
            if this_package:
                opts.start_with = this_package
            else:
                sys.exit(
                    "[build] Error: In order to use --this, the current directory must be part of a catkin package.")

    if opts.no_deps and not opts.packages and not opts.unbuilt:
        sys.exit(clr("[build] @!@{rf}Error:@| With --no-deps, you must specify packages to build."))

    # Load the context
    ctx = Context.load(opts.workspace, opts.profile, opts, append=True)

    # Initialize the build configuration
    make_args, makeflags, cli_flags, jobserver = configure_make_args(
        ctx.make_args, ctx.jobs_args, ctx.use_internal_make_jobserver)

    # Set the jobserver memory limit
    if jobserver and opts.mem_limit:
        log(clr("@!@{pf}EXPERIMENTAL: limit memory to '%s'@|" % str(opts.mem_limit)))
        # At this point psuitl will be required, check for it and bail out if not set
        try:
            import psutil  # noqa
        except ImportError as exc:
            log("Could not import psutil, but psutil is required when using --mem-limit.")
            log("Please either install psutil or avoid using --mem-limit.")
            sys.exit("Exception: {0}".format(exc))
        job_server.set_max_mem(opts.mem_limit)

    ctx.make_args = make_args

    # Load the environment of the workspace to extend
    if ctx.extend_path is not None:
        try:
            load_resultspace_environment(ctx.extend_path)
        except IOError as exc:
            sys.exit(clr("[build] @!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" %
                         (ctx.extend_path, exc.message)))

    # Check if the context is valid before writing any metadata
    if not ctx.source_space_exists():
        sys.exit(clr("[build] @!@{rf}Error:@| Unable to find source space `%s`") % ctx.source_space_abs)

    # ensure the build space was previously built by catkin_tools
    previous_tool = get_previous_tool_used_on_the_space(ctx.build_space_abs)
    if previous_tool is not None and previous_tool != 'catkin build':
        if opts.override_build_tool_check:
            log(clr(
                "@{yf}Warning: build space at '%s' was previously built by '%s', "
                "but --override-build-tool-check was passed so continuing anyways."
                % (ctx.build_space_abs, previous_tool)))
        else:
            sys.exit(clr(
                "@{rf}The build space at '%s' was previously built by '%s'. "
                "Please remove the build space or pick a different build space."
                % (ctx.build_space_abs, previous_tool)))
    # the build space will be marked as catkin build's if dry run doesn't return

    # ensure the devel space was previously built by catkin_tools
    previous_tool = get_previous_tool_used_on_the_space(ctx.devel_space_abs)
    if previous_tool is not None and previous_tool != 'catkin build':
        if opts.override_build_tool_check:
            log(clr(
                "@{yf}Warning: devel space at '%s' was previously built by '%s', "
                "but --override-build-tool-check was passed so continuing anyways."
                % (ctx.devel_space_abs, previous_tool)))
        else:
            sys.exit(clr(
                "@{rf}The devel space at '%s' was previously built by '%s'. "
                "Please remove the devel space or pick a different devel space."
                % (ctx.devel_space_abs, previous_tool)))
    # the devel space will be marked as catkin build's if dry run doesn't return

    # Display list and leave the file system untouched
    if opts.dry_run:
        # TODO: Add unbuilt
        dry_run(ctx, opts.packages, opts.no_deps, opts.start_with)
        return

    # Print the build environment for a given package and leave the filesystem untouched
    if opts.get_env:
        return print_build_env(ctx, opts.get_env[0])

    # Now mark the build and devel spaces as catkin build's since dry run didn't return.
    mark_space_as_built_by(ctx.build_space_abs, 'catkin build')
    mark_space_as_built_by(ctx.devel_space_abs, 'catkin build')

    # Get the last build context
    build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build')

    if build_metadata.get('cmake_args') != ctx.cmake_args or build_metadata.get('cmake_args') != opts.cmake_args:
        opts.force_cmake = True

    if build_metadata.get('needs_force', False):
        opts.force_cmake = True
        update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False})

    # Always save the last context under the build verb
    update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict())

    # Save the context as the configuration
    if opts.save_config:
        Context.save(ctx)

    # Get parallel toplevel jobs
    try:
        parallel_jobs = int(opts.parallel_jobs)
    except TypeError:
        parallel_jobs = None

    # Set VERBOSE environment variable
    if opts.verbose:
        os.environ['VERBOSE'] = '1'

    return build_isolated_workspace(
        ctx,
        packages=opts.packages,
        start_with=opts.start_with,
        no_deps=opts.no_deps,
        unbuilt=opts.unbuilt,
        n_jobs=parallel_jobs,
        force_cmake=opts.force_cmake,
        pre_clean=opts.pre_clean,
        force_color=opts.force_color,
        quiet=not opts.verbose,
        interleave_output=opts.interleave_output,
        no_status=opts.no_status,
        limit_status_rate=opts.limit_status_rate,
        lock_install=not opts.no_install_lock,
        no_notify=opts.no_notify,
        continue_on_failure=opts.continue_on_failure,
        summarize_build=opts.summarize  # Can be True, False, or None
    )
コード例 #5
0
ファイル: cli.py プロジェクト: srini196/catkin_tools
def main(opts):

    # Check for develdebug mode
    if opts.develdebug is not None:
        os.environ['TROLLIUSDEBUG'] = opts.develdebug.lower()
        logging.basicConfig(level=opts.develdebug.upper())

    # Set color options
    opts.force_color = os.environ.get('CATKIN_TOOLS_FORCE_COLOR',
                                      opts.force_color)
    if (opts.force_color or is_tty(sys.stdout)) and not opts.no_color:
        set_color(True)
    else:
        set_color(False)

    # Context-aware args
    if opts.build_this or opts.start_with_this:
        # Determine the enclosing package
        try:
            ws_path = find_enclosing_workspace(getcwd())
            # Suppress warnings since this won't necessaraly find all packages
            # in the workspace (it stops when it finds one package), and
            # relying on it for warnings could mislead people.
            this_package = find_enclosing_package(search_start_path=getcwd(),
                                                  ws_path=ws_path,
                                                  warnings=[])
        except (InvalidPackage, RuntimeError):
            this_package = None

        # Handle context-based package building
        if opts.build_this:
            if this_package:
                opts.packages += [this_package]
            else:
                sys.exit(
                    "[build] Error: In order to use --this, the current directory must be part of a catkin package."
                )

        # If --start--with was used without any packages and --this was specified, start with this package
        if opts.start_with_this:
            if this_package:
                opts.start_with = this_package
            else:
                sys.exit(
                    "[build] Error: In order to use --this, the current directory must be part of a catkin package."
                )

    if opts.no_deps and not opts.packages and not opts.unbuilt:
        sys.exit(
            clr("[build] @!@{rf}Error:@| With --no-deps, you must specify packages to build."
                ))

    # Load the context
    ctx = Context.load(opts.workspace, opts.profile, opts, append=True)

    # Initialize the build configuration
    make_args, makeflags, cli_flags, jobserver = configure_make_args(
        ctx.make_args, ctx.jobs_args, ctx.use_internal_make_jobserver)

    # Set the jobserver memory limit
    if jobserver and opts.mem_limit:
        log(
            clr("@!@{pf}EXPERIMENTAL: limit memory to '%s'@|" %
                str(opts.mem_limit)))
        # At this point psuitl will be required, check for it and bail out if not set
        try:
            import psutil  # noqa
        except ImportError as exc:
            log("Could not import psutil, but psutil is required when using --mem-limit."
                )
            log("Please either install psutil or avoid using --mem-limit.")
            sys.exit("Exception: {0}".format(exc))
        job_server.set_max_mem(opts.mem_limit)

    ctx.make_args = make_args

    # Load the environment of the workspace to extend
    if ctx.extend_path is not None:
        try:
            load_resultspace_environment(ctx.extend_path)
        except IOError as exc:
            sys.exit(
                clr("[build] @!@{rf}Error:@| Unable to extend workspace from \"%s\": %s"
                    % (ctx.extend_path, exc.message)))

    # Check if the context is valid before writing any metadata
    if not ctx.source_space_exists():
        sys.exit(
            clr("[build] @!@{rf}Error:@| Unable to find source space `%s`") %
            ctx.source_space_abs)

    # ensure the build space was previously built by catkin_tools
    previous_tool = get_previous_tool_used_on_the_space(ctx.build_space_abs)
    if previous_tool is not None and previous_tool != 'catkin build':
        if opts.override_build_tool_check:
            log(
                clr("@{yf}Warning: build space at '%s' was previously built by '%s', "
                    "but --override-build-tool-check was passed so continuing anyways."
                    % (ctx.build_space_abs, previous_tool)))
        else:
            sys.exit(
                clr("@{rf}The build space at '%s' was previously built by '%s'. "
                    "Please remove the build space or pick a different build space."
                    % (ctx.build_space_abs, previous_tool)))
    # the build space will be marked as catkin build's if dry run doesn't return

    # ensure the devel space was previously built by catkin_tools
    previous_tool = get_previous_tool_used_on_the_space(ctx.devel_space_abs)
    if previous_tool is not None and previous_tool != 'catkin build':
        if opts.override_build_tool_check:
            log(
                clr("@{yf}Warning: devel space at '%s' was previously built by '%s', "
                    "but --override-build-tool-check was passed so continuing anyways."
                    % (ctx.devel_space_abs, previous_tool)))
        else:
            sys.exit(
                clr("@{rf}The devel space at '%s' was previously built by '%s'. "
                    "Please remove the devel space or pick a different devel space."
                    % (ctx.devel_space_abs, previous_tool)))
    # the devel space will be marked as catkin build's if dry run doesn't return

    # Display list and leave the file system untouched
    if opts.dry_run:
        # TODO: Add unbuilt
        dry_run(ctx, opts.packages, opts.no_deps, opts.start_with)
        return

    # Print the build environment for a given package and leave the filesystem untouched
    if opts.get_env:
        return print_build_env(ctx, opts.get_env[0])

    # Now mark the build and devel spaces as catkin build's since dry run didn't return.
    mark_space_as_built_by(ctx.build_space_abs, 'catkin build')
    mark_space_as_built_by(ctx.devel_space_abs, 'catkin build')

    # Get the last build context
    build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build')

    # Force cmake if the CMake arguments have changed
    if build_metadata.get('cmake_args') != ctx.cmake_args:
        opts.force_cmake = True

    # Check the devel layout compatibility
    last_devel_layout = build_metadata.get('devel_layout', ctx.devel_layout)
    if last_devel_layout != ctx.devel_layout:
        sys.exit(
            clr("@{rf}@!Error:@|@{rf} The current devel space layout, `{}`,"
                "is incompatible with the configured layout, `{}`.@|").format(
                    last_devel_layout, ctx.devel_layout))

    # Check if some other verb has changed the workspace in such a way that it needs to be forced
    if build_metadata.get('needs_force', False):
        opts.force_cmake = True
        update_metadata(ctx.workspace, ctx.profile, 'build',
                        {'needs_force': False})

    # Always save the last context under the build verb
    update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict())

    # Save the context as the configuration
    if opts.save_config:
        Context.save(ctx)

    # Get parallel toplevel jobs
    try:
        parallel_jobs = int(opts.parallel_jobs)
    except TypeError:
        parallel_jobs = None

    # Set VERBOSE environment variable
    if opts.verbose:
        os.environ['VERBOSE'] = '1'

    return build_isolated_workspace(
        ctx,
        packages=opts.packages,
        start_with=opts.start_with,
        no_deps=opts.no_deps,
        unbuilt=opts.unbuilt,
        n_jobs=parallel_jobs,
        force_cmake=opts.force_cmake,
        pre_clean=opts.pre_clean,
        force_color=opts.force_color,
        quiet=not opts.verbose,
        interleave_output=opts.interleave_output,
        no_status=opts.no_status,
        limit_status_rate=opts.limit_status_rate,
        lock_install=not opts.no_install_lock,
        no_notify=opts.no_notify,
        continue_on_failure=opts.continue_on_failure,
        summarize_build=opts.summarize  # Can be True, False, or None
    )
コード例 #6
0
ファイル: cli.py プロジェクト: davetcoleman/catkin_tools
def main(opts):
    # Context-aware args
    if opts.build_this or opts.start_with_this:
        # Determine the enclosing package
        try:
            ws_path = find_enclosing_workspace(getcwd())
            # Suppress warnings since this won't necessaraly find all packages
            # in the workspace (it stops when it finds one package), and
            # relying on it for warnings could mislead people.
            this_package = find_enclosing_package(
                search_start_path=getcwd(),
                ws_path=ws_path,
                warnings=[])
        except (InvalidPackage, RuntimeError):
            this_package = None

        # Handle context-based package building
        if opts.build_this:
            if this_package:
                opts.packages += [this_package]
            else:
                sys.exit("catkin build: --this was specified, but this directory is not in a catkin package.")

        # If --start--with was used without any packages and --this was specified, start with this package
        if opts.start_with_this:
            if this_package:
                opts.start_with = this_package
            else:
                sys.exit("catkin build: --this was specified, but this directory is not in a catkin package.")

    if opts.no_deps and not opts.packages:
        sys.exit("With --no-deps, you must specify packages to build.")

    # Load the context
    ctx = Context.load(opts.workspace, opts.profile, opts, append=True)

    # Initialize the build configuration
    make_args, makeflags, cli_flags, jobserver = configure_make_args(ctx.make_args, ctx.use_internal_make_jobserver)

    # Set the jobserver memory limit
    if jobserver and opts.mem_limit:
        log(clr("@!@{pf}EXPERIMENTAL: limit memory to '%s'@|" % str(opts.mem_limit)))
        # At this point psuitl will be required, check for it and bail out if not set
        try:
            import psutil  # noqa
        except ImportError as exc:
            log("Could not import psutil, but psutil is required when using --mem-limit.")
            log("Please either install psutil or avoid using --mem-limit.")
            sys.exit("Exception: {0}".format(exc))
        set_jobserver_max_mem(opts.mem_limit)

    ctx.make_args = make_args

    # Load the environment of the workspace to extend
    if ctx.extend_path is not None:
        try:
            load_resultspace_environment(ctx.extend_path)
        except IOError as exc:
            log(clr("@!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" %
                    (ctx.extend_path, exc.message)))
            return 1

    # Display list and leave the file system untouched
    if opts.dry_run:
        dry_run(ctx, opts.packages, opts.no_deps, opts.start_with)
        return

    # Check if the context is valid before writing any metadata
    if not ctx.source_space_exists():
        print("catkin build: error: Unable to find source space `%s`" % ctx.source_space_abs)
        return 1

    # Always save the last context under the build verb
    update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict())

    build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build')
    if build_metadata.get('needs_force', False):
        opts.force_cmake = True
        update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False})

    # Save the context as the configuration
    if opts.save_config:
        Context.save(ctx)

    start = time.time()
    try:
        return build_isolated_workspace(
            ctx,
            packages=opts.packages,
            start_with=opts.start_with,
            no_deps=opts.no_deps,
            jobs=opts.parallel_jobs,
            force_cmake=opts.force_cmake,
            force_color=opts.force_color,
            quiet=not opts.verbose,
            interleave_output=opts.interleave_output,
            no_status=opts.no_status,
            limit_status_rate=opts.limit_status_rate,
            lock_install=not opts.no_install_lock,
            no_notify=opts.no_notify,
            continue_on_failure=opts.continue_on_failure,
            summarize_build=opts.summarize  # Can be True, False, or None
        )
    finally:
        log("[build] Runtime: {0}".format(format_time_delta(time.time() - start)))
コード例 #7
0
ファイル: cli.py プロジェクト: lucasw/catkin_tools
def main(opts):
    # Set color options
    opts.force_color = os.environ.get('CATKIN_TOOLS_FORCE_COLOR',
                                      opts.force_color)
    if (opts.force_color or is_tty(sys.stdout)) and not opts.no_color:
        set_color(True)
    else:
        set_color(False)

    # Context-aware args
    if opts.build_this:
        # Determine the enclosing package
        try:
            ws_path = find_enclosing_workspace(getcwd())
            # Suppress warnings since this won't necessarily find all packages
            # in the workspace (it stops when it finds one package), and
            # relying on it for warnings could mislead people.
            this_package = find_enclosing_package(search_start_path=getcwd(),
                                                  ws_path=ws_path,
                                                  warnings=[])
        except InvalidPackage as ex:
            sys.exit(
                clr("[test] @!@{rf}Error:@| The file {} is an invalid package.xml file."
                    " See below for details:\n\n{}").format(
                        ex.package_path, ex.msg))

        # Handle context-based package building
        if this_package:
            opts.packages += [this_package]
        else:
            sys.exit(
                clr("[test] @!@{rf}Error:@| In order to use --this, "
                    "the current directory must be part of a catkin package."))

    # Load the context
    ctx = Context.load(opts.workspace, opts.profile, opts, append=True)

    # Load the environment of the workspace to extend
    if ctx.extend_path is not None:
        try:
            load_resultspace_environment(ctx.extend_path)
        except IOError as exc:
            sys.exit(
                clr("[test] @!@{rf}Error:@| Unable to extend workspace from \"{}\": {}"
                    ).format(ctx.extend_path, str(exc)))

    # Check if the context is valid before writing any metadata
    if not ctx.source_space_exists():
        sys.exit(
            clr("[test] @!@{rf}Error:@| Unable to find source space `{}`").
            format(ctx.source_space_abs))

    # Extract make arguments
    make_args, _, _, _ = configure_make_args(ctx.make_args, ctx.jobs_args,
                                             ctx.use_internal_make_jobserver)
    ctx.make_args = make_args

    # Get parallel toplevel jobs
    try:
        parallel_jobs = int(opts.parallel_jobs)
    except TypeError:
        parallel_jobs = None

    # Set VERBOSE environment variable
    if opts.verbose and 'VERBOSE' not in os.environ:
        os.environ['VERBOSE'] = '1'

    # Get test targets
    catkin_test_target = 'run_tests'
    cmake_test_target = 'test'
    if opts.test_target:
        catkin_test_target = opts.test_target
        cmake_test_target = opts.test_target
    if opts.catkin_test_target:
        catkin_test_target = opts.catkin_test_target

    return test_workspace(
        ctx,
        packages=opts.packages,
        n_jobs=parallel_jobs,
        quiet=not opts.verbose,
        interleave_output=opts.interleave_output,
        no_status=opts.no_status,
        limit_status_rate=opts.limit_status_rate,
        no_notify=opts.no_notify,
        continue_on_failure=opts.continue_on_failure,
        summarize_build=opts.summarize,
        catkin_test_target=catkin_test_target,
        cmake_test_target=cmake_test_target,
    )