<commit_before>## Copyright (C) 2011 Aldebaran Robotics

import os
import shlex
import logging

import qibuild.sh

LOGGER = logging.getLogger("qibuild.toc.project")

class Project:
    """ Store information about a project:
         - name
         - source directory
         - build directory
         - build configuration
         - dependencies
    """
    def __init__(self, name, directory):
        self.name            = name
        self.directory       = directory
        self.depends         = list()
        self.rdepends        = list()

        #build related flags
        self.cmake_flags     = list()
        self.build_directory = None
        self.sdk_directory   = None
        self._custom_sdk_dir = False

    def get_sdk_dir(self):
        """ Return the SDK dir of the project.
        To use the project build results, from an other project,
        you just have to add this directory to CMAKE_PREFIX_PATH

        """
        return os.path.join(self.build_directory, "sdk")

    def update_depends(self, toc):
        """ Update project dependency list """
        deps  = toc.configstore.get("project", self.name, "depends", default="").split()
        rdeps = toc.configstore.get("project", self.name, "rdepends", default="").split()
        self.depends.extend(deps)
        self.rdepends.extend(rdeps)

    def update_build_config(self, toc, build_directory_name):
        """ Update cmake_flags
           - add flags from the build_config (read in toc's configstore)
           - add flags from the project config (read in toc's configstore project section)
           - add flags from the command line (stored in toc.cmake_flags when toc is built)
        """

        #handle custom global build directory containing all projects
        singlebdir = toc.configstore.get("general", "build", "build_dir", default=None)
        if singlebdir:
            if not os.path.isabs(singlebdir):
                singlebdir = os.path.join(toc.work_tree, singlebdir)
            bname = "%s-build-%s" % (self.name, build_directory_name)
            self.build_directory = os.path.join(singlebdir, bname)
        else:
            bname = "build-%s" % (build_directory_name)
            self.build_directory = os.path.join(self.directory, bname)

        build_config_flags = toc.configstore.get("general", "build", "cmake", "flags",
            default=None)
        if build_config_flags:
            self.cmake_flags.extend(shlex.split(build_config_flags))

        project_flags = toc.configstore.get("project", self.name, "cmake", "flags",
            default=None)
        if project_flags:
            self.cmake_flags.extend(shlex.split(project_flags))

        if toc.build_type:
            self.cmake_flags.append("CMAKE_BUILD_TYPE=%s" % (toc.build_type.upper()))

        if toc.cmake_flags:
            self.cmake_flags.extend(toc.cmake_flags)

        #handle single sdk dir
        sdk_dir = toc.configstore.get("general", "build", "sdk_dir", default=None)
        if sdk_dir:
            if os.path.isabs(sdk_dir):
                self.sdk_directory = sdk_dir
            else:
                self.sdk_directory = os.path.join(toc.work_tree, sdk_dir)
            self._custom_sdk_dir = True
            self.cmake_flags.append("QI_SDK_DIR=%s" % (self.sdk_directory))<commit_msg>python: single build dir: use a common subfolder for each build arch<commit_after>## Copyright (C) 2011 Aldebaran Robotics

import os
import shlex
import logging

import qibuild.sh

LOGGER = logging.getLogger("qibuild.toc.project")

class Project:
    """ Store information about a project:
         - name
         - source directory
         - build directory
         - build configuration
         - dependencies
    """
    def __init__(self, name, directory):
        self.name            = name
        self.directory       = directory
        self.depends         = list()
        self.rdepends        = list()

        #build related flags
        self.cmake_flags     = list()
        self.build_directory = None
        self.sdk_directory   = None
        self._custom_sdk_dir = False

    def get_sdk_dir(self):
        """ Return the SDK dir of the project.
        To use the project build results, from an other project,
        you just have to add this directory to CMAKE_PREFIX_PATH

        """
        return os.path.join(self.build_directory, "sdk")

    def update_depends(self, toc):
        """ Update project dependency list """
        deps  = toc.configstore.get("project", self.name, "depends", default="").split()
        rdeps = toc.configstore.get("project", self.name, "rdepends", default="").split()
        self.depends.extend(deps)
        self.rdepends.extend(rdeps)

    def update_build_config(self, toc, build_directory_name):
        """ Update cmake_flags
           - add flags from the build_config (read in toc's configstore)
           - add flags from the project config (read in toc's configstore project section)
           - add flags from the command line (stored in toc.cmake_flags when toc is built)
        """

        #handle custom global build directory containing all projects
        singlebdir = toc.configstore.get("general", "build", "build_dir", default=None)
        if singlebdir:
            if not os.path.isabs(singlebdir):
                singlebdir = os.path.join(toc.work_tree, singlebdir)
            bname = os.path.join("build-%s" % (build_directory_name), self.name)
            self.build_directory = os.path.join(singlebdir, bname)
        else:
            bname = "build-%s" % (build_directory_name)
            self.build_directory = os.path.join(self.directory, bname)

        build_config_flags = toc.configstore.get("general", "build", "cmake", "flags",
            default=None)
        if build_config_flags:
            self.cmake_flags.extend(shlex.split(build_config_flags))

        project_flags = toc.configstore.get("project", self.name, "cmake", "flags",
            default=None)
        if project_flags:
            self.cmake_flags.extend(shlex.split(project_flags))

        if toc.build_type:
            self.cmake_flags.append("CMAKE_BUILD_TYPE=%s" % (toc.build_type.upper()))

        if toc.cmake_flags:
            self.cmake_flags.extend(toc.cmake_flags)

        #handle single sdk dir
        sdk_dir = toc.configstore.get("general", "build", "sdk_dir", default=None)
        if sdk_dir:
            if os.path.isabs(sdk_dir):
                self.sdk_directory = sdk_dir
            else:
                self.sdk_directory = os.path.join(toc.work_tree, sdk_dir)
            self._custom_sdk_dir = True
            self.cmake_flags.append("QI_SDK_DIR=%s" % (self.sdk_directory))
{'fraction_non_alphanumeric': 0.10286225402504472, 'fraction_numerical': 0.0011926058437686344, 'mean_word_length': 2.290338401177048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2612047', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1957, 'n_words': 464}