## Copyright (C) 2011 Aldebaran Robotics

"""Configure a project

"""

import logging
import qibuild

def configure_parser(parser):
    """Configure parser for this action"""
    qibuild.parsers.toc_parser(parser)
    qibuild.parsers.build_parser(parser)
    qibuild.parsers.project_parser(parser)
    group = parser.add_argument_group("cmake arguments")
    group.add_argument("--bootstrap", dest="bootstrap", action="store_true", help="only bootstrap projects, do not call cmake.")
    group.add_argument("--build-directory", dest="build_directory", action="store", help="override the default build directory used by cmake")
    group.add_argument("-D", dest="cmake_flags", action="append", help="additional cmake flags")

def do(args):
    """Main entry point"""
    if args.build_directory and not args.single:
        raise Exception("You should use --single when specifying a build directory")

    logger   = logging.getLogger(__name__)
    toc      = qibuild.toc_open(args.work_tree, args, use_env=True)

    (project_names, _, not_found) = qibuild.toc.resolve_deps(toc, args)
    if not_found:
        mess  = "Could not find all required dependencies !\n"
        mess += "Missing: "+ " ".join(not_found)

        if toc.toolchain.name == "system":
            logger.warning(mess)
        else:
            raise Exception(mess)

    projects = [toc.get_project(name) for name in project_names]
    if args.build_directory:
        projects[0].set_custom_build_directory(args.build_directory)

    for project_name in project_names:
        logger.info("Bootstraping [%s]", project_name)
        dep_sdk_dirs = toc.get_sdk_dirs(project_name)
        qibuild.project.bootstrap(toc.get_project(project_name), dep_sdk_dirs)

    if args.bootstrap:
        return
    for project in projects:
        logger.info("Configuring %s in %s", project.name, toc.build_folder_name)
        toc.configure_project(project)



@@ -1029,25 +1029,17 @@
 mes, _, 
-not_found
+_
 ) = qibu
@@ -1073,263 +1073,8 @@
 rgs)
-%0A    if not_found:%0A        mess  = %22Could not find all required dependencies !%5Cn%22%0A        mess += %22Missing: %22+ %22 %22.join(not_found)%0A%0A        if toc.toolchain.name == %22system%22:%0A            logger.warning(mess)%0A        else:%0A            raise Exception(mess)
 %0A%0A  

Remove useless throw