Abderrahim Kitouni pushed to branch abderrahim/cmake-variable-types at BuildStream / buildstream
Commits:
- 
6f4351ec
by Benjamin Schubert at 2018-11-09T16:53:42Z
- 
e6e03451
by richardmaw-codethink at 2018-11-12T11:05:15Z
- 
ae5ccd76
by Phillip Smyth at 2018-11-12T14:57:51Z
- 
56a54161
by Phillip Smyth at 2018-11-12T14:57:51Z
- 
e55a9703
by Jürg Billeter at 2018-11-12T15:44:45Z
- 
e8bc5515
by Abderrahim Kitouni at 2018-11-13T09:37:07Z
6 changed files:
- buildstream/_project.py
- buildstream/plugins/elements/cmake.yaml
- buildstream/source.py
- tests/format/variables.py
- + tests/frontend/invalid_element_path/project.conf
- tests/frontend/show.py
Changes:
| ... | ... | @@ -219,6 +219,19 @@ class Project(): | 
| 219 | 219 |  | 
| 220 | 220 |          return self._cache_key
 | 
| 221 | 221 |  | 
| 222 | +    def _validate_node(self, node):
 | |
| 223 | +        _yaml.node_validate(node, [
 | |
| 224 | +            'format-version',
 | |
| 225 | +            'element-path', 'variables',
 | |
| 226 | +            'environment', 'environment-nocache',
 | |
| 227 | +            'split-rules', 'elements', 'plugins',
 | |
| 228 | +            'aliases', 'name',
 | |
| 229 | +            'artifacts', 'options',
 | |
| 230 | +            'fail-on-overlap', 'shell', 'fatal-warnings',
 | |
| 231 | +            'ref-storage', 'sandbox', 'mirrors', 'remote-execution',
 | |
| 232 | +            'sources', '(@)'
 | |
| 233 | +        ])
 | |
| 234 | + | |
| 222 | 235 |      # create_element()
 | 
| 223 | 236 |      #
 | 
| 224 | 237 |      # Instantiate and return an element
 | 
| ... | ... | @@ -402,6 +415,8 @@ class Project(): | 
| 402 | 415 |                  "Project requested format version {}, but BuildStream {}.{} only supports up until format version {}"
 | 
| 403 | 416 |                  .format(format_version, major, minor, BST_FORMAT_VERSION))
 | 
| 404 | 417 |  | 
| 418 | +        self._validate_node(pre_config_node)
 | |
| 419 | + | |
| 405 | 420 |          # FIXME:
 | 
| 406 | 421 |          #
 | 
| 407 | 422 |          #   Performing this check manually in the absense
 | 
| ... | ... | @@ -467,16 +482,7 @@ class Project(): | 
| 467 | 482 |  | 
| 468 | 483 |          self._load_pass(config, self.config)
 | 
| 469 | 484 |  | 
| 470 | -        _yaml.node_validate(config, [
 | |
| 471 | -            'format-version',
 | |
| 472 | -            'element-path', 'variables',
 | |
| 473 | -            'environment', 'environment-nocache',
 | |
| 474 | -            'split-rules', 'elements', 'plugins',
 | |
| 475 | -            'aliases', 'name',
 | |
| 476 | -            'artifacts', 'options',
 | |
| 477 | -            'fail-on-overlap', 'shell', 'fatal-warnings',
 | |
| 478 | -            'ref-storage', 'sandbox', 'mirrors', 'remote-execution'
 | |
| 479 | -        ])
 | |
| 485 | +        self._validate_node(config)
 | |
| 480 | 486 |  | 
| 481 | 487 |          #
 | 
| 482 | 488 |          # Now all YAML composition is done, from here on we just load
 | 
| ... | ... | @@ -19,7 +19,7 @@ variables: | 
| 19 | 19 |    cmake-args: |
 | 
| 20 | 20 |  | 
| 21 | 21 |      -DCMAKE_INSTALL_PREFIX:PATH="%{prefix}" \
 | 
| 22 | -    -DCMAKE_INSTALL_LIBDIR=%{lib} %{cmake-extra} %{cmake-global} %{cmake-local}
 | |
| 22 | +    -DCMAKE_INSTALL_LIBDIR:PATH="%{lib}" %{cmake-extra} %{cmake-global} %{cmake-local}
 | |
| 23 | 23 |  | 
| 24 | 24 |    cmake: |
 | 
| 25 | 25 |  | 
| ... | ... | @@ -973,32 +973,34 @@ class Source(Plugin): | 
| 973 | 973 |              # the items of source_fetchers, if it happens to be a generator.
 | 
| 974 | 974 |              #
 | 
| 975 | 975 |              source_fetchers = iter(source_fetchers)
 | 
| 976 | -            try:
 | |
| 977 | 976 |  | 
| 978 | -                while True:
 | |
| 977 | +            while True:
 | |
| 979 | 978 |  | 
| 980 | -                    with context.silence():
 | |
| 979 | +                with context.silence():
 | |
| 980 | +                    try:
 | |
| 981 | 981 |                          fetcher = next(source_fetchers)
 | 
| 982 | - | |
| 983 | -                    alias = fetcher._get_alias()
 | |
| 984 | -                    for uri in project.get_alias_uris(alias, first_pass=self.__first_pass):
 | |
| 985 | -                        try:
 | |
| 986 | -                            fetcher.fetch(uri)
 | |
