From 7cf00627beaa3e0aec12df6e70282bd981c792b3 Mon Sep 17 00:00:00 2001
From: Xavier Claessens <xavier.claessens@collabora.com>
Date: Tue, 17 Sep 2019 15:53:40 -0400
Subject: [PATCH] Simplify generate_plugins_path.py script

This also fix an empty plugin name being prepended to the list.
---
 meson.build                      | 24 ++++++++++++++----------
 scripts/generate_plugins_path.py |  8 ++++----
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/meson.build b/meson.build
index 4b16d23ed1..382eb42724 100644
--- a/meson.build
+++ b/meson.build
@@ -86,13 +86,11 @@ if build_system == 'windows'
   subproject('win-nasm')
 endif
 
-pathsep = host_machine.system() == 'windows' ? ';' : ':'
-
 subproject('orc', required: get_option('orc'))
 
 subprojects_names = []
 plugins_doc_caches = []
-all_plugins = ''
+all_plugins = []
 foreach sp : subprojects
   project_name = sp[0]
   build_infos = sp[1]
@@ -114,10 +112,7 @@ foreach sp : subprojects
     else
       plugins = []
     endif
-
-    foreach plugin: plugins
-      all_plugins += pathsep + plugin.full_path()
-    endforeach
+    all_plugins += plugins
 
     subprojects_names += [project_name]
     cmdres = run_command(python3, '-c', symlink.format(project_name, meson.current_source_dir()))
@@ -170,9 +165,18 @@ else
   endif
 endif
 
-cmdres = run_command(python3, find_program('scripts/generate_plugins_path.py'), '--builddir',
-    meson.build_root(), all_plugins)
-assert(cmdres.returncode() == 0, 'Could not create plugins path: @0@'.format(cmdres.stderr()))
+all_plugins_paths = []
+foreach plugin: all_plugins
+  all_plugins_paths += plugin.full_path()
+endforeach
+
+generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
+configure_file(
+  output : 'GstPluginsPath.json',
+  command : [generate_plugins_paths,
+             '@OUTPUT@',
+             all_plugins_paths]
+)
 
 message('Building subprojects: ' + ', '.join(subprojects_names))
 setenv = find_program('gst-env.py')
diff --git a/scripts/generate_plugins_path.py b/scripts/generate_plugins_path.py
index d57c60c2fe..17a38f123b 100644
--- a/scripts/generate_plugins_path.py
+++ b/scripts/generate_plugins_path.py
@@ -6,14 +6,14 @@ import json
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
-    parser.add_argument("--builddir", help="The meson build directory")
-    parser.add_argument(dest="plugins", help="The list of plugins")
+    parser.add_argument(dest="output", help="Output file")
+    parser.add_argument(dest="plugins", nargs=argparse.REMAINDER, help="The list of plugins")
 
     options = parser.parse_args()
 
     all_paths = set()
-    for plugin in options.plugins.split(os.pathsep):
+    for plugin in options.plugins:
         all_paths.add(os.path.dirname(plugin))
 
-    with open(os.path.join(options.builddir, 'GstPluginsPath.json'), "w") as f:
+    with open(options.output, "w") as f:
         json.dump(list(all_paths), f, indent=4, sort_keys=True)