Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez Gual <lluis@xamarin.com>2014-02-07 18:01:46 +0400
committerLluis Sanchez Gual <lluis@xamarin.com>2014-02-07 19:35:36 +0400
commitca5ab235140fd5a27f3cdf90df1e3e4085ad57f7 (patch)
treee9527c6bdf796869319c18b6176f3cc1a5195354 /scripts
parentcbff71d4c13611a48d4c4001603464db29fe5bc9 (diff)
Make configuration script reusable
Diffstat (limited to 'scripts')
-rw-r--r--scripts/configure.bat6
-rw-r--r--scripts/configure.cs364
2 files changed, 196 insertions, 174 deletions
diff --git a/scripts/configure.bat b/scripts/configure.bat
new file mode 100644
index 0000000000..e1fc3ff8d6
--- /dev/null
+++ b/scripts/configure.bat
@@ -0,0 +1,6 @@
+@echo off
+set DIR=%~dp0\
+if not exist %DIR%\configure.exe (
+ csc /nologo /out:%DIR%\configure.exe %DIR%\configure.cs
+)
+%DIR%\configure.exe %* \ No newline at end of file
diff --git a/scripts/configure.cs b/scripts/configure.cs
index 4688826cd8..4c407efc44 100644
--- a/scripts/configure.cs
+++ b/scripts/configure.cs
@@ -10,23 +10,8 @@ using System.Xml;
using System.Net;
using System.Reflection;
-namespace SetupConfig
+namespace MonoDevelop.Configuration
{
- public class Config
- {
- public string MonoDevelopPath;
- public int InstallerVersion;
- public string Version;
- public string ProductVersion;
- public string ProductVersionText;
- public string CompatVersion;
- public string AssemblyVersion = "4.0.0.0";
- public string ReleaseId;
- public string PlatformGuid;
- public string PlatformUpdaterGuid;
- public PlatformInfo PlatformInfo;
- }
-
public class PlatformInfo
{
public string AppId;
@@ -43,65 +28,50 @@ namespace SetupConfig
class Program
{
- const string MacId = "a3140c14-ef90-4019-ae6c-9d93804d6611";
- const string MacUpdaterId = "42baf30f-edc9-4feb-b99d-d6d311271c65";
- const string WindowsId = "E55A5A70-C6F6-4845-8A01-89DAA5B6DA43";
- const string WindowsUpdaterId = "PlEhBk81kBfey9Va";
-
- static StreamWriter logFile;
-
- static Config config;
+ static IdeConfigurationTool config;
static int Main (string[] args)
{
- logFile = new StreamWriter ("config.log");
try {
- ReadConfig ();
- return Run (args);
- }
+ config = new IdeConfigurationTool (new FileInfo(Assembly.GetEntryAssembly().Location).Directory.Parent.FullName);
+
+ if (args.Length == 0)
+ {
+ PrintHelp();
+ return 0;
+ }
+
+ var cmd = args[0];
+ args = args.Skip(1).ToArray();
+
+ switch (cmd)
+ {
+ case "get-version":
+ GetVersion(args);
+ break;
+ case "get-releaseid":
+ GetReleaseId(args);
+ break;
+ case "gen-updateinfo":
+ GenerateUpdateInfo(args);
+ break;
+ case "gen-buildinfo":
+ GenerateBuildInfo(args);
+ break;
+ default:
+ Console.WriteLine("Unknown command: " + cmd);
+ return 1;
+ }
+ return 0;
+ }
catch (UserException ex) {
- ReportError (ex.Message);
- ReportInfo ("See config.log for details.");
+ Console.WriteLine (ex.Message);
return 1;
}
catch (Exception ex) {
- ReportError (ex.ToString ());
- ReportInfo ("See config.log for details.");
+ Console.WriteLine (ex.ToString());
return 1;
}
- finally {
- logFile.Close ();
- }
- }
-
- static int Run (string[] args)
- {
- if (args.Length == 0) {
- PrintHelp ();
- return 0;
- }
-
- var cmd = args [0];
- args = args.Skip (1).ToArray ();
-
- switch (cmd) {
- case "get-version":
- GetVersion (args);
- break;
- case "get-releaseid":
- GetReleaseId (args);
- break;
- case "gen-updateinfo":
- GenerateUpdateInfo (args);
- break;
- case "gen-buildinfo":
- GenerateBuildInfo (args);
- break;
- default:
- Console.WriteLine ("Unknown command: " + cmd);
- return 1;
- }
- return 0;
}
static void GetVersion (string[] args)
@@ -114,141 +84,106 @@ namespace SetupConfig
Console.WriteLine (config.ReleaseId);
}
- static void GenerateUpdateInfo (string[] args)
+ static void GenerateUpdateInfo(string[] args)
+ {
+ if (args.Length == 0)
+ throw new UserException("Platform config file not provided");
+ if (args.Length == 1)
+ throw new UserException("Target directory not provided");
+
+ config.GenerateUpdateInfo(args[0], args[1]);
+ }
+
+ static void GenerateBuildInfo(string[] args)
+ {
+ if (args.Length == 0)
+ throw new UserException("Target directory not provided");
+
+ config.GenerateBuildInfo(args[0]);
+ }
+
+ static void PrintHelp()
+ {
+ Console.WriteLine("MonoDevelop Configuration Script");
+ Console.WriteLine();
+ Console.WriteLine("Commands:");
+ Console.WriteLine("\tget-version: Prints the version of this release");
+ Console.WriteLine("\tget-releaseid: Prints the release id");
+ Console.WriteLine("\tgen-updateinfo <config-file> <path>: Generates the updateinfo file");
+ Console.WriteLine("\t\tin the provided path");
+ Console.WriteLine("\tgen-buildinfo <path>: Generates the buildinfo file in the provided path");
+ Console.WriteLine();
+ }
+ }
+
+ public class IdeConfigurationTool
+ {
+ public readonly string MonoDevelopPath;
+ public readonly string Version;
+ public readonly string ProductVersion;
+ public readonly string ProductVersionText;
+ public readonly string CompatVersion;
+ public readonly string AssemblyVersion = "4.0.0.0";
+ public readonly string ReleaseId;
+ public readonly PlatformInfo PlatformInfo;
+
+ public IdeConfigurationTool(string monoDevelopPath)
+ {
+ MonoDevelopPath = monoDevelopPath;
+
+ string versionTxt = Path.Combine(MonoDevelopPath, "version.config");
+ Version = SystemUtil.Grep(versionTxt, @"Version=(.*)");
+ ProductVersionText = SystemUtil.Grep(versionTxt, "Label=(.*)");
+ CompatVersion = SystemUtil.Grep(versionTxt, "CompatVersion=(.*)");
+
+ Version ver = new Version(Version);
+ int vbuild = ver.Build != -1 ? ver.Build : 0;
+ var cd = GetVersionCommitDistance(MonoDevelopPath);
+ int vbrev = ver.Revision != -1 ? ver.Revision : cd;
+ ReleaseId = "" + ver.Major + ver.Minor.ToString("00") + vbuild.ToString("00") + vbrev.ToString("0000");
+ ProductVersion = ver.Major + "." + ver.Minor + "." + vbuild + "." + vbrev;
+ }
+
+ public void GenerateUpdateInfo (string platformConfigFile, string targetDir)
{
- if (args.Length == 0)
- throw new UserException ("Platform config file not provided");
- if (args.Length == 1)
- throw new UserException ("Target directory not provided");
-
PlatformInfo pinfo;
- using (var sr = new StreamReader (args [0])) {
+ using (var sr = new StreamReader(platformConfigFile))
+ {
XmlSerializer ser = new XmlSerializer (typeof(PlatformInfo));
pinfo = (PlatformInfo)ser.Deserialize (sr);
}
if (pinfo.AppId != null)
- File.WriteAllText (Path.Combine (args [1], "updateinfo"), pinfo.AppId + " " + config.ReleaseId);
+ File.WriteAllText (Path.Combine (targetDir, "updateinfo"), pinfo.AppId + " " + ReleaseId);
if (pinfo.UpdaterId != null)
- File.WriteAllText (Path.Combine (args [1], "updateinfo.updater"), pinfo.UpdaterId + " " + pinfo.UpdaterVersion);
+ File.WriteAllText (Path.Combine (targetDir, "updateinfo.updater"), pinfo.UpdaterId + " " + pinfo.UpdaterVersion);
}
- static void GenerateBuildInfo (string[] args)
+ public void GenerateBuildInfo(string targetDir)
{
- if (args.Length == 0)
- throw new UserException ("Target directory not provided");
-
- string head = RunProcess (SystemInfo.GitExe, "rev-parse HEAD", config.MonoDevelopPath).Trim ();
+ string head = SystemUtil.RunProcess(SystemUtil.GitExe, "rev-parse HEAD", MonoDevelopPath).Trim();
- var txt = "Release ID: " + config.ReleaseId + "\n";
+ var txt = "Release ID: " + ReleaseId + "\n";
txt += "Git revision: " + head + "\n";
txt += "Build date: " + DateTime.Now.ToString ("yyyy-MM-dd HH:mm:sszz") + "\n";
- File.WriteAllText (Path.Combine (args [0], "buildinfo"), txt);
- }
-
- static void PrintHelp ()
- {
- Console.WriteLine ("MonoDevelop Configuration Script");
- Console.WriteLine ();
- Console.WriteLine ("Commands:");
- Console.WriteLine ("\tget-version: Prints the version of this release");
- Console.WriteLine ("\tget-releaseid: Prints the release id");
- Console.WriteLine ("\tgen-updateinfo <config-file> <path>: Generates the updateinfo file in the provided path");
- Console.WriteLine ("\tgen-buildinfo <path>: Generates the buildinfo file in the provided path");
- Console.WriteLine ();
- }
-
- static void ReadConfig ()
- {
- config = new Config () {
- InstallerVersion = 2
- };
-
- config.MonoDevelopPath = new FileInfo (Assembly.GetEntryAssembly ().Location).Directory.Parent.ToString ();
-
- string versionTxt = Path.Combine (config.MonoDevelopPath, "version.config");
- config.Version = Grep (versionTxt, @"Version=(.*)");
- config.ProductVersionText = Grep (versionTxt, "Label=(.*)");
- config.CompatVersion = Grep (versionTxt, "CompatVersion=(.*)");
-
- Version ver = new Version(config.Version);
- int vbuild = ver.Build != -1 ? ver.Build : 0;
- var cd = GetVersionCommitDistance (config.MonoDevelopPath);
- int vbrev = ver.Revision != -1 ? ver.Revision : cd;
- config.ReleaseId = "" + ver.Major + ver.Minor.ToString ("00") + vbuild.ToString ("00") + vbrev.ToString ("0000");
- config.ProductVersion = ver.Major + "." + ver.Minor + "." + vbuild + "." + vbrev;
- }
-
- static void ReportError (string msg)
- {
- logFile.WriteLine ("[ERROR] " + msg);
- Console.WriteLine ("[ERROR] " + msg);
- }
-
- static void ReportInfo (string msg)
- {
- logFile.WriteLine ("[INFO] " + msg);
- Console.WriteLine (msg);
+ File.WriteAllText(Path.Combine(targetDir, "buildinfo"), txt);
}
static int GetVersionCommitDistance (string path)
{
- var blame = new StringReader (RunProcess (SystemInfo.GitExe, "blame version.config", path));
+ var blame = new StringReader(SystemUtil.RunProcess(SystemUtil.GitExe, "blame version.config", path));
string line;
while ((line = blame.ReadLine ()) != null && line.IndexOf ("Version=") == -1)
;
if (line != null) {
string hash = line.Substring (0, line.IndexOf (' '));
- string dist = RunProcess (SystemInfo.GitExe, "rev-list --count " + hash + "..HEAD", path);
+ string dist = SystemUtil.RunProcess(SystemUtil.GitExe, "rev-list --count " + hash + "..HEAD", path);
return int.Parse (dist.Trim ());
}
return 0;
}
-
- static string Grep (string file, string regex)
- {
- string txt = File.ReadAllText (file);
- var m = Regex.Match (txt, regex);
- if (m == null)
- throw new UserException ("Match not found for regex: " + regex);
- if (m.Groups.Count != 2)
- throw new UserException ("Invalid regex: expression must have a single capture group: " + regex);
- Group cap = m.Groups[1];
- return cap.Value;
- }
-
- static string RunProcess (string file, string args, string workingDir)
- {
- logFile.WriteLine (file + " " + args);
-
- Process p = new Process ();
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.WorkingDirectory = workingDir;
- p.StartInfo.FileName = file;
- p.StartInfo.Arguments = args;
- StringBuilder sb = new StringBuilder ();
- p.OutputDataReceived += delegate (object s, DataReceivedEventArgs e)
- {
- logFile.WriteLine (e.Data);
- sb.AppendLine (e.Data);
- };
- p.ErrorDataReceived += delegate (object s, DataReceivedEventArgs e)
- {
- logFile.WriteLine (e.Data);
- };
- p.Start ();
- p.BeginOutputReadLine ();
- p.BeginErrorReadLine ();
- p.WaitForExit ();
- if (p.ExitCode != 0)
- throw new UserException (file + " failed");
- return sb.ToString ();
- }
}
class UserException: Exception
@@ -259,9 +194,47 @@ namespace SetupConfig
}
}
- static class SystemInfo
+ public static class Logging
+ {
+ static string logFile;
+ static object localLock = new object ();
+
+ public static void Initialize(string logFileName)
+ {
+ logFile = logFileName;
+ }
+
+ public static void ReportError(string msg)
+ {
+ if (logFile != null) {
+ lock (localLock)
+ File.AppendAllText(logFile, "[ERROR] " + msg + Environment.NewLine);
+ }
+ Console.WriteLine("[ERROR] " + msg);
+ }
+
+ public static void ReportInfo(string msg)
+ {
+ if (logFile != null) {
+ lock (localLock)
+ File.AppendAllText(logFile, "[INFO] " + msg + Environment.NewLine);
+ }
+ Console.WriteLine(msg);
+ }
+
+ public static void ReportDebug(string msg)
+ {
+ if (logFile != null)
+ {
+ lock (localLock)
+ File.AppendAllText(logFile, "[INFO] " + msg + Environment.NewLine);
+ }
+ }
+ }
+
+ public static class SystemUtil
{
- static SystemInfo ()
+ static SystemUtil ()
{
if (Path.DirectorySeparatorChar == '\\')
Platform = Platform.Windows;
@@ -287,5 +260,48 @@ namespace SetupConfig
public static string GitExe { get; private set; }
public static Platform Platform { get; private set; }
- }
+
+ public static string Grep(string file, string regex)
+ {
+ string txt = File.ReadAllText(file);
+ var m = Regex.Match(txt, regex);
+ if (m == null)
+ throw new UserException("Match not found for regex: " + regex);
+ if (m.Groups.Count != 2)
+ throw new UserException("Invalid regex: expression must have a single capture group: " + regex);
+ Group cap = m.Groups[1];
+ return cap.Value;
+ }
+
+ public static string RunProcess(string file, string args, string workingDir)
+ {
+ Logging.ReportDebug(file + " " + args);
+
+ Process p = new Process();
+ p.StartInfo.CreateNoWindow = true;
+ p.StartInfo.UseShellExecute = false;
+ p.StartInfo.RedirectStandardOutput = true;
+ p.StartInfo.RedirectStandardError = true;
+ p.StartInfo.WorkingDirectory = workingDir;
+ p.StartInfo.FileName = file;
+ p.StartInfo.Arguments = args;
+ StringBuilder sb = new StringBuilder();
+ p.OutputDataReceived += delegate(object s, DataReceivedEventArgs e)
+ {
+ Logging.ReportDebug(e.Data);
+ sb.AppendLine(e.Data);
+ };
+ p.ErrorDataReceived += delegate(object s, DataReceivedEventArgs e)
+ {
+ Logging.ReportDebug(e.Data);
+ };
+ p.Start();
+ p.BeginOutputReadLine();
+ p.BeginErrorReadLine();
+ p.WaitForExit();
+ if (p.ExitCode != 0)
+ throw new UserException(file + " failed");
+ return sb.ToString();
+ }
+ }
}