diff options
-rw-r--r-- | buildstream/_loader/loader.py | 38 | ||||
-rw-r--r-- | tests/frontend/show.py | 43 |
2 files changed, 57 insertions, 24 deletions
diff --git a/buildstream/_loader/loader.py b/buildstream/_loader/loader.py index 1d7476776..2efc4d360 100644 --- a/buildstream/_loader/loader.py +++ b/buildstream/_loader/loader.py @@ -534,29 +534,31 @@ class Loader(): element = Element._new_from_meta(meta_element, self._context.artifactcache) element._preflight() + element._update_state() - for source in element.sources(): - # Handle the case where a subproject needs to be fetched - # - if source.get_consistency() == Consistency.RESOLVED: - if fetch_subprojects: + # Handle the case where a subproject needs to be fetched + # + if element._get_consistency() == Consistency.RESOLVED: + if fetch_subprojects: + for source in element.sources(): if ticker: ticker(filename, 'Fetching subproject from {} source'.format(source.get_kind())) - source._fetch() - else: - detail = "Try fetching the project with `bst fetch {}`".format(filename) - raise LoadError(LoadErrorReason.SUBPROJECT_FETCH_NEEDED, - "Subproject fetch needed for junction: {}".format(filename), - detail=detail) - - # Handle the case where a subproject has no ref - # - elif source.get_consistency() == Consistency.INCONSISTENT: - detail = "Try tracking the junction element with `bst track {}`".format(filename) - raise LoadError(LoadErrorReason.SUBPROJECT_INCONSISTENT, - "Subproject has no ref for junction: {}".format(filename), + if source._get_consistency() != Consistency.CACHED: + source._fetch() + else: + detail = "Try fetching the project with `bst fetch {}`".format(filename) + raise LoadError(LoadErrorReason.SUBPROJECT_FETCH_NEEDED, + "Subproject fetch needed for junction: {}".format(filename), detail=detail) + # Handle the case where a subproject has no ref + # + elif element._get_consistency() == Consistency.INCONSISTENT: + detail = "Try tracking the junction element with `bst track {}`".format(filename) + raise LoadError(LoadErrorReason.SUBPROJECT_INCONSISTENT, + "Subproject has no ref for junction: {}".format(filename), + detail=detail) + # Stage sources os.makedirs(self._context.builddir, exist_ok=True) basedir = tempfile.mkdtemp(prefix="{}-".format(element.normal_name), dir=self._context.builddir) diff --git a/tests/frontend/show.py b/tests/frontend/show.py index a7d71dc42..2569d4611 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -114,7 +114,8 @@ def test_target_is_dependency(cli, tmpdir, datafiles): @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')]) @pytest.mark.parametrize("element_name", ['junction-dep.bst', 'junction.bst:import-etc.bst']) -def test_unfetched_junction(cli, tmpdir, datafiles, ref_storage, element_name): +@pytest.mark.parametrize("workspaced", [True, False], ids=["workspace", "no-workspace"]) +def test_unfetched_junction(cli, tmpdir, datafiles, ref_storage, element_name, workspaced): project = os.path.join(datafiles.dirname, datafiles.basename) subproject_path = os.path.join(project, 'files', 'sub-project') junction_path = os.path.join(project, 'elements', 'junction.bst') @@ -156,17 +157,29 @@ def test_unfetched_junction(cli, tmpdir, datafiles, ref_storage, element_name): } _yaml.dump(project_refs, os.path.join(project, 'junction.refs')) + # Open a workspace if we're testing workspaced behavior + if workspaced: + result = cli.run(project=project, silent=True, args=[ + 'workspace', 'open', '--no-checkout', 'junction.bst', subproject_path + ]) + result.assert_success() + # Assert the correct error when trying to show the pipeline result = cli.run(project=project, silent=True, args=[ 'show', element_name]) - result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_FETCH_NEEDED) + # If a workspace is open, no fetch is needed + if workspaced: + result.assert_success() + else: + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_FETCH_NEEDED) @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')]) @pytest.mark.parametrize("element_name", ['junction-dep.bst', 'junction.bst:import-etc.bst']) -def test_inconsistent_junction(cli, tmpdir, datafiles, ref_storage, element_name): +@pytest.mark.parametrize("workspaced", [True, False], ids=["workspace", "no-workspace"]) +def test_inconsistent_junction(cli, tmpdir, datafiles, ref_storage, element_name, workspaced): project = os.path.join(datafiles.dirname, datafiles.basename) subproject_path = os.path.join(project, 'files', 'sub-project') junction_path = os.path.join(project, 'elements', 'junction.bst') @@ -192,16 +205,28 @@ def test_inconsistent_junction(cli, tmpdir, datafiles, ref_storage, element_name } _yaml.dump(element, element_path) + # Open a workspace if we're testing workspaced behavior + if workspaced: + result = cli.run(project=project, silent=True, args=[ + 'workspace', 'open', '--no-checkout', 'junction.bst', subproject_path + ]) + result.assert_success() + # Assert the correct error when trying to show the pipeline result = cli.run(project=project, silent=True, args=[ 'show', element_name]) - result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_INCONSISTENT) + # If a workspace is open, no ref is needed + if workspaced: + result.assert_success() + else: + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_INCONSISTENT) @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("element_name", ['junction-dep.bst', 'junction.bst:import-etc.bst']) -def test_fetched_junction(cli, tmpdir, datafiles, element_name): +@pytest.mark.parametrize("workspaced", [True, False], ids=["workspace", "no-workspace"]) +def test_fetched_junction(cli, tmpdir, datafiles, element_name, workspaced): project = os.path.join(datafiles.dirname, datafiles.basename) subproject_path = os.path.join(project, 'files', 'sub-project') junction_path = os.path.join(project, 'elements', 'junction.bst') @@ -225,9 +250,15 @@ def test_fetched_junction(cli, tmpdir, datafiles, element_name): result = cli.run(project=project, silent=True, args=[ 'fetch', 'junction.bst']) - result.assert_success() + # Open a workspace if we're testing workspaced behavior + if workspaced: + result = cli.run(project=project, silent=True, args=[ + 'workspace', 'open', '--no-checkout', 'junction.bst', subproject_path + ]) + result.assert_success() + # Assert the correct error when trying to show the pipeline result = cli.run(project=project, silent=True, args=[ 'show', '--format', '%{name}-%{state}', element_name]) |