Exemple #1
0
    def __get_compile_cmds(self, task: Task, args: list):
        """
        Get compilation command to compile all of the task source files.

        :param task: related task
        :param args: additional arguments
        :return: list of compilation commands
        """
        compiler = task.get_compiler()
        if '' != compiler:
            bin_path = task.path_to_task_bin(self.__workdir)
            if not os.path.exists(bin_path):
                os.makedirs(bin_path)

            path = task.path_to_task_src(self.__workdir)
            if task.is_file_archive():
                if self.__cmake_handler is not None and task.uses_cmake():
                    if not self.__cmake_handler.is_cmake_target(path):
                        self.__cmake_handler.create_cmake_lists(task)
                    commands = self.__cmake_handler.get_compilation_commands_using_cmake(
                        task)
                else:
                    commands = self.__no_cmake_compile_cmd(
                        compiler, task, args)
            else:
                commands = self.__get_compile_cmd_for_single_file(
                    compiler, task, args)

            self.__log_writer.log(json.dumps(commands, indent=4),
                                  level=LogLevel.DEBUG)
            return commands
        else:
            raise RuntimeError('No compiler is set for the task: {}'.format(
                task.get_name()))
Exemple #2
0
    async def get_sources(self, task: Task):
        zip_name = 'sources.zip'
        path, files, zip_res = self.__extract_path_files_and_zip_res(
            task, zip_name)
        if zip_name not in files:
            path = task.path_to_task_src(self.workdir)
            files = list(map(lambda x: os.path.join(path, x),
                             os.listdir(path)))

            await self.__executor.async_execution(self.__write_zip_file, files,
                                                  zip_res)

        return zip_res
Exemple #3
0
    async def write_recvd_data(self, task: Task, recv_name: str,
                               recvd_data: bytes):
        # Create directory for task files if it doesn't exist
        srcdir = task.path_to_task_src(self.workdir)
        if not os.path.exists(srcdir):
            os.makedirs(srcdir)

        # Write incoming file on disk
        recv_file = os.path.join(srcdir, recv_name)
        await self.__async_rw.async_write_file(recv_file, recvd_data)

        if task.is_file_archive():
            await self.__executor.async_execution(self.__handle_archive, task,
                                                  srcdir, recv_file)

        return
Exemple #4
0
    def create_cmake_lists(self, task: Task):
        """
        Generates CMakeLists.txt to make an archive into the CMake project

        :param task: task to handle
        :return: None
        """
        path = task.path_to_task_src(self.__workdir)
        cmake_lists_filename = os.path.join(path, self.__C_MAKE_LISTS_TXT__)

        main_file = self.__get_main_file_in_project(path)

        task_name = task.get_name()
        file_contents = [
            'cmake_minimum_required(VERSION {})'.format(self.__cmake_version),
            'project({})'.format(task_name),
            'SET(CMAKE_BUILD_TYPE Release)',
        ]

        extension = main_file.split('.')[-1]

        file_contents.append('file(GLOB SOURCES "./*.{}")'.format(extension))

        file_contents.append(' '.join(
            ['add_executable('.format(task_name), '${SOURCES})']))

        dirs = self.__filter_dirs(path)

        include_dirs = list(filter(lambda x: 'include' in x, dirs))
        include_dirs = set(include_dirs)

        file_contents.append('include_directories({})'.format(
            ', '.join(include_dirs)))

        dirs = set(dirs) - include_dirs

        for dir_name in dirs:
            file_contents.append('add_subdirectory({})'.format(dir_name))

        file_contents = '\n'.join(file_contents)
        file_contents = correct_line_breaks(file_contents)

        with open(cmake_lists_filename, 'w') as cmake_lists_file:
            cmake_lists_file.write(file_contents)
Exemple #5
0
    def __get_flat_archive_files(self, c_compiler, task: Task):
        """
        Get files list relevant for compilation

        :param c_compiler: whether the program would be compiled using C/C++ compiler
        :param task: task to handle
        :return: source files list
        """
        path = task.path_to_task_src(self.__workdir)
        dirfiles = os.listdir(path)
        if c_compiler:
            files = list(
                filter(lambda x: '.cxx' in x or '.cpp' in x or '.c' in x,
                       dirfiles))
        else:
            files = list(filter(lambda x: '.f' in x, dirfiles))
        files = list(map(lambda x: os.path.join(path, x), files))
        files = ' '.join(files)
        return files
Exemple #6
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