public void Execute(PostProcessorContext context)
        {
            if (this.OnProgress != null)
            {
                this.OnProgress(this, "Processing native plugins");
            }
            this._stagingArea = context.Get <string>("StagingArea");
            string str = context.Get <string>("TargetLibrariesFolder");

            context.Set <bool>("HasJarPlugins", false);
            this._pluginsFolder = Path.Combine(this._stagingArea, "plugins");
            Directory.CreateDirectory(this._pluginsFolder);
            this._aarFolder = Path.Combine(this._stagingArea, "aar");
            Directory.CreateDirectory(this._aarFolder);
            BuildTarget target = context.Get <BuildTarget>("BuildTarget");

            foreach (PluginDesc desc in PluginImporter.GetExtensionPlugins(target))
            {
                string pluginTargetCPU = desc.architecture.ToString();
                this.ProcessPlugin(context, desc.pluginPath, pluginTargetCPU);
            }
            foreach (PluginImporter importer in PluginImporter.GetImporters(target))
            {
                string assetPath = importer.assetPath;
                if (Directory.Exists(assetPath) && AndroidLibraries.IsAndroidLibraryProject(assetPath))
                {
                    FileUtil.CopyDirectoryRecursiveForPostprocess(assetPath, Path.Combine(str, Path.GetFileName(assetPath)), true);
                }
                this.UpgradePluginCPU(importer, target);
                string platformData = importer.GetPlatformData(target, "CPU");
                this.ProcessPlugin(context, assetPath, platformData);
            }
        }
Exemple #2
0
    private void CopyNativePlugins(BuildPostProcessArgs args, BuildTarget buildTarget, out List <string> cppPlugins)
    {
        string buildTargetName = BuildPipeline.GetBuildTargetName(buildTarget);
        IPluginImporterExtension pluginImpExtension = new DesktopPluginImporterExtension();

        string pluginsFolder = GetStagingAreaPluginsFolder(args);

        bool haveCreatedPluginsFolder = false;
        var  createdFolders           = new HashSet <string>();

        cppPlugins = new List <string>();

        foreach (PluginImporter imp in PluginImporter.GetImporters(buildTarget))
        {
            // Skip .cpp files. They get copied to il2cpp output folder just before code compilation
            if (DesktopPluginImporterExtension.IsCppPluginFile(imp.assetPath))
            {
                cppPlugins.Add(imp.assetPath);
                continue;
            }

            // Skip managed DLLs.
            if (!imp.isNativePlugin)
            {
                continue;
            }

            // HACK: This should never happen.
            if (string.IsNullOrEmpty(imp.assetPath))
            {
                UnityEngine.Debug.LogWarning("Got empty plugin importer path for " + buildTarget);
                continue;
            }

            if (!haveCreatedPluginsFolder)
            {
                Directory.CreateDirectory(pluginsFolder);
                haveCreatedPluginsFolder = true;
            }


            bool isDirectory = Directory.Exists(imp.assetPath);

            string destinationPath = pluginImpExtension.CalculateFinalPluginPath(buildTargetName, imp);
            if (string.IsNullOrEmpty(destinationPath))
            {
                continue;
            }

            string finalDestinationPath = Path.Combine(pluginsFolder, destinationPath);

            var finalDestinationFolder = Path.GetDirectoryName(finalDestinationPath);
            if (!createdFolders.Contains(finalDestinationFolder))
            {
                Directory.CreateDirectory(finalDestinationFolder);
                createdFolders.Add(finalDestinationFolder);
            }

            if (isDirectory)
            {
                // Since we may be copying from Assets make sure to not include .meta files to the build
                FileUtil.CopyDirectoryRecursive(imp.assetPath, finalDestinationPath, overwrite: false, ignoreMeta: true);
            }
            else
            {
                FileUtil.UnityFileCopy(imp.assetPath, finalDestinationPath);
            }
        }

        // TODO: Move all plugins using GetExtensionPlugins to GetImporters and remove GetExtensionPlugins
        foreach (UnityEditorInternal.PluginDesc pluginDesc in PluginImporter.GetExtensionPlugins(buildTarget))
        {
            if (!haveCreatedPluginsFolder)
            {
                Directory.CreateDirectory(pluginsFolder);
                haveCreatedPluginsFolder = true;
            }

            string pluginCopyPath = Path.Combine(pluginsFolder, Path.GetFileName(pluginDesc.pluginPath));

            // Plugins copied through GetImporters take priority, don't overwrite
            if (Directory.Exists(pluginCopyPath) || File.Exists(pluginCopyPath))
            {
                continue;
            }

            if (Directory.Exists(pluginDesc.pluginPath))
            {
                FileUtil.CopyDirectoryRecursive(pluginDesc.pluginPath, pluginCopyPath);
            }
            else
            {
                FileUtil.CopyFileIfExists(pluginDesc.pluginPath, pluginCopyPath, false);
            }
        }
    }
