mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 05:59:10 +00:00
gst-uninstalled: Display current git branch name in the shell prompt
This is really useful when using multiple git worktrees. https://bugzilla.gnome.org/show_bug.cgi?id=796989
This commit is contained in:
parent
d3ea533b20
commit
c78f0ef222
2 changed files with 10 additions and 8 deletions
|
@ -44,7 +44,7 @@ class Colors:
|
||||||
|
|
||||||
def git(*args, repository_path='.'):
|
def git(*args, repository_path='.'):
|
||||||
return subprocess.check_output(["git"] + list(args), cwd=repository_path,
|
return subprocess.check_output(["git"] + list(args), cwd=repository_path,
|
||||||
stderr=subprocess.STDOUT).decode()
|
).decode()
|
||||||
|
|
||||||
def accept_command(commands):
|
def accept_command(commands):
|
||||||
"""Search @commands and returns the first found absolute path."""
|
"""Search @commands and returns the first found absolute path."""
|
||||||
|
|
|
@ -15,6 +15,7 @@ import tempfile
|
||||||
from distutils.sysconfig import get_python_lib
|
from distutils.sysconfig import get_python_lib
|
||||||
|
|
||||||
from common import get_meson
|
from common import get_meson
|
||||||
|
from common import git
|
||||||
|
|
||||||
SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
|
SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
PREFIX_DIR = os.path.join(SCRIPTDIR, 'prefix')
|
PREFIX_DIR = os.path.join(SCRIPTDIR, 'prefix')
|
||||||
|
@ -29,7 +30,7 @@ def prepend_env_var(env, var, value):
|
||||||
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
|
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
|
||||||
|
|
||||||
|
|
||||||
def get_subprocess_env(options):
|
def get_subprocess_env(options, gst_version):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
|
|
||||||
env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
|
env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
|
||||||
|
@ -42,8 +43,8 @@ def get_subprocess_env(options):
|
||||||
prepend_env_var(env, "PATH", os.path.normpath(
|
prepend_env_var(env, "PATH", os.path.normpath(
|
||||||
"%s/subprojects/gst-devtools/validate/tools" % options.builddir))
|
"%s/subprojects/gst-devtools/validate/tools" % options.builddir))
|
||||||
prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
|
prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
|
||||||
env["GST_VERSION"] = options.gst_version
|
env["GST_VERSION"] = gst_version
|
||||||
env["GST_ENV"] = 'gst-' + options.gst_version
|
env["GST_ENV"] = 'gst-' + gst_version
|
||||||
env["GST_PLUGIN_SYSTEM_PATH"] = ""
|
env["GST_PLUGIN_SYSTEM_PATH"] = ""
|
||||||
env["GST_PLUGIN_SCANNER"] = os.path.normpath(
|
env["GST_PLUGIN_SCANNER"] = os.path.normpath(
|
||||||
"%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
|
"%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
|
||||||
|
@ -197,8 +198,6 @@ if __name__ == "__main__":
|
||||||
parser.add_argument("--srcdir",
|
parser.add_argument("--srcdir",
|
||||||
default=SCRIPTDIR,
|
default=SCRIPTDIR,
|
||||||
help="The top level source directory")
|
help="The top level source directory")
|
||||||
parser.add_argument("--gst-version", default="master",
|
|
||||||
help="The GStreamer major version")
|
|
||||||
options, args = parser.parse_known_args()
|
options, args = parser.parse_known_args()
|
||||||
|
|
||||||
if not os.path.exists(options.builddir):
|
if not os.path.exists(options.builddir):
|
||||||
|
@ -212,6 +211,9 @@ if __name__ == "__main__":
|
||||||
options.srcdir)
|
options.srcdir)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
# The following incantation will retrieve the current branch name.
|
||||||
|
gst_version = git("rev-parse", "--symbolic-full-name", "--abbrev-ref", "HEAD", repository_path=options.srcdir)
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
if os.name is 'nt':
|
if os.name is 'nt':
|
||||||
args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
|
args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
|
||||||
|
@ -223,13 +225,13 @@ if __name__ == "__main__":
|
||||||
tmprc = tempfile.NamedTemporaryFile(mode='w')
|
tmprc = tempfile.NamedTemporaryFile(mode='w')
|
||||||
with open(bashrc, 'r') as src:
|
with open(bashrc, 'r') as src:
|
||||||
shutil.copyfileobj(src, tmprc)
|
shutil.copyfileobj(src, tmprc)
|
||||||
tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
|
tmprc.write('\nexport PS1="[gst-%s] $PS1"' % gst_version)
|
||||||
tmprc.flush()
|
tmprc.flush()
|
||||||
# Let the GC remove the tmp file
|
# Let the GC remove the tmp file
|
||||||
args.append("--rcfile")
|
args.append("--rcfile")
|
||||||
args.append(tmprc.name)
|
args.append(tmprc.name)
|
||||||
try:
|
try:
|
||||||
exit(subprocess.call(args, cwd=options.srcdir, close_fds=False,
|
exit(subprocess.call(args, cwd=options.srcdir, close_fds=False,
|
||||||
env=get_subprocess_env(options)))
|
env=get_subprocess_env(options, gst_version)))
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
exit(e.returncode)
|
exit(e.returncode)
|
||||||
|
|
Loading…
Reference in a new issue