@@ -125,6 +125,18 @@ def get_workspace_members(crate_dir):
125125 return [os .path .join (crate_dir , m ) for m in members ]
126126
127127
128+ def get_checksum (src , log ):
129+ """Get the checksum from an extracted source"""
130+ checksum = src ['checksum' ]
131+ if isinstance (checksum , dict ):
132+ try :
133+ checksum = checksum [src ['name' ]]
134+ except KeyError :
135+ log .warning ('No checksum for %s in %s' , checksum , src ['name' ])
136+ checksum = None
137+ return checksum
138+
139+
128140class Cargo (ExtensionEasyBlock ):
129141 """Support for installing Cargo packages (Rust)"""
130142
@@ -186,13 +198,7 @@ def __init__(self, *args, **kwargs):
186198 """Constructor for Cargo easyblock."""
187199 super (Cargo , self ).__init__ (* args , ** kwargs )
188200 self .cargo_home = os .path .join (self .builddir , '.cargo' )
189- env .setvar ('CARGO_HOME' , self .cargo_home )
190- env .setvar ('RUSTC' , 'rustc' )
191- env .setvar ('RUSTDOC' , 'rustdoc' )
192- env .setvar ('RUSTFMT' , 'rustfmt' )
193- env .setvar ('RUSTFLAGS' , self .rustc_optarch ())
194- env .setvar ('RUST_LOG' , 'DEBUG' )
195- env .setvar ('RUST_BACKTRACE' , '1' )
201+ self .set_cargo_vars ()
196202
197203 # Populate sources from "crates" list of tuples
198204 sources = []
@@ -219,11 +225,31 @@ def __init__(self, *args, **kwargs):
219225
220226 self .cfg .update ('sources' , sources )
221227
228+ def set_cargo_vars (self ):
229+ """Set environment variables for Rust compilation and Cargo"""
230+ env .setvar ('CARGO_HOME' , self .cargo_home )
231+ env .setvar ('RUSTC' , 'rustc' )
232+ env .setvar ('RUSTDOC' , 'rustdoc' )
233+ env .setvar ('RUSTFMT' , 'rustfmt' )
234+ env .setvar ('RUSTFLAGS' , self .rustc_optarch ())
235+ env .setvar ('RUST_LOG' , 'DEBUG' )
236+ env .setvar ('RUST_BACKTRACE' , '1' )
237+
222238 @property
223239 def crates (self ):
224240 """Return the crates as defined in the EasyConfig"""
225241 return self .cfg ['crates' ]
226242
243+ def load_module (self , * args , ** kwargs ):
244+ """(Re)set environment variables after loading module file.
245+
246+ Required here to ensure the variables are defined for stand-alone installations and extensions,
247+ because the environment is reset to the initial environment right before loading the module.
248+ """
249+
250+ super (Cargo , self ).load_module (* args , ** kwargs )
251+ self .set_cargo_vars ()
252+
227253 def extract_step (self ):
228254 """
229255 Unpack the source files and populate them with required .cargo-checksum.json if offline
@@ -257,12 +283,13 @@ def extract_step(self):
257283 except KeyError :
258284 git_sources [git_key ] = src
259285 else :
260- previous_checksum = previous_source [ 'checksum' ]
261- current_checksum = src [ 'checksum' ]
286+ previous_checksum = get_checksum ( previous_source , self . log )
287+ current_checksum = get_checksum ( src , self . log )
262288 if previous_checksum and current_checksum and previous_checksum != current_checksum :
263- raise EasyBuildError ("Sources for the same git repository need to be identical."
264- "Mismatch found for %s rev %s in %s vs %s" ,
265- git_repo , rev , previous_source ['name' ], src ['name' ])
289+ raise EasyBuildError ("Sources for the same git repository need to be identical. "
290+ "Mismatch found for %s rev %s in %s (checksum: %s) vs %s (checksum: %s)" ,
291+ git_repo , rev , previous_source ['name' ], previous_checksum ,
292+ src ['name' ], current_checksum )
266293 self .log .info ("Source %s already extracted to %s by %s. Skipping extraction." ,
267294 src ['name' ], previous_source ['finalpath' ], previous_source ['name' ])
268295 src ['finalpath' ] = previous_source ['finalpath' ]
0 commit comments