junctions seem broken for `link`

Summary

My project seems broken when trying to use a link

I thought it was that the link had the same name as the junction in the sub project but when i changed that it still has the same issue, Could the issue be that because i include files from the junction in to my project.conf, eg to update your plugin defaults for usr merge etc. then something is going pop? please see bellow for details

Steps to reproduce

git clone https://gitlab.com/celduin/bsps/bst-boardsupport
cd bst-boardsupport
git checkout debug_junctions
cd sample/rpi4-features
bst show deploy/image.bst

What is the current bug behavior?

(venvbuildstream) [will@wsx280 rpi4-features]$ bst show deploy/image.bst
[--:--:--][        ][    main:core activity                 ] START   Loading elements
[--:--:--][        ][    main:core activity                 ] BUG     'NoneType' object has no attribute 'create'

    Traceback (most recent call last):
      File "/home/will/projects/buildstream/venvbuildstream/bin/bst", line 8, in <module>
        sys.exit(cli())
      File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 829, in __call__
        return self.main(*args, **kwargs)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_frontend/cli.py", line 238, in override_main
        original_main(self, args=args, prog_name=prog_name, complete_var=None, standalone_mode=standalone_mode, **extra)
      File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 782, in main
        rv = self.invoke(ctx)
      File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 1259, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 1066, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 610, in invoke
        return callback(*args, **kwargs)
      File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/decorators.py", line 33, in new_func
        return f(get_current_context().obj, *args, **kwargs)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_frontend/cli.py", line 564, in show
        dependencies = app.stream.load_selection(elements, selection=deps, except_targets=except_)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_stream.py", line 159, in load_selection
        load_refs=load_refs,
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_stream.py", line 1268, in _load
        targets, except_targets, rewritable=False
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_stream.py", line 1150, in _load_elements_from_targets
        elements, except_elements = self._pipeline.load(loadable)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_pipeline.py", line 75, in load
        elements = self._project.load_elements(targets)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_project.py", line 436, in load_elements
        meta_elements = self.loader.load(targets)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_loader/loader.py", line 138, in load
        element = loader._load_file(name, None)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_loader/loader.py", line 432, in _load_file
        top_element = self._load_file_no_deps(filename, provenance)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_loader/loader.py", line 400, in _load_file_no_deps
        self.project.ensure_fully_loaded()
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_project.py", line 507, in ensure_fully_loaded
        self._load_second_pass()
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_project.py", line 828, in _load_second_pass
        self._project_includes.process(project_conf_second_pass, process_project_options=False)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_includes.py", line 32, in process
        self._process(node, only_local=only_local, process_project_options=process_project_options)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_includes.py", line 57, in _process
        process_project_options=process_project_options,
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_includes.py", line 124, in _process_node
        process_project_options=process_project_options,
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_includes.py", line 180, in _process_value
        process_project_options=process_project_options,
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_includes.py", line 91, in _process_node
        include_node, file_path, sub_loader = self._include_file(include, current_loader)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_includes.py", line 141, in _include_file
        current_loader = loader.get_loader(junction, provenance)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_loader/loader.py", line 221, in get_loader
        loader = loader._get_loader(junction_name, provenance, load_subprojects=load_subprojects)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_loader/loader.py", line 694, in _get_loader
        self._load_file(filename, provenance, load_subprojects=load_subprojects)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_loader/loader.py", line 432, in _load_file
        top_element = self._load_file_no_deps(filename, provenance)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_loader/loader.py", line 404, in _load_file_no_deps
        element = LoadElement(node, filename, self)
      File "src/buildstream/_loader/loadelement.pyx", line 133, in buildstream._loader.loadelement.LoadElement.__cinit__
      File "/home/will/projects/buildstream/buildstream/src/buildstream/element.py", line 908, in _new_from_meta
        element = meta.project.create_element(meta, first_pass=meta.first_pass)
      File "/home/will/projects/buildstream/buildstream/src/buildstream/_project.py", line 357, in create_element
        return self.config.element_factory.create(self._context, self, meta)
    AttributeError: 'NoneType' object has no attribute 'create'

(venvbuildstream) [will@wsx280 rpi4-features]$ 

I though the issue was the name clash so i did the bellow to debug that. but the includes in project.conf also need fixing, if you fix the includes to be freedesktop-sdk-B.bst then you get the same error as above which suggest that the include are trying to run before the link is resolved.

(venvbuildstream) [will@wsx280 rpi4-features]$ mv elements/freedesktop-sdk.bst elements/freedesktop-sdk-B.bst 
(venvbuildstream) [will@wsx280 rpi4-features]$ bst show freedesktop-sdk-B.bst
[--:--:--][        ][    main:core activity                 ] START   Loading elements
[00:00:00][        ][    main:core activity                 ] FAILURE Loading elements

/home/will/projects/bsp/bst-boardsupport/sample/rpi4-features/project.conf [line 59 column 4]: Could not find element 'freedesktop-sdk.bst' in elements directory '/home/will/projects/bsp/bst-boardsupport/sample/rpi4-features/elements'

Edited by William Salmon