Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform an initial checkout if library is missing #720

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions fusesoc/fusesoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ def _register_libraries(self):
try:
self.add_library(library)
except (RuntimeError, OSError) as e:
_s = "Failed to register library '{}'"
logger.warning(_s.format(str(e)))
try:
temporary_lm = LibraryManager(self.config.library_root)
# try to initialize library
temporary_lm.add_library(library)
temporary_lm.update([library.name])
# the initialization worked, now register it properly
self.add_library(library)
except (RuntimeError, OSError) as e:
_s = "Failed to register library '{}'"
logger.warning(_s.format(str(e)))

@staticmethod
def init_logging(verbose, monochrome, log_file=None):
Expand Down
17 changes: 12 additions & 5 deletions fusesoc/librarymanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,23 @@ def l(s):
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(f"{self.location} does not exist. Ignoring update"))
return

if not (self.auto_sync or force):
logger.info(l("auto-sync disabled. Ignoring update"))
return

provider = get_provider(self.sync_type)

if not os.path.exists(self.location):
logger.info(l(f"{self.location} does not exist. Trying a checkout"))
try:
provider.init_library(self)
except RuntimeError as e:
# Keep old behavior of logging a warning if there is a library
# in `fusesoc.conf`, but the directory does not exist for some
# reason and it could not be initialized.
logger.warning(l(f"{self.location} does not exist. Ignoring update"))
return

try:
logger.info(l("Updating..."))
provider.update_library(self)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,36 @@ def test_library_update(caplog):
fs.update_libraries([])

assert "test_lib : sync-type is local. Ignoring update" in caplog.text


def test_library_update_with_initialize(caplog):
with tempfile.TemporaryDirectory() as library:

with tempfile.NamedTemporaryFile(mode="w+") as tcf:
tcf.write(
f"""[main]
library_root = {library}

[library.vlog_tb_utils]
location = fusesoc_libraries/vlog_tb_utils
sync-uri = https://github.com/fusesoc/vlog_tb_utils
sync-type = git
auto-sync = true

"""
)
tcf.flush()

conf = Config(tcf.name)

args = Namespace()

Fusesoc.init_logging(False, False)
fs = Fusesoc(conf)

with caplog.at_level(logging.INFO):
fs.update_libraries([])

assert "vlog_tb_utils does not exist. Trying a checkout" in caplog.text
assert "Cloning library into fusesoc_libraries/vlog_tb_utils" in caplog.text
assert "Updating..." in caplog.text
Loading