summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2020-05-29 17:31:24 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2020-05-29 17:31:24 +0000
commitf2a5dbe9f888d5b8a4fc4e6abd666fde722bc8f7 (patch)
tree7d8c7ec1d9d4dfb0bef8f8aab639aa70e4f585b1
parente0716d781920886ac0493577442667e0ce495bcb (diff)
parent30d8cb606d9adb84d9377b981f69f779bc85182a (diff)
downloadbuildstream-f2a5dbe9f888d5b8a4fc4e6abd666fde722bc8f7.tar.gz
Merge branch 'tristan/version-specific-config' into 'master'
Support version specific configuration files See merge request BuildStream/buildstream!1941
-rw-r--r--doc/source/using_config.rst11
-rw-r--r--src/buildstream/_context.py14
-rw-r--r--tests/internals/context.py28
3 files changed, 50 insertions, 3 deletions
diff --git a/doc/source/using_config.rst b/doc/source/using_config.rst
index 302abb2f1..ba38173e3 100644
--- a/doc/source/using_config.rst
+++ b/doc/source/using_config.rst
@@ -22,6 +22,17 @@ invoking ``bst``, an attempt is made to load user specific configuration from
``$XDG_CONFIG_HOME/buildstream.conf``. On most Linux based systems, the location
will be ``~/.config/buildstream.conf``
+.. note::
+
+ If you have have multiple major versions of BuildStream installed, you
+ can have separate configuration files in your ``${XDG_CONFIG_HOME}``.
+
+ You can do this by naming them according to the major versions of
+ BuildStream you have installed. BuildStream 1 will load it's configuration
+ from ``$XDG_CONFIG_HOME/buildstream1.conf`` and BuildStream 2 will load
+ it's configuration from ``$XDG_CONFIG_HOME/buildstream2.conf``, while
+ any version will fallback to ``$XDG_CONFIG_HOME/buildstream.conf``.
+
Project specific value
----------------------
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 090b3e0bc..19e0781c1 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -219,9 +219,17 @@ class Context:
# a $XDG_CONFIG_HOME/buildstream.conf file
#
if not config:
- default_config = os.path.join(os.environ["XDG_CONFIG_HOME"], "buildstream.conf")
- if os.path.exists(default_config):
- config = default_config
+ #
+ # Support parallel installations of BuildStream by first
+ # trying a (major point) version specific configuration file
+ # and then falling back to buildstream.conf.
+ #
+ major_version, _ = utils._get_bst_api_version()
+ for config_filename in ("buildstream{}.conf".format(major_version), "buildstream.conf"):
+ default_config = os.path.join(os.environ["XDG_CONFIG_HOME"], config_filename)
+ if os.path.exists(default_config):
+ config = default_config
+ break
# Load default config
#
diff --git a/tests/internals/context.py b/tests/internals/context.py
index a8b9f6dd3..9d06a68bf 100644
--- a/tests/internals/context.py
+++ b/tests/internals/context.py
@@ -5,6 +5,7 @@ import os
import pytest
from buildstream._context import Context
+from buildstream import _yaml, utils
from buildstream._exceptions import LoadError
from buildstream.exceptions import LoadErrorReason
@@ -80,6 +81,33 @@ def test_context_load_user_config(context_fixture, datafiles):
assert context.logdir == os.path.join(cache_home, "buildstream", "logs")
+@pytest.mark.datafiles(os.path.join(DATA_DIR))
+def test_context_priority(datafiles):
+ confdir = os.path.join(str(datafiles), "config")
+ os.makedirs(confdir)
+
+ # The fallback (usual) config file
+ bst_conf_path = os.path.join(confdir, "buildstream.conf")
+ bst_conf = {"sourcedir": "/sources"}
+ _yaml.roundtrip_dump(bst_conf, bst_conf_path)
+
+ # The version specific config file
+ major_version, _ = utils._get_bst_api_version()
+ bst_conf_path = os.path.join(confdir, "buildstream{}.conf".format(major_version))
+ bst_conf = {"sourcedir": "/other_sources"}
+ _yaml.roundtrip_dump(bst_conf, bst_conf_path)
+
+ # Load the Context() object and assert that we've chosen
+ # the version specific one.
+ #
+ os.environ["XDG_CONFIG_HOME"] = confdir
+ with Context() as context:
+ context.load()
+ assert context.sourcedir == "/other_sources"
+
+ del os.environ["XDG_CONFIG_HOME"]
+
+
#######################################
# Test failure modes #
#######################################