dev environment: allow printing only env without starting a shell
authorCharlie Turner <mail@charles.plus>
Mon, 6 Jan 2020 13:22:54 +0000 (13:22 +0000)
committerCharlie Turner <mail@charles.plus>
Mon, 6 Jan 2020 21:06:42 +0000 (21:06 +0000)
allow for workflows that don't want the gst scripts to start shells,
this can be awkward for higher-level scripts setting up shells
themselves.

this is especially useful in combination with eval, and mimics the sort
of thing you can do with ssh-agent -s.

README.md
gst-env.py

index ff16c00dde36f97c2718ddc0b4e9030ee45c679e..c5b7c8591d9a9d0baa75b2e5a6500827a096520b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -314,6 +314,16 @@ You can get into the development environment the usual way:
 ninja -C $BUILDDIR/ devenv
 ```
 
+Alternatively, if you'd rather not start a shell in your workflow, you
+can mutate the current environment into a suitable state like so:
+
+```
+gst-env.py --only-environment
+```
+
+This will print output suitable for an sh-compatible `eval` function,
+just like `ssh-agent -s`.
+
 After setting up [binfmt] to use wine for windows binaries,
 you can run GStreamer tools under wine by running:
 
index 2f83fc1b827a04bc45577d24dbe617fed982d330..86bb32bea0b3461db80b07cee6431ae7e952bb51 100755 (executable)
@@ -7,6 +7,7 @@ import os
 import platform
 import re
 import site
+import shlex
 import shutil
 import subprocess
 import sys
@@ -371,6 +372,10 @@ if __name__ == "__main__":
     parser.add_argument("--winepath",
                         default='',
                         help="Exra path to set to WINEPATH.")
+    parser.add_argument("--only-environment",
+                        action='store_true',
+                        default=False,
+                        help="Do not start a shell, only print required environment.")
     options, args = parser.parse_known_args()
 
     if not os.path.exists(options.builddir):
@@ -440,6 +445,12 @@ if __name__ == "__main__":
             tmprc.flush()
             env['ZDOTDIR'] = tmpdir.name
     try:
-        exit(subprocess.call(args, close_fds=False, env=env))
+        if options.only_environment:
+            for name, value in env.items():
+                print('{}={}'.format(name, shlex.quote(value)))
+                print('export {}'.format(name))
+        else:
+            exit(subprocess.call(args, close_fds=False, env=env))
+
     except subprocess.CalledProcessError as e:
         exit(e.returncode)