prepare.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // C# implementation of a handful of shell steps
  3. // this is used to automate the buidl in Windows
  4. //
  5. using System;
  6. using System.Text;
  7. using System.IO;
  8. class Prepare {
  9. delegate void filt (StreamReader sr, StreamWriter sw);
  10. static void Filter (string inpath, string outpath, filt filter)
  11. {
  12. using (var ins = new StreamReader (inpath)){
  13. using (var outs = new StreamWriter (outpath)){
  14. filter (ins, outs);
  15. }
  16. }
  17. }
  18. static void SystemDataConnectionReplace (string srcdir, string targetdir, string target, string ns, string factory, string conn)
  19. {
  20. var t = File.ReadAllText (Path.Combine (srcdir, "DbConnectionHelper.cs"));
  21. File.WriteAllText (Path.Combine (targetdir, target), t.Replace ("NAMESPACE", ns).Replace ("CONNECTIONFACTORYOBJECTNAME", factory).Replace ("CONNECTIONOBJECTNAME", conn));
  22. }
  23. static void SystemDataParameterReplace (string srcdir, string targetdir, string target, string resns, string ns, string parname)
  24. {
  25. var t = File.ReadAllText (Path.Combine (srcdir, "DbParameterHelper.cs"));
  26. File.WriteAllText (Path.Combine (targetdir, target), t.Replace ("RESNAMESPACE", resns).Replace ("NAMESPACE", ns).Replace ("PARAMETEROBJECTNAME", parname));
  27. }
  28. static void SystemDataParameterCollReplace (string srcdir, string targetdir, string target, string resns, string ns, string parname)
  29. {
  30. var t = File.ReadAllText (Path.Combine (srcdir, "DbParameterCollectionHelper.cs"));
  31. Console.WriteLine ("Creating " + Path.Combine (targetdir, target));
  32. File.WriteAllText (Path.Combine (targetdir, target), t.Replace ("RESNAMESPACE", resns).Replace ("PARAMETERCOLLECTIONOBJECTNAME", parname + "Collection").Replace ("NAMESPACE", ns).Replace ("PARAMETEROBJECTNAME", parname));
  33. }
  34. static void GenerateSystemData (string bdir)
  35. {
  36. var rs = Path.Combine (bdir, "class", "referencesource", "System.Data", "System", "Data", "ProviderBase");
  37. var sd = Path.Combine (bdir, "class", "System.Data");
  38. SystemDataConnectionReplace (rs, sd, "gen_OdbcConnection.cs", "System.Data.Odbc", "OdbcConnectionFactory.SingletonInstance", "OdbcConnection");
  39. SystemDataConnectionReplace (rs, sd, "gen_OleDbConnection.cs", "System.Data.OleDb", "OleDbConnectionFactory.SingletonInstance", "OleDbConnection");
  40. SystemDataConnectionReplace (rs, sd, "gen_SqlConnection.cs", "System.Data.SqlClient", "SqlConnectionFactory.SingletonInstance", "SqlConnection");
  41. SystemDataParameterReplace (rs, sd, "gen_OdbcParameter.cs", "System.Data", "System.Data.Odbc", "OdbcParameter");
  42. SystemDataParameterReplace (rs, sd, "gen_OleDbParameter.cs", "System.Data", "System.Data.OleDb", "OleDbParameter");
  43. SystemDataParameterReplace (rs, sd, "gen_SqlParameter.cs", "System.Data", "System.Data.SqlClient", "SqlParameter");
  44. SystemDataParameterCollReplace (rs, sd, "gen_OdbcParameterCollection.cs", "System.Data", "System.Data.Odbc", "OdbcParameter");
  45. SystemDataParameterCollReplace (rs, sd, "gen_OleDbParameterCollection.cs", "System.Data", "System.Data.OleDb", "OleDbParameter");
  46. SystemDataParameterCollReplace (rs, sd, "gen_SqlParameterCollection.cs", "System.Data", "System.Data.SqlClient", "SqlParameter");
  47. }
  48. static void Main (string [] args)
  49. {
  50. string bdir = args.Length == 0 ? "../../../mcs" : args [0];
  51. if (!Directory.Exists (Path.Combine(bdir, "class"))){
  52. Console.Error.WriteLine ("The directory {0} does not contain class at {1}", Path.GetFullPath (bdir), Environment.CurrentDirectory);
  53. Environment.Exit (1);
  54. }
  55. switch (args [1]){
  56. case "core":
  57. Filter (bdir + "/build/common/Consts.cs.in",
  58. bdir + "/build/common/Consts.cs",
  59. (i, o) => o.Write (i.ReadToEnd ().Replace ("@MONO_VERSION@", "2.5.0")));
  60. GenerateSystemData (bdir);
  61. break;
  62. default:
  63. Console.Error.WriteLine ("Unknonw option to prepare.exe {0}", args [1]);
  64. Environment.Exit (1);
  65. break;
  66. }
  67. }
  68. }