Exemplo n.º 1
0
    def _check_config(self):
        try:
            self.__source_directories = self.configuration[
                "source_directories"]
        except KeyError:
            logger.error("No source directories given")
            exit(-1)

        try:
            self.__output_file = self.configuration["output_file"]
        except KeyError:
            logger.error("No output directory given")
            exit(-1)

        try:
            self.__types = self.configuration["types"]
        except KeyError:
            logger.error("No type given")
            exit(-1)

        try:
            self.__additional_flags = self.configuration["additional_flags"]
        except KeyError:
            logger.debug("additional_flags not set.")
            self.__additional_flags = []
Exemplo n.º 2
0
    def _check_config(self):
        try:
            self.__defines = self.configuration["defines"]
        except KeyError:
            logger.debug("defines not set")
            self.__defines = []

        try:
            self.__includes = self.configuration["includes"]
        except KeyError:
            logger.debug("defines not set")
            self.__includes = []

        try:
            self.__steps_list = self.configuration["steps"]
        except KeyError:
            logger.debug("steps not set")
            self.__steps_list = []

        try:
            os.chdir(
                os.path.join(os.getcwd(), self.configuration["project_root"]))
        except KeyError:
            logger.debug("project_root not set")

        self.__steps = []
Exemplo n.º 3
0
    def _check_config(self):
        try:
            self.__repository_location = self.configuration["repo_location"]
        except KeyError:
            logger.error("No repository location given")
            exit(-1)

        try:
            self.__clone_destination = self.configuration["destination"]
        except KeyError:
            logger.error("No clone destination given")
            exit(-1)

        try:
            self.__branch = self.configuration["branch"]
        except KeyError:
            logger.debug("Pulling master branch")
            self.__branch = "master"
Exemplo n.º 4
0
    def __init__(self, project_config_file, toolchain):
        config_file_abs_path = os.path.abspath(project_config_file)
        os.chdir(os.path.dirname(config_file_abs_path))

        logger.debug("Reading project configuration file.")
        ConfigReader.__init__(self, config_file_abs_path)

        self.__project_name = ((project_config_file.replace("\\", "/")).split(
            "/")[-1]).split(".")[0]  # take the file name as a projecct name

        self.__toolchain = toolchain

        self.__toolchain.get_compiler().set_defines(self.__defines)
        self.__toolchain.get_compiler().set_includes(self.__includes)

        self._parse_steps_list()

        self.run()
Exemplo n.º 5
0
    def __init__(self, config_yaml_file, path_to_toolchain=""):

        logger.debug("Reading toolchain configuration file.")
        ConfigReader.__init__(self, config_yaml_file)

        self._check_compiler_config_file()

        self.__linker_path = os.path.join(path_to_toolchain, self.__linker_name).replace("\\", "/")
        self.__compiler_path = os.path.join(path_to_toolchain, self.__compiler_name).replace("\\", "/")

        self._check_toolchain_path()

        self.__compiler = Compiler(self.__compiler_path, self.__define_flag, self.__output_flag,
                                   self.__compile_flag, self.__include_flag)

        self.__compiler.set_flags(self.__compiler_flags)

        self.__linker = Linker(self.__linker_path, self.__output_flag, self.__command_line_file)
        self.__linker.set_flags(self.__linker_flags)
Exemplo n.º 6
0
    def compile(self, list_of_files, output_directory, list_of_additional_flags=[],
                list_of_additional_defines=[], list_of_additionals_includes=[]):
        exit_code = 0

        flags = self.__flags + list_of_additional_flags + [self.__compile_flag]
        defines = self._compose_defines(self.__defines + list_of_additional_defines)
        includes = self._compose_includes(self.__includes + list_of_additionals_includes)

        for file in list_of_files:
            output_file_name = file.split("/")[-1]  # take the file name
            output_file_name = output_file_name.split(".")[0] + ".o"  # change expention to ".o"

            output_flag = self.__output_flag + "/".join([output_directory, output_file_name])

            logger.debug("Compiling: " + file)
            command = [self.__compiler_path] + flags + defines + includes + [output_flag] + [file]
            exit_code = subprocess.call(command)

            if(exit_code != 0):
                raise ChildProcessError(f"Compilation of {file} failed with exit code: {exit_code}")
Exemplo n.º 7
0
    def link(self, list_of_files, output_file, list_of_additional_flags=[]):
        filename = str(int(time.time())) + "linker_file"

        with open(filename, "w") as comand_line_file:

            logger.debug("Created " + filename)

            for file in list_of_files:
                comand_line_file.write(" " + file)
                logger.debug("Added " + file)

        logger.debug("Linking {}".format(list_of_files))
        command = [self.__linker_path] + self.__flags + [
            self.__command_line_file + filename
        ] + [self.__output_flag + output_file] + list_of_additional_flags
        exit_code = subprocess.call(command)

        os.remove(filename)
        logger.debug("Removed " + filename)

        return exit_code
Exemplo n.º 8
0
    def perform(self):
        base_location = os.getcwd()
        logger.debug("Changing directory to " +
                     self.__command_execution_location)
        os.chdir(self.__command_execution_location)

        exit_code = 0

        for command in self.__commands:
            logger.debug("Calling " + command)
            if command.startswith("cd "):  # TODO: To be done better.
                os.chdir(command.replace("cd ", ""))
            else:
                exit_code += subprocess.call(command, shell=True)

        logger.debug("Changing directory to " + base_location)
        os.chdir(base_location)

        if exit_code:
            self.exit_code = -1
        self.exit_code = 0
Exemplo n.º 9
0
 def _create_outpu_directory(self):
     logger.debug("Creating " + self.__output_directory)
     os.makedirs(self.__output_directory, exist_ok=True)