Skip to content
Snippets Groups Projects
Commit 590b0b47 authored by Jonathan Maw's avatar Jonathan Maw Committed by Tristan Van Berkom
Browse files

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"
parent 0af3deda
No related branches found
No related tags found
Loading
......@@ -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')
......
......@@ -203,7 +203,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
......
......@@ -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
......
......@@ -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.
......
......@@ -27,6 +27,7 @@ MAIN_OPTIONS = [
"--colors ",
"--config ",
"--debug ",
"--default-mirror ",
"--directory ",
"--error-lines ",
"--fetchers ",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment