diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-06 19:31:13 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-06 19:31:13 +0900 |
commit | ea74f326fb75c4b4b6378987ede884b47ac9e09c (patch) | |
tree | 8c5d345c572f84a05759cf74d9e3aa889416399e /buildstream | |
parent | eef265834d60578adae0401cfc00ea9076a108bc (diff) | |
download | buildstream-ea74f326fb75c4b4b6378987ede884b47ac9e09c.tar.gz |
Implement explicit environment assignments for `bst shell`
This introduces a new `environment` section of the project `shell`
configuration to set explicit env vars when running a non-isolated shell.
This supports host environment variable expansion.
This is a part of addressing #223
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_project.py | 11 | ||||
-rw-r--r-- | buildstream/element.py | 4 |
2 files changed, 13 insertions, 2 deletions
diff --git a/buildstream/_project.py b/buildstream/_project.py index 360bf7faa..253d5210d 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -39,7 +39,7 @@ from ._sourcefactory import SourceFactory # This version is bumped whenever enhancements are made # to the `project.conf` format or the core element format. # -BST_FORMAT_VERSION = 3 +BST_FORMAT_VERSION = 4 # The separator we use for user specified aliases _ALIAS_SEPARATOR = ':' @@ -104,6 +104,7 @@ class Project(): # Shell options self._shell_command = [] # The default interactive shell command self._shell_env_inherit = [] # Environment vars to inherit when non-isolated + self._shell_environment = {} # Statically set environment vars self._shell_host_files = [] # A list of HostMount objects profile_start(Topics.LOAD_PROJECT, self.directory.replace(os.sep, '-')) @@ -298,12 +299,18 @@ class Project(): # Parse shell options shell_options = _yaml.node_get(config, Mapping, 'shell', default_value={}) - _yaml.node_validate(shell_options, ['command', 'environment-inherit', 'host-files']) + _yaml.node_validate(shell_options, ['command', 'environment-inherit', 'environment', 'host-files']) self._shell_command = _yaml.node_get(shell_options, list, 'command', default_value=['sh', '-i']) self._shell_env_inherit = _yaml.node_get(shell_options, list, 'environment-inherit', default_value=[]) + # Perform environment expansion right away + shell_environment = _yaml.node_get(shell_options, Mapping, 'environment', default_value={}) + for key, _ in _yaml.node_items(shell_environment): + value = _yaml.node_get(shell_environment, str, key) + self._shell_environment[key] = os.path.expandvars(value) + # Host files is parsed as a list for convenience host_files = _yaml.node_get(shell_options, list, 'host-files', default_value=[]) for host_file in host_files: diff --git a/buildstream/element.py b/buildstream/element.py index bf36ee6ab..ad0e87bcf 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1439,6 +1439,10 @@ class Element(Plugin): if os.environ.get(inherit) is not None: environment[inherit] = os.environ.get(inherit) + # Now add in the explicitly set environment variables + for key, value in _yaml.node_items(project._shell_environment): + environment[key] = value + # Setup any requested bind mounts if mounts is None: mounts = [] |