Esempio n. 1
0
    def test_bad_build_from_relative_path(self):
        error = None
        try:
            create_builder("dummy", self.cmake_build_path)
        except IOError as e:
            error = e
        assert "Watch path dummy must be absolute" in str(error)

        error = None
        try:
            create_builder(self.cmake_source_path, "dummy")
        except IOError as e:
            error = e
        assert "Build path dummy must be absolute" in str(error)
Esempio n. 2
0
    def test_bad_build_from_relative_path(self):
        error = None
        try:
            create_builder('dummy', self.cmake_build_path)
        except IOError as e:
            error = e
        assert 'Watch path dummy must be absolute' in str(error)

        error = None
        try:
            create_builder(self.cmake_source_path, 'dummy')
        except IOError as e:
            error = e
        assert 'Build path dummy must be absolute' in str(error)
Esempio n. 3
0
    def test_build_with_generator(self):
        builder = create_builder(self.cmake_source_path, self.cmake_build_path,
                                 "Ninja")
        builder()

        assert exists(join(self.cmake_build_path, "CMakeFiles"))
        assert exists(join(self.cmake_build_path, "build.ninja"))
Esempio n. 4
0
    def test_good_build(self):
        build_file = 'test.sln' if platform.system() == 'Windows' else 'Makefile' # noqa
        builder = create_builder(self.cmake_source_path, self.cmake_build_path)
        builder()

        assert exists(join(self.cmake_build_path, 'CMakeFiles'))
        assert exists(join(self.cmake_build_path, build_file))
Esempio n. 5
0
    def test_build_with_default_build_type(self):
        builder = create_builder(self.cmake_source_path, self.cmake_build_path)
        builder()

        cmakecache = join(self.cmake_build_path, "CMakeCache.txt")
        assert exists(cmakecache)
        assert find_in_file(cmakecache,
                            "CMAKE_BUILD_TYPE:STRING=" + os.linesep)
Esempio n. 6
0
    def test_build_with_none_define(self):
        builder = create_builder(self.cmake_source_path, self.cmake_build_path,
                                 build_type="release",
                                 defines=None)
        builder()

        cmakecache = join(self.cmake_build_path, 'CMakeCache.txt')
        assert exists(cmakecache)
Esempio n. 7
0
    def test_build_with_default_build_type(self):
        builder = create_builder(self.cmake_source_path, self.cmake_build_path)
        builder()

        cmakecache = join(self.cmake_build_path, 'CMakeCache.txt')
        assert exists(cmakecache)
        assert find_in_file(cmakecache,
                            'CMAKE_BUILD_TYPE:STRING=' + os.linesep)
Esempio n. 8
0
    def test_build_with_generator(self):
        builder = create_builder(self.cmake_source_path,
                                 self.cmake_build_path,
                                 'Ninja')
        builder()

        assert exists(join(self.cmake_build_path, 'CMakeFiles'))
        assert exists(join(self.cmake_build_path, 'build.ninja'))
Esempio n. 9
0
    def test_good_build(self):
        build_file = (
            "test.sln" if platform.system() == "Windows" else "Makefile"
        )  # noqa
        builder = create_builder(self.cmake_source_path, self.cmake_build_path)
        builder()

        assert exists(join(self.cmake_build_path, "CMakeFiles"))
        assert exists(join(self.cmake_build_path, build_file))
Esempio n. 10
0
    def test_build_with_define(self):
        builder = create_builder(self.cmake_source_path, self.cmake_build_path,
                                 build_type="release",
                                 defines=['FOO=BAR', 'A:STRING=VALUE'])
        builder()

        cmakecache = join(self.cmake_build_path, 'CMakeCache.txt')
        assert exists(cmakecache)
        assert find_in_file(cmakecache, 'FOO:UNINITIALIZED=BAR' + os.linesep)
        assert find_in_file(cmakecache, 'A:STRING=VALUE' + os.linesep)
Esempio n. 11
0
    def test_build_with_none_define(self):
        builder = create_builder(
            self.cmake_source_path,
            self.cmake_build_path,
            build_type="release",
            defines=None,
        )
        builder()

        cmakecache = join(self.cmake_build_path, "CMakeCache.txt")
        assert exists(cmakecache)
Esempio n. 12
0
    def test_bad_build(self):
        source_path = '{}'.format(join(os.getcwd(), 'dummy'))
        build_path = join(os.getcwd(), 'dummy-build')

        builder = create_builder(source_path, build_path)
        raised = None
        try:
            builder()
        except IOError as e:
            raised = str(e)
        assert raised == "[Errno 22] No CMakeLists.txt detected in {}".format(source_path) # noqa
Esempio n. 13
0
    def test_no_cmakelists_txt(self):
        source_path = "{}".format(join(os.getcwd(), "dummy"))
        build_path = join(os.getcwd(), "dummy-build")

        builder = create_builder(source_path, build_path)
        raised = None
        try:
            builder()
        except IOError as e:
            raised = str(e)
        assert raised == "[Errno 22] No CMakeLists.txt detected in {}".format(
            source_path)  # noqa
Esempio n. 14
0
    def test_build_with_define(self):
        builder = create_builder(
            self.cmake_source_path,
            self.cmake_build_path,
            build_type="release",
            defines=["FOO=BAR", "A:STRING=VALUE"],
        )
        builder()

        cmakecache = join(self.cmake_build_path, "CMakeCache.txt")
        assert exists(cmakecache)
        assert find_in_file(cmakecache, "FOO:UNINITIALIZED=BAR" + os.linesep)
        assert find_in_file(cmakecache, "A:STRING=VALUE" + os.linesep)
