#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2012-2021 SoftBank Robotics. All rights reserved.
# Use of this source code is governed by a BSD-style license (see the COPYING file).
""" Collection of parser fonctions for qibuild actions. """
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function

import qibuild.deps
import qibuild.worktree
import qibuild.cmake_builder
import qisys.parsers
from qisys import ui


def cmake_build_parser(parser, group=None, with_build_parser=True):
    """ CMake Build Parser """
    if with_build_parser:
        qisys.parsers.build_parser(parser, group=None)
    if not group:
        group = parser.add_argument_group("Build options")
    qisys.parsers.parallel_parser(group, default=None)
    group.add_argument("--verbose-make", action="store_true", default=False,
                       help="Print the executed commands while building")


def cmake_configure_parser(parser):
    """ CMAke Configure Parser """
    group = parser.add_argument_group("configure options")
    group.add_argument("-G", "--cmake-generator", action="store",
                       help="Specify the CMake generator")
    group.add_argument("-D", dest="cmake_flags",
                       action="append",
                       help="additional cmake flags")
    group.add_argument("--no-clean-first", dest="clean_first",
                       action="store_false",
                       help="do not clean CMake cache")
    group.add_argument("--debug-trycompile", dest="debug_trycompile",
                       action="store_true",
                       help="pass --debug-trycompile to CMake call")
    group.add_argument("--eff-c++", dest="effective_cplusplus",
                       action="store_true",
                       help="activate warnings from the 'Effective C++' book (gcc only)")
    group.add_argument("--werror", dest="werror",
                       action="store_true",
                       help="treat warnings as error")
    group.add_argument("--profiling", dest="profiling", action="store_true",
                       help="profile cmake execution")
    group.add_argument("--summarize-options", dest="summarize_options",
                       action="store_true",
                       help="summarize build options at the end")
    group.add_argument("--trace-cmake", dest="trace_cmake",
                       action="store_true",
                       help="run cmake in trace mode")
    group.add_argument("--coverage", dest="coverage",
                       action="store_true",
                       help="activate coverage support (gcc only)")
    group.add_argument("--32-bits", dest="force_32_bits",
                       action="store_true", help="force 32 bits build")
    group.add_argument("--with-debug-info", action="store_true", dest="debug_info",
                       help="include debug information in binaries, even when used with --release. "
                       "Note that you can also use --build-type=RelWithDebInfo "
                       "for the same effect")
    group.add_argument("--without-debug-info", action="store_false", dest="debug_info",
                       help="remove debug information from binaries, even when used with --debug")
    group.add_argument("--release", action="store_const", const="Release",
                       dest="build_type",
                       help="Build in release")
    group.add_argument("--debug", action="store_const", const="Debug",
                       dest="build_type",