summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@igalia.com>2018-11-12 20:23:14 -0300
committerThibault Saunier <tsaunier@igalia.com>2019-05-13 11:42:15 -0400
commitfda837941179fc384489883a8492aaf15c4ab609 (patch)
tree57909edd71364c9513493adde969c202f5c5bd9c /scripts
parentfbb81c6c78e098550687fd3758e9a6e515c5e00e (diff)
downloadgstreamer-fda837941179fc384489883a8492aaf15c4ab609.tar.gz
scripts: Add a script to check that all repos are clean
This is useful to check that a build didn't result in changes in the code/generated files This will be used to check that the plugins documentation cache file is properly commited, and that necessary workaround for particular case are adopted.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/__init__.py0
-rwxr-xr-xscripts/check-clean-repos.py27
-rw-r--r--scripts/common.py124
3 files changed, 151 insertions, 0 deletions
diff --git a/scripts/__init__.py b/scripts/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/scripts/__init__.py
diff --git a/scripts/check-clean-repos.py b/scripts/check-clean-repos.py
new file mode 100755
index 0000000000..2b50fd938b
--- /dev/null
+++ b/scripts/check-clean-repos.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import os
+import subprocess
+import sys
+from common import git
+
+
+SCRIPTDIR = os.path.realpath(os.path.dirname(__file__))
+
+
+if __name__ == "__main__":
+ subprojects_dir = os.path.join(SCRIPTDIR, "..", "subprojects")
+ exitcode = 0
+ for repo_name in os.listdir(subprojects_dir):
+ repo_dir = os.path.normpath(os.path.join(SCRIPTDIR, subprojects_dir, repo_name))
+ if not os.path.exists(os.path.join(repo_dir, '.git')):
+ continue
+
+ diff = git('diff', repository_path=repo_dir).strip('\n')
+ if diff:
+ print('ERROR: Repository %s is not clean' % repo_dir)
+ print('NOTE: Make sure to commit necessary changes in the gst_plugins_cache.json files')
+ print(diff)
+ exitcode += 1
+
+ sys.exit(exitcode) \ No newline at end of file
diff --git a/scripts/common.py b/scripts/common.py
new file mode 100644
index 0000000000..5cea742027
--- /dev/null
+++ b/scripts/common.py
@@ -0,0 +1,124 @@
+import os
+import sys
+import shlex
+import shutil
+import argparse
+import platform
+import subprocess
+
+
+ROOTDIR = os.path.abspath(os.path.dirname(__file__))
+
+
+if os.name is 'nt':
+ import ctypes
+ from ctypes import wintypes
+ _GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
+ _GetShortPathNameW.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD]
+ _GetShortPathNameW.restype = wintypes.DWORD
+
+def win32_get_short_path_name(long_name):
+ """
+ Gets the short path name of a given long path.
+ http://stackoverflow.com/a/23598461/200291
+ """
+ output_buf_size = 0
+ while True:
+ output_buf = ctypes.create_unicode_buffer(output_buf_size)
+ needed = _GetShortPathNameW(long_name, output_buf, output_buf_size)
+ if output_buf_size >= needed:
+ return output_buf.value
+ else:
+ output_buf_size = needed
+
+class Colors:
+ HEADER = '\033[95m'
+ OKBLUE = '\033[94m'
+ OKGREEN = '\033[92m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ ENDC = '\033[0m'
+
+ force_disable = False
+
+ def _windows_ansi():
+ from ctypes import windll, byref
+ from ctypes.wintypes import DWORD
+
+ kernel = windll.kernel32
+ stdout = kernel.GetStdHandle(-11)
+ mode = DWORD()
+ if not kernel.GetConsoleMode(stdout, byref(mode)):
+ return False
+ # Try setting ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
+ # If that fails (returns 0), we disable colors
+ return kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON')
+
+ @classmethod
+ def can_enable(cls):
+ if not os.isatty(sys.stdout.fileno()):
+ return False
+ if platform.system().lower() == 'windows':
+ return cls._windows_ansi()
+ return os.environ.get('TERM') != 'dumb'
+
+ @classmethod
+ def disable(cls):
+ cls.HEADER = ''
+ cls.OKBLUE = ''
+ cls.OKGREEN = ''
+ cls.WARNING = ''
+ cls.FAIL = ''
+ cls.ENDC = ''
+
+ @classmethod
+ def enable(cls):
+ if cls.force_disable:
+ return
+
+ cls.HEADER = '\033[95m'
+ cls.OKBLUE = '\033[94m'
+ cls.OKGREEN = '\033[92m'
+ cls.WARNING = '\033[93m'
+ cls.FAIL = '\033[91m'
+ cls.ENDC = '\033[0m'
+
+
+
+def git(*args, repository_path='.'):
+ return subprocess.check_output(["git"] + list(args), cwd=repository_path,
+ stdin=subprocess.DEVNULL,
+ stderr=subprocess.STDOUT).decode()
+
+def accept_command(commands):
+ """Search @commands and returns the first found absolute path."""
+ for command in commands:
+ command = shutil.which(command)
+ if command:
+ return command
+ return None
+
+def get_meson():
+ meson = os.path.join(ROOTDIR, 'meson', 'meson.py')
+ if os.path.exists(meson):
+ return [sys.executable, meson]
+
+ mesonintrospect = os.environ.get('MESONINTROSPECT', '')
+ for comp in shlex.split (mesonintrospect):
+ # mesonintrospect might look like "/usr/bin/python /somewhere/meson introspect",
+ # let's not get tricked
+ if 'python' in os.path.basename (comp):
+ continue
+ if os.path.exists(comp):
+ if comp.endswith('.py'):
+ return [sys.executable, comp]
+ else:
+ return [comp]
+
+ meson = accept_command(['meson.py'])
+ if meson:
+ return [sys.executable, meson]
+ meson = accept_command(['meson'])
+ if meson:
+ return [meson]
+ raise RuntimeError('Could not find Meson')