diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 6d5848da384f4260a22d6206d520add8ea13b0f5..4249ec6f85cbb194273a64ff60a6a7553499c731 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -296,13 +296,21 @@ def _need_to_create_path(self): def expected_archive_files(self): """Possible archive file paths.""" paths = [] + + fnames = [] + expanded = True if isinstance(self.default_fetcher, fs.URLFetchStrategy): - paths.append(os.path.join( - self.path, os.path.basename(self.default_fetcher.url))) + expanded = self.default_fetcher.expand_archive + fnames.append(os.path.basename(self.default_fetcher.url)) if self.mirror_path: - paths.append(os.path.join( - self.path, os.path.basename(self.mirror_path))) + fnames.append(os.path.basename(self.mirror_path)) + + paths.extend(os.path.join(self.path, f) for f in fnames) + if not expanded: + # If the download file is not compressed, the "archive" is a + # single file placed in Stage.source_path + paths.extend(os.path.join(self.source_path, f) for f in fnames) return paths diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py index 908771de90e323451589a3dfd624b6bcbe50c8ee..9f5e7363f537331092647bd8a63ca1da5ea5878b 100644 --- a/lib/spack/spack/test/stage.py +++ b/lib/spack/spack/test/stage.py @@ -465,6 +465,19 @@ def test_setup_and_destroy_no_name_with_tmp(self, mock_stage_archive): check_setup(stage, None, archive) check_destroy(stage, None) + @pytest.mark.usefixtures('tmpdir_for_stage') + def test_noexpand_stage_file( + self, mock_stage_archive, mock_noexpand_resource): + """When creating a stage with a nonexpanding URL, the 'archive_file' + property of the stage should refer to the path of that file. + """ + test_noexpand_fetcher = spack.fetch_strategy.from_kwargs( + url='file://' + mock_noexpand_resource, expand=False) + with Stage(test_noexpand_fetcher) as stage: + stage.fetch() + stage.expand_archive() + assert os.path.exists(stage.archive_file) + @pytest.mark.disable_clean_stage_check @pytest.mark.usefixtures('tmpdir_for_stage') def test_composite_stage_with_noexpand_resource(