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

enhance Cargo constructor to avoid processing list of crates multiple times into sources #2934

Merged
merged 2 commits into from
May 24, 2023
Merged
Changes from 1 commit
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
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 paramter,
ocaisa marked this conversation as resolved.
Show resolved Hide resolved
# 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