From 6d153cd5813ca03b9ba2ea96c68b444355a46dc2 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Fri, 31 May 2013 18:08:20 +0900 Subject: [PATCH] [mkbundle] do not require dos2unix (and sh) on Windows. Skip it if it does not exist. --- mcs/tools/mkbundle/mkbundle.cs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/mcs/tools/mkbundle/mkbundle.cs b/mcs/tools/mkbundle/mkbundle.cs index b2e5752b2de0..fa8e7166019a 100644 --- a/mcs/tools/mkbundle/mkbundle.cs +++ b/mcs/tools/mkbundle/mkbundle.cs @@ -37,6 +37,7 @@ class MakeBundle { static string style = "linux"; static bool compress; static bool nomain; + static bool? use_dos2unix = null; static int Main (string [] args) { @@ -667,11 +668,42 @@ static int Execute (string cmdLine) Console.WriteLine (cmdLine); return system (cmdLine); } - + // on Windows, we have to pipe the output of a // `cmd` interpolation to dos2unix, because the shell does not // strip the CRLFs generated by the native pkg-config distributed // with Mono. + // + // But if it's *not* on cygwin, just skip it. + + // check if dos2unix is applicable. + if (use_dos2unix == null) { + use_dos2unix = false; + try { + var dos2unix = Process.Start ("dos2unix"); + dos2unix.StandardInput.WriteLine ("aaa"); + dos2unix.StandardInput.WriteLine ("\u0004"); + dos2unix.WaitForExit (); + if (dos2unix.ExitCode == 0) + use_dos2unix = true; + } catch { + // ignore + } + } + // and if there is no dos2unix, just run cmd /c. + if (use_dos2unix == false) { + Console.WriteLine (cmdLine); + ProcessStartInfo dos2unix = new ProcessStartInfo (); + dos2unix.UseShellExecute = false; + dos2unix.FileName = "cmd"; + dos2unix.Arguments = String.Format ("/c \"{0}\"", cmdLine); + + using (Process p = Process.Start (dos2unix)) { + p.WaitForExit (); + return p.ExitCode; + } + } + StringBuilder b = new StringBuilder (); int count = 0; for (int i = 0; i < cmdLine.Length; i++) {