Beispiel #1
0
def test_list_expr_iterator():
    bool_yes = BoolValueExpr(True)
    bool_no = BoolValueExpr(False)
    empty_list = ListExpr([])
    a_list = ListExpr([bool_yes, bool_no])
    assert len(empty_list) == 0
    assert not empty_list
    assert len(a_list) == 2
    assert a_list
    assert list(a_list) == [bool_yes, bool_no]

    null = NullExpr()
    assert not null
    assert len(null) == 0
Beispiel #2
0
class LoadableModuleType(NativeLinkedType):
    """
    Runtime-loaded dynamic module (plugin).
    """
    name = "loadable-module"

    properties = [
        Property("basename",
                 type=StringType(),
                 default="$(id)",
                 inheritable=False,
                 doc="""
                     Base name of the loadable module.

                     This is not full filename or even path, it's only its base part,
                     to which platform-specific prefix and/or extension are
                     added. By default, it's the same as target's ID, but it can be changed e.g.
                     if the filename should contain version number, which would be impractical
                     to use as target identifier in the bakefile.

                     .. code-block:: bkl

                        loadable-module myplugin {
                          basename = myplugin-v1;
                        }
                     """),
        Property("extension",
                 type=StringType(),
                 default=NullExpr(),
                 inheritable=False,
                 doc="""
                     File extension of the module, including the leading dot.

                     By default, native extension for shared libraries (e.g.
                     ".dll" on Windows) is used.

                     .. code-block:: bkl

                        loadable-module excel_plugin {
                          extension = .xll;
                        }
                     """),
    ]

    def get_build_subgraph(self, toolset, target):
        return get_compilation_subgraph(
            toolset,
            target,
            ft_to=NativeLoadableModuleFileType.get(),
            outfile=self.target_file(toolset, target))
Beispiel #3
0
 def target_file_extension(self, toolset, target):
     """
     Returns expression with extension of the target's filename (as returned
     by :meth:`target_file()`), including the leading dot.
     """
     if not target.is_variable_null("extension"):
         return target["extension"]
     else:
         try:
             fileclass = self.name.replace("-", "_")
             ext = "%s_extension" % fileclass
             return LiteralExpr(".%s" % getattr(toolset, ext))
         except AttributeError:
             return NullExpr()
