diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-06 21:04:32 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-06 21:20:27 +0900 |
commit | be6b5564595872c9e6ff54c3d812be1061c0837d (patch) | |
tree | 4abbf2b373a26703aec748769e90c0e549194a78 | |
parent | f8a71cabb009e04dc8deee8c1244ab75e06420a2 (diff) | |
download | buildstream-be6b5564595872c9e6ff54c3d812be1061c0837d.tar.gz |
Removing all traces of `environment-inherit` shell configuration.
This is made redundant by the more complete `environment` configuration,
so lets quickly remove the former in this new format version 4.
-rw-r--r-- | buildstream/_project.py | 5 | ||||
-rw-r--r-- | buildstream/element.py | 7 | ||||
-rw-r--r-- | doc/source/projectconf.rst | 44 | ||||
-rw-r--r-- | tests/integration/shell.py | 34 |
4 files changed, 29 insertions, 61 deletions
diff --git a/buildstream/_project.py b/buildstream/_project.py index 253d5210d..db0b7aee9 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -103,7 +103,6 @@ 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 @@ -299,11 +298,9 @@ class Project(): # Parse shell options shell_options = _yaml.node_get(config, Mapping, 'shell', default_value={}) - _yaml.node_validate(shell_options, ['command', 'environment-inherit', 'environment', 'host-files']) + _yaml.node_validate(shell_options, ['command', '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={}) diff --git a/buildstream/element.py b/buildstream/element.py index ad0e87bcf..394439e37 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1434,12 +1434,7 @@ class Element(Plugin): # flags |= SandboxFlags.NETWORK_ENABLED | SandboxFlags.INHERIT_UID - # Use the project defined list of env vars to inherit - for inherit in project._shell_env_inherit: - if os.environ.get(inherit) is not None: - environment[inherit] = os.environ.get(inherit) - - # Now add in the explicitly set environment variables + # Apply project defined environment vars to set for a shell for key, value in _yaml.node_items(project._shell_environment): environment[key] = value diff --git a/doc/source/projectconf.rst b/doc/source/projectconf.rst index 156efdb36..2f7e4aa7a 100644 --- a/doc/source/projectconf.rst +++ b/doc/source/projectconf.rst @@ -161,13 +161,20 @@ ensure that the customized prompt is not overwritten: command: [ 'bash', '--noprofile', '--norc', '-i' ] -.. _project_shell_env_inherit: - -Environment Inheritance +Environment Assignments ~~~~~~~~~~~~~~~~~~~~~~~ In order to cooperate with your host environment, a debugging shell -sometimes needs to know some of your host environment variables in -order to be more useful. +sometimes needs to be configured with some extra knowledge inheriting +from your host environment. + +This can be achieved by setting up the shell ``environment`` configuration, +which is expressed as a dictionary very similar to the +:ref:`default environment <project_defaults_environment>`, except that it +supports host side environment variable expansion in values. + +.. note:: + + The ``environment`` configuration is available since :ref:`format version 4 <project_format_version>` For example, to share your host ``DISPLAY`` and ``DBUS_SESSION_BUS_ADDRESS`` environments with debugging shells for your project, specify the following: @@ -176,26 +183,13 @@ environments with debugging shells for your project, specify the following: shell: - # Environment variables to inherit from the host environment - environment-inherit: - - DISPLAY - - DBUS_SESSION_BUS_ADDRESS - - -Environment Assignments -~~~~~~~~~~~~~~~~~~~~~~~ -In addition to :ref:`simple environment inheritance <project_shell_env_inherit>` -it is also possible to explicitly set environment variables using the ``environment`` -shell configuration. - -.. note:: - - The ``environment`` configuration is available since :ref:`format version 4 <project_format_version>` + # Share some environment variables from the host environment + environment: + DISPLAY: '$DISPLAY' + DBUS_SESSION_BUS_ADDRESS: '$DBUS_SESSION_BUS_ADDRESS' -Host side environment variable expansion is also supported in -the values specified in the ``environment`` dictionary. This can be -useful for more complex configurations where the shell environment -needs more explicit setup, example: +Or, a more complex example is how one might share the host pulseaudio +server with a ``bst shell`` environment: .. code:: yaml @@ -632,6 +626,8 @@ project is defined here. prefix: "/usr" +.. _project_defaults_environment: + Environment ~~~~~~~~~~~ The defaults environment for the build sandbox is defined here. diff --git a/tests/integration/shell.py b/tests/integration/shell.py index 49a97a6d0..e2a4740bf 100644 --- a/tests/integration/shell.py +++ b/tests/integration/shell.py @@ -65,26 +65,6 @@ def test_executable(cli, tmpdir, datafiles): assert result.output == "Horseys!\n" -# Test host environment variable inheritance -@pytest.mark.parametrize("animal", [("Horse"), ("Pony")]) -@pytest.mark.datafiles(DATA_DIR) -def test_env_inherit(cli, tmpdir, datafiles, animal): - project = os.path.join(datafiles.dirname, datafiles.basename) - - # Set the env var, and expect the same with added newline - os.environ['ANIMAL'] = animal - expected = animal + '\n' - - result = execute_shell(cli, project, ['/bin/sh', '-c', 'echo ${ANIMAL}'], config={ - 'shell': { - 'environment-inherit': ['ANIMAL'] - } - }) - - assert result.exit_code == 0 - assert result.output == expected - - # Test shell environment variable explicit assignments @pytest.mark.parametrize("animal", [("Horse"), ("Pony")]) @pytest.mark.datafiles(DATA_DIR) @@ -125,20 +105,20 @@ def test_env_assign_expand_host_environ(cli, tmpdir, datafiles, animal): assert result.output == expected -# Test that environment variable inheritance is disabled with --isolate +# Test that shell environment variable explicit assignments are discarded +# when running an isolated shell @pytest.mark.parametrize("animal", [("Horse"), ("Pony")]) @pytest.mark.datafiles(DATA_DIR) -def test_env_isolated_no_inherit(cli, tmpdir, datafiles, animal): +def test_env_assign_isolated(cli, tmpdir, datafiles, animal): project = os.path.join(datafiles.dirname, datafiles.basename) - - # Set the env var, but expect that it is not applied - os.environ['ANIMAL'] = animal - result = execute_shell(cli, project, ['/bin/sh', '-c', 'echo ${ANIMAL}'], isolate=True, config={ 'shell': { - 'environment-inherit': ['ANIMAL'] + 'environment': { + 'ANIMAL': animal + } } }) + assert result.exit_code == 0 assert result.output == '\n' |