Mono.Cairo: Re-order a few native methods and update API index URL
[mono.git] / mcs / class / build-rx-dll-sources.sh
1
2 // useful grep
3 // grep -h "#if" /svn/mono/external/rx/Rx/NET/Source/System.Reactive.*/*.cs /svn/mono/external/rx/Rx/NET/Source/System.Reactive.*/*/*.cs /svn/mono/external/rx/Rx/NET/Source/System.Reactive.*/*/*/*.cs | sort | uniq
4
5 using System.Diagnostics;
6 using System.IO;
7 using System.Xml.Linq;
8 using System.Xml.XPath;
9
10 var template_android = File.ReadAllText ("project_template_android.txt");
11 var template_ios = File.ReadAllText ("project_template_ios.txt");
12
13 var guids_android = new string [] { "4fa878dc-6e88-43c4-b37b-8c1151cec56f", "fef62c23-10cd-4def-a5ae-54a8b309e970", "d263c126-9d3c-4299-a0c1-f25c703d07c9", "ec704077-ea31-4852-ad24-6732244174c0", "9360e845-d79d-4288-9100-63a80fad2bf0", "00dc3654-e373-4e3f-80fe-109f795adf1f", "e662282b-4341-4f86-aaaa-a942335b47fb", "a153a379-670c-42c2-9018-fc0d933a4f7f", "b29d45a6-0b8c-49c5-82a2-457e4d3cbc33", "3a3b5e76-029f-46b0-9ccf-fefe06eb61e7", "cb2ab716-bfcb-43bc-a03b-a3bda427746c", "73c5260f-8972-4e7c-822b-1a3a0358fa0b" };
14 var guids_ios = new string [] { "6f2675f5-fcc7-4a28-9dc3-657b4613dcc5", "a67f34b5-75c1-4319-a93e-93df87e728a4", "79a43ceb-1a18-49ea-aac4-b72b9c90bf5a", "0a977063-0796-4cd4-84b8-aedb2d648b26", "b41cb61a-dca0-4539-8f99-7b3499e18e6d", "24f995bd-7075-489c-b7a5-7fde08c304b6", "894021ec-14fb-430a-8572-bea9569ae435", "92857c8e-0e83-4d02-a831-8af3fed43336", "912e14a2-7bdf-4600-8d55-e8c4f33a2063", "0f6c2933-8d0c-41e6-9f77-e8714ab8c4ab", "47d85a91-e8e2-4088-bf5a-68a161754d48", "45377009-1425-47fc-985e-05f98022f9e3" };
15
16 var asses = new string [] {
17         "System.Reactive.Interfaces",
18         "System.Reactive.Core",
19         "System.Reactive.PlatformServices",
20         "System.Reactive.Linq",
21         "System.Reactive.Debugger", // maybe needed for testing assembly.
22         "System.Reactive.Experimental", // needed for testing assembly.
23         "System.Reactive.Providers",
24         "System.Reactive.Runtime.Remoting",
25         "System.Reactive.Windows.Forms",
26         "System.Reactive.Windows.Threading",
27         "Microsoft.Reactive.Testing",
28         "Tests.System.Reactive",
29         };
30
31 var excluded_android_asses = new string [] {
32         "System.Reactive.Windows.Forms",
33         "System.Reactive.Windows.Threading",
34         };
35 var excluded_ios_asses = new string [] {
36         "System.Reactive.Providers",
37         "System.Reactive.Windows.Forms",
38         "System.Reactive.Windows.Threading",
39         }
40
41 var blacklist = new string [] {
42         // WPF Dispatcher.Invoke() is not implemented.
43         "DispatcherSchedulerTest.cs",
44         // This is not limited to Dispatcher, but many of them are relevant to it, or Winforms (we filter it out by not defining HAS_WINFORMS)
45         "ObservableConcurrencyTest.cs",
46         };
47
48 var dstAndroid = "../../external/rx/Rx/NET/Source/Rx_Xamarin/android";
49 var dstIOS = "../../external/rx/Rx/NET/Source/Rx_Xamarin/iOS";
50
51 int guid_idx = 0;
52 foreach (var ass in asses) {
53
54         var monoass = ass == "Microsoft.Reactive.Testing" ?
55                 "Mono.Reactive.Testing" : ass;
56         var basePath = "../../external/rx/Rx/NET/Source";
57         var csproj = Path.Combine (basePath, ass, ass + ".csproj");
58         var pathPrefix = ass == "Tests.System.Reactive" ? "../" : "";
59
60         var android_dir = Path.GetFullPath (Path.Combine (csproj, "..", "..", "Rx_Xamarin", "android", "rx", monoass));
61         var ios_dir = Path.GetFullPath (Path.Combine (csproj, "..", "..", "Rx_Xamarin", "iOS", "rx", monoass));
62         var android_proj = Path.Combine (android_dir, "android_" + monoass + ".csproj");
63         var ios_proj = Path.Combine (ios_dir, "ios_" + monoass + ".csproj");
64         if (!Directory.Exists (android_dir))
65                 Directory.CreateDirectory (android_dir);
66         if (!Directory.Exists (ios_dir))
67                 Directory.CreateDirectory (ios_dir);
68
69         // tests are built under Mono.Reactive.Testing directory.
70         
71         var sources =
72                 monoass == "Tests.System.Reactive" ?
73                 Path.Combine ("Mono.Reactive.Testing", "Mono.Reactive.Testing_test.dll.sources") :
74                 Path.Combine (monoass, monoass + ".dll.sources");
75
76         var assdir = Path.Combine (monoass, "Assembly");
77         var assinfo = Path.Combine (monoass, "Assembly", "AssemblyInfo.cs");
78
79         var projectRefs = "";
80
81         if (monoass != "Tests.System.Reactive") {
82                 if (!Directory.Exists (assdir))
83                         Directory.CreateDirectory (assdir);
84                 using (var tw = File.CreateText (assinfo)) {
85                         tw.WriteLine ("[assembly:System.Reflection.AssemblyVersion (\"2.1.30214.0\")]");
86                         tw.WriteLine ("[assembly:System.Reflection.AssemblyFileVersion (\"2.1.30214.0\")]");
87                 }
88         }
89
90         var sourcesXml = "";
91         var projectRefsXml = "";
92         var resourcesXml = "";
93
94         var doc = XDocument.Load (csproj);
95         var rootNS = doc.XPathSelectElement ("//*[local-name()='RootNamespace']").Value;
96         var guid = doc.XPathSelectElement ("//*[local-name()='ProjectGuid']").Value;
97
98         foreach (var e in doc.XPathSelectElements ("//*[local-name()='ProjectReference']"))
99                 projectRefsXml += e;
100
101         Console.WriteLine ("Writing " + sources + " ...");
102         using (var tw = File.CreateText (sources)) {
103                 if (monoass != "Tests.System.Reactive")
104                         tw.WriteLine ("Assembly/AssemblyInfo.cs");
105                 foreach (var path in doc.XPathSelectElements ("//*[local-name()='Compile']")
106                         .Select (el => el.Attribute ("Include").Value)
107                         .Select (s => s.Replace ("\\", "/"))) {
108                         if (!blacklist.Any (b => path.Contains (b))) {
109                                 var p = Path.Combine (ass, path);
110                                 var p2 = Path.Combine ("..", basePath, ass, path);
111                                 tw.WriteLine (Path.Combine (pathPrefix, p2));
112                                 sourcesXml += "    <Compile Include=\"..\\..\\..\\..\\" + p.Replace ('/', '\\') + "\">\n      <Link>" + path.Replace ('/', '\\') + "</Link>\n    </Compile>\n";
113                         }
114                 }
115         }
116
117         Console.WriteLine ("Writing more_build_args...");
118         var argsPath = Path.Combine (Path.GetDirectoryName (sources), "more_build_args");
119         using (var tw = File.CreateText (argsPath)) {
120                 if (ass.StartsWith ("System")) {
121                         tw.WriteLine ("-d:SIGNED");
122                         tw.WriteLine ("-delaysign");
123                         tw.WriteLine ("-keyfile:../reactive.pub");
124                 }
125
126                 foreach (var path in doc.XPathSelectElements ("//*[local-name()='EmbeddedResource']")) {
127                         var res = path.Attribute ("Include").Value;
128                         var resx = Path.Combine (basePath, ass, res);
129                         var resFileName = res.Replace ("resx", "resources");
130                         var resxDest = Path.Combine (monoass, res);
131                         var resPath = Path.Combine (monoass, resFileName);
132                         if (File.Exists (resxDest))
133                                 File.Delete (resxDest);
134                         File.Copy (resx, resxDest);
135                         //Process.Start ("resgen", String.Format ("{0} {1}", resx, resPath));
136                         tw.WriteLine ("-resource:{0},{1}.{2}", resFileName, rootNS, resFileName);
137                         var p = Path.Combine ("..", basePath, ass, res);
138                         resourcesXml += "    <EmbeddedResource Include='..\\..\\..\\..\\..\\..\\" + p + "'>\n      <Link>" + res + "</Link>\n    </EmbeddedResource>\n";
139                 }
140         }
141         foreach (var f in new string [] { android_proj, ios_proj}) {
142                 string prj_guid;
143                 string template, prj_prefix, nunitProjRef, nunitRef;
144                 var androidNUnit = "<ProjectReference Include=\"..\\..\\Andr.Unit\\Android.NUnitLite\\Android.NUnitLite.csproj\"><Project>{6A005891-A3D6-4398-A729-F645397D573A}</Project><Name>Android.NUnitLite</Name></ProjectReference>";
145                 if (f == android_proj) {
146                         prj_guid = guids_android [guid_idx].ToUpper ();
147                         template = template_android;
148                         prj_prefix ="android_";
149                         nunitProjRef = ass.Contains ("Test") ? androidNUnit : "";
150                         nunitRef = "";
151                 } else {
152                         prj_guid = guids_ios [guid_idx].ToUpper ();
153                         template = template_ios;
154                         prj_prefix ="ios_";
155                         nunitProjRef = "";
156                         nunitRef = ass.Contains ("Test") ? "<Reference Include='MonoTouch.NUnitLite' />" : "";
157                 }
158                 using (var tw = File.CreateText (f)) {
159                         tw.Write (template
160                                 .Replace ("PROJECT_GUID_GOES_HERE", '{' + prj_guid + '}')
161                                 .Replace ("ASSEMBLY_NAME_GOES_HERE", monoass)
162                                 .Replace ("OPTIONAL_ANDROID_NUNITLITE", nunitProjRef)
163                                 .Replace ("OPTIONAL_MONOTOUCH_NUNITLITE", nunitRef)
164                                 .Replace ("PROJECT_REFERENCES_GO_HERE",
165                                         projectRefsXml
166                                                 .Replace (" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"", "")
167                                                 .Replace ("Microsoft.Reactive.Testing", "Mono.Reactive.Testing")
168                                                 .Replace ("System", prj_prefix + "System")
169                                                 .Replace ("Mono", prj_prefix + "Mono")
170                                                 .Replace ("Include=\"..\\" + prj_prefix, "Include=\"..\\"))
171                                 .Replace ("RESOURCES_GO_HERE", resourcesXml.Replace ('\\', f == ios_proj ? '/' : '\\')) // whoa, BACKSLASH doesn't work only on android on MD/mac...!
172                                 .Replace ("SOURCES_GO_HERE", sourcesXml.Replace ('\\', f == ios_proj ? '/' : '\\'))); // whoa, BACKSLASH doesn't work only on android on MD/mac...!
173                 }
174         }
175         guid_idx++;
176 }
177