summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2020-05-29 17:32:26 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2020-05-29 17:32:26 +0000
commitc910eca450e7863583b58f106a8f049189372a0f (patch)
tree79fa2445cb9c135c80689544e932a2e571134e2a
parente252b637df82986b099be812456f0f5d44165b8c (diff)
parent86ed40131a26c5480960f197117da0336905149a (diff)
downloadbuildstream-c910eca450e7863583b58f106a8f049189372a0f.tar.gz
Merge branch 'tristan/bst-1/version-specific-config' into 'bst-1'
Support version specific configuration files See merge request BuildStream/buildstream!1945
-rw-r--r--buildstream/_context.py13
-rw-r--r--doc/source/using_config.rst11
-rw-r--r--tests/context/context.py28
3 files changed, 48 insertions, 4 deletions
diff --git a/buildstream/_context.py b/buildstream/_context.py
index 8a7cec70c..f36bfd343 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -147,10 +147,15 @@ 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 buildstream1.conf and then falling back to buildstream.conf.
+ #
+ for config_filename in ("buildstream1.conf", "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/doc/source/using_config.rst b/doc/source/using_config.rst
index 8b6cb58b0..f7469555b 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/tests/context/context.py b/tests/context/context.py
index 35428105b..f76a4f07b 100644
--- a/tests/context/context.py
+++ b/tests/context/context.py
@@ -3,6 +3,7 @@ import pytest
from buildstream._context import Context
from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream import _yaml
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
@@ -83,6 +84,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.dump(bst_conf, bst_conf_path)
+
+ # The version specific config file
+ bst_conf_path = os.path.join(confdir, "buildstream1.conf")
+ bst_conf = {"sourcedir": "/other_sources"}
+ _yaml.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
+ context = Context()
+ context.load()
+
+ assert context.sourcedir == "/other_sources"
+
+ del os.environ["XDG_CONFIG_HOME"]
+
+
#######################################
# Test failure modes #
#######################################