| 987 | -                        # FIXME: Need to consider temporary vs. permanent failures,
 | |
| 988 | -                        #        and how this works with retries.
 | |
| 989 | -                        except BstError as e:
 | |
| 990 | -                            last_error = e
 | |
| 991 | -                            continue
 | |
| 992 | - | |
| 993 | -                        # No error, we're done with this fetcher
 | |
| 982 | +                    except StopIteration:
 | |
| 983 | +                        # as per PEP479, we are not allowed to let StopIteration
 | |
| 984 | +                        # thrown from a context manager.
 | |
| 985 | +                        # Catching it here and breaking instead.
 | |
| 994 | 986 |                          break
 | 
| 995 | 987 |  | 
| 996 | -                    else:
 | |
| 997 | -                        # No break occurred, raise the last detected error
 | |
| 998 | -                        raise last_error
 | |
| 988 | +                alias = fetcher._get_alias()
 | |
| 989 | +                for uri in project.get_alias_uris(alias, first_pass=self.__first_pass):
 | |
| 990 | +                    try:
 | |
| 991 | +                        fetcher.fetch(uri)
 | |
| 992 | +                    # FIXME: Need to consider temporary vs. permanent failures,
 | |
| 993 | +                    #        and how this works with retries.
 | |
| 994 | +                    except BstError as e:
 | |
| 995 | +                        last_error = e
 | |
| 996 | +                        continue
 | |
| 999 | 997 |  | 
| 1000 | -            except StopIteration:
 | |
| 1001 | -                pass
 | |
| 998 | +                    # No error, we're done with this fetcher
 | |
| 999 | +                    break
 | |
| 1000 | + | |
| 1001 | +                else:
 | |
| 1002 | +                    # No break occurred, raise the last detected error
 | |
| 1003 | +                    raise last_error
 | |
| 1002 | 1004 |  | 
| 1003 | 1005 |          # Default codepath is to reinstantiate the Source
 | 
| 1004 | 1006 |          #
 | 
| ... | ... | @@ -20,7 +20,7 @@ DATA_DIR = os.path.join( | 
| 20 | 20 |      ('autotools.bst', 'make-install', "make -j1 DESTDIR=\"/buildstream-install\" install"),
 | 
| 21 | 21 |      ('cmake.bst', 'cmake',
 | 
| 22 | 22 |       "cmake -B_builddir -H\".\" -G\"Unix Makefiles\" " + "-DCMAKE_INSTALL_PREFIX:PATH=\"/usr\" \\\n" +
 | 
| 23 | -     "-DCMAKE_INSTALL_LIBDIR=lib   "),
 | |
| 23 | +     "-DCMAKE_INSTALL_LIBDIR:PATH=\"lib\"   "),
 | |
| 24 | 24 |      ('distutils.bst', 'python-install',
 | 
| 25 | 25 |       "python3 ./setup.py install --prefix \"/usr\" \\\n" +
 | 
| 26 | 26 |       "--root \"/buildstream-install\""),
 | 
| ... | ... | @@ -46,7 +46,7 @@ def test_defaults(cli, datafiles, tmpdir, target, varname, expected): | 
| 46 | 46 |      ('autotools.bst', 'make-install', "make -j1 DESTDIR=\"/custom/install/root\" install"),
 | 
| 47 | 47 |      ('cmake.bst', 'cmake',
 | 
| 48 | 48 |       "cmake -B_builddir -H\".\" -G\"Ninja\" " + "-DCMAKE_INSTALL_PREFIX:PATH=\"/opt\" \\\n" +
 | 
| 49 | -     "-DCMAKE_INSTALL_LIBDIR=lib   "),
 | |
| 49 | +     "-DCMAKE_INSTALL_LIBDIR:PATH=\"lib\"   "),
 | |
| 50 | 50 |      ('distutils.bst', 'python-install',
 | 
| 51 | 51 |       "python3 ./setup.py install --prefix \"/opt\" \\\n" +
 | 
| 52 | 52 |       "--root \"/custom/install/root\""),
 | 
| 1 | +# Project config for frontend build test
 | |
| 2 | +name: test
 | |
| 3 | + | |
| 4 | +elephant-path: elements | 
| ... | ... | @@ -36,6 +36,19 @@ def test_show(cli, datafiles, target, format, expected): | 
| 36 | 36 |                               .format(expected, result.output))
 | 
| 37 | 37 |  | 
| 38 | 38 |  | 
| 39 | +@pytest.mark.datafiles(os.path.join(
 | |
| 40 | +    os.path.dirname(os.path.realpath(__file__)),
 | |
| 41 | +    "invalid_element_path",
 | |
| 42 | +))
 | |
| 43 | +def test_show_invalid_element_path(cli, datafiles):
 | |
| 44 | +    project = os.path.join(datafiles.dirname, datafiles.basename)
 | |
| 45 | +    result = cli.run(project=project, silent=True, args=[
 | |
| 46 | +        'show',
 | |
| 47 | +        "foo.bst"])
 | |
| 48 | + | |
| 49 | +    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
 | |
| 50 | + | |
| 51 | + | |
| 39 | 52 |  @pytest.mark.datafiles(DATA_DIR)
 | 
| 40 | 53 |  @pytest.mark.parametrize("target,except_,expected", [
 | 
| 41 | 54 |      ('target.bst', 'import-bin.bst', ['import-dev.bst', 'compose-all.bst', 'target.bst']),
 | 
