class StructureInitializer(Initializer):
    def __init__(self, main_dir=join(getcwd(), 'SampleProject')):
        self.__main_dir = main_dir
        self.scanner = FileScanner()

    def main_dir(self):
        return self.__main_dir

    def init(self):
        self.scanner.check_structure(main_dir=self.__main_dir)
        # if(not self.scanner.check_structure()):
        #     for missing_dir in self.scanner.check_missing_dirs():
        #         makedirs(missing_dir)

    def __str__(self):
        return "StructureInitializer: " + self.main_dir()
Exemple #2
0
class LinkerTool:
    def __init__(self, main_dir):
        self.__main_dir = main_dir
        self.binary = main_dir + '/' + CONST.BIN_DIR + '/' + CONST.PROGRAM_BIN_NAME
        self.lib_path = main_dir + '/' + CONST.LIB_DIR
        self.scanner = FileScanner()
    
    def link_executable(self):
        # command = "{0} -o {1} {2}".format(CONST.COMPILER, self.binary, ' '.join(output_list))
        command = [CONST.COMPILER, "-o", self.binary, "-L" + self.lib_path]
        lib_names = list()
        for lib_name in self.scanner.scan_for_libs(self.lib_path):
            lib_names.append("-l" + lib_name)
        for source in db_manager.scan_all_sources():
            command.append(create_obj_path(self.__main_dir, source))
        if hasattr(CONST, "LINKER_FLAGS"):
            command.append(CONST.LINKER_FLAGS)
        command.append(" ".join(lib_names))

        result = Popen(command, stdout=PIPE, stderr=PIPE)
        output = result.communicate()
        if result.returncode == 0:
            logging.info("Linking complete %s", self.binary)
            # db_manager.set_linker_status(True)
        else:
            logging.error("Linker error: %s", output[1].decode('UTF-8'))
 def __init__(self, main_dir):
     self.__main_dir = main_dir
     self.scanner = FileScanner()
     self.dep_scanner = DependecyScanner()
     self.src_path = self.main_dir() + '/' + CONST.SRC_DIR
     self.include_path = self.main_dir() + '/' + CONST.INCLUDE_DIR
class DependecyInitializer(Initializer):
    def __init__(self, main_dir):
        self.__main_dir = main_dir
        self.scanner = FileScanner()
        self.dep_scanner = DependecyScanner()
        self.src_path = self.main_dir() + '/' + CONST.SRC_DIR
        self.include_path = self.main_dir() + '/' + CONST.INCLUDE_DIR

    def main_dir(self):
        return self.__main_dir

    def __clean(self, file):
        _, dependecies = self.dep_scanner.scan_dependecy(src_path=self.src_path, file=file, 
                                                                    include_path=self.include_path)
        hashed_file = self.dep_scanner.generate_checksum(file=file, src_path=self.src_path)
        if file.endswith(CONST.SOURCE_EXT):
            db_manager.save_dependecy(file=file, dependencies=dependecies, hashed_file=hashed_file, rebuild=True)
        else:
            db_manager.save_dependecy(file=file, dependencies=dependecies, hashed_file=hashed_file)

    def __clean_build(self):
        for file in self.scanner.scan_sources(main_dir=self.src_path, filter=(CONST.SOURCE_EXT, CONST.HEADER_EXT)):
            #self.__clean(file=file)            
            if threading.active_count() < multiprocessing.cpu_count():
                t = threading.Thread(target=self.__clean, args=(file,))
                t.start()
            else:
                self.__clean(file)
        main_thread = threading.currentThread()
        for t in threading.enumerate():
            if t is main_thread:
                continue
            t.join()

    def __update_build(self):
        headers = set()
        file_list = list()
    #        import config.helpers as helpers
    #        helpers.ls_database(self.db_manager)
        for file in self.scanner.scan_sources(main_dir=self.src_path, filter=(CONST.SOURCE_EXT, CONST.HEADER_EXT)):
            file_list.append(file)
            checksum = db_manager.get_file_checksum(file)
            hashed_file = self.dep_scanner.generate_checksum(file=file, src_path=self.src_path)
            if hashed_file != checksum:
                logging.debug("Checksum changed for file: %s", file)
                _, dependecies = self.dep_scanner.scan_dependecy(src_path=self.src_path, file=file, 
                                                                            include_path=self.include_path)
                if file.endswith(CONST.SOURCE_EXT):
                    db_manager.save_dependecy(file=file, dependencies=dependecies, hashed_file=hashed_file, rebuild=True)
                else:
                    db_manager.save_dependecy(file=file, dependencies=dependecies, hashed_file=hashed_file)
                    headers.add(file)
        db_manager.rebuild_related_header_sources(headers)
        db_manager.delete_unused_file(file_list)

    def init(self):
        if db_manager.check_if_empty():
            logging.info("Clean build")
            self.__clean_build()
        else:
            logging.info("Update build")
            self.__update_build()
 def __init__(self, main_dir=join(getcwd(), 'SampleProject')):
     self.__main_dir = main_dir
     self.scanner = FileScanner()
Exemple #6
0
 def __init__(self, main_dir):
     self.__main_dir = main_dir
     self.binary = main_dir + '/' + CONST.BIN_DIR + '/' + CONST.PROGRAM_BIN_NAME
     self.lib_path = main_dir + '/' + CONST.LIB_DIR
     self.scanner = FileScanner()