Esempio n. 15
0
    def test_clean_build(self):
        cmake_source_directory = TempDirectory()
        source_path = cmake_source_directory.path
        cmake_build_directory = TempDirectory()
        build_path = cmake_build_directory.path

        builder = create_builder(source_path, build_path)
        raised = None
        try:
            builder()
        except IOError as e:
            raised = str(e)
        assert raised == "[Errno 22] No CMakeLists.txt detected in {}".format(
            source_path)  # noqa

        cmake_source_directory.write("CMakeLists.txt", b"project(test)")
        builder()
        assert exists(join(build_path, "CMakeFiles"))
Esempio n. 16
0
def create_monitor(watch_path=None, patterns=None, **kwargs):
    """Creates a monitor and its subordinate objects.

    By default, one reporter object is created to output to the terminal.
    An optional IRC reporter may be created if irc_server is provided.

    :param watch_path: (optional) the root of the source tree, either relative
        or absolute. If not provided, the current working directory is assumed
        to be the root of the source tree.
    :param patterns: (optional) a list of file names or patterns that identify
        the files to be tracked. By default, all files are tracked unless this
        list is specified and not empty.
    :param build_path: (optional) the desired build path. May be relative. If
        not provided, it will be generated from the watch path.
    :param generator: (optional) the cmake build system generator
    :param defines: (optional) list of var=val strings for CMake's -D option
    :param irc_server: (optional) the IRC server host if an IRC reporter is
        required.
    :param irc_port (optional) the IRC server port. Has no meaning without
        irc_server.
    :param irc_channel (optional) the IRC channel to join once connected. Has
        no meaning without irc_server.
    :param irc_nick (optional) the IRC nickname to use once connected. Has
        no meaning without irc_server.
    """
    build_config = kwargs.pop("config", None)
    generator = kwargs.pop("generator", None)
    watch_path = make_watch_path(watch_path)
    build_path = make_build_path(kwargs.pop('build_path', None),
                                 watch_path,
                                 build_config)
    term = Terminal(stream=sys.stdout)
    exclusions = kwargs.pop("exclude", [])
    watcher = Watcher(watch_path, build_path, patterns, exclusions, term)

    run_tests = kwargs.pop("test", False)
    defines = kwargs.pop("define", [])
    if run_tests:
        if defines is None:
            defines = []
        defines.append('ENABLE_TESTS=ON')
    builder = create_builder(
            watch_path,
            build_path,
            generator,
            build_config,
            defines,
            term
        )

    reporters = [TerminalReporter(watch_path, build_path)]

    irc_server = kwargs.pop("irc_server", None)
    if irc_server:
        irc = IRCClient(
            (kwargs.pop('irc_channel', None) or
                '#ttt-{}'.format(os.path.basename(watch_path))),
            (kwargs.pop('irc_nick', None) or
                '{}_{}'.format(platform.system(), build_config)),
            irc_server,
            kwargs.pop("irc_port", None)
        )
        # print('{}@{}:{}/{}'.format(
        #     irc._nickname, irc.server.host, irc.server.port, irc.channel)
        # )
        r = IRCReporter(irc)
        reporters.append(r)

    executor = Executor() if run_tests else None
    return Monitor(watcher, builder, executor, reporters)
Esempio n. 17
0
def create_monitor(watch_path=None, patterns=None, **kwargs):
    """Creates a monitor and its subordinate objects.

    By default, one reporter object is created to output to the terminal.
    An optional IRC reporter may be created if irc_server is provided.

    :param watch_path: (optional) the root of the source tree, either relative
        or absolute. If not provided, the current working directory is assumed
        to be the root of the source tree.
    :param patterns: (optional) a list of file names or patterns that identify
        the files to be tracked. By default, all files are tracked unless this
        list is specified and not empty.
    :param build_path: (optional) the desired build path. May be relative. If
        not provided, it will be generated from the watch path.
    :param generator: (optional) the cmake build system generator
    :param defines: (optional) list of var=val strings for CMake's -D option
    :param irc_server: (optional) the IRC server host if an IRC reporter is
        required.
    :param irc_port (optional) the IRC server port. Has no meaning without
        irc_server.
    :param irc_channel (optional) the IRC channel to join once connected. Has
        no meaning without irc_server.
    :param irc_nick (optional) the IRC nickname to use once connected. Has
        no meaning without irc_server.
    """
    build_config = kwargs.pop("config", None)
    generator = kwargs.pop("generator", None)
    watch_path = make_watch_path(watch_path)
    build_path = make_build_path(kwargs.pop("build_path", None), watch_path,
                                 build_config)
    term = Terminal(stream=sys.stdout)
    exclusions = kwargs.pop("exclude", [])
    watcher = Watcher(watch_path, build_path, patterns, exclusions, term)

    run_tests = kwargs.pop("test", False)
    defines = kwargs.pop("define", [])
    clean = kwargs.pop("clean", False)
    if run_tests:
        if defines is None:
            defines = []
        defines.append("ENABLE_TESTS=ON")
    builder = create_builder(watch_path, build_path, generator, build_config,
                             defines, term, clean)

    reporters = [TerminalReporter(watch_path, build_path)]

    irc_server = kwargs.pop("irc_server", None)
    if irc_server:
        irc = IRCClient(
            (kwargs.pop("irc_channel", None)
             or "#{}-{}".format(__progname__, os.path.basename(watch_path))),
            (kwargs.pop("irc_nick", None)
             or "{}_{}".format(platform.system(), build_config)),
            irc_server,
            kwargs.pop("irc_port", None),
        )
        # print('{}@{}:{}/{}'.format(
        #     irc._nickname, irc.server.host, irc.server.port, irc.channel)
        # )
        r = IRCReporter(irc)
        reporters.append(r)

    executor = Executor() if run_tests else None
    return Monitor(watcher, builder, executor, reporters)