コード例 #1
0
        void ExportApi(ICollection <string> referencePaths)
        {
            string[] includeNamespaces = this.PluginInfo.AndroidPlatform.NamespaceMappings.Select(m => m.Namespace)
                                         .Concat(new[] { typeof(AndroidApiCompiler).Namespace }).ToArray();
            Assembly apiAssembly = ClrApi.LoadFrom(
                this.BuiltBindingsAssemblyPath,
                referencePaths,
                includeNamespaces);

            ClrApi androidApi = new ClrApi
            {
                Platform   = PluginInfo.AndroidPlatformName,
                Assemblies = new List <Assembly>(new[] { apiAssembly }),
            };

            string apiXmlPath = Path.GetFullPath(Path.Combine(
                                                     this.PlatformIntermediatePath, this.PlatformName + "-api.xml"));

            using (StreamWriter writer = File.CreateText(apiXmlPath))
            {
                androidApi.ToXml(writer);
            }

            Log.Important($"Exported {this.PlatformName} API metadata to {apiXmlPath}");
        }
コード例 #2
0
        void GenerateWindowsAdapterProject()
        {
            Log.Important("Generating Windows C# bindings project at\n" + this.bindingsProject);

            string project = Utils.ExtractResourceText(ProjectFiles.Project);

            project = project.Replace($"$({MsbuildProperties.AssemblyName})", this.PluginInfo.Assembly.Name);
            project = project.Replace(
                $"$({MsbuildProperties.PluginAssemblyName})",
                Path.GetFileNameWithoutExtension(this.pluginMetadataFilePath));
            project = project.Replace(
                $"$({MsbuildProperties.PluginAssemblyPath})",
                this.pluginMetadataFilePath.Replace("x86", "$(Platform)"));

            File.WriteAllText(this.bindingsProject, project);

            Utils.ExtractResource(ProjectFiles.ProjectJson, this.PlatformIntermediatePath);

            string propertiesPath = Path.Combine(this.PlatformIntermediatePath, "Properties");

            if (!Directory.Exists(propertiesPath))
            {
                Directory.CreateDirectory(propertiesPath);
            }

            this.GenerateAssemblyInfo(Path.Combine(propertiesPath, ProjectFiles.AssemblyInfo));

            string adaptersPath = Path.Combine(this.PlatformIntermediatePath, "Adapters");

            if (!Directory.Exists(adaptersPath))
            {
                Directory.CreateDirectory(adaptersPath);
            }

            string refPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) +
                             @"\Reference Assemblies\Microsoft\Framework\";

            string[] referenceAssemblyPaths = new string[]
            {
                refPath + @".NETFramework\v4.5\System.dll",
                refPath + @".NETFramework\v4.5\Facades\System.Runtime.dll",
                refPath + @".NETFramework\v4.6.1\Facades\System.Diagnostics.Debug.dll",
                refPath + @".NETFramework\v4.6.1\Facades\System.Runtime.dll",
                refPath + @".NETFramework\v4.6.1\Facades\System.Threading.Tasks.dll",
                refPath + @".NETCore\v4.5\System.Runtime.WindowsRuntime.dll",
                refPath + @".NETCore\v4.5\System.Runtime.WindowsRuntime.UI.Xaml.dll",
                refPath + @".NETCore\v4.5.1\System.Runtime.InteropServices.WindowsRuntime.dll",
            };

            Assembly          androidApi = ClrApi.LoadFrom(this.pluginMetadataFilePath, referenceAssemblyPaths);
            WindowsApiAdapter adapter    = new WindowsApiAdapter();

            adapter.PluginInfo          = this.PluginInfo;
            adapter.OutputDirectoryPath = adaptersPath;
            adapter.GenerateAdapterCodeForApi(androidApi);
        }
コード例 #3
0
        void GenerateIOSCSharpBindingsProject(bool includeAdapters, ICollection <string> referencePaths = null)
        {
            Log.Important("Generating iOS C# bindings project at\n" + this.bindingsProjectFilePath);

            string project          = Utils.ExtractResourceText(Resources.Project);
            string assemblyName     = this.PluginInfo.Assembly.Name;
            string tempAssemblyName = "temp";

            project = project.Replace(
                $"$({MsbuildProperties.AssemblyName})", (includeAdapters ? assemblyName : tempAssemblyName));
            project = project.Replace($"$({MsbuildProperties.NativeLibFileName})", this.nativeLibFileName);

            File.WriteAllText(this.bindingsProjectFilePath, project);

            string propertiesPath = Path.Combine(this.PlatformIntermediatePath, "Properties");

            if (!Directory.Exists(propertiesPath))
            {
                Directory.CreateDirectory(propertiesPath);
            }

            this.GenerateAssemblyInfo(
                Path.Combine(propertiesPath, ProjectFiles.AssemblyInfo),
                new string[]
            {
                "[assembly: ObjCRuntime.LinkWith(" +
                $"\"{this.nativeLibFileName}\", SmartLink = true, ForceLoad = true)]",
            });

            string adaptersPath = Path.Combine(this.PlatformIntermediatePath, "Adapters");

            if (!Directory.Exists(adaptersPath))
            {
                Directory.CreateDirectory(adaptersPath);
            }

            if (includeAdapters)
            {
                string tempPath = Path.Combine(
                    Path.GetDirectoryName(this.BuiltBindingsAssemblyPath), tempAssemblyName + ".dll");
                Assembly      iosApi  = ClrApi.LoadFrom(tempPath, referencePaths);
                IOSApiAdapter adapter = new IOSApiAdapter();
                adapter.PluginInfo          = this.PluginInfo;
                adapter.OutputDirectoryPath = adaptersPath;
                adapter.GenerateAdapterCodeForApi(iosApi);
            }
        }
