Beispiel #1
0
    async def handle_compilation(self, task: Task, args: list):
        task.set_bin_name(
            os.path.join(task.path_to_task_bin(self.__workdir),
                         task.get_name() + '.out'))

        compilation_commands = self.__get_compile_cmds(task, args)

        compilation_output = await self.__executor.async_exec_cmds_with_wrapping(
            commands=compilation_commands,
            dir_to_use=task.path_to_task_bin(self.__workdir),
        )

        compilation_log_file = os.path.join(
            task.get_dir_name_for_task(self.__workdir), 'compilation.log')
        with open(compilation_log_file, 'w') as output_file:
            output_file.write(compilation_output)

        return
Beispiel #2
0
    def get_compilation_commands_using_cmake(self, task: Task):
        """
        Constructs commands to build CMake project and sets target executable name for task.
        For now supports only project build using Unix Makefiles.

        :param task: task to handle
        :return: command list to build CMake project
        """
        path = task.path_to_task_src(self.__workdir)
        bin_path = task.path_to_task_bin(self.__workdir)

        if not os.path.exists(bin_path):
            os.makedirs(bin_path)

        commands = [
            # invoking cmake in the 'bin' directory so that all of the generated files are inside 'bin' directory
            'cmake {} --warn-uninitialized --warn-unused-vars -Wno-dev'.format(
                path),
            # invoking build through the CMake build tool using appropriate tool for the system
            'cmake --build .',
        ]
        self.__log_writer.log(json.dumps(commands, indent=4), LogLevel.DEBUG)

        with open(os.path.join(path, self.__C_MAKE_LISTS_TXT__),
                  'r') as cmake_file:
            lines = cmake_file.read().splitlines()

        lines = list(filter(lambda x: 'project' in x, lines))
        # line = 'project(project_name)'
        lines = list(filter(lambda x: len(x) > 0, lines))
        lines = list(map(lambda x: re.split(r'[() ]', x), lines))
        self.__log_writer.log('LINES: {}'.format(lines))
        bin_name = os.path.join(bin_path, lines[0][1])
        task.set_bin_name(bin_name)

        return commands