Exemplo n.º 1
0
def load_component(name, package_path):
    """Load a component.

    Args:
        name (str): The name of the component.
        package_path (str): The path to the package containing the component.

    Returns:
        None
    """
    component = repounits.Component(name)
    base_path = os.path.join(package_path, component.name)
    header_path = base_path + '.h'
    cxx_path = base_path + '.cpp'
    c_path = base_path + '.c'

    if not os.path.isfile(header_path):
        raise blderror.MissingFileError('Missing header file "%s"' %
                                        header_path)

    if os.path.isfile(cxx_path):
        component.type_ = repounits.ComponentType.CXX
        test_path = base_path + '.t.cpp'
    elif os.path.isfile(c_path):
        component.type_ = repounits.ComponentType.C
        test_path = base_path + '.t.c'
    else:
        raise blderror.MissingFileError(
            'Missing source (cpp) file for header file "%s"' % header_path)

    component.has_test_driver = os.path.isfile(test_path)
    return component
Exemplo n.º 2
0
def load_package(path, package_type):
    """Load a package.

    Args:
        path (str): Path to the root of the package.
        type_ (PackageType): The package type.

    Returns:
        A type derived from PackageBase
    """

    package = repounits.Package(path, package_type)
    package.mem = set(_load_lsv(
        os.path.join(package.path, 'package',
                     package.name + '.mem')))
    package.pub = set(_load_lsv(
        os.path.join(package.path, 'package',
                     package.name + '.pub')))
    package.dep = set(_load_lsv(
        os.path.join(package.path, 'package',
                     package.name + '.dep')))

    package.opts = _load_opts(os.path.join(package.path, 'package',
                                           package.name + '.opts'))
    package.defs = _load_opts(os.path.join(package.path, 'package',
                                           package.name + '.defs'))
    package.cap = _load_opts(os.path.join(package.path, 'package',
                                          package.name + '.cap'))

    dums_path = os.path.join(package.path, 'package', package.name + '.dums')
    package.has_dums = os.path.isfile(dums_path)

    if package.type_ == repounits.PackageType.PACKAGE_PLUS:
        package.pt_extras = _load_plus_package_extras(package)
    else:
        if package.type_ == repounits.PackageType.PACKAGE_APPLICATION:
            main_ext = '.m.cpp'
            valid_prefixes = [package.name]
            if package.name.startswith('m_'):
                valid_prefixes.append(package.name[2:])
            for prefix in valid_prefixes:
                main_path = os.path.join(package.path, prefix + main_ext)
                if os.path.isfile(main_path):
                    package.app_main = prefix
                    break

            if not package.app_main:
                raise blderror.MissingFileError(
                    'Missing source file "%s" for '
                    'application package "%s"' %
                    (os.path.join(package.path, package.name + main_ext),
                     package.name))

        for component_name in sorted(package.mem):
            component = load_component(component_name, package.path)
            package.components.append(component)

    return package
Exemplo n.º 3
0
def get_default_option_rules():
    """Return the default option rules.

    Args:
        msg_func (func, optional): function to print status messages

    Returns:
        list of OptionRule.

    Raises:
        MissingFileError: If default.opts can not be found.
    """
    default_opts_path = os.path.join(sysutil.repo_root_path(), 'etc',
                                     'default.opts')
    bde_root = os.environ.get('BDE_ROOT')

    found_default_opts = False
    found_default_internal_opts = False
    if not os.path.isfile(default_opts_path):
        logutil.warn('Cannot find default.opts at %s. '
                     'Trying to use $BDE_ROOT/etc/default.opts instead.' %
                     default_opts_path)
        if bde_root:
            default_opts_path = os.path.join(bde_root, 'etc', 'default.opts')
            if os.path.isfile(default_opts_path):
                found_default_opts = True
    else:
        found_default_opts = True

    if not found_default_opts:
        raise blderror.MissingFileError('Cannot find default.opts.')

    option_rules = optionsparser.parse_option_rules_file(default_opts_path)

    if bde_root:
        default_internal_opts_path = os.path.join(bde_root, 'etc',
                                                  'default_internal.opts')

        if os.path.isfile(default_internal_opts_path):
            found_default_internal_opts = True
            option_rules += optionsparser.parse_option_rules_file(
                default_internal_opts_path)
        else:
            logutil.warn('The BDE_ROOT environment variable is set, '
                         'but $BDE_ROOT/etc/default_internal.opts does '
                         'not exist.')

    logutil.msg("Using default option rules from", default_opts_path)
    if found_default_internal_opts:
        logutil.msg("Using default option rules from",
                    default_internal_opts_path)

    return option_rules
Exemplo n.º 4
0
def get_default_option_rules():
    """Return the default option rules.

    Returns:
        list of OptionRule.

    Raises:
        MissingFileError: If default.opts can not be found.
    """
    default_opts_path = os.path.join(sysutil.repo_root_path(), "etc",
                                     "default.opts")
    bde_root = os.environ.get("BDE_ROOT")

    found_default_opts = False
    found_default_internal_opts = False
    if not os.path.isfile(default_opts_path):
        logutil.warn("Cannot find default.opts at %s. "
                     "Trying to use $BDE_ROOT/etc/default.opts instead." %
                     default_opts_path)
        if bde_root:
            default_opts_path = os.path.join(bde_root, "etc", "default.opts")
            if os.path.isfile(default_opts_path):
                found_default_opts = True
    else:
        found_default_opts = True

    if not found_default_opts:
        raise blderror.MissingFileError("Cannot find default.opts.")

    option_rules = optionsparser.parse_option_rules_file(default_opts_path)

    if bde_root:
        default_internal_opts_path = os.path.join(bde_root, "etc",
                                                  "default_internal.opts")

        if os.path.isfile(default_internal_opts_path):
            found_default_internal_opts = True
            option_rules += optionsparser.parse_option_rules_file(
                default_internal_opts_path)
        else:
            logutil.warn('The BDE_ROOT environment variable is set to "%s", '
                         'but $BDE_ROOT/etc/default_internal.opts ("%s") does '
                         "not exist." % (bde_root, default_internal_opts_path))

    logutil.msg("Using default option rules from", default_opts_path)
    if found_default_internal_opts:
        logutil.msg("Using default option rules from",
                    default_internal_opts_path)

    return option_rules
Exemplo n.º 5
0
def get_config_path():
    """Return the path to the compiler configuration file.

    This is either ~/.bdecompilerconfig if it exists, or
    $BDE_ROOT/bdecompilerconfig.

    Returns:
       Path to the config file.

    Raises:
       MissingFileError if no valid configuration file is found.
    """
    localconfig_path = os.path.join(os.path.expanduser('~'),
                                    '.bdecompilerconfig')

    path = None

    if (os.path.isfile(localconfig_path)
            and os.access(localconfig_path, os.R_OK)):
        path = localconfig_path
    bde_root = os.environ.get('BDE_ROOT')

    if not path and bde_root:
        defaultconfig_path = os.path.join(bde_root, 'etc', 'bdecompilerconfig')
        if (os.path.isfile(defaultconfig_path)
                and os.access(defaultconfig_path, os.R_OK)):
            path = defaultconfig_path

    if not path:
        raise blderror.MissingFileError(
            'Cannot find a compiler configuration file at %s '
            'or $BDE_ROOT/etc/bdecompilerconfig' % localconfig_path)

    if path:
        print('using configuration: %s' % path, file=sys.stderr)
        return path