def update(self, force=False): def l(s): return self.name + " : " + s if self.sync_type == "local": logger.info(l("sync-type is local. Ignoring update")) return # FIXME: Do an initial checkout if missing if not os.path.exists(self.location): logger.warning( l("{} does not exist. Ignoring update".format(self.location)) ) return if not (self.auto_sync or force): logger.info(l("auto-sync disabled. Ignoring update")) return provider = get_provider(self.sync_type) try: logger.info(l("Updating...")) provider.update_library(self) except RuntimeError as e: logger.error(l("Failed to update library: " + str(e)))
def __new__(cls, *args, **kwargs): provider_name = args[0]['name'] if provider_name is None: raise RuntimeError('Missing "name" in section [provider]') return get_provider(provider_name)( args[0], "FIXME: core_root is used by local providers", "FIXME: cache_root can be set in fetch call")
def add_library(self, name, library): from fusesoc.provider import get_provider if not hasattr(self, '_path'): raise RuntimeError( "No FuseSoC config file found - can't add library") section_name = 'library.' + name config = configparser.SafeConfigParser() config.read(self._path) if not section_name in config.sections(): config.add_section(section_name) # This is not user-controlled at all so an assert is OK assert ('location' in library or 'sync-uri' in library) # sync-uri is absent for local libraries if 'sync-uri' in library: config.set(section_name, 'sync-uri', library['sync-uri']) if 'sync-type' in library: config.set(section_name, 'sync-type', library['sync-type']) else: library['sync-type'] = 'git' if 'auto-sync' in library: if library['auto-sync']: config.set(section_name, 'auto-sync', 'true') else: config.set(section_name, 'auto-sync', 'false') else: library['auto-sync'] = True if 'location' in library: config.set(section_name, 'location', library['location']) else: library['location'] = os.path.join(self.library_root, name) self.libraries[name] = library try: provider = get_provider(library['sync-type']) except ImportError as e: raise RuntimeError("Invalid sync-type '{}'".format( library['sync-type'])) provider.init_library(library) with open(self._path, 'w') as conf_file: config.write(conf_file)
def add_library(self, library): from fusesoc.provider import get_provider if not hasattr(self, "_path"): raise RuntimeError("No FuseSoC config file found - can't add library") section_name = "library." + library.name config = CP() config.read(self._path) if section_name in config.sections(): logger.warning( "Not adding library. {} already exists in configuration file".format( library.name ) ) return config.add_section(section_name) config.set(section_name, "location", library.location) if library.sync_type: config.set(section_name, "sync-uri", library.sync_uri) if library.sync_version is not None: config.set(section_name, "sync-version", library.sync_version) config.set(section_name, "sync-type", library.sync_type) _auto_sync = "true" if library.auto_sync else "false" config.set(section_name, "auto-sync", _auto_sync) try: provider = get_provider(library.sync_type) except ImportError as e: raise RuntimeError("Invalid sync-type '{}'".format(library["sync-type"])) provider.init_library(library) with open(self._path, "w") as conf_file: config.write(conf_file)
def update(cm, args): if "warn" in args: logger.warn(args.warn) libraries = args.libraries for root in cm.get_cores_root(): if not root in cm.config.cores_root: # This is a library - handled differently continue if os.path.exists(root) and (not libraries or root in libraries): args = ['-C', root, 'config', '--get', 'remote.origin.url'] repo_root = "" try: repo_root = subprocess.check_output(['git'] + args).decode("utf-8") if repo_root.strip() in [repo[1] for repo in REPOS]: logger.info("Updating '{}'".format(root)) args = ['-C', root, 'pull'] Launcher('git', args).run() except subprocess.CalledProcessError: pass for (name, library) in cm.config.libraries.items(): # TODO I don't like this huge "if", get rid of it if os.path.exists(library['location']) and \ not library['sync-uri'] is None and \ (name in libraries or \ library['location'] in libraries or \ library['auto-sync']): logger.info("Updating '{}'".format(name)) try: provider = get_provider(library['sync-type']) except ImportError as e: logger.error( "Invalid sync-type '{}' for library '{}' - skipping". format(library['sync-type'], name)) continue try: provider.update_library(library) except RuntimeError as e: logger.error("Failed to update library: " + str(e) + ". Continuing...")
def add_library(self, library): from fusesoc.provider import get_provider if not hasattr(self, '_path'): raise RuntimeError( "No FuseSoC config file found - can't add library") section_name = 'library.' + library.name config = CP() config.read(self._path) if section_name in config.sections(): logger.warn( "Not adding library. {} already exists in configuration file". format(library.name)) return config.add_section(section_name) config.set(section_name, 'location', library.location) if library.sync_type: config.set(section_name, 'sync-uri', library.sync_uri) config.set(section_name, 'sync-type', library.sync_type) _auto_sync = 'true' if library.auto_sync else 'false' config.set(section_name, 'auto-sync', _auto_sync) try: provider = get_provider(library.sync_type) except ImportError as e: raise RuntimeError("Invalid sync-type '{}'".format( library['sync-type'])) provider.init_library(library) with open(self._path, 'w') as conf_file: config.write(conf_file)
def __init__(self, core_file, cache_root=""): basename = os.path.basename(core_file) self.depend = [] self.simulators = [] self.plusargs = None self.provider = None self.backend = None for s in section.SECTION_MAP: assert not hasattr(self, s) if section.SECTION_MAP[s].named: setattr(self, s, OrderedDict()) else: setattr(self, s, None) self.core_root = os.path.dirname(core_file) self.files_root = self.core_root self.export_files = [] config = FusesocConfigParser(core_file) # Add .system options to .core file system_file = os.path.join(self.core_root, basename.split(".core")[0] + ".system") if os.path.exists(system_file): self._merge_system_file(system_file, config) # FIXME : Make simulators part of the core object self.simulator = config.get_section("simulator") if not "toplevel" in self.simulator: self.simulator["toplevel"] = "orpsoc_tb" for s in section.load_all(config, core_file): if type(s) == tuple: _l = getattr(self, s[0].TAG) _l[s[1]] = s[0] setattr(self, s[0].TAG, _l) else: setattr(self, s.TAG, s) if not self.main: self.main = section.MainSection() if self.main.name: self.name = Vlnv(self.main.name) else: self.name = Vlnv(basename.split(".core")[0]) self.sanitized_name = self.name.sanitized_name self.depend = self.main.depend[:] self.simulators = self.main.simulators if self.main.backend: try: self.backend = getattr(self, self.main.backend) except AttributeError: raise SyntaxError('Invalid backend "{}"'.format( self.main.backend)) self._collect_filesets() cache_root = os.path.join(cache_root, self.sanitized_name) if config.has_section("plusargs"): self._warning( "plusargs section is deprecated and will not be parsed by FuseSoC. Please migrate to parameters" ) self.plusargs = Plusargs(dict(config.items("plusargs"))) if config.has_section("verilator") and config.has_option( "verilator", "define_files"): self._warning("verilator define_files are deprecated") if config.has_section("provider"): items = dict(config.items("provider")) patch_root = os.path.join(self.core_root, "patches") patches = self.main.patches if os.path.exists(patch_root): for p in sorted(os.listdir(patch_root)): patches.append(os.path.join("patches", p)) items["patches"] = patches provider_name = items.get("name") if provider_name is None: raise RuntimeError('Missing "name" in section [provider]') self.provider = get_provider(provider_name)(items, self.core_root, cache_root) if self.provider: self.files_root = self.provider.files_root # We need the component file here, but it might not be # available until the core is fetched. Try to fetch first if any # of the component files are missing if False in [os.path.exists(f) for f in self.main.component]: self.setup() for f in self.main.component: self._parse_component(f)
def __init__(self, core_file, cache_root=''): basename = os.path.basename(core_file) self.depend = [] self.simulators = [] self.plusargs = None self.provider = None self.backend = None for s in section.SECTION_MAP: assert(not hasattr(self, s)) if(section.SECTION_MAP[s].named): setattr(self, s, OrderedDict()) else: setattr(self, s, None) self.core_root = os.path.dirname(core_file) self.files_root = self.core_root self.export_files = [] config = FusesocConfigParser(core_file) #Add .system options to .core file system_file = os.path.join(self.core_root, basename.split('.core')[0]+'.system') if os.path.exists(system_file): self._merge_system_file(system_file, config) #FIXME : Make simulators part of the core object self.simulator = config.get_section('simulator') if not 'toplevel' in self.simulator: self.simulator['toplevel'] = 'orpsoc_tb' for s in section.load_all(config, core_file): if type(s) == tuple: _l = getattr(self, s[0].TAG) _l[s[1]] = s[0] setattr(self, s[0].TAG, _l) else: setattr(self, s.TAG, s) if not self.main: self.main = section.MainSection() if self.main.name: self.name = Vlnv(self.main.name) else: self.name = Vlnv(basename.split('.core')[0]) self.sanitized_name = self.name.sanitized_name self.depend = self.main.depend[:] self.simulators = self.main.simulators if self.main.backend: try: self.backend = getattr(self, self.main.backend) except AttributeError: raise SyntaxError('Invalid backend "{}"'.format(self.main.backend)) self._collect_filesets() cache_root = os.path.join(cache_root, self.sanitized_name) if config.has_section('plusargs'): self._warning("plusargs section is deprecated and will not be parsed by FuseSoC. Please migrate to parameters") self.plusargs = Plusargs(dict(config.items('plusargs'))) if config.has_section('verilator') and config.has_option('verilator', 'define_files'): self._warning("verilator define_files are deprecated") if config.has_section('provider'): items = dict(config.items('provider')) patch_root = os.path.join(self.core_root, 'patches') patches = self.main.patches if os.path.exists(patch_root): for p in sorted(os.listdir(patch_root)): patches.append(os.path.join('patches', p)) items['patches'] = patches provider_name = items.get('name') if provider_name is None: raise RuntimeError('Missing "name" in section [provider]') self.provider = get_provider(provider_name)( items, self.core_root, cache_root) if self.provider: self.files_root = self.provider.files_root # We need the component file here, but it might not be # available until the core is fetched. Try to fetch first if any # of the component files are missing if False in [os.path.exists(f) for f in self.main.component]: self.setup() for f in self.main.component: self._parse_component(f)