diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-05-16 14:15:47 +0100 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-07-27 12:24:56 +0000 |
commit | f81e8e7bcd2e4558a1a061f1534ac4dffe471547 (patch) | |
tree | f727d8efcaa392c244e8e7ba98e0b008890918d7 | |
parent | 2889003cb2667f88628204fac655a06def8f136b (diff) | |
download | buildstream-f81e8e7bcd2e4558a1a061f1534ac4dffe471547.tar.gz |
Set default mirror via command-line or user config
In user config (buildstream.conf), it is set with the "default-mirror"
field.
On the command-line, it is set with "--default-mirror"
-rw-r--r-- | buildstream/_context.py | 2 | ||||
-rw-r--r-- | buildstream/_frontend/app.py | 3 | ||||
-rw-r--r-- | buildstream/_frontend/cli.py | 2 | ||||
-rw-r--r-- | buildstream/_project.py | 8 | ||||
-rw-r--r-- | tests/completions/completions.py | 1 |
5 files changed, 12 insertions, 4 deletions
diff --git a/buildstream/_context.py b/buildstream/_context.py index fbb0a9686..7dc68af79 100644 --- a/buildstream/_context.py +++ b/buildstream/_context.py @@ -259,7 +259,7 @@ class Context(): # Shallow validation of overrides, parts of buildstream which rely # on the overrides are expected to validate elsewhere. for _, overrides in _yaml.node_items(self._project_overrides): - _yaml.node_validate(overrides, ['artifacts', 'options', 'strict']) + _yaml.node_validate(overrides, ['artifacts', 'options', 'strict', 'default-mirror']) profile_end(Topics.LOAD_CONTEXT, 'load') diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py index 5fae0307b..04a90ea32 100644 --- a/buildstream/_frontend/app.py +++ b/buildstream/_frontend/app.py @@ -202,7 +202,8 @@ class App(): # Load the Project # try: - self.project = Project(directory, self.context, cli_options=self._main_options['option']) + self.project = Project(directory, self.context, cli_options=self._main_options['option'], + default_mirror=self._main_options.get('default_mirror')) except LoadError as e: # Let's automatically start a `bst init` session in this case diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index bd2ce8a73..20624e2ac 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -217,6 +217,8 @@ def print_version(ctx, param, value): help="Elements must be rebuilt when their dependencies have changed") @click.option('--option', '-o', type=click.Tuple([str, str]), multiple=True, metavar='OPTION VALUE', help="Specify a project option") +@click.option('--default-mirror', default=None, + help="The mirror to fetch from first, before attempting other mirrors") @click.pass_context def cli(context, **kwargs): """Build and manipulate BuildStream projects diff --git a/buildstream/_project.py b/buildstream/_project.py index fd64f1a7f..1c30fb9bb 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -67,7 +67,7 @@ class HostMount(): # class Project(): - def __init__(self, directory, context, *, junction=None, cli_options=None): + def __init__(self, directory, context, *, junction=None, cli_options=None, default_mirror=None): # The project name self.name = None @@ -92,7 +92,7 @@ class Project(): self.element_overrides = {} # Element specific configurations self.source_overrides = {} # Source specific configurations self.mirrors = OrderedDict() # contains dicts of alias-mappings to URIs. - self.default_mirror = None # The name of the preferred mirror. + self.default_mirror = default_mirror # The name of the preferred mirror. # # Private Members @@ -319,6 +319,10 @@ class Project(): # self.options.process_node(config) + # Override default_mirror if not set by command-line + if not self.default_mirror: + self.default_mirror = _yaml.node_get(overrides, str, 'default-mirror', default_value=None) + # # Now all YAML composition is done, from here on we just load # the values from our loaded configuration dictionary. diff --git a/tests/completions/completions.py b/tests/completions/completions.py index 7c169c2d2..1ff026ea5 100644 --- a/tests/completions/completions.py +++ b/tests/completions/completions.py @@ -27,6 +27,7 @@ MAIN_OPTIONS = [ "--colors ", "--config ", "--debug ", + "--default-mirror ", "--directory ", "--error-lines ", "--fetchers ", |