def test_load_package(self):
        path = os.path.join(self.repo_root, 'groups', 'gr3', 'gr3p1')
        package = repoloadutil.load_package(
            path, repounits.PackageType.PACKAGE_NORMAL)

        opts_str = """*                   _   OPTS_FILE       = gr3p1.opts

*       _   COMPONENT_BDEBUILD_CFLAGS      = -DGR3P1_OPTS_C
*       _   COMPONENT_BDEBUILD_CXXFLAGS    = -DGR3P1_OPTS_CXX
*       _   COMPONENT_BDEBUILD_LDFLAGS     = -DGR3P1_OPTS_LD

*       _   TESTDRIVER_BDEBUILD_CFLAGS     = -DTEST_GR3P1_OPTS_C
*       _   TESTDRIVER_BDEBUILD_CXXFLAGS   = -DTEST_GR3P1_OPTS_CXX
*       _   TESTDRIVER_BDEBUILD_LDFLAGS    = -DTEST_GR3P1_OPTS_LD
"""
        cap_str = """ !! unix  _  CAPABILITY = ALWAYS
"""

        exp_package = repounits.Package(path,
                                        repounits.PackageType.PACKAGE_NORMAL)
        exp_package.mem = set(['gr3p1_comp1', 'gr3p1_comp2'])
        exp_package.dep = set(['gr3p2'])
        exp_package.opts = self._parse_opts_str(opts_str)
        exp_package.cap = self._parse_opts_str(cap_str)
        exp_package.has_dums = True
        exp_package.components = [
            repounits.Component("gr3p1_comp1"),
            repounits.Component("gr3p1_comp2")
        ]

        self.assertEqual(package, exp_package)
Exemple #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
    def test_load_plus_package(self):
        path = os.path.join(self.repo_root, 'groups', 'gr2', 'gr2a+b')
        package = repoloadutil.load_package(path,
                                            repounits.PackageType.PACKAGE_PLUS)

        exp_package = repounits.Package(path,
                                        repounits.PackageType.PACKAGE_PLUS)
        exp_package.pt_extras = repounits.PlusPackageExtras()
        exp_package.pt_extras.headers = set(['h1.h', 'h2.h', 'subh/h3.h'])
        exp_package.pt_extras.cpp_sources = set(['h1.cpp', 'h2.cpp'])
        exp_package.pt_extras.cpp_tests = set(
            ['test/test1.cpp', 'test/test2.cpp'])
        exp_package.pt_extras.c_tests = set(['test/test3.c'])
        self.assertEqual(package, exp_package)

        path = os.path.join(self.repo_root, 'groups', 'gr2', 'gr2b+c')
        package = repoloadutil.load_package(path,
                                            repounits.PackageType.PACKAGE_PLUS)
        exp_package = repounits.Package(path,
                                        repounits.PackageType.PACKAGE_PLUS)
        exp_package.pub = set(['h1.h', 'h2.h'])
        exp_package.pt_extras = repounits.PlusPackageExtras()
        exp_package.pt_extras.headers = set(['h1.h', 'h2.h'])
        self.assertEqual(package, exp_package)