@@ -275,7 +275,7 @@ def load_module(self, *args, **kwargs):
275275
276276 def extract_step (self ):
277277 """
278- Unpack the source files and populate them with required .cargo-checksum.json if offline
278+ Unpack the source files and populate them with required .cargo-checksum.json
279279 """
280280 self .vendor_dir = os .path .join (self .builddir , 'easybuild_vendor' )
281281 mkdir (self .vendor_dir )
@@ -339,15 +339,21 @@ def extract_step(self):
339339
340340 src ['finalpath' ] = src_dir
341341
342- if self .cfg ['offline' ]:
343- self ._setup_offline_config (git_sources )
342+ if self .cfg ['crates' ]:
343+ if not self .cfg ['offline' ]:
344+ self .log .warning (f'{ self .name } has crates but `offline = False`. '
345+ 'This might donwload newer versions or just fail.' )
346+ self ._setup_vendored_crates (git_sources )
347+ elif self .cfg ['offline' ]:
348+ self .log .warning (f'{ self .name } specifies `offline = True` but has no crates. '
349+ 'The build will fail if any crate needs to be downloaded' )
344350
345- def _setup_offline_config (self , git_sources ):
351+ def _setup_vendored_crates (self , git_sources ):
346352 """
347- Setup the configuration required for offline builds
353+ Setup the configuration required to use the vendored crates specified in the easyconfig
348354 :param git_sources: dict mapping (git_repo, rev) to extracted source
349355 """
350- self .log .info ("Setting up vendored crates for offline operation" )
356+ self .log .info ("Setting up vendored crates%s" , " for offline operation" if self . cfg [ 'offline' ] else " " )
351357
352358 self .log .debug ("Setting up checksum files and unpacking workspaces with virtual manifest" )
353359 path_to_source = {src ['finalpath' ]: src for src in self .src }
@@ -363,7 +369,7 @@ def _setup_offline_config(self, git_sources):
363369 self .log .debug (f"Computing checksum for { src ['path' ]} ." )
364370 checksum = compute_checksum (src ['path' ], checksum_type = CHECKSUM_TYPE_SHA256 )
365371 else :
366- self .log .debug (f'No source found for { crate_dir } . Using nul -checksum for vendoring' )
372+ self .log .debug (f'No source found for { crate_dir } . Using null -checksum for vendoring' )
367373 checksum = 'null'
368374 cargo_pkg_dirs = [crate_dir ] # Default case: Single crate
369375 # Sources might contain multiple crates/folders in a so-called "workspace".
@@ -412,10 +418,15 @@ def _setup_offline_config(self, git_sources):
412418 chkfile = os .path .join (pkg_dir , '.cargo-checksum.json' )
413419 write_file (chkfile , CARGO_CHECKSUM_JSON .format (checksum = checksum ))
414420
415- self .log .debug ("Writting config.toml entry for vendored crates from crate.io" )
416421 config_toml = os .path .join (self .cargo_home , 'config.toml' )
417- # Replace crates-io with vendored sources using build dir wide toml file in CARGO_HOME
418- write_file (config_toml , CONFIG_TOML_SOURCE_VENDOR .format (vendor_dir = self .vendor_dir ))
422+ # Only "redirect" crate.io sources if any crate from it was provided.
423+ if any (len (crate ) == 2 for crate in self .crates ):
424+ self .log .debug ("Writting config.toml entry for vendored crates from crate.io" )
425+ if not self .cfg ['offline' ]:
426+ self .log .warning ("Downloads from crates.io won't be possible even though `offline = False` is set." )
427+ write_file (config_toml , CONFIG_TOML_SOURCE_VENDOR .format (vendor_dir = self .vendor_dir ))
428+ elif not self .cfg ['offline' ]:
429+ self .log .info ("No vendored crates from crate.io given, downloading from crate.io may be possible" )
419430
420431 # Tell cargo about the vendored git sources to avoid it failing with:
421432 # Unable to update https://github.com/[...]
0 commit comments