Skip to content

Commit

Permalink
Merge pull request #2934 from boegel/20230524165422_new_pr_cargo
Browse files Browse the repository at this point in the history
enhance Cargo constructor to avoid processing list of crates multiple times into sources
  • Loading branch information
Micket authored May 24, 2023
2 parents 411f81c + f6c717a commit fa9b2c3
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions easybuild/easyblocks/generic/cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,36 @@ def __init__(self, *args, **kwargs):
env.setvar('RUST_LOG', 'DEBUG')
env.setvar('RUST_BACKTRACE', '1')

# Populate sources from "crates" list of tuples
sources = []
for crate_info in self.cfg['crates']:
if len(crate_info) == 2:
crate, version = crate_info
sources.append({
'download_filename': crate + '/' + version + '/download',
'filename': crate + '-' + version + '.tar.gz',
'source_urls': [CRATESIO_SOURCE],
'alt_location': 'crates.io',
})
else:
crate, version, repo, rev = crate_info
url, repo_name_git = repo.rsplit('/', maxsplit=1)
sources.append({
'git_config': {'url': url, 'repo_name': repo_name_git[:-4], 'commit': rev},
'filename': crate + '-' + version + '.tar.gz',
'source_urls': [CRATESIO_SOURCE],
})
# Populate sources from "crates" list of tuples (only once)
if self.cfg['crates']:
# copy list of crates, so we can wipe 'crates' easyconfig parameter,
# to avoid that creates are processed into 'sources' easyconfig parameter again
# when easyblock is initialized again using same parsed easyconfig
# (for example when check_sha256_checksums function is called, like in easyconfigs test suite)
self.crates = self.cfg['crates'][:]
sources = []
for crate_info in self.cfg['crates']:
if len(crate_info) == 2:
crate, version = crate_info
sources.append({
'download_filename': crate + '/' + version + '/download',
'filename': crate + '-' + version + '.tar.gz',
'source_urls': [CRATESIO_SOURCE],
'alt_location': 'crates.io',
})
else:
crate, version, repo, rev = crate_info
url, repo_name_git = repo.rsplit('/', maxsplit=1)
sources.append({
'git_config': {'url': url, 'repo_name': repo_name_git[:-4], 'commit': rev},
'filename': crate + '-' + version + '.tar.gz',
'source_urls': [CRATESIO_SOURCE],
})

self.cfg.update('sources', sources)
self.cfg.update('sources', sources)

def configure_step(self):
pass
# set 'crates' easyconfig parameter to empty list to prevent re-processing into sources
self.cfg['crates'] = []

def extract_step(self):
"""
Expand All @@ -112,7 +118,7 @@ def extract_step(self):

# also vendor sources from other git sources (could be many crates for one git source)
git_sources = set()
for crate_info in self.cfg['crates']:
for crate_info in self.crates:
if len(crate_info) == 4:
_, _, repo, rev = crate_info
git_sources.add((repo, rev))
Expand Down Expand Up @@ -144,6 +150,10 @@ def extract_step(self):
chkfile = os.path.join(self.builddir, cratedir, '.cargo-checksum.json')
write_file(chkfile, '{"files":{},"package":"%s"}' % chksum)

def configure_step(self):
"""Empty configuration step."""
pass

@property
def profile(self):
return 'debug' if self.toolchain.options.get('debug', None) else 'release'
Expand Down

0 comments on commit fa9b2c3

Please sign in to comment.