[vlc-commits] [Git][videolan/vlc][master] 2 commits: bank: add support for browsing frameworks

Jean-Baptiste Kempf gitlab at videolan.org
Thu Jun 10 22:28:29 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
70d3002b by Alexandre Janniaux at 2021-06-10T20:04:25+00:00
bank: add support for browsing frameworks

Darwin platforms are using frameworks to embed libraries. Some of them
like iOS and tvOS even forbid the use of dynamic libraries that are not
wrapped into a framework.

Since frameworks can contain various things (headers, resources, etc),
we don't necessarily want to browse their whole tree if their structure
is well-defined. In our case, since plugins are bundles and not dylibs,
there's not linking and there's no point in supporting versionning so we
can expect the plugin's dynamic library in the root of the framework,
named like the framework without the .framework part.

Since MacOSX can also make use of frameworks, this is enabled for all
darwin platforms, though it might not use them.

- - - - -
89e90672 by Alexandre Janniaux at 2021-06-10T20:04:25+00:00
darwin: redirect VLC_PKG_LIB_DIR/plugins on iOS

On iOS and tvOS, dylibs must be wrapped into a framework and frameworks
must be flattened into the frameworks/ application directory (or global
to the system which is not possible in the general case), so dylibs
can't be in the VLC_PKG_LIB_DIR/plugins folder. Redirect
VLC_PKG_LIB_DIR/plugins toward VLC_PKG_LIB_DIR/ on those platforms.

- - - - -


2 changed files:

- src/darwin/dirs.m
- src/modules/bank.c


Changes:

=====================================
src/darwin/dirs.m
=====================================
@@ -35,6 +35,7 @@
 #include <dlfcn.h>
 
 #include <Foundation/Foundation.h>
+#include <TargetConditionals.h>
 
 static bool config_isBundle()
 {
@@ -104,6 +105,13 @@ char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
 
         case VLC_PKG_LIB_DIR:
             dir = config_getLibraryDirReal(PKGLIBDIR);
+            /* On iOS and tvOS, dylibs must be located in frameworks and
+             * frameworks must be flatten in the frameworks/ directory.
+             * To respect that, redirect plugins directory to flatten it. */
+#if TARGET_OS_IPHONE
+            if (filename && strcmp("plugins", filename) == 0)
+                return dir;
+#endif
             break;
         case VLC_LIB_DIR:
             dir = config_getLibraryDirReal(LIBDIR);


=====================================
src/modules/bank.c
=====================================
@@ -358,6 +358,56 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
     return  0;
 }
 
+#ifdef __APPLE__
+/* Apple specific framework library browsing */
+
+static int AllocatePluginFramework (module_bank_t *bank, const char *file,
+                                    const char *relpath, const char *abspath)
+{
+    int i_ret = VLC_EGENERIC;
+    size_t len_name = strlen (file);
+
+    /* Skip frameworks not matching plugins naming conventions. */
+    if (len_name < sizeof "_plugin.framework"
+      || strncmp(file + len_name - sizeof "_plugin.framework" + 1,
+                 "_plugin", sizeof "_plugin" - 1) != 0)
+    {
+        /* The framework doesn't contain plugins, there's no need to
+         * browse the rest of the framework folder. */
+        return VLC_EGENERIC;
+    }
+
+    /* The framework is a plugin, extract the dylib from it. */
+    int filename_len = len_name - sizeof ".framework" - 1;
+
+    char *framework_relpath = NULL, *framework_abspath = NULL;
+    /* Compute absolute path */
+    if (asprintf (&framework_abspath, "%s"DIR_SEP"%.*s",
+                  abspath, filename_len, file) == -1)
+    {
+        framework_abspath = NULL;
+        goto end;
+    }
+
+    struct stat framework_st;
+    if (vlc_stat (framework_abspath, &framework_st) == -1
+     || !S_ISREG (framework_st.st_mode))
+        goto end;
+
+    if (asprintf (&framework_relpath, "%s"DIR_SEP"%.*s",
+                  relpath, filename_len, file) == -1)
+        framework_relpath = NULL;
+
+    i_ret = AllocatePluginFile (bank, framework_abspath, framework_relpath, &framework_st);
+
+end:
+    free(framework_relpath);
+    free(framework_abspath);
+    return i_ret;
+}
+#endif
+
+
 /**
  * Recursively browses a directory to look for plug-ins.
  */
@@ -426,8 +476,24 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
                 AllocatePluginFile (bank, abspath, relpath, &st);
         }
         else if (S_ISDIR (st.st_mode))
+        {
+#ifdef __APPLE__
+            size_t len_name = strlen (file);
+            const char *framework_extension =
+                file + len_name - sizeof ".framework" + 1;
+
+            if (len_name > sizeof ".framework" - 1
+             && strcmp(framework_extension, ".framework") == 0)
+            {
+                AllocatePluginFramework (bank, file, abspath, relpath);
+                /* Don't browse framework directories. */
+                goto skip;
+            }
+#endif
+
             /* Recurse into another directory */
             AllocatePluginDir (bank, maxdepth, abspath, relpath);
+        }
     skip:
         free (relpath);
         free (abspath);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/787270534aee964a51db6dc86d764f2834c284ae...89e90672db4a10243ae802c32272da8c062bc7bb

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/787270534aee964a51db6dc86d764f2834c284ae...89e90672db4a10243ae802c32272da8c062bc7bb
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list