Exemple #3
0
    private void CopyNativePlugins(BuildPostProcessArgs args, out List <string> cppPlugins)
    {
        string buildTargetName = BuildPipeline.GetBuildTargetName(args.target);
        IPluginImporterExtension pluginImpExtension = new DesktopPluginImporterExtension();

        string pluginsFolder = GetStagingAreaPluginsFolder(args);
        string subDir32Bit   = Path.Combine(pluginsFolder, "x86");
        string subDir64Bit   = Path.Combine(pluginsFolder, "x86_64");

        bool haveCreatedPluginsFolder = false;
        bool haveCreatedSubDir32Bit   = false;
        bool haveCreatedSubDir64Bit   = false;

        cppPlugins = new List <string>();

        foreach (PluginImporter imp in PluginImporter.GetImporters(args.target))
        {
            BuildTarget t = args.target;

            // Skip .cpp files. They get copied to il2cpp output folder just before code compilation
            if (DesktopPluginImporterExtension.IsCppPluginFile(imp.assetPath))
            {
                cppPlugins.Add(imp.assetPath);
                continue;
            }

            // Skip managed DLLs.
            if (!imp.isNativePlugin)
            {
                continue;
            }

            // HACK: This should never happen.
            if (string.IsNullOrEmpty(imp.assetPath))
            {
                UnityEngine.Debug.LogWarning("Got empty plugin importer path for " + args.target.ToString());
                continue;
            }

            if (!haveCreatedPluginsFolder)
            {
                Directory.CreateDirectory(pluginsFolder);
                haveCreatedPluginsFolder = true;
            }

            bool   isDirectory = Directory.Exists(imp.assetPath);
            string cpu         = imp.GetPlatformData(t, "CPU");
            switch (cpu)
            {
            case "x86":
                if (t == BuildTarget.StandaloneWindows64 ||
                    t == BuildTarget.StandaloneLinux64)
                {
                    continue;
                }
                if (!haveCreatedSubDir32Bit)
                {
                    Directory.CreateDirectory(subDir32Bit);
                    haveCreatedSubDir32Bit = true;
                }
                break;

            case "x86_64":
                if (t != BuildTarget.StandaloneOSX &&
                    t != BuildTarget.StandaloneWindows64 &&
                    t != BuildTarget.StandaloneLinux64)
                {
                    continue;
                }
                if (!haveCreatedSubDir64Bit)
                {
                    Directory.CreateDirectory(subDir64Bit);
                    haveCreatedSubDir64Bit = true;
                }
                break;

            // This is a special case for CPU targets, means no valid CPU is selected
            case "None":
                continue;
            }

            string destinationPath = pluginImpExtension.CalculateFinalPluginPath(buildTargetName, imp);
            if (string.IsNullOrEmpty(destinationPath))
            {
                continue;
            }

            string finalDestinationPath = Path.Combine(pluginsFolder, destinationPath);

            if (isDirectory)
            {
                FileUtil.CopyDirectoryRecursive(imp.assetPath, finalDestinationPath);
            }
            else
            {
                FileUtil.UnityFileCopy(imp.assetPath, finalDestinationPath);
            }
        }

        // TODO: Move all plugins using GetExtensionPlugins to GetImporters and remove GetExtensionPlugins
        foreach (UnityEditorInternal.PluginDesc pluginDesc in PluginImporter.GetExtensionPlugins(args.target))
        {
            if (!haveCreatedPluginsFolder)
            {
                Directory.CreateDirectory(pluginsFolder);
                haveCreatedPluginsFolder = true;
            }

            string pluginCopyPath = Path.Combine(pluginsFolder, Path.GetFileName(pluginDesc.pluginPath));

            // Plugins copied through GetImporters take priority, don't overwrite
            if (Directory.Exists(pluginCopyPath) || File.Exists(pluginCopyPath))
            {
                continue;
            }

            if (Directory.Exists(pluginDesc.pluginPath))
            {
                FileUtil.CopyDirectoryRecursive(pluginDesc.pluginPath, pluginCopyPath);
            }
            else
            {
                FileUtil.CopyFileIfExists(pluginDesc.pluginPath, pluginCopyPath, false);
            }
        }
    }
    private void CopyNativePlugins()
    {
        string buildTargetName = BuildPipeline.GetBuildTargetName(this.m_PostProcessArgs.target);
        IPluginImporterExtension pluginImporterExtension = new DesktopPluginImporterExtension();
        string stagingAreaPluginsFolder = this.StagingAreaPluginsFolder;
        string path  = Path.Combine(stagingAreaPluginsFolder, "x86");
        string path2 = Path.Combine(stagingAreaPluginsFolder, "x86_64");
        bool   flag  = false;
        bool   flag2 = false;
        bool   flag3 = false;

        PluginImporter[] importers = PluginImporter.GetImporters(this.m_PostProcessArgs.target);
        for (int i = 0; i < importers.Length; i++)
        {
            PluginImporter pluginImporter = importers[i];
            BuildTarget    target         = this.m_PostProcessArgs.target;
            if (pluginImporter.isNativePlugin)
            {
                if (string.IsNullOrEmpty(pluginImporter.assetPath))
                {
                    Debug.LogWarning("Got empty plugin importer path for " + this.m_PostProcessArgs.target.ToString());
                }
                else
                {
                    if (!flag)
                    {
                        Directory.CreateDirectory(stagingAreaPluginsFolder);
                        flag = true;
                    }
                    bool   flag4        = Directory.Exists(pluginImporter.assetPath);
                    string platformData = pluginImporter.GetPlatformData(target, "CPU");
                    string text         = platformData;
                    switch (text)
                    {
                    case "x86":
                        if (target == BuildTarget.StandaloneOSXIntel64 || target == BuildTarget.StandaloneWindows64 || target == BuildTarget.StandaloneLinux64)
                        {
                            goto IL_22F;
                        }
                        if (!flag2)
                        {
                            Directory.CreateDirectory(path);
                            flag2 = true;
                        }
                        break;

                    case "x86_64":
                        if (target != BuildTarget.StandaloneOSXIntel64 && target != BuildTarget.StandaloneOSXUniversal && target != BuildTarget.StandaloneWindows64 && target != BuildTarget.StandaloneLinux64 && target != BuildTarget.StandaloneLinuxUniversal)
                        {
                            goto IL_22F;
                        }
                        if (!flag3)
                        {
                            Directory.CreateDirectory(path2);
                            flag3 = true;
                        }
                        break;

                    case "None":
                        goto IL_22F;
                    }
                    string text2 = pluginImporterExtension.CalculateFinalPluginPath(buildTargetName, pluginImporter);
                    if (!string.IsNullOrEmpty(text2))
                    {
                        string text3 = Path.Combine(stagingAreaPluginsFolder, text2);
                        if (flag4)
                        {
                            FileUtil.CopyDirectoryRecursive(pluginImporter.assetPath, text3);
                        }
                        else
                        {
                            FileUtil.UnityFileCopy(pluginImporter.assetPath, text3);
                        }
                    }
                }
            }
            IL_22F :;
        }
        foreach (PluginDesc current in PluginImporter.GetExtensionPlugins(this.m_PostProcessArgs.target))
        {
            if (!flag)
            {
                Directory.CreateDirectory(stagingAreaPluginsFolder);
                flag = true;
            }
            string text4 = Path.Combine(stagingAreaPluginsFolder, Path.GetFileName(current.pluginPath));
            if (!Directory.Exists(text4) && !File.Exists(text4))
            {
                if (Directory.Exists(current.pluginPath))
                {
                    FileUtil.CopyDirectoryRecursive(current.pluginPath, text4);
                }
                else
                {
                    FileUtil.CopyFileIfExists(current.pluginPath, text4, false);
                }
            }
        }
    }
    private void CopyNativePlugins()
    {
        string buildTargetName             = BuildPipeline.GetBuildTargetName(this.m_PostProcessArgs.target);
        IPluginImporterExtension extension = new DesktopPluginImporterExtension();
        string stagingAreaPluginsFolder    = this.StagingAreaPluginsFolder;
        string path  = Path.Combine(stagingAreaPluginsFolder, "x86");
        string str4  = Path.Combine(stagingAreaPluginsFolder, "x86_64");
        bool   flag  = false;
        bool   flag2 = false;
        bool   flag3 = false;

        foreach (PluginImporter importer in PluginImporter.GetImporters(this.m_PostProcessArgs.target))
        {
            BuildTarget platform = this.m_PostProcessArgs.target;
            if (importer.isNativePlugin)
            {
                if (string.IsNullOrEmpty(importer.assetPath))
                {
                    Debug.LogWarning("Got empty plugin importer path for " + this.m_PostProcessArgs.target.ToString());
                    continue;
                }
                if (!flag)
                {
                    Directory.CreateDirectory(stagingAreaPluginsFolder);
                    flag = true;
                }
                bool flag4 = Directory.Exists(importer.assetPath);
                switch (importer.GetPlatformData(platform, "CPU"))
                {
                case "x86":
                    switch (platform)
                    {
                    case BuildTarget.StandaloneOSXIntel64:
                    case BuildTarget.StandaloneWindows64:
                    case BuildTarget.StandaloneLinux64:
                    {
                        continue;
                    }
                    }
                    if (!flag2)
                    {
                        Directory.CreateDirectory(path);
                        flag2 = true;
                    }
                    break;

                case "x86_64":
                    if ((((platform != BuildTarget.StandaloneOSXIntel64) && (platform != BuildTarget.StandaloneOSXUniversal)) && ((platform != BuildTarget.StandaloneWindows64) && (platform != BuildTarget.StandaloneLinux64))) && (platform != BuildTarget.StandaloneLinuxUniversal))
                    {
                        continue;
                    }
                    if (!flag3)
                    {
                        Directory.CreateDirectory(str4);
                        flag3 = true;
                    }
                    break;

                case "None":
                {
                    continue;
                }
                }
                string str6 = extension.CalculateFinalPluginPath(buildTargetName, importer);
                if (!string.IsNullOrEmpty(str6))
                {
                    string target = Path.Combine(stagingAreaPluginsFolder, str6);
                    if (flag4)
                    {
                        FileUtil.CopyDirectoryRecursive(importer.assetPath, target);
                    }
                    else
                    {
                        FileUtil.UnityFileCopy(importer.assetPath, target);
                    }
                }
            }
        }
        foreach (PluginDesc desc in PluginImporter.GetExtensionPlugins(this.m_PostProcessArgs.target))
        {
            if (!flag)
            {
                Directory.CreateDirectory(stagingAreaPluginsFolder);
                flag = true;
            }
            string str8 = Path.Combine(stagingAreaPluginsFolder, Path.GetFileName(desc.pluginPath));
            if (!Directory.Exists(str8) && !File.Exists(str8))
            {
                if (Directory.Exists(desc.pluginPath))
                {
                    FileUtil.CopyDirectoryRecursive(desc.pluginPath, str8);
                }
                else
                {
                    FileUtil.CopyFileIfExists(desc.pluginPath, str8, false);
                }
            }
        }
    }