コード例 #4
0
        void ExportApi()
        {
            string refPath = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework";

            string[] referenceAssemblyPaths = new string[]
            {
                refPath + @"\v4.5\System.dll",
                refPath + @"\v4.5\Facades\System.Runtime.dll",
                refPath + @"\v4.6.1\Facades\System.Diagnostics.Debug.dll",
                refPath + @"\v4.6.1\Facades\System.Runtime.dll",
                refPath + @"\v4.6.1\Facades\System.Threading.Tasks.dll",
                this.pluginMetadataFilePath,
            };
            string[] includeNamespaces = this.PluginInfo.WindowsPlatform.IncludeNamespaces?.Select(m => m.Namespace)
                                         .Concat(new[] { typeof(WindowsApiCompiler).Namespace }).ToArray();

            Assembly apiAssembly = ClrApi.LoadFrom(
                this.BuiltBindingsAssemblyPath, referenceAssemblyPaths, includeNamespaces);

            ClrApi androidApi = new ClrApi
            {
                Platform   = PluginInfo.WindowsPlatformName,
                Assemblies = new List <Assembly>(new[] { apiAssembly }),
                Language   = this.Language,
            };

            string apiXmlPath = Path.GetFullPath(Path.Combine(
                                                     this.PlatformIntermediatePath, this.PlatformName + "-api.xml"));

            using (StreamWriter writer = File.CreateText(apiXmlPath))
            {
                androidApi.ToXml(writer);
            }

            Log.Important($"Exported {this.PlatformName} API metadata to {apiXmlPath}");
        }
コード例 #5
0
        void GenerateAndroidCSharpBindingsProject(bool includeAdapters, ICollection <string> referencePaths = null)
        {
            Log.Important("Generating Android C# bindings project at\n" + this.bindingsProject);

            string project          = Utils.ExtractResourceText(ProjectFiles.Project);
            string assemblyName     = this.PluginInfo.Assembly.Name;
            string tempAssemblyName = "temp";

            project = project.Replace($"$({MsbuildProperties.JavadocPath})", Path.GetFullPath(this.javadocPath));
            project = project.Replace(
                $"$({MsbuildProperties.AssemblyName})", (includeAdapters ? assemblyName : tempAssemblyName));
            project = project.Replace(
                "<ItemGroup Label=\"Jars\">", "<ItemGroup Label=\"Jars\">\n" + this.GetMsbuildJarItems());
            project = project.Replace(
                "<ItemGroup Label=\"Libs\">", "<ItemGroup Label=\"Libs\">\n" + this.GetMsbuildLibItems());

            File.WriteAllText(this.bindingsProject, project);

            string propertiesPath = Path.Combine(this.PlatformIntermediatePath, "Properties");

            if (!Directory.Exists(propertiesPath))
            {
                Directory.CreateDirectory(propertiesPath);
            }

            this.GenerateAssemblyInfo(Path.Combine(propertiesPath, ProjectFiles.AssemblyInfo));

            string adaptersPath = Path.Combine(this.PlatformIntermediatePath, "Adapters");

            if (!Directory.Exists(adaptersPath))
            {
                Directory.CreateDirectory(adaptersPath);
            }

            string transformsPath = Path.Combine(this.PlatformIntermediatePath, "Transforms");

            if (!Directory.Exists(transformsPath))
            {
                Directory.CreateDirectory(transformsPath);
            }

            if (includeAdapters)
            {
                string apiXmlPath = Path.Combine(
                    this.PlatformIntermediatePath, "obj", (this.DebugConfiguration ? "Debug" : "Release"), "api.xml");
                if (!File.Exists(apiXmlPath))
                {
                    throw new FileNotFoundException("Exported Java API XML file not found at " + apiXmlPath);
                }

                JavaApi javaApi;
                using (StreamReader reader = File.OpenText(apiXmlPath))
                {
                    javaApi = JavaApi.FromXml(reader);
                }

                string tempPath = Path.Combine(
                    Path.GetDirectoryName(this.BuiltBindingsAssemblyPath), tempAssemblyName + ".dll");
                Assembly androidApi = ClrApi.LoadFrom(
                    tempPath,
                    referencePaths);
                AndroidApiAdapter adapter = new AndroidApiAdapter();
                adapter.PluginInfo          = this.PluginInfo;
                adapter.JavaApi             = javaApi;
                adapter.OutputDirectoryPath = adaptersPath;
                adapter.GenerateAdapterCodeForApi(androidApi);
            }

            this.GenerateBindingMetadata(transformsPath);

            string enumFields = "<enum-field-mappings></enum-field-mappings>";

            File.WriteAllText(Path.Combine(transformsPath, ProjectFiles.EnumFields), enumFields);

            string enumMethods = "<enum-method-mappings></enum-method-mappings>";

            File.WriteAllText(Path.Combine(transformsPath, ProjectFiles.EnumMethods), enumMethods);
        }