Beispiel #4
0
class NativeCompiledType(TargetType):
    """Base class for natively-compiled targets."""
    properties = [
        Property("sources",
                 type=ListType(PathType()),
                 default=[],
                 inheritable=False,
                 doc="Source files."),
        Property("headers",
                 type=ListType(PathType()),
                 default=[],
                 inheritable=False,
                 doc="Header files."),
        Property("defines",
                 type=ListType(StringType()),
                 default=[],
                 inheritable=True,
                 doc="List of preprocessor macros to define."),
        Property("includedirs",
                 type=ListType(PathType()),
                 default=[],
                 inheritable=True,
                 doc="Directories where to look for header files."),
        Property("warnings",
                 type=EnumType("warnings",
                               ["no", "minimal", "default", "all", "max"]),
                 default="default",
                 inheritable=True,
                 doc="""
                     Warning level for the compiler.

                     Use ``no`` to completely disable warning, ``minimal`` to
                     show only the most important warning messages, ``all``
                     to enable all warnings that usually don't result in false
                     positives and ``max`` to enable absolutely all warnings.
                     """),
        Property("compiler-options",
                 type=ListType(StringType()),
                 default=[],
                 inheritable=True,
                 doc="""
                     Additional compiler options common to all C-like compilers
                     (C, C++, Objective-C, Objective-C++).

                     Note that the options are compiler-specific and so this
                     property should only be set conditionally for particular
                     compilers that recognize the options.
                     """),
        Property("c-compiler-options",
                 type=ListType(StringType()),
                 default=[],
                 inheritable=True,
                 doc="""
                     Additional options for C compiler.

                     Note that the options are compiler-specific and so this
                     property should only be set conditionally for particular
                     compilers that recognize the options.
                     """),
        Property("cxx-compiler-options",
                 type=ListType(StringType()),
                 default=[],
                 inheritable=True,
                 doc="""
                     Additional options for C++ compiler.

                     Note that the options are compiler-specific and so this
                     property should only be set conditionally for particular
                     compilers that recognize the options.
                     """),
        Property("libs",
                 type=ListType(StringType()),
                 default=[],
                 inheritable=True,
                 doc="""
                     Additional libraries to link with.

                     Do not use this property to link with libraries built as
                     part of your project; use `deps` for that.

                     When this list is non-empty on a
                     :ref:`ref_target_library`, it will be used when linking
                     executables that use the library.
                     """),
        Property("libdirs",
                 type=ListType(PathType()),
                 default=[],
                 inheritable=True,
                 doc="""
                     Additional directories where to look for libraries.

                     When this list is non-empty on a
                     :ref:`ref_target_library`, it will be used when linking
                     executables that use the library.
                     """),
        Property("link-options",
                 type=ListType(StringType()),
                 default=[],
                 inheritable=True,
                 doc="""
                     Additional linker options.

                     Note that the options are compiler/linker-specific and so this
                     property should only be set conditionally for particular
                     compilers that recognize the options.

                     When this list is non-empty on a
                     :ref:`ref_target_library`, it will be used when linking
                     executables that use the library.
                     """),
        Property("archs",
                 type=ListType(EnumType("architecture", ["x86", "x86_64"])),
                 default=NullExpr(),
                 inheritable=True,
                 doc="""
                     Architectures to compile for.

                     Adds support for building binaries for specified
                     architectures, if supported by the toolset. Support may
                     take the form of either multi-arch binaries (OS X) or
                     additional build configurations (Visual Studio).

                     The default empty value means to do whatever the default
                     behavior of the toolset is.

                     Currently only supported on OS X and in Visual Studio.
                     """),
        Property("win32-crt-linkage",
                 type=EnumType("linkage", ["static", "dll"]),
                 default="dll",
                 inheritable=True,
                 doc="""
                     How to link against the C Runtime Library.

                     If ``dll`` (the default), the executable may depend on
                     some DLLs provided by the compiler. If ``static`` then a
                     static version of the CRT is linked directly into the
                     executable.
                     """),
        Property("win32-unicode",
                 type=BoolType(),
                 default=True,
                 inheritable=True,
                 doc="Compile win32 code in Unicode mode? If enabled, "
                 "``_UNICODE`` symbol is defined and the wide character "
                 "entry point (``WinMain``, ...) is used."),
        Property("outputdir",
                 type=PathType(),
                 default=PathExpr([], anchor=ANCHOR_BUILDDIR),
                 inheritable=True,
                 doc="""
                     Directory where final binaries are put.

                     Note that this is not the directory for intermediate files
                     such as object files -- these are put in ``@builddir``. By
                     default, output location is the same, ``@builddir``, but
                     can be overwritten to for example put all executables into
                     ``bin/`` subdirectory.
                     """),
        Property("pic",
                 type=BoolType(),
                 default=lambda target: target.type.use_pic_by_default,
                 inheritable=True,
                 doc="""
                     Compile position-independent code.

                     By default, libraries (both shared and static, because the
                     latter could be linked into a shared lib too) are linked
                     with -fPIC and executables are not.
                     """),
        Property("multithreading",
                 type=BoolType(),
                 default=True,
                 inheritable=True,
                 doc="""
                     Enable support for multithreading.

                     MT support is enabled by default, but can be disabled when
                     not needed.

                     On Unix, this option causes the use of pthreads library.
                     Visual Studio always uses MT-safe CRT, even if this
                     setting is disabled.
                     """),
    ]

    use_pic_by_default = True

    def target_file(self, toolset, target):
        """
        Returns main filename of the target.
        """
        return self._get_filename(toolset, target, "basename", self.name)

    def _get_filename(self, toolset, target, propname, fileclass):
        """
        Returns expression with filename of the target using given property
        (typically, "basename") for use with given toolset.
        """
        fileclass = fileclass.replace("-", "_")
        tdir = dir(toolset)
        prefix = "%s_prefix" % fileclass
        ext = "%s_extension" % fileclass
        parts = []
        if prefix in tdir:
            parts.append(getattr(toolset, prefix))
        parts.append(target[propname])
        if not target.is_variable_null("extension"):
            parts.append(target["extension"])
        elif ext in tdir:
            parts.append("." + getattr(toolset, ext))
        outdir = target["outputdir"]
        return PathExpr(outdir.components + [concat(*parts)], outdir.anchor,
                        outdir.anchor_file)

    def target_file_extension(self, toolset, target):
        """
        Returns expression with extension of the target's filename (as returned
        by :meth:`target_file()`), including the leading dot.
        """
        if not target.is_variable_null("extension"):
            return target["extension"]
        else:
            try:
                fileclass = self.name.replace("-", "_")
                ext = "%s_extension" % fileclass
                return LiteralExpr(".%s" % getattr(toolset, ext))
            except AttributeError:
                return NullExpr()